def post(self):
        import api.util as util
        import data.crud as crud
        import service.assoc as assoc
        from models import Patient

        try:
            request_body = _get_request_body()
        except:
            return {"HTTP 400": decoding_error}, 400
        if not request_body["patientId"]:
            return {"HTTP 400": "Patient Id is empty."}, 400

        # Emulate old API functionality with new systems, use of /api/associations is
        # preferred over this method now
        patient = crud.read(Patient, patientId=request_body["patientId"])
        if patient:
            user = util.current_user()
            facility = user.healthFacility
            if not assoc.has_association(patient, facility, user):
                assoc.associate(patient, facility, user)
            else:
                abort(409, message="Duplicate entry")
            return {
                "message": "patient has been added to facility successfully"
            }, 201
        else:
            abort(404, message="This patient does not exist.")
Ejemplo n.º 2
0
    def post(self):
        logging.debug('Received request: POST api/patient/reading')
        try:
            patient_reading_data = _get_request_body()
        except:
            return {'HTTP 400': decoding_error}, 400
        patient_reading_data = _get_request_body()
        # Ensure all data is valid
        abort_if_body_empty(patient_reading_data)
        is_invalid_patient = PatientValidation.check_patient_fields(
            patient_reading_data['patient'])
        is_invalid_reading = PatientValidation.check_reading_fields(
            patient_reading_data['reading'])

        if is_invalid_patient is not None:
            return is_invalid_patient

        # validate with new reading validator
        if is_invalid_reading is not None:
            return is_invalid_reading

        patient_data = patient_reading_data['patient']
        if 'dob' in patient_data and patient_data[
                'dob'] and patient_data['patientAge'] is None:
            patient_reading_data['patient']['dob'] = int(
                patient_reading_data['patient']['dob'])
            patient_reading_data['patient'] = calculate_age_from_dob(
                patient_data)

        # create new reading (and patient if it does not already exist)
        reading_and_patient = readingManager.create_reading_and_patient(
            patient_reading_data['patient']['patientId'], patient_reading_data)

        # add patient to the facility of the user that took their reading
        user = userManager.read("id",
                                patient_reading_data['reading']['userId'])
        userFacility = user['healthFacilityName']
        patientFacilityManager.add_patient_facility_relationship(
            patient_reading_data['patient']['patientId'], userFacility)

        # associate new reading with patient
        reading_and_patient[
            'message'] = 'Patient reading created successfully!'

        return reading_and_patient, 201
    def post(self):
        req_data = _get_request_body()

        current_user = get_jwt_identity()
        user_id = current_user["userId"]
        return (
            referralManager.create_referral_with_patient_and_reading(req_data, user_id),
            201,
        )
Ejemplo n.º 4
0
    def put(name=None):
        # validate inputs
        if not name:
            abort(400, message="name is required")
    
        new_hf = _get_request_body()
        update_res = healthFacilityManager.update("healthFacilityName", name, new_hf)

        if not update_res:
            abort(400, message=f'No health facility exists with name "{name}"')
        else:
            return update_res
Ejemplo n.º 5
0
    def put(self, patient_id):
        logging.debug('Received request: PUT /patient/' + patient_id)

        data = _get_request_body()

        patient = abort_if_patient_doesnt_exist(patient_id)
        invalid = PatientValidation.update_info_invalid(patient_id, data)
        if invalid is not None:
            return invalid

        response_body = patientManager.update("patientId", patient_id, data)

        return response_body, 200
Ejemplo n.º 6
0
    def put(self, id=None):
        logging.debug('Received request: PUT /follow_up/<id>')
        current_user = get_jwt_identity()
        # validate inputs
        if not id:
            abort(400, message="id is required")

        new_follow_up = _get_request_body()
        update_res = followUpManager.update("id", id, new_follow_up,
                                            current_user)

        if not update_res:
            abort(400, message=f'No FollowUp exists with id "{id}"')
        else:
            return update_res
Ejemplo n.º 7
0
 def post(self):
     logging.debug('Received request: POST /follow_up')
     current_user = get_jwt_identity()
     follow_up_data = _get_request_body()
     response_body = followUpManager.create(follow_up_data, current_user)
     return response_body, 201
    def post(self):
        req_data = _get_request_body()

        return referralManager.create_referral_with_patient_and_reading(
            req_data), 201
Ejemplo n.º 9
0
 def post():
     logging.debug('Received request: POST /health_facility')
     hf_data = _get_request_body()
     response_body = healthFacilityManager.create(hf_data)
     return response_body, 201