Beispiel #1
0
    def get(self):
        """List all patients"""
        only = [
            "id",
            "hn",
            "clinicID",
            "governmentID",
            "napID",
            "name",
            "sex",
            "gender",
            "nationality",
            "healthInsurance",
            "dateOfBirth",
            "phoneNumbers",
        ]

        patient_schema = PatientSchema(
            many=True, exclude=PatientModel.relationship_keys, only=only
        )

        patients_query = PatientModel.query.order_by(
            PatientModel.clinicID
        ).all()
        patients = patient_schema.dump(patients_query)

        return patients, 200
Beispiel #2
0
    def patch_patient(patient_data):
        patient_data["dateOfBirth"] = convertToDate(
            patient_data["dateOfBirth"])

        patient_schema = PatientSchema(many=False, unknown="EXCLUDE")

        patient = PatientModel.query.filter(
            PatientModel.hn == patient_data["hn"]).first()

        try:
            if patient:
                patient_data["id"] = patient.id
                new_patient_model = patient_schema.load(patient_data,
                                                        transient=True)
                new_patient_dict = patient_schema.dump(new_patient_model)
                patient.update(**new_patient_dict)

            else:
                patient = patient_schema.load(patient_data)

            patient.imported = True

            return patient

        except Exception as e:
            current_app.logger.warn(
                f"Unable to import patient HN {patient_data['hn']}"
                f" with this error {e}, skipping.")

            raise e
Beispiel #3
0
    def post(self):
        """Add new patient"""
        patient = parser.parse(PatientSchema, request)

        db.session.add(patient)
        db.session.commit()

        patient_schema = PatientSchema()
        return patient_schema.dump(patient), 200
Beispiel #4
0
    def get(self, args, **kwargs):
        """Get patient with the UUID"""
        if args["only_dermographic"]:
            patient_schema = PatientSchema(
                many=False, exclude=PatientModel.relationship_keys
            )

        else:
            patient_schema = PatientSchema(many=False)

        patient = PatientModel.query.filter_by(id=args["patient_uuid"]).first()

        return patient_schema.dump(patient), 200
Beispiel #5
0
    def get(self, visitDate):
        """List all appointments"""
        only = ["id", "hn", "clinicID", "name"]

        patient_schema = PatientSchema(many=True, only=only)

        patients_query = (
            db.session.query(PatientModel)
            .join(VisitModel)
            .order_by(PatientModel.clinicID)
            .filter(VisitModel.date == visitDate)
        )

        patients = patient_schema.dump(patients_query)

        return patients, 200
Beispiel #6
0
    def get(self, args):
        """Search for patients"""
        if "fieldName" not in args:
            only = ["id", "hn", "clinicID", "name", "nationality"]

            patient_schema = PatientSchema(
                many=True, exclude=PatientModel.relationship_keys, only=only
            )

            patients_query = (
                PatientModel.query.order_by(PatientModel.clinicID)
                .filter(
                    PatientModel.hn.ilike("%{}%".format(args["keyword"]))
                    | PatientModel.clinicID.ilike(
                        "%{}%".format(args["keyword"])
                    )
                    | PatientModel.napID.ilike("%{}%".format(args["keyword"]))
                    | PatientModel.name.ilike("%{}%".format(args["keyword"]))
                )
                .limit(current_app.config["MAX_NUMBER_OF_PATIENT_IN_SEARCH"])
                .all()
            )

        else:
            patient_schema = PatientSchema(
                many=True,
                exclude=PatientModel.relationship_keys,
                only=[args["fieldName"]],
            )

            patients_query = (
                PatientModel.query.filter(
                    getattr(PatientModel, args["fieldName"]).ilike(
                        "%{}%".format(args["keyword"])
                    )
                )
                .limit(current_app.config["MAX_NUMBER_OF_HOSPITAL_IN_SEARCH"])
                .all()
            )

        patients = patient_schema.dump(patients_query)

        return patients, 200
Beispiel #7
0
    def patch(self, patient_uuid):
        """Modify patient with the UUID"""
        patient_schema = PatientSchema(many=False)

        patient_payload = parser.parse(PatientSchema, request)
        patient_payload = patient_schema.dump(patient_payload)

        patient = PatientModel.query.filter_by(id=patient_uuid).first()

        if patient:
            patient.update(**patient_payload)

            db.session.add(patient)
            db.session.commit()

            return patient_schema.dump(patient), 200

        else:
            abort(404, "Patient not found.")