Search in sources :

Example 51 with Concept

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

the class ObsServiceTest method saveObs_shouldAllowSettingPropertiesOnObs.

/**
 * @see ObsService#saveObs(Obs,String)
 */
@Test
public void saveObs_shouldAllowSettingPropertiesOnObs() {
    ObsService obsService = Context.getObsService();
    Order order = null;
    Concept concept = Context.getConceptService().getConcept(3);
    Patient patient = new Patient(2);
    Encounter encounter = new Encounter(3);
    Date datetime = new Date();
    Location location = new Location(1);
    Integer valueGroupId = 7;
    Date valueDatetime = new Date();
    Concept valueCoded = new Concept(3);
    Double valueNumeric = 2.0;
    String valueModifier = "cc";
    String valueText = "value text2";
    String comment = "commenting2";
    Obs obs = new Obs();
    obs.setOrder(order);
    obs.setConcept(concept);
    obs.setPerson(patient);
    obs.setEncounter(encounter);
    obs.setObsDatetime(datetime);
    obs.setLocation(location);
    obs.setValueGroupId(valueGroupId);
    obs.setValueDatetime(valueDatetime);
    obs.setValueCoded(valueCoded);
    obs.setValueNumeric(valueNumeric);
    obs.setValueModifier(valueModifier);
    obs.setValueText(valueText);
    obs.setComment(comment);
    Obs saved = obsService.saveObs(obs, null);
    assertEquals(order, saved.getOrder());
    assertEquals(patient, saved.getPerson());
    assertEquals(comment, saved.getComment());
    assertEquals(concept, saved.getConcept());
    assertEquals(encounter, saved.getEncounter());
    assertEquals(DateUtil.truncateToSeconds(datetime), saved.getObsDatetime());
    assertEquals(location, saved.getLocation());
    assertEquals(valueGroupId, saved.getValueGroupId());
    assertEquals(DateUtil.truncateToSeconds(valueDatetime), saved.getValueDatetime());
    assertEquals(valueCoded, saved.getValueCoded());
    assertEquals(valueNumeric, saved.getValueNumeric());
    assertEquals(valueModifier, saved.getValueModifier());
    assertEquals(valueText, saved.getValueText());
}
Also used : Order(org.openmrs.Order) Concept(org.openmrs.Concept) Obs(org.openmrs.Obs) Patient(org.openmrs.Patient) Encounter(org.openmrs.Encounter) Date(java.util.Date) Location(org.openmrs.Location) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest) Test(org.junit.Test)

Example 52 with Concept

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

the class ObsServiceTest method getObservationsByPersonAndConcept_shouldGetObservationsMatchingPersonAndQuestion.

/**
 * @see ObsService#getObservationsByPersonAndConcept(Person,Concept)
 */
@Test
public void getObservationsByPersonAndConcept_shouldGetObservationsMatchingPersonAndQuestion() {
    ObsService obsService = Context.getObsService();
    List<Obs> obss = obsService.getObservationsByPersonAndConcept(new Person(7), new Concept(5089));
    Assert.assertEquals(3, obss.size());
    Assert.assertEquals(16, obss.get(0).getObsId().intValue());
    Assert.assertEquals(10, obss.get(1).getObsId().intValue());
    Assert.assertEquals(7, obss.get(2).getObsId().intValue());
}
Also used : Concept(org.openmrs.Concept) Obs(org.openmrs.Obs) Person(org.openmrs.Person) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest) Test(org.junit.Test)

Example 53 with Concept

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

the class OrderServiceTest method saveOrder_shouldPassIfAnActiveTestOrderForTheSameConceptAndCareSettingExists.

/**
 * @see OrderService#saveOrder(org.openmrs.Order, OrderContext)
 */
@Test
public void saveOrder_shouldPassIfAnActiveTestOrderForTheSameConceptAndCareSettingExists() {
    final Patient patient = patientService.getPatient(2);
    final Concept cd4Count = conceptService.getConcept(5497);
    // sanity check that we have an active order for the same concept
    TestOrder duplicateOrder = (TestOrder) orderService.getOrder(7);
    assertTrue(duplicateOrder.isActive());
    assertEquals(cd4Count, duplicateOrder.getConcept());
    Order order = new TestOrder();
    order.setPatient(patient);
    order.setCareSetting(orderService.getCareSetting(2));
    order.setConcept(cd4Count);
    order.setEncounter(encounterService.getEncounter(6));
    order.setOrderer(providerService.getProvider(1));
    order.setCareSetting(duplicateOrder.getCareSetting());
    Order savedOrder = orderService.saveOrder(order, null);
    assertNotNull(orderService.getOrder(savedOrder.getOrderId()));
}
Also used : Concept(org.openmrs.Concept) DrugOrder(org.openmrs.DrugOrder) TestOrder(org.openmrs.TestOrder) Matchers.containsInAnyOrder(org.hamcrest.Matchers.containsInAnyOrder) Order(org.openmrs.Order) TestOrder(org.openmrs.TestOrder) Patient(org.openmrs.Patient) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest) OrderUtilTest(org.openmrs.order.OrderUtilTest) Test(org.junit.Test)

Example 54 with Concept

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

the class OrderServiceTest method saveOrder_shouldPassIfAnActiveOrderForTheSameConceptExistsInADifferentCareSetting.

/**
 * @see OrderService#saveOrder(org.openmrs.Order, OrderContext)
 */
@Test
public void saveOrder_shouldPassIfAnActiveOrderForTheSameConceptExistsInADifferentCareSetting() {
    final Patient patient = patientService.getPatient(2);
    final Concept cd4Count = conceptService.getConcept(5497);
    TestOrder duplicateOrder = (TestOrder) orderService.getOrder(7);
    final CareSetting inpatient = orderService.getCareSetting(2);
    assertNotEquals(inpatient, duplicateOrder.getCareSetting());
    assertTrue(duplicateOrder.isActive());
    assertEquals(cd4Count, duplicateOrder.getConcept());
    int initialActiveOrderCount = orderService.getActiveOrders(patient, null, null, null).size();
    TestOrder order = new TestOrder();
    order.setPatient(patient);
    order.setCareSetting(orderService.getCareSetting(2));
    order.setConcept(cd4Count);
    order.setEncounter(encounterService.getEncounter(6));
    order.setOrderer(providerService.getProvider(1));
    order.setCareSetting(inpatient);
    orderService.saveOrder(order, null);
    List<Order> activeOrders = orderService.getActiveOrders(patient, null, null, null);
    assertEquals(++initialActiveOrderCount, activeOrders.size());
}
Also used : Concept(org.openmrs.Concept) DrugOrder(org.openmrs.DrugOrder) TestOrder(org.openmrs.TestOrder) Matchers.containsInAnyOrder(org.hamcrest.Matchers.containsInAnyOrder) Order(org.openmrs.Order) TestOrder(org.openmrs.TestOrder) Patient(org.openmrs.Patient) CareSetting(org.openmrs.CareSetting) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest) OrderUtilTest(org.openmrs.order.OrderUtilTest) Test(org.junit.Test)

Example 55 with Concept

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

the class OrderServiceTest method saveOrderFrequency_shouldAddANewOrderFrequencyToTheDatabase.

/**
 * @see OrderService#saveOrderFrequency(OrderFrequency)
 */
@Test
public void saveOrderFrequency_shouldAddANewOrderFrequencyToTheDatabase() {
    Concept concept = new Concept();
    concept.addName(new ConceptName("new name", Context.getLocale()));
    concept.addDescription(new ConceptDescription("some description", null));
    concept.setDatatype(new ConceptDatatype(1));
    concept.setConceptClass(conceptService.getConceptClassByName("Frequency"));
    concept = conceptService.saveConcept(concept);
    Integer originalSize = orderService.getOrderFrequencies(true).size();
    OrderFrequency orderFrequency = new OrderFrequency();
    orderFrequency.setConcept(concept);
    orderFrequency.setFrequencyPerDay(2d);
    orderFrequency = orderService.saveOrderFrequency(orderFrequency);
    assertNotNull(orderFrequency.getId());
    assertNotNull(orderFrequency.getUuid());
    assertNotNull(orderFrequency.getCreator());
    assertNotNull(orderFrequency.getDateCreated());
    assertEquals(originalSize + 1, orderService.getOrderFrequencies(true).size());
}
Also used : Concept(org.openmrs.Concept) ConceptName(org.openmrs.ConceptName) ConceptDescription(org.openmrs.ConceptDescription) ConceptDatatype(org.openmrs.ConceptDatatype) OrderFrequency(org.openmrs.OrderFrequency) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest) OrderUtilTest(org.openmrs.order.OrderUtilTest) 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