Search in sources :

Example 1 with Allergy

use of org.openmrs.Allergy 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 Allergy

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

the class PatientServiceAllergyTest method setAllergies_shouldVoidAllergiesWithEditedSeverity.

/**
 * @see PatientService#setAllergies(Patient,Allergies)
 */
@Test
public void setAllergies_shouldVoidAllergiesWithEditedSeverity() {
    // 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 severity
    editedAllergy.setSeverity(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));
}
Also used : Concept(org.openmrs.Concept) Allergy(org.openmrs.Allergy) Patient(org.openmrs.Patient) Allergies(org.openmrs.Allergies) Test(org.junit.Test) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest)

Example 3 with Allergy

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

the class PatientServiceAllergyTest method setAllergies_shouldVoidAllergiesWithRemovedReactions.

/**
 * @see PatientService#setAllergies(Patient,Allergies)
 */
@Test
public void setAllergies_shouldVoidAllergiesWithRemovedReactions() {
    // 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);
    // remove a reaction
    editedAllergy.getReactions().remove(0);
    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)

Example 4 with Allergy

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

the class PatientServiceAllergyTest method setAllergies_shouldVoidAllergiesWithEditedNonCodedAllergen.

/**
 * @see PatientService#setAllergies(Patient,Allergies)
 */
@Test
public void setAllergies_shouldVoidAllergiesWithEditedNonCodedAllergen() {
    // 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 non coded allergen
    editedAllergy.getAllergen().setNonCodedAllergen("some non coded allergen");
    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)

Example 5 with Allergy

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

the class PatientServiceAllergyTest method setAllergies_shouldSetTheNonCodedConceptForNonCodedAllergenIfNotSpecified.

@Test
public void setAllergies_shouldSetTheNonCodedConceptForNonCodedAllergenIfNotSpecified() {
    Patient patient = allergyService.getPatient(2);
    Allergen allergen = new Allergen(AllergenType.DRUG, null, "Some allergy name");
    Allergy allergy = new Allergy(patient, allergen, null, null, null);
    Allergies allergies = allergyService.getAllergies(patient);
    allergies.add(allergy);
    allergyService.setAllergies(patient, allergies);
    Assert.assertFalse(allergy.getAllergen().isCoded());
}
Also used : Allergy(org.openmrs.Allergy) Patient(org.openmrs.Patient) Allergies(org.openmrs.Allergies) Allergen(org.openmrs.Allergen) Test(org.junit.Test) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest)

Aggregations

Allergy (org.openmrs.Allergy)18 Allergies (org.openmrs.Allergies)15 Test (org.junit.Test)14 Patient (org.openmrs.Patient)13 BaseContextSensitiveTest (org.openmrs.test.BaseContextSensitiveTest)11 Concept (org.openmrs.Concept)9 Allergen (org.openmrs.Allergen)6 AllergyReaction (org.openmrs.AllergyReaction)4 BindException (org.springframework.validation.BindException)4 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)3 Errors (org.springframework.validation.Errors)3 MessageSourceService (org.openmrs.messagesource.MessageSourceService)2 Before (org.junit.Before)1 APIException (org.openmrs.api.APIException)1 BlankIdentifierException (org.openmrs.api.BlankIdentifierException)1 DuplicateIdentifierException (org.openmrs.api.DuplicateIdentifierException)1 InsufficientIdentifiersException (org.openmrs.api.InsufficientIdentifiersException)1 MissingRequiredIdentifierException (org.openmrs.api.MissingRequiredIdentifierException)1 PatientIdentifierException (org.openmrs.api.PatientIdentifierException)1 PatientIdentifierTypeLockedException (org.openmrs.api.PatientIdentifierTypeLockedException)1