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);
}
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());
}
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);
}
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());
}
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());
}
Aggregations