Search in sources :

Example 46 with Encounter

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

the class OrderServiceTest method discontinueOrder_shouldPassForAnActiveOrderWhichIsScheduledAndNotStartedAsOfDiscontinueDate.

/**
 * @see OrderService#discontinueOrder(Order,String,Date,Provider,Encounter)
 */
@Test
public void discontinueOrder_shouldPassForAnActiveOrderWhichIsScheduledAndNotStartedAsOfDiscontinueDate() {
    Order order = new Order();
    order.setAction(Action.NEW);
    order.setPatient(Context.getPatientService().getPatient(7));
    order.setConcept(Context.getConceptService().getConcept(5497));
    order.setCareSetting(orderService.getCareSetting(1));
    order.setOrderer(orderService.getOrder(1).getOrderer());
    order.setEncounter(encounterService.getEncounter(3));
    order.setEncounter(encounterService.getEncounter(3));
    order.setOrderType(orderService.getOrderType(17));
    order.setDateActivated(new Date());
    order.setScheduledDate(DateUtils.addMonths(new Date(), 2));
    order.setUrgency(Order.Urgency.ON_SCHEDULED_DATE);
    order = orderService.saveOrder(order, null);
    assertTrue(OrderUtilTest.isActiveOrder(order, null));
    assertFalse(order.isStarted());
    Encounter encounter = encounterService.getEncounter(3);
    Provider orderer = providerService.getProvider(1);
    Date discontinueDate = new Date();
    String discontinueReasonNonCoded = "Test if I can discontinue this";
    Order discontinueOrder = orderService.discontinueOrder(order, discontinueReasonNonCoded, discontinueDate, orderer, encounter);
    Assert.assertEquals(order.getDateStopped(), discontinueDate);
    Assert.assertNotNull(discontinueOrder);
    Assert.assertNotNull(discontinueOrder.getId());
    Assert.assertEquals(discontinueOrder.getDateActivated(), discontinueOrder.getAutoExpireDate());
    Assert.assertEquals(discontinueOrder.getAction(), Action.DISCONTINUE);
    Assert.assertEquals(discontinueOrder.getOrderReasonNonCoded(), discontinueReasonNonCoded);
    Assert.assertEquals(discontinueOrder.getPreviousOrder(), order);
}
Also used : DrugOrder(org.openmrs.DrugOrder) TestOrder(org.openmrs.TestOrder) Matchers.containsInAnyOrder(org.hamcrest.Matchers.containsInAnyOrder) Order(org.openmrs.Order) Encounter(org.openmrs.Encounter) Date(java.util.Date) Provider(org.openmrs.Provider) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest) OrderUtilTest(org.openmrs.order.OrderUtilTest) Test(org.junit.Test)

Example 47 with Encounter

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

the class OrderServiceTest method saveOrder_shouldSetOrderTypeOfTestOrderToTestOrderIfNotSetAndConceptNotMapped.

/**
 * @see OrderService#saveOrder(org.openmrs.Order, OrderContext)
 */
@Test
public void saveOrder_shouldSetOrderTypeOfTestOrderToTestOrderIfNotSetAndConceptNotMapped() {
    TestOrder testOrder = new TestOrder();
    testOrder.setPatient(patientService.getPatient(7));
    Concept unmappedConcept = conceptService.getConcept(113);
    Assert.assertNull(orderService.getOrderTypeByConcept(unmappedConcept));
    testOrder.setConcept(unmappedConcept);
    testOrder.setOrderer(providerService.getProvider(1));
    testOrder.setCareSetting(orderService.getCareSetting(1));
    Encounter encounter = encounterService.getEncounter(3);
    testOrder.setEncounter(encounter);
    testOrder.setDateActivated(encounter.getEncounterDatetime());
    testOrder.setClinicalHistory("Patient had a negative reaction to the test in the past");
    testOrder.setFrequency(orderService.getOrderFrequency(3));
    testOrder.setSpecimenSource(conceptService.getConcept(22));
    testOrder.setNumberOfRepeats(3);
    orderService.saveOrder(testOrder, null);
    Assert.assertNotNull(testOrder.getOrderType());
    Assert.assertEquals(orderService.getOrderTypeByUuid(OrderType.TEST_ORDER_TYPE_UUID), testOrder.getOrderType());
}
Also used : Concept(org.openmrs.Concept) TestOrder(org.openmrs.TestOrder) Encounter(org.openmrs.Encounter) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest) OrderUtilTest(org.openmrs.order.OrderUtilTest) Test(org.junit.Test)

Example 48 with Encounter

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

the class OrderServiceTest method discontinueOrder_shouldFailForAVoidedOrder.

/**
 * @see OrderService#discontinueOrder(org.openmrs.Order, String, java.util.Date,
 *      org.openmrs.Provider, org.openmrs.Encounter)
 */
@Test
public void discontinueOrder_shouldFailForAVoidedOrder() {
    Order orderToDiscontinue = orderService.getOrder(8);
    Encounter encounter = encounterService.getEncounter(3);
    assertTrue(orderToDiscontinue.getVoided());
    expectedException.expect(CannotStopInactiveOrderException.class);
    expectedException.expectMessage(mss.getMessage("Order.cannot.discontinue.inactive"));
    orderService.discontinueOrder(orderToDiscontinue, "testing", null, null, encounter);
}
Also used : DrugOrder(org.openmrs.DrugOrder) TestOrder(org.openmrs.TestOrder) Matchers.containsInAnyOrder(org.hamcrest.Matchers.containsInAnyOrder) Order(org.openmrs.Order) Encounter(org.openmrs.Encounter) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest) OrderUtilTest(org.openmrs.order.OrderUtilTest) Test(org.junit.Test)

Example 49 with Encounter

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

the class OrderServiceTest method saveOrder_shouldSetConceptForDrugOrdersIfNull.

/**
 * @see OrderService#saveOrder(org.openmrs.Order, OrderContext)
 */
@Test
public void saveOrder_shouldSetConceptForDrugOrdersIfNull() {
    Patient patient = patientService.getPatient(7);
    CareSetting careSetting = orderService.getCareSetting(2);
    OrderType orderType = orderService.getOrderTypeByName("Drug order");
    // place drug order
    DrugOrder order = new DrugOrder();
    Encounter encounter = encounterService.getEncounter(3);
    order.setEncounter(encounter);
    order.setPatient(patient);
    order.setDrug(conceptService.getDrug(2));
    order.setCareSetting(careSetting);
    order.setOrderer(Context.getProviderService().getProvider(1));
    order.setDateActivated(encounter.getEncounterDatetime());
    order.setOrderType(orderType);
    order.setDosingType(FreeTextDosingInstructions.class);
    order.setInstructions("None");
    order.setDosingInstructions("Test Instruction");
    orderService.saveOrder(order, null);
    assertNotNull(order.getOrderId());
}
Also used : DrugOrder(org.openmrs.DrugOrder) OrderType(org.openmrs.OrderType) Patient(org.openmrs.Patient) CareSetting(org.openmrs.CareSetting) Encounter(org.openmrs.Encounter) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest) OrderUtilTest(org.openmrs.order.OrderUtilTest) Test(org.junit.Test)

Example 50 with Encounter

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

the class ObsServiceTest method getObservationCount_shouldReturnTheCountOfAllObservationsUsingTheSpecifiedConceptNamesAsAnswers.

/**
 * @see ObsService#getObservationCount(List, boolean)
 */
@Test
public void getObservationCount_shouldReturnTheCountOfAllObservationsUsingTheSpecifiedConceptNamesAsAnswers() {
    ObsService os = Context.getObsService();
    Obs o = new Obs();
    o.setConcept(Context.getConceptService().getConcept(3));
    o.setPerson(new Patient(2));
    o.setEncounter(new Encounter(3));
    o.setObsDatetime(new Date());
    o.setLocation(new Location(1));
    ConceptName cn1 = new ConceptName(1847);
    o.setValueCodedName(cn1);
    os.saveObs(o, null);
    Obs o2 = new Obs();
    o2.setConcept(Context.getConceptService().getConcept(3));
    o2.setPerson(new Patient(2));
    o2.setEncounter(new Encounter(3));
    o2.setObsDatetime(new Date());
    o2.setLocation(new Location(1));
    ConceptName cn2 = new ConceptName(2453);
    o2.setValueCodedName(cn2);
    os.saveObs(o2, null);
    List<ConceptName> names = new LinkedList<>();
    names.add(cn1);
    names.add(cn2);
    Assert.assertEquals(2, os.getObservationCount(names, true).intValue());
}
Also used : Obs(org.openmrs.Obs) Patient(org.openmrs.Patient) Encounter(org.openmrs.Encounter) ConceptName(org.openmrs.ConceptName) Date(java.util.Date) LinkedList(java.util.LinkedList) Location(org.openmrs.Location) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest) Test(org.junit.Test)

Aggregations

Encounter (org.openmrs.Encounter)261 Test (org.junit.Test)204 BaseContextSensitiveTest (org.openmrs.test.BaseContextSensitiveTest)153 Patient (org.openmrs.Patient)91 Date (java.util.Date)87 Order (org.openmrs.Order)46 Obs (org.openmrs.Obs)41 Visit (org.openmrs.Visit)40 Location (org.openmrs.Location)38 OrderUtilTest (org.openmrs.order.OrderUtilTest)38 DrugOrder (org.openmrs.DrugOrder)37 TestOrder (org.openmrs.TestOrder)34 EncounterType (org.openmrs.EncounterType)27 ArrayList (java.util.ArrayList)25 Concept (org.openmrs.Concept)25 BindException (org.springframework.validation.BindException)25 Calendar (java.util.Calendar)21 Errors (org.springframework.validation.Errors)21 User (org.openmrs.User)20 PihCoreContextSensitiveTest (org.openmrs.module.pihcore.PihCoreContextSensitiveTest)19