def put(self, doctor_id=None, patient_id=None, _id=None): try: data = PrescriptionDoctor.parser.parse_args() if DoctorModel.find_by_id(doctor_id) is None: return BaseResponse.bad_request_response( 'Doctor does not exists.', {}) elif PatientModel.find_by_id(patient_id) is None: return BaseResponse.bad_request_response( 'Patient does not exists.', {}) prescription = PrescriptionModel.find_by_id(_id) if prescription: prescription.frequency = data['frequency'] if (data['frequency'] is not None) \ else prescription.frequency prescription.quantity = data['quantity'] if ( data['quantity'] is not None) else prescription.quantity prescription.durationInDays = data['durationInDays'] if (data['durationInDays'] is not None) \ else prescription.durationInDays prescription.description = data['description'] if (data['description'] is not None) \ else prescription.description prescription.finishedAt = data['finishedAt'] if (data['finishedAt'] is not None) \ else prescription.finishedAt prescription.save_to_db() return BaseResponse.created_response( 'Prescription updated successfully.', prescription.json(role_id=1)) else: return BaseResponse.not_acceptable_response( 'Prescription does not exists.', {}) except Exception as e: return BaseResponse.server_error_response(unicode(e))
def put(self, patient_id=None, _id=None): try: data = MembershipPatient.parser.parse_args() if PatientModel.find_by_id(patient_id) is None: return BaseResponse.bad_request_response( 'Patient does not exists.', {}) membership = MembershipModel.find_by_id(_id) if membership: membership.accessCode = data['accessCode'] if (data['accessCode'] is not None) \ else membership.accessCode membership.updatedOn = datetime.now().strftime( '%Y-%m-%d %H:%M:%S') membership.save_to_db() return BaseResponse.created_response( 'Membership updated successfully.', membership.json(role_id=2)) else: return BaseResponse.not_acceptable_response( 'Membership does not exists.', {}) except Exception as e: return BaseResponse.server_error_response(unicode(e))
def post(self, doctor_id=None, patient_id=None): try: data = PrescriptionDoctor.parser.parse_args() if DoctorModel.find_by_id(doctor_id) is None: return BaseResponse.bad_request_response( 'Doctor does not exists.', {}) elif PatientModel.find_by_id(patient_id) is None: return BaseResponse.bad_request_response( 'Patient does not exists.', {}) prescription = PrescriptionModel( doctor_id=doctor_id, patient_id=patient_id, prescription_type_id=data['prescriptionTypeId'], frequency=data['frequency'], quantity=data['quantity'], duration_in_days=data['durationInDays'], description=data['description'], created_at=None, started_at=data['startedAt'], finished_at=None, status=None) prescription.save_to_db() return BaseResponse.created_response( 'Prescription created successfully.', prescription.json(role_id=1)) except Exception as e: return BaseResponse.server_error_response(unicode(e))
def delete(self, patient_id=None, doctor_id=None, _id=None): try: if PatientModel.find_by_id(patient_id) is None: return BaseResponse.bad_request_response( 'Patient does not exists.', {}) elif DoctorModel.find_by_id(doctor_id) is None: return BaseResponse.bad_request_response( 'Doctor does not exists.', {}) prescription = PrescriptionModel.find_by_id(_id) if prescription: prescription.status = 'INA' prescription.finishedAt = datetime.now().strftime( '%Y-%m-%d %H:%M:%S') prescription.save_to_db() return BaseResponse.ok_response( 'Prescription deleted successfully.', {}) else: return BaseResponse.not_acceptable_response( 'Prescription does not exists.', {}) except Exception as e: return BaseResponse.server_error_response(unicode(e))
def get(self, _id=None): if _id: patient = PatientModel.find_by_id(_id) if patient: return BaseResponse.ok_response('Successful.', patient.json()) return BaseResponse.bad_request_response( 'Patient does not exists.', {}) else: patients = list(map(lambda x: x.json(), PatientModel.find_all())) return BaseResponse.ok_response('Successful.', patients)
def get(self, _id=None, appointment_id=None): patient = PatientModel.find_by_id(_id) if patient is None: return BaseResponse.bad_request_response('Patient does not exists.', {}) if appointment_id: appointment = AppointmentModel.find_by_id(appointment_id) if appointment: return BaseResponse.ok_response('Successful.', appointment.json(role_id=2)) return BaseResponse.bad_request_response('Appointment does not exists.', {}) else: appointments = list(map(lambda x: x.json(role_id=2), patient.appointments)) return BaseResponse.ok_response('Successful.', appointments)
def get(self, patient_id=None, _id=None): patient = PatientModel.find_by_id(patient_id) if patient: return BaseResponse.bad_request_response( 'Patient does not exists.', {}) if _id: membership = MembershipModel.find_by_doctor_id(_id) if membership: return BaseResponse.ok_response('Successful.', membership.json(role_id=2)) return BaseResponse.bad_request_response( 'Membership does not exists.', {}) else: memberships = list( map(lambda x: x.json(role_id=2), patient.memberships)) return BaseResponse.ok_response('Successful.', memberships)
def delete(self, _id=None, appointment_id=None): try: if PatientModel.find_by_id(_id) is None: return BaseResponse.bad_request_response('Patient does not exists.', {}) appointment = AppointmentModel.find_by_id(appointment_id) if appointment: appointment.status = 'INA' appointment.updatedOn = datetime.now().strftime('%Y-%m-%d %H:%M:%S') appointment.canceledAt = datetime.now().strftime('%Y-%m-%d %H:%M:%S') appointment.save_to_db() return BaseResponse.ok_response('Appointment deleted successfully.', {}) else: return BaseResponse.not_acceptable_response('Appointment does not exists.', {}) except Exception as e: return BaseResponse.server_error_response(str(e))
def post(self, _id=None): try: data = AppointmentPatient.parser.parse_args() if PatientModel.find_by_id(_id) is None: return BaseResponse.bad_request_response('Patient does not exists.', {}) elif AppointmentModel.find_by_appointment_date(data['appointmentDate']): return BaseResponse.bad_request_response('An appointment already exists in that date.', {}) appointment = AppointmentModel(doctor_id=data['doctorId'], patient_id=_id, appointment_date=data['appointmentDate'], reason=data['reason'], created_at=None, canceled_at=data['canceledAt'], updated_on=None, status='INA') appointment.save_to_db() return BaseResponse.created_response('Appointment registered successfully.', appointment.json(role_id=2)) except Exception as e: return BaseResponse.server_error_response(str(e))
def delete(self, _id=None): if _id: patient = PatientModel.find_by_id(_id) if patient: patient.status = 'INA' patient.updatedOn = datetime.now().strftime( '%Y-%m-%d %H:%M:%S') try: patient.save_to_db() except Exception as e: return BaseResponse.server_error_response(str(e)) return BaseResponse.ok_response( 'Patient deleted successfully.', patient.json()) else: return BaseResponse.not_acceptable_response( 'Patient does not exists.', {}) else: return BaseResponse.bad_request_response( 'Patient id is not given.', {})
def get(self, doctor_id=None, patient_id=None, _id=None): if DoctorModel.find_by_id(doctor_id) is None: return BaseResponse.bad_request_response('Doctor does not exists.', {}) elif PatientModel.find_by_id(patient_id) is None: return BaseResponse.bad_request_response( 'Patient does not exists.', {}) if _id: prescription = PrescriptionModel.find_by_id(_id) if prescription: return BaseResponse.ok_response('Successful.', prescription.json(role_id=1)) return BaseResponse.bad_request_response( 'Prescription does not exists.', {}) else: prescriptions = list( map( lambda x: x.json(role_id=1), PrescriptionModel.find_by_doctor_and_patient_id( doctor_id, patient_id))) return BaseResponse.ok_response('Successful.', prescriptions)
def put(self, _id=None, appointment_id=None): try: data = AppointmentPatient.parser.parse_args() if PatientModel.find_by_id(_id) is None: return BaseResponse.bad_request_response('Patient does not exists.', {}) appointment = AppointmentModel.find_by_id(appointment_id) if appointment: appointment.appointmentDate = data['appointmentDate'] if (data['appointmentDate'] is not None) \ else appointment.appointmentDate appointment.reason = data['reason'] if (data['reason'] is not None) else appointment.reason appointment.canceledAt = data['canceledAt'] if (data['canceledAt'] is not None) \ else appointment.canceledAt appointment.updatedOn = datetime.now().strftime('%Y-%m-%d %H:%M:%S') appointment.save_to_db() return BaseResponse.created_response('Appointment updated successfully.', appointment.json(role_id=2)) else: return BaseResponse.not_acceptable_response('Appointment does not exists.', {}) except Exception as e: return BaseResponse.server_error_response(str(e))
def put(self, _id=None): data = Patient.parser.parse_args() if _id: patient = PatientModel.find_by_id(_id) if patient: patient.userId = data['userId'] if ( data['userId'] is not None) else patient.userId patient.planId = data['planId'] if ( data['planId'] is not None) else patient.planId patient.age = data['age'] if (data['age'] is not None) else patient.age patient.bloodType = data['bloodType'] if ( data['bloodType'] is not None) else patient.bloodType patient.weight = data['weight'] if ( data['weight'] is not None) else patient.weight patient.sex = data['sex'] if (data['sex'] is not None) else patient.sex patient.height = data['height'] if ( data['height'] is not None) else patient.height patient.updatedOn = datetime.now().strftime( '%Y-%m-%d %H:%M:%S') try: patient.save_to_db() except Exception as e: return BaseResponse.server_error_response(str(e)) return BaseResponse.ok_response( 'Patient updated successfully.', patient.json()) else: return BaseResponse.not_acceptable_response( 'Patient does not exists.', {}) else: return BaseResponse.bad_request_response( 'Patient id is not given.', {}) pass