Beispiel #1
0
 def delete(self, name):
     """Delete patient from the patient's database."""
     patient = PatientModel.findPatient(name)
     if patient:
         patient.deletePatient()
         return {'message': 'Patient: {} removed from the database'
                 .format(name)}, 200
     return {'message': 'Patient with name {}, not in our database'.format(name)},  404
Beispiel #2
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 #3
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
Beispiel #4
0
 def get(self, name):
     """Define method on the resource i.e get."""
     patient = PatientModel.findPatient(name)
     if patient:
         return patient.json(), 200
     return {'message': 'Patient {} not found in our patient\'s database'.format(name)}, 404