Search in sources :

Example 11 with Allergies

use of org.openmrs.Allergies in project openmrs-core by openmrs.

the class AllergyValidatorTest method validate_shouldRejectADuplicateNonCodedAllergen.

/**
 * @see AllergyValidator#validate(Object, org.springframework.validation.Errors)
 */
@Test
public void validate_shouldRejectADuplicateNonCodedAllergen() {
    PowerMockito.mockStatic(Context.class);
    MessageSourceService ms = mock(MessageSourceService.class);
    when(Context.getMessageSourceService()).thenReturn(ms);
    Allergies allergies = new Allergies();
    Concept nonCodedConcept = createMockConcept(getOtherNonCodedConceptUuid());
    final String freeText = "some text";
    Allergen allergen1 = new Allergen(AllergenType.DRUG, nonCodedConcept, freeText);
    allergies.add(new Allergy(null, allergen1, null, null, null));
    when(ps.getAllergies(any(Patient.class))).thenReturn(allergies);
    Allergen duplicateAllergen = new Allergen(AllergenType.FOOD, nonCodedConcept, freeText);
    Allergy allergy = new Allergy(mock(Patient.class), duplicateAllergen, null, null, null);
    Errors errors = new BindException(allergy, "allergy");
    validator.validate(allergy, errors);
    assertTrue(errors.hasFieldErrors("allergen"));
    assertThat(errors.getFieldError("allergen").getCode(), is("allergyapi.message.duplicateAllergen"));
}
Also used : Concept(org.openmrs.Concept) Allergy(org.openmrs.Allergy) Errors(org.springframework.validation.Errors) MessageSourceService(org.openmrs.messagesource.MessageSourceService) Patient(org.openmrs.Patient) BindException(org.springframework.validation.BindException) Allergies(org.openmrs.Allergies) Allergen(org.openmrs.Allergen) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 12 with Allergies

use of org.openmrs.Allergies in project openmrs-core by openmrs.

the class AllergyValidatorTest method validate_shouldRejectADuplicateAllergen.

/**
 * @see AllergyValidator#validate(Object, org.springframework.validation.Errors)
 */
@Test
public void validate_shouldRejectADuplicateAllergen() {
    PowerMockito.mockStatic(Context.class);
    MessageSourceService ms = mock(MessageSourceService.class);
    when(Context.getMessageSourceService()).thenReturn(ms);
    Allergies allergies = new Allergies();
    Concept aspirin = createMockConcept();
    Allergen allergen1 = new Allergen(AllergenType.DRUG, aspirin, null);
    allergies.add(new Allergy(null, allergen1, null, null, null));
    when(ps.getAllergies(any(Patient.class))).thenReturn(allergies);
    Allergen duplicateAllergen = new Allergen(AllergenType.FOOD, aspirin, null);
    Allergy allergy = new Allergy(mock(Patient.class), duplicateAllergen, null, null, null);
    Errors errors = new BindException(allergy, "allergy");
    validator.validate(allergy, errors);
    assertTrue(errors.hasFieldErrors("allergen"));
    assertThat(errors.getFieldError("allergen").getCode(), is("allergyapi.message.duplicateAllergen"));
}
Also used : Concept(org.openmrs.Concept) Allergy(org.openmrs.Allergy) Errors(org.springframework.validation.Errors) MessageSourceService(org.openmrs.messagesource.MessageSourceService) Patient(org.openmrs.Patient) BindException(org.springframework.validation.BindException) Allergies(org.openmrs.Allergies) Allergen(org.openmrs.Allergen) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 13 with Allergies

use of org.openmrs.Allergies in project openmrs-core by openmrs.

the class PatientServiceAllergyTest method setAllergies_shouldVoidAllergiesWithEditedReactionNonCoded.

/**
 * @see PatientService#setAllergies(Patient,Allergies)
 */
@Test
public void setAllergies_shouldVoidAllergiesWithEditedReactionNonCoded() {
    // get a patient with some allergies
    Patient patient = allergyService.getPatient(2);
    Allergies allergies = allergyService.getAllergies(patient);
    Assert.assertEquals(Allergies.SEE_LIST, allergies.getAllergyStatus());
    Assert.assertEquals(4, allergies.size());
    Allergy editedAllergy = allergies.get(0);
    // clear any cache for this object such that the next calls fetch it from the database
    Context.evictFromSession(editedAllergy);
    // edit a reaction
    AllergyReaction reaction = editedAllergy.getReactions().get(0);
    reaction.setReactionNonCoded("some non coded text");
    Assert.assertTrue(allergies.contains(editedAllergy));
    allergyService.setAllergies(patient, allergies);
    // should remain with four unvoided allergies and status maintained as see list
    allergies = allergyService.getAllergies(patient);
    Assert.assertEquals(Allergies.SEE_LIST, allergies.getAllergyStatus());
    Assert.assertEquals(4, allergies.size());
    // the edited allergy should have been voided
    Assert.assertFalse(allergies.contains(editedAllergy));
}
Also used : Allergy(org.openmrs.Allergy) Patient(org.openmrs.Patient) AllergyReaction(org.openmrs.AllergyReaction) Allergies(org.openmrs.Allergies) Test(org.junit.Test) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest)

Example 14 with Allergies

use of org.openmrs.Allergies in project openmrs-core by openmrs.

the class PatientServiceAllergyTest method setAllergies_shouldSetStatusToNoKnownAllergiesForPatientWithoutAllergies.

/**
 * @see PatientService#setAllergies(Patient,Allergies)
 */
@Test
public void setAllergies_shouldSetStatusToNoKnownAllergiesForPatientWithoutAllergies() {
    // get a patient without any allergies
    Patient patient = allergyService.getPatient(7);
    Allergies allergies = allergyService.getAllergies(patient);
    Assert.assertEquals(Allergies.UNKNOWN, allergies.getAllergyStatus());
    Assert.assertEquals(0, allergies.size());
    // confirm that patient has no known allergies
    allergies = new Allergies();
    allergies.confirmNoKnownAllergies();
    allergyService.setAllergies(patient, allergies);
    // now the patient should have the no known allergies status
    allergies = allergyService.getAllergies(patient);
    Assert.assertEquals(Allergies.NO_KNOWN_ALLERGIES, allergies.getAllergyStatus());
    Assert.assertEquals(0, allergies.size());
}
Also used : Patient(org.openmrs.Patient) Allergies(org.openmrs.Allergies) Test(org.junit.Test) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest)

Example 15 with Allergies

use of org.openmrs.Allergies in project openmrs-core by openmrs.

the class PatientServiceAllergyTest method setAllergies_shouldVoidAllergiesWithEditedComment.

/**
 * @see PatientService#setAllergies(Patient,Allergies)
 */
@Test
public void setAllergies_shouldVoidAllergiesWithEditedComment() {
    // get a patient with some allergies
    Patient patient = allergyService.getPatient(2);
    Allergies allergies = allergyService.getAllergies(patient);
    Assert.assertEquals(Allergies.SEE_LIST, allergies.getAllergyStatus());
    Assert.assertEquals(4, allergies.size());
    Allergy editedAllergy = allergies.get(0);
    // clear any cache for this object such that the next calls fetch it from the database
    Context.evictFromSession(editedAllergy);
    // edit comment
    editedAllergy.setComment("edited comment");
    Assert.assertTrue(allergies.contains(editedAllergy));
    allergyService.setAllergies(patient, allergies);
    // should remain with four unvoided allergies and status maintained as see list
    allergies = allergyService.getAllergies(patient);
    Assert.assertEquals(Allergies.SEE_LIST, allergies.getAllergyStatus());
    Assert.assertEquals(4, allergies.size());
    // the edited allergy should have been voided
    Assert.assertFalse(allergies.contains(editedAllergy));
}
Also used : Allergy(org.openmrs.Allergy) Patient(org.openmrs.Patient) Allergies(org.openmrs.Allergies) Test(org.junit.Test) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest)

Aggregations

Allergies (org.openmrs.Allergies)20 Test (org.junit.Test)18 Patient (org.openmrs.Patient)18 Allergy (org.openmrs.Allergy)15 BaseContextSensitiveTest (org.openmrs.test.BaseContextSensitiveTest)15 Concept (org.openmrs.Concept)9 Allergen (org.openmrs.Allergen)6 AllergyReaction (org.openmrs.AllergyReaction)5 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)3 BindException (org.springframework.validation.BindException)3 Errors (org.springframework.validation.Errors)3 MessageSourceService (org.openmrs.messagesource.MessageSourceService)2 Transactional (org.springframework.transaction.annotation.Transactional)1