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"));
}
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"));
}
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));
}
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());
}
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));
}
Aggregations