def get(self, _id=None): if _id: device = DeviceModel.find_by_id(_id) if device: return BaseResponse.ok_response('Successful.', device.json()) return BaseResponse.bad_request_response('Device does not exists.', {}) else: devices = list(map(lambda x: x.json(), DeviceModel.find_all())) return BaseResponse.ok_response('Successful.', devices)
def get(self, _id=None): if _id: role = RoleModel.find_by_id(_id) if role: return BaseResponse.ok_response('Successful.', role.json()) return BaseResponse.bad_request_response('Role does not exists.', {}) else: roles = list(map(lambda x: x.json(), RoleModel.find_all())) return BaseResponse.ok_response('Successful.', roles)
def get(self, _id=None): if _id: doctor = DoctorModel.find_by_id(_id) if doctor: return BaseResponse.ok_response('Successful.', doctor.json()) return BaseResponse.bad_request_response('Doctor does not exists.', {}) else: doctors = list(map(lambda x: x.json(), DoctorModel.find_all())) return BaseResponse.ok_response('Successful.', doctors)
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): if _id: district = DistrictModel.find_by_id(_id) if district: return BaseResponse.ok_response('Successful.', district.json()) return BaseResponse.bad_request_response( 'District does not exists.', {}) else: districts = list(map(lambda x: x.json(), DistrictModel.find_all())) return BaseResponse.ok_response('Successful.', districts) pass
def get(self, _id=None): if _id: plan = PlanModel.find_by_id(_id) if plan: return BaseResponse.ok_response('Successful.', plan.json()) return BaseResponse.bad_request_response('Plan does not exists.', {}) else: plans = list(map(lambda x: x.json(), PlanModel.find_all())) return BaseResponse.ok_response('Successful.', plans) pass
def get(self, _id=None): if _id: user = UserModel.find_by_id(_id) if user: return BaseResponse.ok_response('Successful.', user.json(is_long=True)) return BaseResponse.bad_request_response('User does not exists.', {}) else: users = list( map(lambda x: x.json(is_long=True), UserModel.find_all())) return BaseResponse.ok_response('Successful.', users)
def get(self, _id=None): if _id: indicator_type = IndicatorTypeModel.find_by_id(_id) if indicator_type: return BaseResponse.ok_response('Successful.', indicator_type.json()) return BaseResponse.bad_request_response( 'Indicator type does not exists.', {}) else: indicators_type = list( map(lambda x: x.json(), IndicatorTypeModel.find_all())) return BaseResponse.ok_response('Successful.', indicators_type)
def get(self, _id=None): if _id: prescription_type = PrescriptionTypeModel.find_by_id(_id) if prescription_type: return BaseResponse.ok_response('Successful.', prescription_type.json()) return BaseResponse.bad_request_response( 'Prescription type does not exists.', {}) else: prescriptions_type = list( map(lambda x: x.json(), PrescriptionTypeModel.find_all())) return BaseResponse.ok_response('Successful.', prescriptions_type)
def get(self, _id=None): if _id: unit_of_measure = UnitOfMeasureModel.find_by_id(_id) if unit_of_measure: return BaseResponse.ok_response('Successful.', unit_of_measure.json()) return BaseResponse.bad_request_response( 'Unit of measure does not exists.', {}) else: units_of_measure = list( map(lambda x: x.json(), UnitOfMeasureModel.find_all())) return BaseResponse.ok_response('Successful.', units_of_measure) pass
def get(self, _id=None): if _id: medical_speciality = MedicalSpecialityModel.find_by_id(_id) if medical_speciality: return BaseResponse.ok_response('Successful.', medical_speciality.json()) return BaseResponse.bad_request_response( 'Medical speciality does not exists.', {}) else: medical_specialities = list( map(lambda x: x.json(), MedicalSpecialityModel.find_all())) return BaseResponse.ok_response('Successful.', medical_specialities) pass
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, appointment_id=None): doctor = DoctorModel.find_by_id(_id) if doctor is None: return BaseResponse.bad_request_response('Doctor does not exists.', {}) if appointment_id: appointment = AppointmentModel.find_by_id(appointment_id) if appointment: return BaseResponse.ok_response('Successful.', appointment.json(role_id=1)) return BaseResponse.bad_request_response( 'Appointment does not exists.', {}) else: appointments = list( map(lambda x: x.json(role_id=1), doctor.appointments)) return BaseResponse.ok_response('Successful.', appointments)
def get(self, doctor_id=None, _id=None): doctor = DoctorModel.find_by_id(doctor_id) if doctor is None: return BaseResponse.bad_request_response('Doctor does not exists.', {}) if _id: membership = MembershipModel.find_by_patient_id(_id) if membership: return BaseResponse.ok_response('Successful.', membership.json(role_id=1)) return BaseResponse.bad_request_response( 'Membership does not exists.', {}) else: memberships = list( map(lambda x: x.json(role_id=1), doctor.memberships)) return BaseResponse.ok_response('Successful.', memberships)
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 get(self, _id=None, ): if _id: address = AddressModel.find_by_id(_id) doctors_list = True if 'doctors' in request.path else False if address: return BaseResponse.ok_response('Successful.', address.json(doctors_list=doctors_list)) return BaseResponse.bad_request_response('Address does not exists.', {}) else: return BaseResponse.bad_request_response('It is necessary an address id.', {})
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, _id=None, doc_spec_id=None): if DoctorModel.find_by_id(_id) is None: return BaseResponse.bad_request_response('Doctor does not exists.', {}) if doc_spec_id: doctor_speciality = DoctorSpecialityModel.find_by_id(doc_spec_id) if doctor_speciality: return BaseResponse.ok_response( 'Successful.', doctor_speciality.json(only_spec=False)) return BaseResponse.bad_request_response( 'Doctor speciality does not exists.', {}) else: doctor = DoctorModel.find_by_id(_id) doctor_specialities = list( map(lambda x: x.json(only_spec=True), doctor.doctorSpecialities)) return BaseResponse.ok_response('Successful.', doctor_specialities)
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 delete(self, _id=None): try: user = UserModel.find_by_id(_id) if user: user.status = 'INA' user.updatedOn = datetime.now().strftime('%Y-%m-%d %H:%M:%S') user.save_to_db() return BaseResponse.ok_response('User deleted successfully.', {}) else: return BaseResponse.not_acceptable_response( 'User does not exists.', []) except Exception as e: return BaseResponse.server_error_response(str(e))
def delete(self, _id=None, doc_spec_id=None): try: if DoctorModel.find_by_id(_id) is None: return BaseResponse.bad_request_response( 'Doctor does not exists.', {}) doctor_speciality = DoctorSpecialityModel.find_by_id(doc_spec_id) if doctor_speciality: doctor_speciality.delete_from_db() return BaseResponse.ok_response( 'Doctor speciality deleted successfully.', {}) else: return BaseResponse.not_acceptable_response( 'Doctor speciality does not exists.', {}) except Exception as e: return BaseResponse.server_error_response(unicode(e))
def delete(self, _id=None): try: if _id: doctor = DoctorModel.find_by_id(_id) if doctor: doctor.status = 'INA' doctor.updatedOn = datetime.now().strftime('%Y-%m-%d %H:%M:%S') doctor.save_to_db() return BaseResponse.ok_response('User deleted successfully.', doctor.json()) else: return BaseResponse.not_acceptable_response('Doctor does not exists.', {}) else: return BaseResponse.bad_request_response('Doctor id is not given.', {}) except Exception as e: return BaseResponse.server_error_response(str(e))
def delete(self, _id=None): try: address = AddressModel.find_by_id(_id) doctors_list = True if 'doctors' not in request.path else False if address and doctors_list: address.status = 'INA' address.updatedOn = datetime.now().strftime('%Y-%m-%d %H:%M:%S') address.save_to_db() return BaseResponse.ok_response('Address deleted successfully.', {}) elif doctors_list is False: return BaseResponse.not_acceptable_response('Url request is not acceptable.', {}) else: return BaseResponse.not_acceptable_response('Address does not exists.', {}) except Exception as e: return BaseResponse.server_error_response(str(e))
def put(self, _id=None): try: data = User.parser.parse_args() user = UserModel.find_by_id(_id) if user: hash_password = UserModel.hash_password(data['password']) user.roleId = data['roleId'] if (data['roleId'] is not None) else user.roleId user.email = data['email'] if (data['email'] is not None) else user.email user.password = hash_password if ( data['password'] is not None) else user.password user.fullName = data['fullName'] if ( data['fullName'] is not None) else user.fullName user.lastName = data['lastName'] if ( data['lastName'] is not None) else user.lastName user.phoneNumber = data['phoneNumber'] if ( data['phoneNumber'] is not None) else user.phoneNumber user.profilePicture = data['profilePicture'] if (data['profilePicture'] is not None) \ else user.profilePicture user.lastIPConnection = data['lastIPConnection'] if (data['lastIPConnection'] is not None) \ else user.lastIPConnection user.updatedOn = datetime.now().strftime('%Y-%m-%d %H:%M:%S') user.save_to_db() if user.lastIPConnection and DeviceModel.find_by_ip( user.lastIPConnection) is None: device = DeviceModel(user_id=user.id, ip=user.lastIPConnection, created_at=datetime.now().strftime( '%Y-%m-%d %H:%M:%S')) device.save_to_db() return BaseResponse.ok_response('User updated successfully.', user.json(is_long=True)) else: return BaseResponse.not_acceptable_response( 'User does not exists.', {}) 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 delete(self, doctor_id=None, _id=None): try: if DoctorModel.find_by_id(doctor_id) is None: return BaseResponse.bad_request_response( 'Doctor does not exists.', {}) membership = MembershipModel.find_by_id(_id) if membership: membership.status = 'INA' membership.updatedOn = datetime.now().strftime( '%Y-%m-%d %H:%M:%S') membership.save_to_db() return BaseResponse.ok_response( 'Membership deleted successfully.', {}) else: return BaseResponse.not_acceptable_response( 'Membership does not exists.', {}) except Exception as e: return BaseResponse.server_error_response(unicode(e))
def put(self, _id=None): try: data = Doctor.parser.parse_args() if _id: doctor = DoctorModel.find_by_id(_id) if doctor: doctor.userId = data['userId'] if (data['userId'] is not None) else doctor.userId doctor.planId = data['planId'] if (data['planId'] is not None) else doctor.planId doctor.addressId = data['addressId'] if (data['addressId'] is not None) else doctor.addressId doctor.doctorIdentification = data['doctorIdentification'] if \ (data['doctorIdentification'] is not None) else doctor.doctorIdentification doctor.updatedOn = datetime.now().strftime('%Y-%m-%d %H:%M:%S') doctor.save_to_db() return BaseResponse.ok_response('User updated successfully.', doctor.json()) else: return BaseResponse.not_acceptable_response('Doctor does not exists.', {}) else: return BaseResponse.bad_request_response('Doctor id is not given.', {}) except Exception as e: return BaseResponse.server_error_response(str(e))
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(): try: data = Login.parser.parse_args() if data['email']: user = UserModel.find_by_email(data['email']) else: user = UserModel.find_by_phone(data['phoneNumber']) pass if data['lastIPConnection'] and DeviceModel.find_by_ip(data['lastIPConnection']) is None \ and user is not None: user.lastIPConnection = data['lastIPConnection'] if (data['lastIPConnection'] is not None) \ else user.lastIPConnection user.save_to_db() device = DeviceModel( user_id=user.id, ip=data['lastIPConnection'], created_at=datetime.now().strftime('%Y-%m-%d %H:%M:%S')) device.save_to_db() if user and user.check_password(data['password']): access_token = create_access_token( identity=user.json(is_long=False), fresh=True) refresh_token = create_refresh_token(identity=user.json( is_long=False)) return BaseResponse.ok_response( 'Login successfully.', { 'accessToken': access_token, 'refreshToken': refresh_token, 'user': user.json(is_long=False) }) return BaseResponse.bad_request_response('Incorrect credentials.', {}) 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