use of org.openmrs.Allergies in project openmrs-core by openmrs.
the class PatientServiceAllergyTest method setAllergies_shouldVoidAllergiesWithEditedReactionCoded.
/**
* @see PatientService#setAllergies(Patient,Allergies)
*/
@Test
public void setAllergies_shouldVoidAllergiesWithEditedReactionCoded() {
// 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.setReaction(new Concept(11));
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 getAllergies_shouldGetTheAllergyListAndStatus.
/**
* @see PatientService#getAllergies(Patient)
*/
@Test
public void getAllergies_shouldGetTheAllergyListAndStatus() {
// 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());
// should properly load reactions
Assert.assertEquals(2, allergies.get(0).getReactions().size());
Assert.assertEquals(2, allergies.get(1).getReactions().size());
Assert.assertEquals(0, allergies.get(2).getReactions().size());
Assert.assertEquals(0, allergies.get(3).getReactions().size());
// get a patient without allergies
patient = allergyService.getPatient(6);
allergies = allergyService.getAllergies(patient);
Assert.assertEquals(Allergies.UNKNOWN, allergies.getAllergyStatus());
Assert.assertEquals(0, allergies.size());
}
use of org.openmrs.Allergies in project openmrs-core by openmrs.
the class PatientServiceAllergyTest method setAllergies_shouldVoidRemovedAllergiesAndMaintainStatusAsSeeListIfSomeAllergiesAreRemoved.
/**
* @see PatientService#setAllergies(Patient,Allergies)
*/
@Test
public void setAllergies_shouldVoidRemovedAllergiesAndMaintainStatusAsSeeListIfSomeAllergiesAreRemoved() {
// 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());
// remove one allergy
allergies.remove(0);
// remove one reaction out of the two
allergies.get(0).getReactions().remove(0);
// add a reaction to the third allergy
AllergyReaction reaction = new AllergyReaction(null, new Concept(22), null);
allergies.get(2).addReaction(reaction);
allergyService.setAllergies(patient, allergies);
// should remain with three un voided allergies and status maintained as see list
allergies = allergyService.getAllergies(patient);
Assert.assertEquals(Allergies.SEE_LIST, allergies.getAllergyStatus());
Assert.assertEquals(3, allergies.size());
Assert.assertEquals(1, allergies.get(0).getReactions().size());
Assert.assertEquals(0, allergies.get(1).getReactions().size());
Assert.assertEquals(1, allergies.get(2).getReactions().size());
}
use of org.openmrs.Allergies in project openmrs-core by openmrs.
the class PatientServiceAllergyTest method setAllergies_shouldVoidAllergiesWithEditedCodedAllergen.
/**
* @see PatientService#setAllergies(Patient,Allergies)
*/
@Test
public void setAllergies_shouldVoidAllergiesWithEditedCodedAllergen() {
// 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 coded allergen
editedAllergy.getAllergen().setCodedAllergen(new Concept(24));
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_shouldVoidAllAllergiesAndSetStatusToNoKnownAllergiesIfAllAllergiesAreRemovedAndStatusSetAsSuch.
/**
* @see PatientService#setAllergies(Patient,Allergies)
*/
@Test
public void setAllergies_shouldVoidAllAllergiesAndSetStatusToNoKnownAllergiesIfAllAllergiesAreRemovedAndStatusSetAsSuch() {
// 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());
// remove all allergies
while (allergies.size() > 0) {
allergies.remove(0);
}
// set the status to no known allergies
allergies.confirmNoKnownAllergies();
allergyService.setAllergies(patient, allergies);
// all allergies should be voided and status set to no known allergies
allergies = allergyService.getAllergies(patient);
Assert.assertEquals(Allergies.NO_KNOWN_ALLERGIES, allergies.getAllergyStatus());
Assert.assertEquals(0, allergies.size());
}
Aggregations