def setUp(self):

        # Creating user in database.
        self.user = HealthProfessional()
        self.user.email = "*****@*****.**"
        self.user.save()

        self.patient = Patient()
        self.patient.email = "*****@*****.**"
        self.patient.save()

        self.link = AssociatedHealthProfessionalAndPatient()
        self.link.associated_health_professional = self.user
        self.link.associated_patient = self.patient
        self.link.is_active = True
        self.link.save()

        self.not_linked_patient = Patient()
        self.not_linked_patient.email = "*****@*****.**"
        self.not_linked_patient.save()

        self.subject = "a"
        self.text = "a"

        self.factory = RequestFactory()
        self.my_view = ComposeView()
        self.my_view_class = ComposeView
        self.client = Client()
Exemplo n.º 2
0
def register_post():
    data = request.form
    p = Patient(fname=data['fname'],
                lname=data['lname'],
                phone=data['phone'],
                email=data['email'],
                passwd=data['passwd'])
    id = p.manager().create()
    return str(id)
class TestListFavoritePrescription(TestCase):
    def setUp(self):
        self.factory = RequestFactory()
        self.client = Client()
        self.view = CreatePrescriptionView()

        self.patient = Patient()
        self.patient.pk = 1
        self.patient.name = "Paciente de teste"
        self.patient.date_of_birth = "1991-10-21"
        self.patient.phone = "06199999999"
        self.patient.email = "*****@*****.**"
        self.patient.sex = "M"
        self.patient.id_document = "1000331"
        self.patient.CEP = "72850735"
        self.patient.UF = "DF"
        self.patient.city = "Brasília"
        self.patient.neighborhood = "Asa sul"
        self.patient.complement = "Bloco 2 QD 701"
        self.patient.save()

        self.health_professional = HealthProfessional()
        self.health_professional.pk = 1
        self.health_professional.crm = '12345'
        self.health_professional.crm_state = 'US'
        self.health_professional.save()

        self.manipulated_medicine = ManipulatedMedicine()
        self.manipulated_medicine.pk = 1
        self.manipulated_medicine.recipe_name = "teste"
        self.manipulated_medicine.physical_form = "asdadsafdf"
        self.manipulated_medicine.quantity = 12
        self.manipulated_medicine.measurement = "kg"
        self.manipulated_medicine.composition = "aosdjoaisjdoiajsdoij"
        self.manipulated_medicine.health_professional = self.health_professional
        self.manipulated_medicine.save()

        self.disease = Disease()
        self.disease.pk = 1
        self.disease.id_cid_10 = "A01"
        self.disease.description = "A random disease"
        self.disease.save()

        self.health_professional = HealthProfessional.objects.create_user(email='*****@*****.**',
                                                                          password='******')

    def teste_list_prescription(self):
        request = self.factory.get('/')
        request.user = self.health_professional

        response = ListFavoritePrescription.as_view()(request)
        self.assertEqual(response.status_code, 200)
Exemplo n.º 4
0
	def test_nurse_creation(self):
		user = User.objects.create(username="******", first_name = "test",
			last_name = "test")
		user.save()
		person = Patient(user = user,
			sex="1", birthdate=date.today(), address="30 allée des Chardons, Paris, France", 
			profile_type = "PATIENT", information = "allergique au doliprane")
		person.save()
		user = User.objects.get(username = "******")
		self.assertEqual(user.person.patient.sex, "1")
		self.assertEqual(user.person.patient.birthdate, date.today())
		self.assertEqual(user.person.patient.address, "30 allée des Chardons, Paris, France")
		self.assertEqual(user.person.patient.profile_type, "PATIENT")
		self.assertEqual(user.person.patient.information, "allergique au doliprane")
Exemplo n.º 5
0
def patient_register():
    form = PatientRegForm()
    if form.validate_on_submit():
        hashed_password = generate_password_hash(form.password.data)
        patient = Patient('PATIENT', "ACTIVE", form.fname.data,
                          form.lname.data, form.dob.data, form.gender.data,
                          form.houseNo.data, form.street.data, form.city.data,
                          form.state.data, form.zipcode.data, form.phone.data,
                          form.email.data, hashed_password, form.pmry_opt.data)

        db.session.add(patient)
        db.session.commit()

        emergency_contact = EmergencyContact(
            patient.patient_id,
            form.emer_fname.data,
            form.emer_lname.data,
            form.emer_relationship.data,
            form.emer_phone.data,
        )
        print(form.emer_lname.data)
        db.session.add(emergency_contact)
        db.session.commit()

        flash(
            f'Welcome, {form.fname.data}. Your forMED account has been registered. Please log in to continue.'
        )
        return redirect(url_for('.login'))
    return render_template('user/patient_reg.html', form=form)
Exemplo n.º 6
0
class TestListPatterns(TestCase):
    def setUp(self):
        self.factory = RequestFactory()
        self.client = Client()
        self.view = CreatePatternView()

        self.patient = Patient()
        self.patient.pk = 1
        self.patient.name = "Paciente de teste"
        self.patient.date_of_birth = "1991-10-21"
        self.patient.phone = "06199999999"
        self.patient.email = "*****@*****.**"
        self.patient.sex = "M"
        self.patient.id_document = "1000331"
        self.patient.CEP = "72850735"
        self.patient.UF = "DF"
        self.patient.city = "Brasília"
        self.patient.neighborhood = "Asa sul"
        self.patient.complement = "Bloco 2 QD 701"
        self.patient.save()

        self.health_professional = HealthProfessional()
        self.health_professional.pk = 1
        self.health_professional.crm = '12345'
        self.health_professional.crm_state = 'US'
        self.health_professional.save()

        self.health_professional = HealthProfessional.objects.create_user(
            email='*****@*****.**', password='******')

        self.pattern = Pattern()
        self.pattern.name = "Nome teste"
        self.pattern.user_creator = self.health_professional
        self.pattern.font = "Times-Roman"
        self.pattern.font_size = "12"
        self.pattern.pagesize = "letter"
        self.pattern.clinic = "Clinic name"
        self.pattern.header = "Header"
        self.pattern.footer = "Footer"

    def teste_list_prescription(self):
        request = self.factory.get('prescription/list_patterns/')
        request.user = self.health_professional

        response = ListPatterns.as_view()(request)
        self.assertEqual(response.status_code, 200)
    def create_send_invitation_profile(email):
        salt = hashlib.sha1(str(
            random.random()).encode('utf-8')).hexdigest()[:5]
        activation_key = hashlib.sha1(
            str(salt + email).encode('utf‌​-8')).hexdigest()
        key_expires = timezone.now() + datetime.timedelta(days=2)

        patient = Patient(email=email)
        patient.save()

        # Creating the temporary profile.
        new_profile = SendInvitationProfile(patient=patient,
                                            activation_key=activation_key,
                                            key_expires=key_expires)
        new_profile.save()

        return new_profile
 def setUp(self):
     self.factory = RequestFactory()
     self.email = '*****@*****.**'
     self.salt = hashlib.sha1(str(
         random.random()).encode('utf-8')).hexdigest()[:5]
     self.activation_key = hashlib.sha1(
         str(self.salt + self.email).encode('utf‌​-8')).hexdigest()
     self.key_expires = datetime.datetime.today() + datetime.timedelta(2)
     self.patient = Patient(email=self.email)
     self.patient.save()
     self.patient_profile = SendInvitationProfile.objects.create(
         activation_key=self.activation_key,
         patient=self.patient,
         key_expires=self.key_expires)
     self.email_invalid = '*****@*****.**'
     self.another_activation_key = hashlib.sha1(
         str(self.salt + self.email_invalid).encode('utf‌​-8')).hexdigest()
class ConfirmAccountViewTest(TestCase):
    def setUp(self):
        self.factory = RequestFactory()
        self.email = '*****@*****.**'
        self.salt = hashlib.sha1(str(
            random.random()).encode('utf-8')).hexdigest()[:5]
        self.activation_key = hashlib.sha1(
            str(self.salt + self.email).encode('utf‌​-8')).hexdigest()
        self.key_expires = datetime.datetime.today() + datetime.timedelta(2)
        self.patient = Patient(email=self.email)
        self.patient.save()
        self.patient_profile = SendInvitationProfile.objects.create(
            activation_key=self.activation_key,
            patient=self.patient,
            key_expires=self.key_expires)
        self.email_invalid = '*****@*****.**'
        self.another_activation_key = hashlib.sha1(
            str(self.salt + self.email_invalid).encode('utf‌​-8')).hexdigest()

    def test_user_user_get(self):
        request = self.factory.get('user/confirm/(?P<activation_key>\w+)/')
        request.user = AnonymousUser()
        setattr(request, 'session', {})
        setattr(request, '_messages', FallbackStorage(request))
        response = ConfirmAccountView.activate_register_user(
            request, activation_key=self.activation_key)
        self.assertEqual(response.status_code, 302)

    def test_user_user_get_without_invitation(self):
        '''
        this method tests when the user tryes to register a not invited patient.
        '''
        request = self.factory.get('user/confirm/(?P<activation_key>\w+)/')
        request.user = AnonymousUser()
        setattr(request, 'session', {})
        setattr(request, '_messages', FallbackStorage(request))
        response = ConfirmAccountView.activate_register_user(
            request, activation_key=self.another_activation_key)
        self.assertEqual(response.status_code, 302)
 def setUp(self):
     self.factory = RequestFactory()
     self.email = '*****@*****.**'
     self.salt = hashlib.sha1(str(
         random.random()).encode('utf-8')).hexdigest()[:5]
     self.activation_key = hashlib.sha1(
         str(self.salt + self.email).encode('utf‌​-8')).hexdigest()
     self.key_expires = datetime.datetime.today() + datetime.timedelta(2)
     self.key_expired = datetime.datetime.today() - datetime.timedelta(2)
     self.patient = Patient(email=self.email)
     self.patient.save()
     self.patient_profile = SendInvitationProfile.objects.create(
         activation_key=self.activation_key,
         patient=self.patient,
         key_expires=self.key_expires)
     self.patient_profile.save()
     self.email_invalid = '*****@*****.**'
     self.another_activation_key = hashlib.sha1(
         str(self.salt + self.email_invalid).encode('utf‌​-8')).hexdigest()
     self.name_valid = 'Teste Nome'
     self.name_invalid = 'Te'
     self.date_of_birth_valid = '10/12/1990'
     self.phone_valid = '(61)1234-56789'
     self.sex_valid = 'M'
     self.password_valid = '1234567'
     self.password_invalid = '1'
     self.CPF_document_valid = '61367541000'
     self.CPF_document_invalid = '11111111111'
     self.CEP_valid = 72850735
     self.CEP_invalid = '7285073A'
     self.UF_valid = 'DF'
     self.UF_invalid = ''
     self.city_valid = 'Brasília'
     self.city_invalid = ''
     self.neighborhood_valid = 'Setor Leste'
     self.neighborhood_invalid = ''
     self.complement_valid = 'Rua 01, Quadra 10, Lote 15'
     self.complement_invalid = ''
    def setUp(self):
        self.health_professional = HealthProfessional()
        self.health_professional.email = "*****@*****.**"
        self.health_professional.pk = 0
        self.health_professional.save()

        self.patient = Patient()
        self.patient.email = "*****@*****.**"
        self.patient.save()

        self.link = AssociatedHealthProfessionalAndPatient()
        self.link.associated_health_professional = self.health_professional
        self.link.associated_patient = self.patient
        self.link.is_active = True
        self.link.save()

        self.not_linked_patient = Patient.objects.create(
            email="*****@*****.**")

        self.subject = "a"
        self.text = "a"
        self.subject_max = 'a' * 1000
        self.text_max = 'a' * 1000
        self.email_invalid = 'a2d'
Exemplo n.º 12
0
def register_patient():
    form = PatientRegForm()
    #Disable and autofill fields
    form.pmry_opt.data = Physician.query.filter_by(
        id=session['id']).first().practice_name

    #TODO: Randomly generate a password...
    #PROBLEM: Cannot directly modify PasswordField data.
    # charString = string.ascii_letters+string.digits
    # randomPW = ''.join(random.sample(charString,10))
    # form.password.data = randomPW
    # form.confirm.data = randomPW
    # print(randomPW)

    if form.validate_on_submit():
        hashed_password = generate_password_hash(form.password.data)
        patient = Patient('PATIENT', "TEMP", form.fname.data, form.lname.data,
                          form.dob.data, form.gender.data, form.houseNo.data,
                          form.street.data, form.city.data, form.state.data,
                          form.zipcode.data, form.phone.data, form.email.data,
                          hashed_password, form.pmry_opt.data)

        db.session.add(patient)
        db.session.commit()

        emergency_contact = EmergencyContact(
            patient.patient_id,
            form.emer_fname.data,
            form.emer_lname.data,
            form.emer_relationship.data,
            form.emer_phone.data,
        )

        db.session.add(emergency_contact)
        db.session.commit()

        #Send Email to the newly registered patient with the unhashed password
        #Redirect to Home Page and Flash a message saying account created.
        flash(
            'Patient has been registered. An Email has been sent to the Patient with the account information'
        )
        form.sendTempEmail(form.password.data)
        return redirect(url_for('physician_app.physician_home'))

    return render_template('physician/register_patient.html', form=form)
class RegisterPatientViewTest(TestCase):
    def setUp(self):
        self.factory = RequestFactory()
        self.email = '*****@*****.**'
        self.salt = hashlib.sha1(str(
            random.random()).encode('utf-8')).hexdigest()[:5]
        self.activation_key = hashlib.sha1(
            str(self.salt + self.email).encode('utf‌​-8')).hexdigest()
        self.key_expires = datetime.datetime.today() + datetime.timedelta(2)
        self.key_expired = datetime.datetime.today() - datetime.timedelta(2)
        self.patient = Patient(email=self.email)
        self.patient.save()
        self.patient_profile = SendInvitationProfile.objects.create(
            activation_key=self.activation_key,
            patient=self.patient,
            key_expires=self.key_expires)
        self.patient_profile.save()
        self.email_invalid = '*****@*****.**'
        self.another_activation_key = hashlib.sha1(
            str(self.salt + self.email_invalid).encode('utf‌​-8')).hexdigest()
        self.name_valid = 'Teste Nome'
        self.name_invalid = 'Te'
        self.date_of_birth_valid = '10/12/1990'
        self.phone_valid = '(61)1234-56789'
        self.sex_valid = 'M'
        self.password_valid = '1234567'
        self.password_invalid = '1'
        self.CPF_document_valid = '61367541000'
        self.CPF_document_invalid = '11111111111'
        self.CEP_valid = 72850735
        self.CEP_invalid = '7285073A'
        self.UF_valid = 'DF'
        self.UF_invalid = ''
        self.city_valid = 'Brasília'
        self.city_invalid = ''
        self.neighborhood_valid = 'Setor Leste'
        self.neighborhood_invalid = ''
        self.complement_valid = 'Rua 01, Quadra 10, Lote 15'
        self.complement_invalid = ''

    def test_user_get(self):
        request = self.factory.get(
            'user/register_patient/(?P<activation_key>\w+)/')
        request.user = AnonymousUser()

        response = RegisterPatientView.as_view()(
            request, activation_key=self.activation_key)
        self.assertEqual(response.status_code, 200)

    def test_user_post(self):
        '''
        Test post method with a valid form.
        '''
        # Create the request
        context = {
            'name': self.name_valid,
            'phone': self.phone_valid,
            'email': self.email,
            'password': self.password_valid,
            'confirm_password': self.password_valid,
            'sex': self.sex_valid,
            'date_of_birth': self.date_of_birth_valid,
            'CPF_document': self.CPF_document_valid,
            'CEP': self.CEP_valid,
            'UF': self.UF_valid,
            'city': self.city_valid,
            'neighborhood': self.neighborhood_valid,
            'complement': self.complement_valid,
        }

        request = self.factory.post(
            '/user/register_patient/(?P<activation_key>\w+)/', context)
        setattr(request, 'session', {})
        setattr(request, '_messages', FallbackStorage(request))
        request.user = AnonymousUser()

        # Get the response
        response = RegisterPatientView.as_view()(
            request, activation_key=self.activation_key)
        self.assertEqual(response.status_code, 302)

    def test_user_post_invalid(self):
        '''
        Test post method with a valid form.
        '''
        # Create the request
        context = {
            'name': self.name_invalid,
            'phone': self.phone_valid,
            'email': self.email,
            'password': self.password_invalid,
            'confirm_password': self.password_valid,
            'sex': self.sex_valid,
            'date_of_birth': self.date_of_birth_valid,
            'CPF_document': self.CPF_document_valid,
            'CEP': self.CEP_invalid,
            'UF': self.UF_valid,
            'city': self.city_valid,
            'neighborhood': self.neighborhood_valid,
            'complement': self.complement_invalid,
        }

        request = self.factory.post(
            '/user/register_patient/(?P<activation_key>\w+)/', context)
        request.user = AnonymousUser()
        setattr(request, 'session', {})
        setattr(request, '_messages', FallbackStorage(request))

        # Get the response
        response = RegisterPatientView.as_view()(
            request, activation_key=self.activation_key)
        self.assertEqual(response.status_code, 200)

    def test_user_post_invalid_patient_not_invited(self):
        '''
        This method tests when you try to register a not invited patient.
        '''

        # Create the request
        context = {
            'name': self.name_invalid,
            'phone': self.phone_valid,
            'email': self.email,
            'password': self.password_invalid,
            'confirm_password': self.password_valid,
            'sex': self.sex_valid,
            'date_of_birth': self.date_of_birth_valid,
            'CPF_document': self.CPF_document_valid,
            'CEP': self.CEP_invalid,
            'UF': self.UF_valid,
            'city': self.city_valid,
            'neighborhood': self.neighborhood_valid,
            'complement': self.complement_invalid,
        }

        request = self.factory.post(
            '/user/register_patient/(?P<activation_key>\w+)/', context)
        request.user = AnonymousUser()
        setattr(request, 'session', {})
        setattr(request, '_messages', FallbackStorage(request))

        # Get the response
        response = RegisterPatientView.as_view()(
            request, activation_key=self.another_activation_key)
        self.assertEqual(response.status_code, 302)

    def test_user_post_invalid_patient_register_time_expired(self):
        '''
        This method tests when you try to register after the expiration date of the invitation.
        '''
        patient_profile = Patient.objects.get(email=self.email)
        SendInvitationProfile.objects.filter(patient=patient_profile).update(
            key_expires=self.key_expired)
        # Create the request
        context = {
            'name': self.name_invalid,
            'phone': self.phone_valid,
            'email': self.email,
            'password': self.password_invalid,
            'confirm_password': self.password_valid,
            'sex': self.sex_valid,
            'date_of_birth': self.date_of_birth_valid,
            'CPF_document': self.CPF_document_valid,
            'CEP': self.CEP_invalid,
            'UF': self.UF_valid,
            'city': self.city_valid,
            'neighborhood': self.neighborhood_valid,
            'complement': self.complement_invalid,
        }

        request = self.factory.post(
            '/user/register_patient/(?P<activation_key>\w+)/', context)
        request.user = AnonymousUser()
        setattr(request, 'session', {})
        setattr(request, '_messages', FallbackStorage(request))

        # Get the response
        response = RegisterPatientView.as_view()(
            request, activation_key=self.activation_key)
        self.assertEqual(response.status_code, 302)
Exemplo n.º 14
0
    def setUp(self):
        self.client = Client()
        self.factory = RequestFactory()
        self.patient = Patient()
        self.patient.pk = 1
        self.patient.name = "Paciente de teste"
        self.patient.date_of_birth = "1991-10-21"
        self.patient.phone = "06199999999"
        self.patient.email = "*****@*****.**"
        self.patient.sex = "M"
        self.patient.id_document = "1000331"
        self.patient.CEP = "72850735"
        self.patient.UF = "DF"
        self.patient.city = "Brasília"
        self.patient.neighborhood = "Asa sul"
        self.patient.complement = "Bloco 2 QD 701"
        self.patient.save()

        self.health_professional = HealthProfessional()
        self.health_professional.pk = 1
        self.health_professional.crm = '12345'
        self.health_professional.crm_state = 'US'
        self.health_professional.specialty_first = 'Nutricao'
        self.health_professional.specialty_second = 'Pediatria'
        self.health_professional.save()

        self.health_professional = HealthProfessional.objects.create_user(
            email='*****@*****.**', password='******')

        self.health_professional_no_specialty_second = HealthProfessional()
        self.health_professional_no_specialty_second.pk = 2
        self.health_professional_no_specialty_second.crm = '11111'
        self.health_professional_no_specialty_second.crm_state = 'US'
        self.health_professional_no_specialty_second.specialty_first = 'Nutricao'
        self.health_professional_no_specialty_second.specialty_second = 'Nao Possui'
        self.health_professional_no_specialty_second.email = '*****@*****.**'
        self.health_professional_no_specialty_second.password = '******'
        self.health_professional_no_specialty_second.save()

        self.disease = Disease()
        self.disease.pk = 1
        self.disease.id_cid_10 = "A01"
        self.disease.description = "A random disease"
        self.disease.save()

        self.prescription = NoPatientPrescription()
        self.prescription.pk = 1
        self.prescription.health_professional = self.health_professional
        self.prescription.cid = self.disease
        self.prescription.patient = "Algum nome"
        self.prescription.save()

        self.prescription_2 = NoPatientPrescription()
        self.prescription_2.pk = 2
        self.prescription_2.health_professional = self.health_professional
        self.prescription_2.cid = self.disease
        self.prescription_2.patient = "Algum nome"
        self.prescription_2.save()

        self.prescription_3 = PatientPrescription()
        self.prescription_3.pk = 3
        self.prescription_3.health_professional = self.health_professional
        self.prescription_3.cid = self.disease
        self.prescription_3.patient = self.patient
        self.prescription_3.save()

        self.prescription_4 = PatientPrescription()
        self.prescription_4.pk = 4
        self.prescription_4.health_professional = self.health_professional
        self.prescription_4.cid = self.disease
        self.prescription_4.patient = self.patient
        self.prescription_4.save()

        self.prescription_5 = PatientPrescription()
        self.prescription_5.pk = 5
        self.prescription_5.health_professional = self.health_professional
        self.prescription_5.cid = self.disease
        self.prescription_5.patient = self.patient
        self.prescription_5.save()

        self.prescription_6 = PatientPrescription()
        self.prescription_6.pk = 6
        self.prescription_6.health_professional = self.health_professional_no_specialty_second
        self.prescription_6.cid = self.disease
        self.prescription_6.patient = self.patient
        self.prescription_6.save()

        self.manipulated_medicine = ManipulatedMedicine()
        self.manipulated_medicine.pk = 1
        self.manipulated_medicine.recipe_name = "teste"
        self.manipulated_medicine.physical_form = "asdadsafdf"
        self.manipulated_medicine.quantity = 12
        self.manipulated_medicine.measurement = "kg"
        self.manipulated_medicine.composition = "aosdjoaisjdoiajsdoij"
        self.manipulated_medicine.health_professional = self.health_professional
        self.manipulated_medicine.save()

        self.manipulated_medicine_2 = ManipulatedMedicine()
        self.manipulated_medicine_2.pk = 2
        self.manipulated_medicine_2.recipe_name = "teste"
        self.manipulated_medicine_2.physical_form = "asdadsafdf"
        self.manipulated_medicine_2.quantity = 12
        self.manipulated_medicine_2.measurement = "kg"
        self.manipulated_medicine_2.composition = "aosdjoaisjdoiajsdoij"
        self.manipulated_medicine_2.health_professional = self.health_professional
        self.manipulated_medicine_2.save()

        self.hasmanipulated_medicine = PrescriptionHasManipulatedMedicine()
        self.hasmanipulated_medicine.manipulated_medicine = self.manipulated_medicine
        self.hasmanipulated_medicine.posology = "asd"
        self.hasmanipulated_medicine.quantity = 1
        self.hasmanipulated_medicine.pk = 2
        self.hasmanipulated_medicine.via = 'Via Intravenosa'
        self.hasmanipulated_medicine.prescription_medicine = self.prescription
        self.hasmanipulated_medicine.save()

        self.hasmanipulated_medicine = PrescriptionHasManipulatedMedicine()
        self.hasmanipulated_medicine.manipulated_medicine = self.manipulated_medicine_2
        self.hasmanipulated_medicine.posology = "asd"
        self.hasmanipulated_medicine.quantity = 1
        self.hasmanipulated_medicine.pk = 12
        self.hasmanipulated_medicine.via = 'Via Intravenosa'
        self.hasmanipulated_medicine.prescription_medicine = self.prescription
        self.hasmanipulated_medicine.save()

        self.hasmanipulated_medicine = PrescriptionHasManipulatedMedicine()
        self.hasmanipulated_medicine.manipulated_medicine = self.manipulated_medicine
        self.hasmanipulated_medicine.posology = "asd"
        self.hasmanipulated_medicine.quantity = 1
        self.hasmanipulated_medicine.pk = 4
        self.hasmanipulated_medicine.via = 'Via Intravenosa'
        self.hasmanipulated_medicine.prescription_medicine = self.prescription_2
        self.hasmanipulated_medicine.save()

        self.recommendation = NewRecommendation()
        self.recommendation.recommendation_description = "recomendacao de teste"
        self.recommendation.save()

        self.prescription_has_recommendation = PrescriptionNewRecommendation()
        self.prescription_has_recommendation.prescription = self.prescription
        self.prescription_has_recommendation.recommendation = self.recommendation
        self.prescription_has_recommendation.save()

        self.prescription_has_recommendation = PrescriptionNewRecommendation()
        self.prescription_has_recommendation.prescription = self.prescription_3
        self.prescription_has_recommendation.recommendation = self.recommendation
        self.prescription_has_recommendation.save()

        self.medicine = Medicine()
        self.medicine.name = "asdoajsdoiasj"
        self.medicine.active_ingredient = "dsofaksdofk"
        self.medicine.laboratory = "dofijasoifjjf"
        self.medicine.description = "oiajdoaisjddj"
        self.medicine.save()

        self.medicine_2 = Medicine()
        self.medicine_2.name = "asdoajsdoiasj"
        self.medicine_2.active_ingredient = "dsofaksdofk"
        self.medicine_2.laboratory = "dofijasoifjjf"
        self.medicine_2.description = "oiajdoaisjddj"
        self.medicine_2.save()

        self.prescription_has_medicine = PrescriptionHasMedicine()
        self.prescription_has_medicine.medicine = self.medicine
        self.prescription_has_medicine.posology = "asd"
        self.prescription_has_medicine.quantity = 1
        self.prescription_has_medicine.pk = 2
        self.prescription_has_medicine.via = 'Via Intravenosa'
        self.prescription_has_medicine.prescription_medicine = self.prescription
        self.prescription_has_medicine.save()

        self.prescription_has_medicine = PrescriptionHasMedicine()
        self.prescription_has_medicine.medicine = self.medicine_2
        self.prescription_has_medicine.posology = "asd"
        self.prescription_has_medicine.quantity = 1
        self.prescription_has_medicine.pk = 21
        self.prescription_has_medicine.via = 'Via Intravenosa'
        self.prescription_has_medicine.prescription_medicine = self.prescription
        self.prescription_has_medicine.save()

        self.default_exam = DefaultExam()
        self.default_exam.id_tuss = 'oiafj'
        self.default_exam.save()

        self.custom_exam = CustomExam()
        self.custom_exam.health_professional_FK = self.health_professional
        self.custom_exam.save()

        self.new_exam = NewExam()
        self.new_exam.exam_description = 'Test String'
        self.new_exam.save()

        self.prescription_default_exam = PrescriptionDefaultExam()
        self.prescription_default_exam.exam = self.default_exam
        self.prescription_default_exam.prescription = self.prescription
        self.prescription_default_exam.save()

        self.prescription_default_exam = PrescriptionDefaultExam()
        self.prescription_default_exam.exam = self.default_exam
        self.prescription_default_exam.prescription = self.prescription_4
        self.prescription_default_exam.save()

        self.prescription_custom_exam = PrescriptionCustomExam()
        self.prescription_custom_exam.exam = self.custom_exam
        self.prescription_custom_exam.prescription = self.prescription
        self.prescription_custom_exam.save()

        self.prescription_new_exam = PrescriptionNewExam()
        self.prescription_new_exam.exam = self.new_exam
        self.prescription_new_exam.prescription = self.prescription
        self.prescription_new_exam.save()

        self.pattern = Pattern()
        self.pattern.name = "Pattern de teste"
        self.pattern.user_creator = self.health_professional
        self.pattern.clinic = "clinica de teste"
        self.pattern.header = "header de teste"
        self.pattern.font = 'Helvetica'
        self.pattern.font_size = '12'
        self.pattern.footer = "footer de teste"
        self.pattern.pagesize = "letter"
        self.pattern.pk = 1
        self.pattern.logo = None
        self.pattern.save()

        self.pattern = Pattern()
        self.pattern.name = "Pattern de teste"
        self.pattern.user_creator = self.health_professional
        self.pattern.clinic = "clinica de teste"
        self.pattern.header = "header de teste"
        self.pattern.font = 'Helvetica'
        self.pattern.font_size = '12'
        self.pattern.footer = "footer de teste"
        self.pattern.pagesize = "A4"
        self.pattern.pk = 2
        self.pattern.logo = None
        self.pattern.save()

        self.pattern = Pattern()
        self.pattern.name = "Pattern de teste"
        self.pattern.user_creator = self.health_professional
        self.pattern.clinic = "clinica de teste"
        self.pattern.header = "header de teste"
        self.pattern.font = 'Helvetica'
        self.pattern.font_size = '12'
        self.pattern.footer = "footer de teste"
        self.pattern.pagesize = "A5"
        self.pattern.pk = 3
        self.pattern.logo = None
        self.pattern.save()
class TestComposeView(TestCase):
    """
    Testing methods of Class ComposeView.
    """
    def setUp(self):

        # Creating user in database.
        self.user = HealthProfessional()
        self.user.email = "*****@*****.**"
        self.user.save()

        self.patient = Patient()
        self.patient.email = "*****@*****.**"
        self.patient.save()

        self.link = AssociatedHealthProfessionalAndPatient()
        self.link.associated_health_professional = self.user
        self.link.associated_patient = self.patient
        self.link.is_active = True
        self.link.save()

        self.not_linked_patient = Patient()
        self.not_linked_patient.email = "*****@*****.**"
        self.not_linked_patient.save()

        self.subject = "a"
        self.text = "a"

        self.factory = RequestFactory()
        self.my_view = ComposeView()
        self.my_view_class = ComposeView
        self.client = Client()

    def test_chat_get(self):
        request = self.factory.get('/chat/compose/')
        request.user = self.user
        response = self.my_view.get(request)
        self.assertEqual(response.status_code, 200)

    def test_chat_post(self):
        request = self.factory.post('chat/compose',
                                    {'text': self.text,
                                     'subject': self.subject,
                                     'user_from': self.user.email,
                                     'user_to': self.patient.email
                                     })
        request.user = self.user

        response = self.my_view_class.as_view()(request)
        self.assertEqual(response.status_code, 302)

    def test_chat_post_invalid_user_to_health_professional(self):
        request = self.factory.post('chat/compose',
                                    {'text': self.text,
                                     'subject': self.subject,
                                     'user_from': self.user.email,
                                     'user_to': self.user.email
                                     })
        request.user = self.user

        response = self.my_view_class.as_view()(request)
        self.assertEqual(response.status_code, 200)

    def test_chat_post_invalid_user_to_not_linked(self):
        request = self.factory.post('chat/compose',
                                    {'text': 'a'*10000,
                                     'subject': 'test suject',
                                     'user_from': self.user.email,
                                     'user_to': self.not_linked_patient.email
                                     })
        request.user = self.user

        response = self.my_view_class.as_view()(request)
        self.assertEqual(response.status_code, 200)
Exemplo n.º 16
0
class TestPrintPrescriptionPatient(TestCase):
    def setUp(self):
        self.factory = RequestFactory()
        self.client = Client()
        self.view = PrintPrescriptionPatient.generate_pdf

        self.patient = Patient()
        self.patient.pk = 1
        self.patient.name = "Paciente de teste"
        self.patient.date_of_birth = "1991-10-21"
        self.patient.phone = "06199999999"
        self.patient.email = "*****@*****.**"
        self.patient.sex = "M"
        self.patient.id_document = "1000331"
        self.patient.CEP = "72850735"
        self.patient.UF = "DF"
        self.patient.city = "Brasília"
        self.patient.neighborhood = "Asa sul"
        self.patient.complement = "Bloco 2 QD 701"
        self.patient.save()

        self.health_professional = HealthProfessional()
        self.health_professional.pk = 1
        self.health_professional.crm = '12345'
        self.health_professional.crm_state = 'US'
        self.health_professional.specialty_first = 'Nutricao'
        self.health_professional.specialty_second = 'Pediatria'
        self.health_professional.email = '*****@*****.**'
        self.health_professional.password = '******'
        self.health_professional.save()

        self.health_professional_no_specialty_second = HealthProfessional()
        self.health_professional_no_specialty_second.pk = 2
        self.health_professional_no_specialty_second.crm = '11111'
        self.health_professional_no_specialty_second.crm_state = 'US'
        self.health_professional_no_specialty_second.specialty_first = 'Nutricao'
        self.health_professional_no_specialty_second.specialty_second = 'Nao Possui'
        self.health_professional_no_specialty_second.email = '*****@*****.**'
        self.health_professional_no_specialty_second.password = '******'
        self.health_professional_no_specialty_second.save()

        self.disease = Disease()
        self.disease.pk = 1
        self.disease.id_cid_10 = "A01"
        self.disease.description = "A random disease"
        self.disease.save()

        self.prescription = NoPatientPrescription()
        self.prescription.pk = 1
        self.prescription.health_professional = self.health_professional
        self.prescription.cid = self.disease
        self.prescription.patient = "Algum nome"
        self.prescription.save()

        self.prescription_2 = NoPatientPrescription()
        self.prescription_2.pk = 2
        self.prescription_2.health_professional = self.health_professional
        self.prescription_2.cid = self.disease
        self.prescription_2.patient = "Algum nome"
        self.prescription_2.save()

        self.prescription_3 = PatientPrescription()
        self.prescription_3.pk = 3
        self.prescription_3.health_professional = self.health_professional
        self.prescription_3.cid = self.disease
        self.prescription_3.patient = self.patient
        self.prescription_3.save()

        self.prescription_4 = PatientPrescription()
        self.prescription_4.pk = 4
        self.prescription_4.health_professional = self.health_professional
        self.prescription_4.cid = self.disease
        self.prescription_4.patient = self.patient
        self.prescription_4.save()

        self.prescription_5 = PatientPrescription()
        self.prescription_5.pk = 5
        self.prescription_5.health_professional = self.health_professional
        self.prescription_5.cid = self.disease
        self.prescription_5.patient = self.patient
        self.prescription_5.save()

        self.prescription_6 = PatientPrescription()
        self.prescription_6.pk = 6
        self.prescription_6.health_professional = self.health_professional_no_specialty_second
        self.prescription_6.cid = self.disease
        self.prescription_6.patient = self.patient
        self.prescription_6.save()

        self.manipulated_medicine = ManipulatedMedicine()
        self.manipulated_medicine.pk = 1
        self.manipulated_medicine.recipe_name = "teste"
        self.manipulated_medicine.physical_form = "asdadsafdf"
        self.manipulated_medicine.quantity = 12
        self.manipulated_medicine.measurement = "kg"
        self.manipulated_medicine.composition = "aosdjoaisjdoiajsdoij"
        self.manipulated_medicine.health_professional = self.health_professional
        self.manipulated_medicine.save()

        self.manipulated_medicine_2 = ManipulatedMedicine()
        self.manipulated_medicine_2.pk = 2
        self.manipulated_medicine_2.recipe_name = "teste"
        self.manipulated_medicine_2.physical_form = "asdadsafdf"
        self.manipulated_medicine_2.quantity = 12
        self.manipulated_medicine_2.measurement = "kg"
        self.manipulated_medicine_2.composition = "aosdjoaisjdoiajsdoij"
        self.manipulated_medicine_2.health_professional = self.health_professional
        self.manipulated_medicine_2.save()

        self.hasmanipulated_medicine = PrescriptionHasManipulatedMedicine()
        self.hasmanipulated_medicine.manipulated_medicine = self.manipulated_medicine
        self.hasmanipulated_medicine.posology = "asd"
        self.hasmanipulated_medicine.quantity = 1
        self.hasmanipulated_medicine.pk = 2
        self.hasmanipulated_medicine.via = 'Via Intravenosa'
        self.hasmanipulated_medicine.prescription_medicine = self.prescription
        self.hasmanipulated_medicine.save()

        self.hasmanipulated_medicine = PrescriptionHasManipulatedMedicine()
        self.hasmanipulated_medicine.manipulated_medicine = self.manipulated_medicine_2
        self.hasmanipulated_medicine.posology = "asd"
        self.hasmanipulated_medicine.quantity = 1
        self.hasmanipulated_medicine.pk = 12
        self.hasmanipulated_medicine.via = 'Via Intravenosa'
        self.hasmanipulated_medicine.prescription_medicine = self.prescription
        self.hasmanipulated_medicine.save()

        self.hasmanipulated_medicine = PrescriptionHasManipulatedMedicine()
        self.hasmanipulated_medicine.manipulated_medicine = self.manipulated_medicine
        self.hasmanipulated_medicine.posology = "asd"
        self.hasmanipulated_medicine.quantity = 1
        self.hasmanipulated_medicine.pk = 4
        self.hasmanipulated_medicine.via = 'Via Intravenosa'
        self.hasmanipulated_medicine.prescription_medicine = self.prescription_2
        self.hasmanipulated_medicine.save()

        self.recommendation = NewRecommendation()
        self.recommendation.recommendation_description = "recomendacao de teste"
        self.recommendation.save()

        self.prescription_has_recommendation = PrescriptionNewRecommendation()
        self.prescription_has_recommendation.prescription = self.prescription
        self.prescription_has_recommendation.recommendation = self.recommendation
        self.prescription_has_recommendation.save()

        self.prescription_has_recommendation = PrescriptionNewRecommendation()
        self.prescription_has_recommendation.prescription = self.prescription_3
        self.prescription_has_recommendation.recommendation = self.recommendation
        self.prescription_has_recommendation.save()

        self.medicine = Medicine()
        self.medicine.name = "asdoajsdoiasj"
        self.medicine.active_ingredient = "dsofaksdofk"
        self.medicine.laboratory = "dofijasoifjjf"
        self.medicine.description = "oiajdoaisjddj"
        self.medicine.save()

        self.medicine_2 = Medicine()
        self.medicine_2.name = "asdoajsdoiasj"
        self.medicine_2.active_ingredient = "dsofaksdofk"
        self.medicine_2.laboratory = "dofijasoifjjf"
        self.medicine_2.description = "oiajdoaisjddj"
        self.medicine_2.save()

        self.prescription_has_medicine = PrescriptionHasMedicine()
        self.prescription_has_medicine.medicine = self.medicine
        self.prescription_has_medicine.posology = "asd"
        self.prescription_has_medicine.quantity = 1
        self.prescription_has_medicine.pk = 2
        self.prescription_has_medicine.via = 'Via Intravenosa'
        self.prescription_has_medicine.prescription_medicine = self.prescription
        self.prescription_has_medicine.save()

        self.prescription_has_medicine = PrescriptionHasMedicine()
        self.prescription_has_medicine.medicine = self.medicine_2
        self.prescription_has_medicine.posology = "asd"
        self.prescription_has_medicine.quantity = 1
        self.prescription_has_medicine.pk = 21
        self.prescription_has_medicine.via = 'Via Intravenosa'
        self.prescription_has_medicine.prescription_medicine = self.prescription
        self.prescription_has_medicine.save()

        self.default_exam = DefaultExam()
        self.default_exam.id_tuss = 'oiafj'
        self.default_exam.save()

        self.custom_exam = CustomExam()
        self.custom_exam.health_professional_FK = self.health_professional
        self.custom_exam.save()

        self.prescription_default_exam = PrescriptionDefaultExam()
        self.prescription_default_exam.exam = self.default_exam
        self.prescription_default_exam.prescription = self.prescription
        self.prescription_default_exam.save()

        self.prescription_default_exam = PrescriptionDefaultExam()
        self.prescription_default_exam.exam = self.default_exam
        self.prescription_default_exam.prescription = self.prescription_4
        self.prescription_default_exam.save()

        self.prescription_custom_exam = PrescriptionCustomExam()
        self.prescription_custom_exam.exam = self.custom_exam
        self.prescription_custom_exam.prescription = self.prescription
        self.prescription_custom_exam.save()

    def test_print_prescription_get_no_second_speciality(self):
        request = self.factory.get('/prescription/print_prescription/1/3')
        response = self.view(request, pk=6)
        self.assertEqual(response.status_code, 200)

    def test_print_prescription(self):
        request = self.factory.get('/prescription/print_prescription/1/3')
        response = self.view(request, pk=1)
        self.assertEqual(response.status_code, 200)

    def test_print_prescription_get_invalid_medicine(self):
        request = self.factory.get('/prescription/print_prescription/2')
        response = self.view(request, pk=2)
        self.assertEqual(response.status_code, 200)

    def test_print_prescription_get_invalid_recommendation(self):
        request = self.factory.get('/prescription/print_prescription/3')
        response = self.view(request, pk=3)
        self.assertEqual(response.status_code, 200)

    def test_print_prescription_get_invalid_exam(self):
        request = self.factory.get('/prescription/print_prescription/4')
        response = self.view(request, pk=4)
        self.assertEqual(response.status_code, 200)

    def test_print_prescription_get_invalid(self):
        request = self.factory.get('/prescription/print_prescription/3')
        response = self.view(request, pk=3)
        self.assertEqual(response.status_code, 200)
class TestCreateMessageForm(TestCase):
    def setUp(self):
        self.health_professional = HealthProfessional()
        self.health_professional.email = "*****@*****.**"
        self.health_professional.pk = 0
        self.health_professional.save()

        self.patient = Patient()
        self.patient.email = "*****@*****.**"
        self.patient.save()

        self.link = AssociatedHealthProfessionalAndPatient()
        self.link.associated_health_professional = self.health_professional
        self.link.associated_patient = self.patient
        self.link.is_active = True
        self.link.save()

        self.not_linked_patient = Patient.objects.create(
            email="*****@*****.**")

        self.subject = "a"
        self.text = "a"
        self.subject_max = 'a' * 1000
        self.text_max = 'a' * 1000
        self.email_invalid = 'a2d'

    def test_valid(self):
        upload_file = open('public/image_profile/user.png', 'rb')
        file_dict = {
            'file': SimpleUploadedFile(upload_file.name, upload_file.read())
        }
        form_data = {
            'subject': self.subject,
            'text': self.text,
            'files': file_dict,
            'user_to': self.patient.email,
        }
        form = CreateMessage(data=form_data)
        self.assertTrue(form.is_valid())

    def test_chat_invalid_subject(self):
        form_data = {
            'subject': self.subject_max,
            'text': self.text,
            'user_to': self.patient.email,
            'pk': self.health_professional.pk
        }
        form = CreateMessage(data=form_data)
        self.assertFalse(form.is_valid())

    def test_chat_invalid_text(self):
        form_data = {
            'subject': self.subject,
            'text': self.text_max,
            'user_to': self.patient.email,
        }
        form = CreateMessage(data=form_data)
        self.assertFalse(form.is_valid())

    def test_chat_invalid_email(self):
        form_data = {
            'subject': self.subject,
            'text': self.text,
            'user_to': self.email_invalid,
        }
        form = CreateMessage(data=form_data)
        self.assertFalse(form.is_valid())

    def test_invalid_email_health_professional(self):
        form_data = {
            'subject': self.subject,
            'text': self.text,
            'user_to': self.health_professional.email,
        }
        form = CreateMessage(data=form_data)
        self.assertFalse(form.is_valid())

    def test_link_does_not_exists(self):
        form_data = {
            'subject': self.subject,
            'text': self.text,
            'user_to': self.not_linked_patient.email,
        }
        form = CreateMessage(data=form_data)
        self.assertFalse(form.is_valid())

    def test_chat_invalid_subject_None(self):
        form_data = {
            'subject': None,
            'text': self.text,
            'user_to': self.email_invalid
        }
        form = CreateMessage(data=form_data)
        self.assertFalse(form.is_valid())

    def test_chat_invalid_text_None(self):
        form_data = {
            'subject': self.subject,
            'text': None,
            'user_to': self.email_invalid
        }
        form = CreateMessage(data=form_data)
        self.assertFalse(form.is_valid())
    def setUp(self):
        self.factory = RequestFactory()
        self.client = Client()
        self.view = CreateCopyPrescription()

        self.patient = Patient()
        self.patient.pk = 1
        self.patient.name = "Paciente de teste"
        self.patient.date_of_birth = "1991-10-21"
        self.patient.phone = "06199999999"
        self.patient.email = "*****@*****.**"
        self.patient.sex = "M"
        self.patient.id_document = "1000331"
        self.patient.CEP = "72850735"
        self.patient.UF = "DF"
        self.patient.city = "Brasília"
        self.patient.neighborhood = "Asa sul"
        self.patient.complement = "Bloco 2 QD 701"
        self.patient.save()

        self.health_professional = HealthProfessional()
        self.health_professional.pk = 1
        self.health_professional.crm = '12345'
        self.health_professional.crm_state = 'US'
        self.health_professional.save()

        self.medicine = Medicine()
        self.medicine.name = "Medicamento Teste"
        self.medicine.active_ingredient = "Teste Lab"
        self.medicine.save()

        self.manipulated_medicine = ManipulatedMedicine()
        self.manipulated_medicine.pk = 1
        self.manipulated_medicine.recipe_name = "teste"
        self.manipulated_medicine.physical_form = "asdadsafdf"
        self.manipulated_medicine.quantity = 12
        self.manipulated_medicine.measurement = "kg"
        self.manipulated_medicine.composition = "aosdjoaisjdoiajsdoij"
        self.manipulated_medicine.health_professional = self.health_professional
        self.manipulated_medicine.save()

        self.disease = Disease()
        self.disease.pk = 1
        self.disease.id_cid_10 = "A01"
        self.disease.description = "A random disease"
        self.disease.save()

        self.health_professional_2 = HealthProfessional.objects.create_user(email='*****@*****.**',
                                                                            password='******')

        self.nopatientprescription = NoPatientPrescription()
        self.nopatientprescription.patient = self.patient
        self.nopatientprescription.cid = self.disease
        self.nopatientprescription.health_professional = self.health_professional_2
        self.nopatientprescription.patient = "Junior Marques"
        self.nopatientprescription.save()

        self.patientprescription = PatientPrescription()
        self.patientprescription.patient = self.patient
        self.patientprescription.cid = self.disease
        self.patientprescription.health_professional = self.health_professional_2
        self.patientprescription.patient = self.patient
        self.patientprescription.save()

        self.posology = "Medicamento de Teste"
        self.quantity = 1
        self.via = constants.VIA_CHOICES[0][0]

        self.has_medicine = PrescriptionHasMedicine()
        self.has_medicine.prescription_medicine = self.nopatientprescription.prescription_ptr
        self.has_medicine.medicine = self.medicine
        self.has_medicine.posology = self.posology
        self.has_medicine.via = self.via
        self.has_medicine.quantity = self.quantity
        self.has_medicine.save()

        self.has_manipulated = PrescriptionHasManipulatedMedicine()
        self.has_manipulated.prescription_medicine = self.nopatientprescription.prescription_ptr
        self.has_manipulated.manipulated_medicine = self.manipulated_medicine
        self.has_manipulated.posology = self.posology
        self.has_manipulated.via = self.via
        self.has_manipulated.quantity = self.quantity
        self.has_manipulated.save()

        self.manipulated_medicine = ManipulatedMedicine()
        self.manipulated_medicine.pk = 1
        self.manipulated_medicine.recipe_name = "teste"
        self.manipulated_medicine.physical_form = "asdadsafdf"
        self.manipulated_medicine.quantity = 12
        self.manipulated_medicine.measurement = "kg"
        self.manipulated_medicine.composition = "aosdjoaisjdoiajsdoij"
        self.manipulated_medicine.health_professional = self.health_professional
        self.manipulated_medicine.save()

        self.hasmanipulated_medicine = PrescriptionHasManipulatedMedicine()
        self.hasmanipulated_medicine.manipulated_medicine = self.manipulated_medicine
        self.hasmanipulated_medicine.posology = "asd"
        self.hasmanipulated_medicine.quantity = 1
        self.hasmanipulated_medicine.pk = 2
        self.hasmanipulated_medicine.via = 'Via Intravenosa'
        self.hasmanipulated_medicine.prescription_medicine = self.nopatientprescription.prescription_ptr
        self.hasmanipulated_medicine.save()

        self.hasmanipulated_medicine = PrescriptionHasManipulatedMedicine()
        self.hasmanipulated_medicine.manipulated_medicine = self.manipulated_medicine
        self.hasmanipulated_medicine.posology = "asd"
        self.hasmanipulated_medicine.quantity = 1
        self.hasmanipulated_medicine.pk = 12
        self.hasmanipulated_medicine.via = 'Via Intravenosa'
        self.hasmanipulated_medicine.prescription_medicine = self.nopatientprescription.prescription_ptr
        self.hasmanipulated_medicine.save()

        self.recommendation = NewRecommendation()
        self.recommendation.recommendation_description = "recomendacao de teste"
        self.recommendation.save()

        self.prescription_has_recommendation = PrescriptionNewRecommendation()
        self.prescription_has_recommendation.prescription = self.nopatientprescription.prescription_ptr
        self.prescription_has_recommendation.recommendation = self.recommendation
        self.prescription_has_recommendation.save()

        self.prescription_has_recommendation = PrescriptionNewRecommendation()
        self.prescription_has_recommendation.prescription = self.nopatientprescription.prescription_ptr
        self.prescription_has_recommendation.recommendation = self.recommendation
        self.prescription_has_recommendation.save()

        self.medicine = Medicine()
        self.medicine.name = "asdoajsdoiasj"
        self.medicine.active_ingredient = "dsofaksdofk"
        self.medicine.laboratory = "dofijasoifjjf"
        self.medicine.description = "oiajdoaisjddj"
        self.medicine.save()

        self.prescription_has_medicine = PrescriptionHasMedicine()
        self.prescription_has_medicine.medicine = self.medicine
        self.prescription_has_medicine.posology = "asd"
        self.prescription_has_medicine.quantity = 1
        self.prescription_has_medicine.pk = 2
        self.prescription_has_medicine.via = 'Via Intravenosa'
        self.prescription_has_medicine.prescription_medicine = self.nopatientprescription.prescription_ptr
        self.prescription_has_medicine.save()

        self.default_exam = DefaultExam()
        self.default_exam.id_tuss = 'oiafj'
        self.default_exam.save()

        self.custom_exam = CustomExam()
        self.custom_exam.health_professional_FK = self.health_professional
        self.custom_exam.save()

        self.prescription_default_exam = PrescriptionDefaultExam()
        self.prescription_default_exam.exam = self.default_exam
        self.prescription_default_exam.prescription = self.nopatientprescription.prescription_ptr
        self.prescription_default_exam.save()

        self.prescription_custom_exam = PrescriptionCustomExam()
        self.prescription_custom_exam.exam = self.custom_exam
        self.prescription_custom_exam.prescription = self.nopatientprescription.prescription_ptr
        self.prescription_custom_exam.save()
Exemplo n.º 19
0
class TestCreatePrescription(TestCase):
    def setUp(self):
        self.factory = RequestFactory()
        self.client = Client()
        self.view = CreatePrescriptionView()

        self.patient = Patient()
        self.patient.pk = 1
        self.patient.name = "Paciente de teste"
        self.patient.date_of_birth = "1991-10-21"
        self.patient.phone = "06199999999"
        self.patient.email = "*****@*****.**"
        self.patient.sex = "M"
        self.patient.id_document = "1000331"
        self.patient.CEP = "72850735"
        self.patient.UF = "DF"
        self.patient.city = "Brasília"
        self.patient.neighborhood = "Asa sul"
        self.patient.complement = "Bloco 2 QD 701"
        self.patient.is_active = True
        self.patient.save()

        self.health_professional = HealthProfessional()
        self.health_professional.pk = 1
        self.health_professional.crm = '12345'
        self.health_professional.crm_state = 'US'
        self.health_professional.is_active = True
        self.health_professional.save()

        self.manipulated_medicine = ManipulatedMedicine()
        self.manipulated_medicine.pk = 1
        self.manipulated_medicine.recipe_name = "teste"
        self.manipulated_medicine.physical_form = "asdadsafdf"
        self.manipulated_medicine.quantity = 12
        self.manipulated_medicine.measurement = "kg"
        self.manipulated_medicine.composition = "aosdjoaisjdoiajsdoij"
        self.manipulated_medicine.health_professional = self.health_professional
        self.manipulated_medicine.save()

        self.disease = Disease()
        self.disease.pk = 1
        self.disease.id_cid_10 = "A01"
        self.disease.description = "A random disease"
        self.disease.save()

        self.health_professional = HealthProfessional.objects.create_user(
            email='*****@*****.**', password='******')

        self.relation = AssociatedHealthProfessionalAndPatient()
        self.relation.associated_health_professional = self.health_professional
        self.relation.associated_patient = self.patient
        self.relation.is_active = True
        self.relation.save()

        self.not_patient = Patient()
        self.not_patient.email = "*****@*****.**"
        self.not_patient.is_active = True
        self.not_patient.save()

        self.patient_not_actived = Patient()
        self.patient_not_actived.email = "*****@*****.**"
        self.patient_not_actived.is_active = False
        self.patient_not_actived.save()

        self.invitation = SendInvitationProfile()
        self.invitation.patient = self.patient_not_actived
        self.invitation.save()

    def test_prescription_get(self):
        request = self.factory.get('/prescription/create_modal/')
        response = self.view.get(request)
        self.assertEqual(response.status_code, 200)

    @patch('prescription.models.NoPatientPrescription.save',
           MagicMock(name="save"))
    @patch('prescription.models.PrescriptionNewRecommendation.save',
           MagicMock(name="save"))
    def test_prescription_post_with_health_professional(self):
        context = {
            'form_medicine-TOTAL_FORMS': 1,
            'form_medicine-INITIAL_FORMS': 0,
            'form_recommendation-TOTAL_FORMS': 1,
            'form_recommendation-INITIAL_FORMS': 0,
            'form_exam-TOTAL_FORMS': 1,
            'form_exam-INITIAL_FORMS': 0,
            'patient': "JOAO",
            'patient_id': 0,
            'cid_id': 1,
            'medicine_type': 'manipulated_medicine',
            'medicine_id': 1,
            'quantity': 10,
            'posology': 'nao fazer nada',
            'via': 'Via oral',
        }

        request = self.factory.post('/prescription/create_modal/', context)
        request.user = self.health_professional

        # Get the response
        response = CreatePrescriptionView.as_view()(request)
        self.assertEqual(response.status_code, 200)

        # # Check save was called
        self.assertTrue(NoPatientPrescription.save.called)
        self.assertEqual(NoPatientPrescription.save.call_count, 1)

    @patch('prescription.models.PatientPrescription.save',
           MagicMock(name="save"))
    @patch('prescription.models.PrescriptionNewRecommendation.save',
           MagicMock(name="save"))
    def test_prescription_post_with_health_professional_patient(self):
        context = {
            'form_medicine-TOTAL_FORMS': 1,
            'form_medicine-INITIAL_FORMS': 0,
            'form_recommendation-TOTAL_FORMS': 1,
            'form_recommendation-INITIAL_FORMS': 0,
            'form_exam-TOTAL_FORMS': 1,
            'form_exam-INITIAL_FORMS': 0,
            'patient': "JOAO",
            'patient_id': 1,
            'email': self.patient.email,
            'cid_id': 1,
            'medicine_type': 'manipulated_medicine',
            'medicine_id': 1,
            'quantity': 10,
            'posology': 'nao fazer nada',
            'via': 'Via oral',
        }

        request = self.factory.post('/prescription/create_modal/', context)
        request.user = self.health_professional

        # Get the response
        response = CreatePrescriptionView.as_view()(request)
        self.assertEqual(response.status_code, 200)

        # # Check save was called
        self.assertTrue(PatientPrescription.save.called)
        self.assertEqual(PatientPrescription.save.call_count, 1)

    @patch('prescription.models.PatientPrescription.save',
           MagicMock(name="save"))
    @patch('prescription.models.PrescriptionNewRecommendation.save',
           MagicMock(name="save"))
    def test_prescription_post_with_patient_not_linked(self):
        context = {
            'form_medicine-TOTAL_FORMS': 1,
            'form_medicine-INITIAL_FORMS': 0,
            'form_recommendation-TOTAL_FORMS': 1,
            'form_recommendation-INITIAL_FORMS': 0,
            'form_exam-TOTAL_FORMS': 1,
            'form_exam-INITIAL_FORMS': 0,
            'patient': "JOAO",
            'email': self.not_patient.email,
            'cid_id': 1,
            'medicine_type': 'manipulated_medicine',
            'medicine_id': 1,
            'quantity': 10,
            'posology': 'nao fazer nada',
            'via': 'Via oral',
        }

        request = self.factory.post('/prescription/create_modal/', context)
        request.user = self.health_professional

        # Get the response
        response = CreatePrescriptionView.as_view()(request)
        self.assertEqual(response.status_code, 200)

        # Checking the creation of link between users.
        link = AssociatedHealthProfessionalAndPatient.objects.filter(
            associated_health_professional=self.health_professional,
            associated_patient=self.not_patient)
        self.assertTrue(link.exists())
        self.assertTrue(link.first().is_active)

        # # Check save was called
        self.assertTrue(PatientPrescription.save.called)
        self.assertEqual(PatientPrescription.save.call_count, 1)

    @patch('prescription.models.PatientPrescription.save',
           MagicMock(name="save"))
    @patch('prescription.models.PrescriptionNewRecommendation.save',
           MagicMock(name="save"))
    def test_prescription_post_with_patient_doesnt_exist(self):
        context = {
            'form_medicine-TOTAL_FORMS': 1,
            'form_medicine-INITIAL_FORMS': 0,
            'form_recommendation-TOTAL_FORMS': 1,
            'form_recommendation-INITIAL_FORMS': 0,
            'form_exam-TOTAL_FORMS': 1,
            'form_exam-INITIAL_FORMS': 0,
            'patient': "JOAO",
            'email': "*****@*****.**",
            'cid_id': 1,
            'medicine_type': 'manipulated_medicine',
            'medicine_id': 1,
            'quantity': 10,
            'posology': 'nao fazer nada',
            'via': 'Via oral',
        }

        request = self.factory.post('/prescription/create_modal/', context)
        request.user = self.health_professional

        # Get the response
        response = CreatePrescriptionView.as_view()(request)
        self.assertEqual(response.status_code, 200)

        # Checking the creation of patient not existence.
        patient = Patient.objects.filter(email="*****@*****.**")
        self.assertTrue(patient.exists())

        # Checking the creation of link between users.
        link = AssociatedHealthProfessionalAndPatient.objects.filter(
            associated_health_professional=self.health_professional,
            associated_patient=patient.first())
        self.assertTrue(link.exists())
        self.assertFalse(link.first().is_active)

        # Check save was called
        self.assertTrue(PatientPrescription.save.called)
        self.assertEqual(PatientPrescription.save.call_count, 1)

    @patch('prescription.models.PatientPrescription.save',
           MagicMock(name="save"))
    @patch('prescription.models.PrescriptionNewRecommendation.save',
           MagicMock(name="save"))
    def test_prescription_post_with_patient_not_actived(self):
        context = {
            'form_medicine-TOTAL_FORMS': 1,
            'form_medicine-INITIAL_FORMS': 0,
            'form_recommendation-TOTAL_FORMS': 1,
            'form_recommendation-INITIAL_FORMS': 0,
            'form_exam-TOTAL_FORMS': 1,
            'form_exam-INITIAL_FORMS': 0,
            'patient': "JOAO",
            'email': self.patient_not_actived.email,
            'cid_id': 1,
            'medicine_type': 'manipulated_medicine',
            'medicine_id': 1,
            'quantity': 10,
            'posology': 'nao fazer nada',
            'via': 'Via oral',
        }

        request = self.factory.post('/prescription/create_modal/', context)
        request.user = self.health_professional

        # Get the response
        response = CreatePrescriptionView.as_view()(request)
        self.assertEqual(response.status_code, 200)

        # # Check save was called
        self.assertTrue(PatientPrescription.save.called)
        self.assertEqual(PatientPrescription.save.call_count, 1)

    def test_prescription_get_with_health_professional(self):

        request = self.factory.post('/prescription/create_modal/')
        request.user = self.health_professional

        # Get the response
        response = CreatePrescriptionView.as_view()(request)
        self.assertEqual(response.status_code, 200)
Exemplo n.º 20
0
    def setUp(self):
        self.factory = RequestFactory()
        self.client = Client()
        self.view = CreatePrescriptionView()

        self.patient = Patient()
        self.patient.pk = 1
        self.patient.name = "Paciente de teste"
        self.patient.date_of_birth = "1991-10-21"
        self.patient.phone = "06199999999"
        self.patient.email = "*****@*****.**"
        self.patient.sex = "M"
        self.patient.id_document = "1000331"
        self.patient.CEP = "72850735"
        self.patient.UF = "DF"
        self.patient.city = "Brasília"
        self.patient.neighborhood = "Asa sul"
        self.patient.complement = "Bloco 2 QD 701"
        self.patient.is_active = True
        self.patient.save()

        self.health_professional = HealthProfessional()
        self.health_professional.pk = 1
        self.health_professional.crm = '12345'
        self.health_professional.crm_state = 'US'
        self.health_professional.is_active = True
        self.health_professional.save()

        self.manipulated_medicine = ManipulatedMedicine()
        self.manipulated_medicine.pk = 1
        self.manipulated_medicine.recipe_name = "teste"
        self.manipulated_medicine.physical_form = "asdadsafdf"
        self.manipulated_medicine.quantity = 12
        self.manipulated_medicine.measurement = "kg"
        self.manipulated_medicine.composition = "aosdjoaisjdoiajsdoij"
        self.manipulated_medicine.health_professional = self.health_professional
        self.manipulated_medicine.save()

        self.disease = Disease()
        self.disease.pk = 1
        self.disease.id_cid_10 = "A01"
        self.disease.description = "A random disease"
        self.disease.save()

        self.health_professional = HealthProfessional.objects.create_user(
            email='*****@*****.**', password='******')

        self.relation = AssociatedHealthProfessionalAndPatient()
        self.relation.associated_health_professional = self.health_professional
        self.relation.associated_patient = self.patient
        self.relation.is_active = True
        self.relation.save()

        self.not_patient = Patient()
        self.not_patient.email = "*****@*****.**"
        self.not_patient.is_active = True
        self.not_patient.save()

        self.patient_not_actived = Patient()
        self.patient_not_actived.email = "*****@*****.**"
        self.patient_not_actived.is_active = False
        self.patient_not_actived.save()

        self.invitation = SendInvitationProfile()
        self.invitation.patient = self.patient_not_actived
        self.invitation.save()