Search in sources :

Example 46 with Concept

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

the class OrderServiceTest method saveOrder_shouldFailIfConceptInPreviousOrderDoesNotMatchThisConcept.

/**
 * @see OrderService#saveOrder(org.openmrs.Order, OrderContext)
 */
@Test
public void saveOrder_shouldFailIfConceptInPreviousOrderDoesNotMatchThisConcept() {
    Order previousOrder = orderService.getOrder(7);
    assertTrue(OrderUtilTest.isActiveOrder(previousOrder, null));
    Order order = previousOrder.cloneForDiscontinuing();
    order.setDateActivated(new Date());
    order.setOrderReasonNonCoded("Discontinue this");
    order.setEncounter(encounterService.getEncounter(6));
    order.setOrderer(providerService.getProvider(1));
    Concept newConcept = conceptService.getConcept(5089);
    assertFalse(previousOrder.getConcept().equals(newConcept));
    order.setConcept(newConcept);
    expectedException.expect(EditedOrderDoesNotMatchPreviousException.class);
    expectedException.expectMessage("The orderable of the previous order and the new one order don't match");
    orderService.saveOrder(order, null);
}
Also used : DrugOrder(org.openmrs.DrugOrder) TestOrder(org.openmrs.TestOrder) Matchers.containsInAnyOrder(org.hamcrest.Matchers.containsInAnyOrder) Order(org.openmrs.Order) Concept(org.openmrs.Concept) Date(java.util.Date) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest) OrderUtilTest(org.openmrs.order.OrderUtilTest) Test(org.junit.Test)

Example 47 with Concept

use of org.openmrs.Concept 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 48 with Concept

use of org.openmrs.Concept 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 49 with Concept

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

the class ObsServiceTest method getObservations_shouldGetAllObsWithAnswerConceptInGivenAnswersParameter.

/**
 * @see ObsService#getObservations(List,List,List,List,List,List,List,Integer,Integer,Date,Date,boolean)
 * @see ObsService#getObservations(List,List,List,List,List,List,List,Integer,Integer,Date,Date,boolean,String)
 */
@Test
public void getObservations_shouldGetAllObsWithAnswerConceptInGivenAnswersParameter() {
    executeDataSet(INITIAL_OBS_XML);
    ObsService obsService = Context.getObsService();
    List<Obs> obss = obsService.getObservations(null, null, null, Collections.singletonList(new Concept(7)), null, null, null, null, null, null, null, false, null);
    // obs 11 in INITIAL_OBS_XML and obs 13 in standardTestDataset
    Assert.assertEquals(3, obss.size());
    Set<Integer> ids = new HashSet<>();
    for (Obs o : obss) {
        ids.add(o.getObsId());
    }
    Assert.assertTrue(ids.contains(11));
    Assert.assertTrue(ids.contains(13));
}
Also used : Concept(org.openmrs.Concept) Obs(org.openmrs.Obs) HashSet(java.util.HashSet) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest) Test(org.junit.Test)

Example 50 with Concept

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

the class ObsServiceTest method saveObs_shouldCreateNewFileFromComplexDataForNewObs.

/**
 * @see ObsService#saveObs(Obs,String)
 */
@Test
public void saveObs_shouldCreateNewFileFromComplexDataForNewObs() {
    executeDataSet(COMPLEX_OBS_XML);
    ObsService os = Context.getObsService();
    ConceptService cs = Context.getConceptService();
    AdministrationService as = Context.getAdministrationService();
    // make sure the file isn't there to begin with
    File complexObsDir = OpenmrsUtil.getDirectoryInApplicationDataDirectory(as.getGlobalProperty(OpenmrsConstants.GLOBAL_PROPERTY_COMPLEX_OBS_DIR));
    File createdFile = new File(complexObsDir, "nameOfFile.txt");
    if (createdFile.exists())
        createdFile.delete();
    // the complex data to put onto an obs that will be saved
    Reader input = new CharArrayReader("This is a string to save to a file".toCharArray());
    ComplexData complexData = new ComplexData("nameOfFile.txt", input);
    // must fetch the concept instead of just new Concept(8473) because the attributes on concept are checked
    // this is a concept mapped to the text handler
    Concept questionConcept = cs.getConcept(8474);
    Obs obsToSave = new Obs(new Person(1), questionConcept, new Date(), new Location(1));
    obsToSave.setComplexData(complexData);
    try {
        os.saveObs(obsToSave, null);
        // make sure the file appears now after the save
        Assert.assertTrue(createdFile.exists());
    } finally {
        // we always have to delete this inside the same unit test because it is outside the
        // database and hence can't be "rolled back" like everything else
        createdFile.delete();
    }
}
Also used : Concept(org.openmrs.Concept) Obs(org.openmrs.Obs) CharArrayReader(java.io.CharArrayReader) ComplexData(org.openmrs.obs.ComplexData) CharArrayReader(java.io.CharArrayReader) Reader(java.io.Reader) File(java.io.File) Person(org.openmrs.Person) Date(java.util.Date) Location(org.openmrs.Location) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest) Test(org.junit.Test)

Aggregations

Concept (org.openmrs.Concept)294 Test (org.junit.Test)210 BaseContextSensitiveTest (org.openmrs.test.BaseContextSensitiveTest)176 ConceptName (org.openmrs.ConceptName)62 OpenmrsMatchers.hasConcept (org.openmrs.test.OpenmrsMatchers.hasConcept)62 Obs (org.openmrs.Obs)49 Date (java.util.Date)48 Patient (org.openmrs.Patient)42 ConceptDescription (org.openmrs.ConceptDescription)33 Locale (java.util.Locale)32 ConceptDatatype (org.openmrs.ConceptDatatype)32 OrderUtilTest (org.openmrs.order.OrderUtilTest)29 ConceptClass (org.openmrs.ConceptClass)27 ArrayList (java.util.ArrayList)26 BindException (org.springframework.validation.BindException)26 DrugOrder (org.openmrs.DrugOrder)25 Encounter (org.openmrs.Encounter)25 Errors (org.springframework.validation.Errors)25 ConceptMapBuilder (org.openmrs.module.metadatadeploy.builder.ConceptMapBuilder)21 Location (org.openmrs.Location)19