Beispiel #1
0
def createPatient():
    '''
        Create a new patient through a POST method. Takes a JSON object


        Returns:
            The newly created patient.
    '''
    json = request.json
    if not json or not 'firstName' in json:
        abort(400)
    lastName = '' if not json.get('lastName') else json.get('lastName')
    mobile = '' if not json.get('mobile') else json.get('mobile')
    gender = '' if not json.get('gender') else json.get('gender')
    email = '' if not json.get('email') else json.get('email')
    note = '' if not json.get('note') else json.get('note')
    storageID = '' if not json.get('storageID') else json.get('storageID')
    date = '' if not json.get('date') else json.get('date')
    age = 0 if not json.get('age') else json.get('age')

    patient = {
        'firstName': request.json['firstName'],
        'lastName': lastName,
        'mobile': mobile,
        'gender': gender,
        'email': email,
        'note': note,
        'storageID': storageID,
        'date': date,
        'age': age
    }
    db = DBConnector()
    result = db.createPatient(patient)
    db.close()
    return jsonify({'patient': result}), 201