Exemple #1
0
def add_care_receiver(version=app.config['ACTUAL_API']):
    """
    This method allow to the Pilots (roletype: developers) to add new users in the system with the role
    care_receivers
    
    An example in JSON could be:

    {
        "pilot_user_source_id": "xxXXX?????",
        "valid_from": "2014-05-20T07:08:41.013+03:00", ** OPTIONAL
        "valid_to": "2018-05-20T07:08:41.013+03:00", ** OPTIONAL
        "username": "******",
        "password": "******"
    }
    
    :param base version: Api version

    :return: Response of the request
    """
    if Utilities.check_connection(app, version):
        data = _convert_to_dict(request.json)
        # Checking if INPUT json is OK
        msg = Utilities.check_add_care_receiver_data(AR_DATABASE, data)
        if data and not msg and USER:
            # User and entered data are OK. save new user into DB
            res_ar = AR_DATABASE.add_new_care_receiver(data, USER.id)
            res_sr = SR_DATABASE.add_new_care_receiver(data, USER.id)
            if res_ar and res_sr:
                # We only return one value, because both database has the same IDS
                logging.info(
                    "add_care_receiver: the username: %s adds new user care receiver into database"
                    % USER.username)
                return jsonify(res_ar)
            else:
                logging.error(
                    "add_care_receiver: %s failed to store data into database. 500"
                    % USER.username)
                return Response("There is an error in DB"), 500
        else:
            logging.error(
                "add_care_receiver: there is a problem with entered data")
            # Data is not valid, check the problem
            if msg and "duplicated" in msg:
                # Data sent is duplicated.
                return Response(msg), 409
            else:
                # Standard Error
                return Response(msg), 400
Exemple #2
0
def add_care_receiver(version=app.config['ACTUAL_API']):
    """
    This method allow to the Pilots (roletype: developers) to add new users in the system with the role
    care_receivers
    
    An example in JSON could be:

    {
        "pilot_user_source_id": "xxXXX?????",
        "valid_from": "2014-05-20T07:08:41.013+03:00", ** OPTIONAL
        "valid_to": "2018-05-20T07:08:41.013+03:00", ** OPTIONAL
        "username": "******",
        "password": "******"
    }
    
    :param version: 
    :return: A urn with --> eu:c4a:user:{city4AgeId}
    """

    if Utilities.check_connection(app, version):
        data = _convert_to_dict(request.json)
        # Checking if INPUT json is OK
        res, msg = Utilities.check_add_care_receiver_data(AR_DATABASE, data)
        if data and res and USER and not msg:
            # User and entered data are OK. save new user into DB
            res_ar = AR_DATABASE.add_new_care_receiver(data, USER.id)
            res_sr = SR_DATABASE.add_new_care_receiver(data, USER.id)
            if res_ar and res_sr:
                Utilities.write_log_info(app, (
                    "add_care_receiver: the username: %s adds new care receiver "
                    "into database" % USER.username))
                # We only return one value, because both database has the same IDS
                return jsonify(res_ar)
            else:
                Utilities.write_log_error(
                    app,
                    ("add_care_receiver: the username: %s failed to store "
                     "data into database. 500" % USER.username))
                return Response("There is an error in DB"), 500
        else:
            # Data is not valid, check the problem

            # TODO maybe detect here the source of message???

            return Response(msg), 400