コード例 #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
コード例 #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