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 put(self, _id=None, doc_spec_id=None):
        try:
            data = DoctorSpeciality.parser.parse_args()

            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.doctorId = data['doctorId'] if (data['doctorId'] is not None) \
                    else doctor_speciality.doctorId
                doctor_speciality.medicalSpecialityId = data['medicalSpecialityId'] \
                    if (data['medicalSpecialityId'] is not None) else doctor_speciality.medicalSpecialityId

                doctor_speciality.save_to_db()

                return BaseResponse.created_response(
                    'Doctor speciality updated successfully.',
                    doctor_speciality.json(only_spec=False))
            else:
                return BaseResponse.not_acceptable_response(
                    'Doctor speciality does not exists.', {})
        except Exception as e:
            return BaseResponse.server_error_response(unicode(e))
Exemple #3
0
    def put(self, doctor_id=None, _id=None):
        try:
            data = MembershipDoctor.parser.parse_args()

            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.expiresAt = data['expiresAt'] if (
                    data['expiresAt'] is not None) else membership.expiresAt
                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=1))
            else:
                return BaseResponse.not_acceptable_response(
                    'Membership does not exists.', {})
        except Exception as e:
            return BaseResponse.server_error_response(unicode(e))
    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))
Exemple #5
0
    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 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 put(self, _id=None):
        try:
            data = Address.parser.parse_args()

            address = AddressModel.find_by_id(_id)
            doctors_list = True if 'doctors' not in request.path else False
            if address and doctors_list:
                address.districtId = data['districtId'] if (
                    data['district'] is not None) else address.districtId
                address.street = data['street'] if (
                    data['street'] is not None) else address.street
                address.neighborhood = data['neighborhood'] if (data['neighborhood'] is not None) \
                    else address.neighborhood
                address.complement = data['complement'] if (
                    data['complement'] is not None) else address.complement
                address.number = data['number'] if (
                    data['number'] is not None) else address.number
                address.updatedOn = datetime.now().strftime(
                    '%Y-%m-%d %H:%M:%S')

                address.save_to_db()

                return BaseResponse.ok_response(
                    'Address updated successfully.',
                    address.json(doctors_list=False))
            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 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))
Exemple #9
0
    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 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:
            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 post(self, _id=None):
        try:
            data = DoctorSpeciality.parser.parse_args()

            if DoctorModel.find_by_id(_id) is None:
                return BaseResponse.bad_request_response('Doctor does not exists.', {})
            elif DoctorSpecialityModel.verify_doctor_speciality(_id, data['medicalSpecialityId']):
                return BaseResponse.bad_request_response('This doctor already have this specialities.', {})

            doctor_speciality = DoctorSpecialityModel(doctor_id=_id, medical_speciality_id=data['medicalSpecialityId'])

            doctor_speciality.save_to_db()

            return BaseResponse.created_response('Doctor speciality created successfully.',
                                                 doctor_speciality.json(only_spec=False))
        except Exception as e:
            return BaseResponse.server_error_response(unicode(e))
Exemple #13
0
    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))
Exemple #14
0
    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))
Exemple #15
0
    def post(self, _id=None):
        try:
            data = AppointmentDoctor.parser.parse_args()

            if DoctorModel.find_by_id(_id) is None:
                return BaseResponse.bad_request_response('Doctor does not exists.', {})
            elif AppointmentModel.find_by_appointment_date(data['appointmentDate']):
                return BaseResponse.bad_request_response('An appointment is already scheduled in that date.', {})

            appointment = AppointmentModel(doctor_id=_id, patient_id=data['patientId'],
                                           appointment_date=data['appointmentDate'], reason=data['reason'],
                                           created_at=None, canceled_at=data['canceledAt'], updated_on=None,
                                           status=None)

            appointment.save_to_db()

            return BaseResponse.created_response('Appointment created successfully.', appointment.json(role_id=1))
        except Exception as e:
            return BaseResponse.server_error_response(unicode(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):
        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 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, _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))
Exemple #20
0
    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 post():
        try:
            data = User.parser.parse_args()

            if UserModel.find_by_email(data['email']):
                return BaseResponse.bad_request_response(
                    'This email already exists.', {})
            elif UserModel.find_by_phone(data['phoneNumber']):
                return BaseResponse.bad_request_response(
                    'This phone number already exists.', {})

            hash_password = UserModel.hash_password(data['password'])
            user = UserModel(role_id=data['roleId'],
                             email=data['email'],
                             password=hash_password,
                             full_name=data['fullName'],
                             last_name=data['lastName'],
                             phone_number=data['phoneNumber'],
                             profile_picture=data['profilePicture'],
                             last_ip_connection=data['lastIPConnection'],
                             created_at=None,
                             updated_on=None,
                             status=None)

            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.created_response('User created successfully.',
                                                 user.json(is_long=True))
        except Exception as e:
            return BaseResponse.server_error_response(str(e))
Exemple #22
0
    def put(self, _id=None, appointment_id=None):
        try:
            data = AppointmentDoctor.parser.parse_args()

            if DoctorModel.find_by_id(_id) is None:
                return BaseResponse.bad_request_response('Doctor 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=1))
            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 = Doctor.parser.parse_args()

            if DoctorModel.find_by_user_id(data['userId']):
                return BaseResponse.bad_request_response(
                    'This doctor already exists.', {})

            doctor = DoctorModel(
                user_id=data['userId'],
                plan_id=data['planId'],
                address_id=data['addressId'],
                doctor_identification=data['doctorIdentification'],
                created_at=None,
                updated_on=None,
                status=None)

            doctor.save_to_db()

            return BaseResponse.created_response(
                'Doctor created successfully.', doctor.json())
        except Exception as e:
            return BaseResponse.server_error_response(str(e))
Exemple #24
0
    def post(self, doctor_id=None):
        try:
            data = MembershipDoctor.parser.parse_args()
            supposed_membership = MembershipModel.find_by_doctor_id(doctor_id)

            if DoctorModel.find_by_id(doctor_id) is None:
                return BaseResponse.bad_request_response(
                    'Doctor does not exists.', {})
            elif supposed_membership.patientId == data['patientId']:
                if supposed_membership.status == 'INA':
                    supposed_membership.status = 'ACT'

                    supposed_membership.save_to_db()

                    return BaseResponse.ok_response(
                        'Membership activated.',
                        supposed_membership.json(role_id=1))
                return BaseResponse.bad_request_response(
                    'A membership with this patient already exists.', {})

            membership = MembershipModel(
                doctor_id=doctor_id,
                patient_id=data['patientId'],
                referenced_email=data['referencedEmail'],
                access_code=None,
                created_at=None,
                expires_at=None,
                updated_on=None,
                status=None)

            membership.save_to_db()

            return BaseResponse.created_response(
                'Membership created successfully.', membership.json(role_id=1))
        except Exception as e:
            return BaseResponse.server_error_response(unicode(e))
    def post(self):
        try:
            data = Address.parser.parse_args()

            if AddressModel.find_by_number(data['number']):
                return BaseResponse.bad_request_response(
                    'This address already exists.', {})

            address = AddressModel(district_id=data['districtId'],
                                   street=data['street'],
                                   neighborhood=data['neighborhood'],
                                   complement=data['complement'],
                                   number=data['number'],
                                   created_at=None,
                                   updated_on=None,
                                   status=None)

            address.save_to_db()

            return BaseResponse.created_response(
                'Address created successfully.',
                address.json(doctors_list=False))
        except Exception as e:
            return BaseResponse.server_error_response(str(e))
    def post():
        data = Patient.parser.parse_args()

        if PatientModel.find_by_user_id(data['userId']):
            return BaseResponse.bad_request_response(
                'This patient already exists.', {})

        patient = PatientModel(user_id=data['userId'],
                               plan_id=data['planId'],
                               age=data['age'],
                               blood_type=data['bloodType'],
                               weight=data['weight'],
                               sex=data['sex'],
                               height=data['height'],
                               created_at=None,
                               updated_on=None,
                               status=None)
        try:
            patient.save_to_db()
        except Exception as e:
            return BaseResponse.server_error_response(str(e))

        return BaseResponse.created_response('Patient created successfully.',
                                             patient.json())
    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