assertTrue(duplicateOrder.isActive()); assertEquals(triomuneThirty, duplicateOrder.getConcept()); DrugOrder drugOrder = new DrugOrder(); drugOrder.setPatient(patient); drugOrder.setCareSetting(orderService.getCareSetting(1)); drugOrder.setConcept(triomuneThirty); drugOrder.setEncounter(encounterService.getEncounter(6)); drugOrder.setOrderer(providerService.getProvider(1)); drugOrder.setCareSetting(duplicateOrder.getCareSetting()); drugOrder.setDrug(duplicateOrder.getDrug()); drugOrder.setDose(duplicateOrder.getDose()); drugOrder.setDoseUnits(duplicateOrder.getDoseUnits()); drugOrder.setRoute(duplicateOrder.getRoute()); drugOrder.setFrequency(duplicateOrder.getFrequency()); drugOrder.setQuantity(duplicateOrder.getQuantity()); drugOrder.setQuantityUnits(duplicateOrder.getQuantityUnits()); drugOrder.setNumRefills(duplicateOrder.getNumRefills());
assertTrue(OrderUtilTest.isActiveOrder(orderToDiscontinue, null)); DrugOrder order = new DrugOrder(); order.setDrug(orderToDiscontinue.getDrug()); order.setOrderType(orderService.getOrderTypeByName("Drug order")); order.setAction(Order.Action.DISCONTINUE); order.setOrderReasonNonCoded("Discontinue this"); order.setPatient(orderToDiscontinue.getPatient()); order.setConcept(orderToDiscontinue.getConcept()); order.setOrderer(orderToDiscontinue.getOrderer()); order.setCareSetting(orderToDiscontinue.getCareSetting()); order.setEncounter(encounterService.getEncounter(6)); order.setDateActivated(new Date()); order.setDosingType(SimpleDosingInstructions.class); order.setDose(orderToDiscontinue.getDose()); order.setDoseUnits(orderToDiscontinue.getDoseUnits()); order.setRoute(orderToDiscontinue.getRoute()); order.setFrequency(orderToDiscontinue.getFrequency()); order.setQuantity(orderToDiscontinue.getQuantity()); order.setQuantityUnits(orderToDiscontinue.getQuantityUnits()); order.setNumRefills(orderToDiscontinue.getNumRefills()); Assert.assertNotNull("previous order should be discontinued", orderToDiscontinue.getDateStopped());
@Override public String toString() { String prefix = DISCONTINUE == getAction() ? "DC " : ""; return prefix + "DrugOrder(" + getDose() + getDoseUnits() + " of " + (isNonCodedDrug() ? getDrugNonCoded() : (getDrug() != null ? getDrug().getName() : "[no drug]")) + " from " + getDateActivated() + " to " + (isDiscontinuedRightNow() ? getDateStopped() : getAutoExpireDate()) + ")"; }
/** * @see org.openmrs.Order#copy() * @should copy all drug order fields */ @Override public DrugOrder copy() { return copyHelper(new DrugOrder()); }
/** * @see org.openmrs.Order#cloneForDiscontinuing() * @should set all the relevant fields * @since 1.10 */ @Override public DrugOrder cloneForDiscontinuing() { DrugOrder newOrder = new DrugOrder(); newOrder.setCareSetting(getCareSetting()); newOrder.setConcept(getConcept()); newOrder.setAction(DISCONTINUE); newOrder.setPreviousOrder(this); newOrder.setPatient(getPatient()); newOrder.setDrug(getDrug()); newOrder.setOrderType(getOrderType()); newOrder.setDrugNonCoded(getDrugNonCoded()); return newOrder; }
/** * @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()); }
/** * @see org.openmrs.Order#copyHelper(Order) */ protected DrugOrder copyHelper(DrugOrder target) { super.copyHelper(target); target.setDose(getDose()); target.setDoseUnits(getDoseUnits()); target.setFrequency(getFrequency()); target.setAsNeeded(getAsNeeded()); target.setAsNeededCondition(getAsNeededCondition()); target.setQuantity(getQuantity()); target.setQuantityUnits(getQuantityUnits()); target.setDrug(getDrug()); target.setDosingType(getDosingType()); target.setDosingInstructions(getDosingInstructions()); target.setDuration(getDuration()); target.setDurationUnits(getDurationUnits()); target.setNumRefills(getNumRefills()); target.setRoute(getRoute()); target.setBrandName(getBrandName()); target.setDispenseAsWritten(getDispenseAsWritten()); target.setDrugNonCoded(getDrugNonCoded()); return target; }
DrugOrder order = new DrugOrder(); Encounter encounter = new Encounter(); Patient patient = Context.getPatientService().getPatient(2); order.setConcept(Context.getConceptService().getConcept(88)); order.setOrderer(Context.getProviderService().getProvider(1)); order.setDosingType(FreeTextDosingInstructions.class); order.setInstructions("Instructions"); order.setDosingInstructions("Test Instruction"); order.setPatient(patient); encounter.setPatient(patient); order.setEncounter(encounter); Calendar cal = Calendar.getInstance(); cal.set(Calendar.DAY_OF_MONTH, cal.get(Calendar.DAY_OF_MONTH) - 1); order.setDateActivated(cal.getTime()); order.setAutoExpireDate(new Date()); order.setOrderType(Context.getOrderService().getOrderTypeByName("Drug order")); order.setDrug(Context.getConceptService().getDrug(3)); order.setCareSetting(Context.getOrderService().getCareSetting(1)); order.setQuantity(2.00); order.setQuantityUnits(Context.getConceptService().getConcept(51)); order.setNumRefills(10); order.setAsNeededCondition("asNeededCondition"); order.setBrandName("brandName");
public void saveOrder_shouldDiscontinuePreviousOrderIfItIsNotAlreadyDiscontinued() { DrugOrder order = new DrugOrder(); order.setAction(Order.Action.DISCONTINUE); order.setOrderReasonNonCoded("Discontinue this"); order.setDrug(conceptService.getDrug(3)); order.setEncounter(encounterService.getEncounter(5)); order.setPatient(Context.getPatientService().getPatient(7)); order.setOrderer(Context.getProviderService().getProvider(1)); order.setCareSetting(orderService.getCareSetting(1)); order.setEncounter(encounterService.getEncounter(3)); order.setOrderType(orderService.getOrderType(1)); order.setDateActivated(new Date()); order.setDosingType(SimpleDosingInstructions.class); order.setDose(500.0); order.setDoseUnits(conceptService.getConcept(50)); order.setFrequency(orderService.getOrderFrequency(1)); order.setRoute(conceptService.getConcept(22)); order.setNumRefills(10); order.setQuantity(20.0); order.setQuantityUnits(conceptService.getConcept(51)); Order previousOrder = orderService.getOrder(111); assertTrue(OrderUtilTest.isActiveOrder(previousOrder, null)); order.setPreviousOrder(previousOrder); Assert.assertEquals(order.getDateActivated(), order.getAutoExpireDate()); Assert.assertNotNull("previous order should be discontinued", previousOrder.getDateStopped());
/** * @see OrderService#saveOrder(org.openmrs.Order, OrderContext, org.openmrs.Order[]) */ @Test public void saveOrder_shouldPassIfAnKnownDrugOrderForTheSameDrugFormulationSpecified() { executeDataSet("org/openmrs/api/include/OrderServiceTest-drugOrdersWithSameConceptAndDifferentFormAndStrength.xml"); final Patient patient = patientService.getPatient(2); //sanity check that we have an active order for the same concept DrugOrder existingOrder = (DrugOrder) orderService.getOrder(1000); assertTrue(existingOrder.isActive()); //New Drug order DrugOrder order = new DrugOrder(); order.setPatient(patient); order.setDrug(existingOrder.getDrug()); order.setEncounter(encounterService.getEncounter(6)); order.setOrderer(providerService.getProvider(1)); order.setCareSetting(existingOrder.getCareSetting()); order.setDosingType(FreeTextDosingInstructions.class); order.setDosingInstructions("2 for 5 days"); order.setQuantity(10.0); order.setQuantityUnits(conceptService.getConcept(51)); order.setNumRefills(2); OrderContext orderContext = new OrderContext(); orderContext.setAttribute(OrderService.PARALLEL_ORDERS, new String[] { existingOrder.getUuid() }); orderService.saveOrder(order, orderContext); assertNotNull(orderService.getOrder(order.getOrderId())); }
@Test public void saveOrder_shouldSetAutoExpireDateOfDrugOrderIfAutoExpireDateIsNotSet() throws ParseException { executeDataSet("org/openmrs/api/include/OrderServiceTest-drugOrderAutoExpireDate.xml"); Drug drug = conceptService.getDrug(3000); DrugOrder drugOrder = new DrugOrder(); Encounter encounter = encounterService.getEncounter(3); drugOrder.setEncounter(encounter); drugOrder.setPatient(patientService.getPatient(7)); drugOrder.setCareSetting(orderService.getCareSetting(1)); drugOrder.setOrderer(Context.getProviderService().getProvider(1)); drugOrder.setDrug(drug); drugOrder.setDosingType(SimpleDosingInstructions.class); drugOrder.setDose(300.0); drugOrder.setDoseUnits(conceptService.getConcept(50)); drugOrder.setQuantity(20.0); drugOrder.setQuantityUnits(conceptService.getConcept(51)); drugOrder.setFrequency(orderService.getOrderFrequency(3)); drugOrder.setRoute(conceptService.getConcept(22)); drugOrder.setNumRefills(0); drugOrder.setOrderType(null); drugOrder.setDateActivated(TestUtil.createDateTime("2014-08-03")); drugOrder.setDuration(20);// 20 days drugOrder.setDurationUnits(conceptService.getConcept(1001)); Order savedOrder = orderService.saveOrder(drugOrder, null); Order loadedOrder = orderService.getOrder(savedOrder.getId()); Assert.assertEquals(TestUtil.createDateTime("2014-08-22 23:59:59"), loadedOrder.getAutoExpireDate()); }
/** * @see DrugOrderValidator#validate(Object, org.springframework.validation.Errors) */ @Test public void validate_shouldNotRequireAllFieldsForADiscontinuationOrder() { DrugOrder orderToDiscontinue = (DrugOrder) Context.getOrderService().getOrder(111); assertTrue(OrderUtilTest.isActiveOrder(orderToDiscontinue, null)); DrugOrder discontinuationOrder = new DrugOrder(); discontinuationOrder.setDosingType(null); discontinuationOrder.setCareSetting(orderToDiscontinue.getCareSetting()); discontinuationOrder.setConcept(orderToDiscontinue.getConcept()); discontinuationOrder.setAction(Order.Action.DISCONTINUE); discontinuationOrder.setPreviousOrder(orderToDiscontinue); discontinuationOrder.setPatient(orderToDiscontinue.getPatient()); discontinuationOrder.setDrug(orderToDiscontinue.getDrug()); discontinuationOrder.setOrderType(orderToDiscontinue.getOrderType()); discontinuationOrder.setOrderer(Context.getProviderService().getProvider(1)); discontinuationOrder.setEncounter(Context.getEncounterService().getEncounter(3)); Errors errors = new BindException(discontinuationOrder, "order"); new DrugOrderValidator().validate(discontinuationOrder, errors); Assert.assertFalse(errors.hasErrors()); }
if (!existingOrder.getAction().equals(Action.DISCONTINUE)) { DrugOrder revisedOrder = existingOrder.cloneForRevision(); setOrderer(session, revisedOrder); revisedOrder.setDrug(orderTag.drug); revisedOrder.setConcept(orderTag.drug.getConcept()); revisedOrder.setDosingType(orderTag.dosingType); revisedOrder.setDose(orderTag.dose); revisedOrder.setDoseUnits(orderTag.doseUnits); revisedOrder.setQuantity(orderTag.quantity); revisedOrder.setQuantityUnits(orderTag.quantityUnits); revisedOrder.setDuration(orderTag.duration); revisedOrder.setDurationUnits(orderTag.durationUnits); revisedOrder.setRoute(orderTag.route); revisedOrder.setCareSetting(Context.getOrderService().getCareSetting(orderTag.careSettingId)); OrderFrequency orderFrequency = Context.getOrderService().getOrderFrequency(Integer.valueOf(orderTag.frequency)); revisedOrder.setFrequency(orderFrequency); revisedOrder.setDateActivated(orderTag.startDate); revisedOrder.setNumRefills(orderTag.numRefills); if (orderTag.orderDuration != null) revisedOrder.setAutoExpireDate(calculateAutoExpireDate(orderTag.startDate, orderTag.orderDuration)); if (!StringUtils.isEmpty(orderTag.instructions)) revisedOrder.setInstructions((String) orderTag.instructions); } else { Context.getOrderService().voidOrder(existingOrder, "Update discontinued date or reason"); discontinuationOrder = existingOrder.cloneForRevision(); discontinuationOrder.setDateActivated(orderTag.discontinuedDate); discontinuationOrder.setOrderReason(HtmlFormEntryUtil.getConcept(orderTag.discontinuedReasonStr));
DrugOrder order = new DrugOrder(); order.setPatient(patient); order.setDrug(existingOrder.getDrug()); order.setEncounter(encounterService.getEncounter(6)); order.setOrderer(providerService.getProvider(1)); order.setCareSetting(existingOrder.getCareSetting()); order.setDosingType(FreeTextDosingInstructions.class); order.setDosingInstructions("2 for 10 days"); order.setQuantity(10.0); order.setQuantityUnits(conceptService.getConcept(51)); order.setNumRefills(2); order.setUrgency(Order.Urgency.ON_SCHEDULED_DATE); order.setScheduledDate(DateUtils.addDays(existingOrder.getDateStopped(), 1));
/** * @see DrugOrder#cloneForDiscontinuing() */ @Test public void cloneForDiscontinuing_shouldSetAllTheRelevantFields() { DrugOrder order = new DrugOrder(); order.setPatient(new Patient()); order.setCareSetting(new CareSetting()); Drug drug = new Drug(); drug.setConcept(new Concept()); order.setDrug(drug); order.setOrderType(new OrderType()); DrugOrder dcOrder = order.cloneForDiscontinuing(); assertEquals(order.getDrug(), dcOrder.getDrug()); assertEquals(order.getPatient(), dcOrder.getPatient()); assertEquals(order.getConcept(), dcOrder.getConcept()); assertEquals("should set previous order to anOrder", order, dcOrder.getPreviousOrder()); assertEquals("should set new order action to new", dcOrder.getAction(), Order.Action.DISCONTINUE); assertEquals(order.getCareSetting(), dcOrder.getCareSetting()); assertEquals(order.getOrderType(), dcOrder.getOrderType()); }
while (drugOrder.getPreviousOrder() != null) { drugOrder = (DrugOrder) drugOrder.getPreviousOrder(); drugWidget.setInitialValue(drugOrder.getDrug().getDrugId()); } else { if (((CheckboxWidget) drugWidget).getValue().equals(drugOrder.getDrug().getDrugId().toString())) ((CheckboxWidget) drugWidget).setInitialValue("CHECKED"); if (!existingOrder.getAction().equals(Action.DISCONTINUE)) { lastRevision = drugOrder; startDateWidget.setInitialValue(lastRevision.getDateActivated()); routeWidget.setInitialValue(lastRevision.getRoute().getId()); careSettingWidget.setInitialValue(lastRevision.getCareSetting().getId()); dosingTypeWidget.setInitialValue(lastRevision.getDosingType().toString()); doseWidget.setInitialValue(lastRevision.getDose()); numRefillsWidget.setInitialValue(lastRevision.getNumRefills()); if (lastRevision.getDoseUnits() != null) { doseUnitsWidget.setInitialValue(lastRevision.getDoseUnits().getId()); quantityWidget.setInitialValue(lastRevision.getQuantity()); if (lastRevision.getQuantityUnits() != null) {
/** * @see DrugOrder#hasSameOrderableAs(Order) */ @Test public void hasSameOrderableAs_shouldReturnFalseIfTheConceptsMatchAndOnlyThisHasADrug() { DrugOrder order = new DrugOrder(); Concept concept = new Concept(); Drug drug1 = new Drug(); drug1.setConcept(concept); order.setDrug(drug1); DrugOrder otherOrder = new DrugOrder(); otherOrder.setConcept(concept); assertEquals(order.getConcept(), otherOrder.getConcept());//sanity check assertFalse(order.hasSameOrderableAs(otherOrder)); }
@Test public void getAutoExpireDate_shouldNotInferAutoExpireDateWhenDrugOrderHasOneOrMoreRefill() throws ParseException { DrugOrder drugOrder = new DrugOrder(); drugOrder.setDateActivated(createDateTime("2014-07-01 10:00:00")); drugOrder.setDuration(30); drugOrder.setDurationUnits(createUnits(Duration.SNOMED_CT_SECONDS_CODE)); drugOrder.setNumRefills(1); Date autoExpireDate = new SimpleDosingInstructions().getAutoExpireDate(drugOrder); assertEquals(null, autoExpireDate); }
/** * @see DrugOrder#setAutoExpireDateBasedOnDuration() */ @Test public void setAutoExpireDateBasedOnDuration_shouldNotCalculateForDiscontinueAction() { DrugOrder drugOrder = new DrugOrder(); drugOrder.setAction(Order.Action.DISCONTINUE); Date expectedAutoExpireDate = new Date(); drugOrder.setAutoExpireDate(expectedAutoExpireDate); drugOrder.setAutoExpireDateBasedOnDuration(); assertEquals(expectedAutoExpireDate, drugOrder.getAutoExpireDate()); }
/** * @see OrderService#saveOrder(org.openmrs.Order, OrderContext) */ @Test public void saveOrder_shouldFailIfTheExistingDrugOrderMatchesTheConceptAndNotDrugOfTheRevisedOrder() { final DrugOrder orderToDiscontinue = (DrugOrder) orderService.getOrder(5); //create a different test drug Drug discontinuationOrderDrug = new Drug(); discontinuationOrderDrug.setConcept(orderToDiscontinue.getConcept()); discontinuationOrderDrug = conceptService.saveDrug(discontinuationOrderDrug); assertNotEquals(discontinuationOrderDrug, orderToDiscontinue.getDrug()); assertNotNull(orderToDiscontinue.getDrug()); DrugOrder order = orderToDiscontinue.cloneForRevision(); order.setDateActivated(new Date()); order.setOrderer(providerService.getProvider(1)); order.setEncounter(encounterService.getEncounter(6)); order.setDrug(discontinuationOrderDrug); expectedException.expect(EditedOrderDoesNotMatchPreviousException.class); expectedException.expectMessage("The orderable of the previous order and the new one order don't match"); orderService.saveOrder(order, null); }