Search in sources :

Example 1 with AllergyReaction

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

the class PatientServiceAllergyTest method setAllergies_shouldVoidAllergiesWithAddedReactions.

/**
 * @see PatientService#setAllergies(Patient,Allergies)
 */
@Test
public void setAllergies_shouldVoidAllergiesWithAddedReactions() {
    // 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);
    // add a reaction
    AllergyReaction reaction = new AllergyReaction(null, new Concept(22), null);
    editedAllergy.addReaction(reaction);
    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 : Concept(org.openmrs.Concept) 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 2 with AllergyReaction

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

the class PatientServiceAllergyTest method setAllergies_shouldSaveTheAllergyListAndStatus.

/**
 * @see PatientService#setAllergies(Patient,Allergies)
 */
@Test
public void setAllergies_shouldSaveTheAllergyListAndStatus() {
    // 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());
    // save some allergies for this patient
    Allergen allergen = new Allergen(AllergenType.DRUG, new Concept(3), null);
    Concept severity = new Concept(4);
    Allergy allergy = new Allergy(patient, allergen, severity, "some comment", new ArrayList<>());
    AllergyReaction reaction = new AllergyReaction(allergy, new Concept(21), null);
    allergy.addReaction(reaction);
    allergies = new Allergies();
    allergies.add(allergy);
    allergyService.setAllergies(patient, allergies);
    // now the patient should have allergies and the correct allergy status
    allergies = allergyService.getAllergies(patient);
    Assert.assertEquals(Allergies.SEE_LIST, allergies.getAllergyStatus());
    Assert.assertEquals(1, allergies.size());
    Assert.assertEquals(1, allergies.get(0).getReactions().size());
}
Also used : Concept(org.openmrs.Concept) Allergy(org.openmrs.Allergy) Patient(org.openmrs.Patient) AllergyReaction(org.openmrs.AllergyReaction) Allergies(org.openmrs.Allergies) Allergen(org.openmrs.Allergen) Test(org.junit.Test) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest)

Example 3 with AllergyReaction

use of org.openmrs.AllergyReaction 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 4 with AllergyReaction

use of org.openmrs.AllergyReaction 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));
}
Also used : Concept(org.openmrs.Concept) 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 5 with AllergyReaction

use of org.openmrs.AllergyReaction 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());
}
Also used : Concept(org.openmrs.Concept) Patient(org.openmrs.Patient) AllergyReaction(org.openmrs.AllergyReaction) Allergies(org.openmrs.Allergies) Test(org.junit.Test) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest)

Aggregations

Test (org.junit.Test)5 Allergies (org.openmrs.Allergies)5 AllergyReaction (org.openmrs.AllergyReaction)5 Patient (org.openmrs.Patient)5 BaseContextSensitiveTest (org.openmrs.test.BaseContextSensitiveTest)5 Allergy (org.openmrs.Allergy)4 Concept (org.openmrs.Concept)4 Allergen (org.openmrs.Allergen)1