Beispiel #1
0
    def post(self, name):
        """Will post data to the database."""
        if PatientModel.findPatient(name):
            return {'message': 'Patient with name {}, already in our database'.format(name)},  400
        dataInput = Patient.parser.parse_args()
        patient = PatientModel(name, dataInput['sex'],
                               dataInput['age'],
                               dataInput['race'],
                               dataInput['clinic_id'])

        try:
            patient.insertPatient()
        except:
            return {'message': 'Error occured during insertion'}, 500
        return patient.json(), 201
Beispiel #2
0
    def put(self, name):
        """Update the table."""
        dataget = Patient.parser.parse_args()
        patient = PatientModel.findPatient(name)

        if patient is None:
            patient = PatientModel(name, dataget['sex'],
                                   dataget['age'],
                                   dataget['race'],
                                   dataget['clinic_id'])
        else:
            patient.name = name
            patient.sex = dataget['sex']
            patient.age = dataget['age']
            patient.race = dataget['race']
            patient.clinic_id = dataget['clinic_id']

        patient.insertPatient()

        return patient.json(), 201
    def post(self):
        data = PatientRegister.patient_parser.parse_args()

        if (data["username"].isspace() or data["password"].isspace()
                or data["address"].isspace() or data["mobile"].isspace()
                or data["email"].isspace() or data["first_name"].isspace()
                or data["last_name"].isspace()):
            return {"message": "One of the inputs is empty"}, 400

        if len(data["username"]) < 5:
            return {"message": "Username is too short"}, 400

        if PatientModel.find_by_username(data["username"]):
            return {"message": "A user with that username already exists"}, 400

        if PatientModel.find_by_email(data["email"]):
            return {"message": "A user with that email already exists"}, 400

        y, m, d = [int(x) for x in data["birthdate"].split("-")]
        data["birthdate"] = datetime(y, m, d).date()
        if ((datetime.now().date() - data["birthdate"]).days // 365) < 1:
            return {"message": "Invalid age"}, 400

        data["gender"] = int(data["gender"])
        if data["gender"] != 0 and data["gender"] != 1:
            return {
                "message":
                "Invalid request: gender is only '0' if male or '1' if female"
            }

        data["created_at"] = datetime.now().date()

        patient = PatientModel(**data)
        patient.save_to_db()

        return {"message": "User created successfully."}, 201