public DrugOrderBuilder withDrug(Integer drugID) { drugOrder.setDrug(conceptService.getDrug(drugID)); return this; }
/** * @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 DrugOrder#hasSameOrderableAs(Order) */ @Test public void hasSameOrderableAs_shouldReturnTrueIfTheDrugsMatch() { DrugOrder order = new DrugOrder(); Concept concept = new Concept(); Drug drug1 = new Drug(); drug1.setConcept(concept); order.setDrug(drug1); DrugOrder otherOrder = new DrugOrder(); otherOrder.setDrug(drug1); assertTrue(order.hasSameOrderableAs(otherOrder)); }
/** * @throws Exception * @see DrugOrder#copy() */ @Test public void copy_shouldCopyAllDrugOrderFields() throws Exception { DrugOrder drugOrder = new DrugOrder(); Drug drug = new Drug(); drug.setConcept(new Concept()); drugOrder.setDrug(drug); OrderTest.assertThatAllFieldsAreCopied(drugOrder, null); }
/** * @throws Exception * @see DrugOrder#cloneForRevision() */ @Test public void cloneForRevision_shouldSetAllTheRelevantFields() throws Exception { DrugOrder drugOrder = new DrugOrder(); Drug drug = new Drug(); drug.setConcept(new Concept()); drugOrder.setDrug(drug); OrderTest.assertThatAllFieldsAreCopied(drugOrder, "cloneForRevision", "creator", "dateCreated", "action", "changedBy", "dateChanged", "voided", "dateVoided", "voidedBy", "voidReason", "encounter", "orderNumber", "orderer", "previousOrder", "dateActivated", "dateStopped", "accessionNumber"); }
/** * @see DrugOrderValidator#validate(Object,Errors) */ @Test public void validate_shouldNotFailValidationIfDrugIsNull() { DrugOrder order = new DrugOrder(); order.setDrug(null); Errors errors = new BindException(order, "order"); new DrugOrderValidator().validate(order, errors); Assert.assertFalse(errors.hasFieldErrors("drug")); }
/** * @see DrugOrder#hasSameOrderableAs(Order) */ @Test public void hasSameOrderableAs_shouldReturnFalseIfTheConceptsMatchAndDrugsAreDifferentAndNotNull() { DrugOrder order = new DrugOrder(); Concept concept = new Concept(); Drug drug1 = new Drug(); drug1.setConcept(concept); order.setDrug(drug1); //should set concept DrugOrder otherOrder = new DrugOrder(); Drug drug2 = new Drug(); drug2.setConcept(concept); otherOrder.setDrug(drug2); //sanity check assertTrue(order.getConcept() != null && otherOrder.getConcept() != null); assertFalse(order.hasSameOrderableAs(otherOrder)); }
/** * @see DrugOrderValidator#validate(Object, org.springframework.validation.Errors) */ @Test public void validate_shouldFailIfConceptIsNullAndCannotInferItFromDrug() { DrugOrder order = new DrugOrder(); Drug drug = Context.getConceptService().getDrug(3); drug.setConcept(null); order.setDrug(drug); Errors errors = new BindException(order, "order"); adminService.validate(order, errors); Assert.assertTrue(errors.hasFieldErrors("concept")); }
/** * @see DrugOrder#hasSameOrderableAs(Order) */ @Test public void hasSameOrderableAs_shouldReturnFalseIfTheOtherOrderIsNotADrugOrder() { DrugOrder order = new DrugOrder(); Drug drug1 = new Drug(); Concept concept = new Concept(); drug1.setConcept(concept); order.setDrug(drug1); Order otherOrder = new Order(); otherOrder.setConcept(concept); assertFalse(order.hasSameOrderableAs(otherOrder)); }
/** * @see DrugOrderValidator#validate(Object,Errors) */ @Test public void validate_shouldFailValidationIfAsNeededIsNull() { DrugOrder order = new DrugOrder(); order.setAsNeeded(null); order.setDrug(Context.getConceptService().getDrug(3)); Errors errors = new BindException(order, "order"); new DrugOrderValidator().validate(order, errors); Assert.assertTrue(errors.hasFieldErrors("asNeeded")); }
/** * @see DrugOrderValidator#validate(Object,Errors) */ @Test public void validate_shouldFailValidationIfDosingTypeIsNull() { DrugOrder order = new DrugOrder(); order.setDosingType(null); order.setDrug(Context.getConceptService().getDrug(3)); Errors errors = new BindException(order, "order"); new DrugOrderValidator().validate(order, errors); Assert.assertTrue(errors.hasFieldErrors("dosingType")); }
/** * @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)); }
/** * @see DrugOrder#hasSameOrderableAs(Order) */ @Test public void hasSameOrderableAs_shouldReturnFalseIfTheConceptsMatchAndOnlyTheOtherHasADrug() { DrugOrder order = new DrugOrder(); Concept concept = new Concept(); order.setConcept(concept); DrugOrder otherOrder = new DrugOrder(); Drug drug1 = new Drug(); drug1.setConcept(concept); otherOrder.setDrug(drug1); //should set the concept assertEquals(order.getConcept(), otherOrder.getConcept());//sanity check assertFalse(order.hasSameOrderableAs(otherOrder)); }
/** * @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); }
/** * @see OrderServiceImpl#discontinueExistingOrdersIfNecessary() */ @Test(expected = AmbiguousOrderException.class) public void saveOrder_shouldThrowAmbiguousOrderExceptionIfDisconnectingMultipleActiveDrugOrdersWithTheSameDrug() { executeDataSet("org/openmrs/api/include/OrderServiceTest-ambiguousDrugOrders.xml"); DrugOrder order = new DrugOrder(); order.setAction(Order.Action.DISCONTINUE); order.setOrderReasonNonCoded("Discontinue this"); order.setDrug(conceptService.getDrug(3)); order.setEncounter(encounterService.getEncounter(7)); order.setPatient(patientService.getPatient(9)); order.setOrderer(providerService.getProvider(1)); order.setCareSetting(orderService.getCareSetting(1)); order = (DrugOrder) orderService.saveOrder(order, null); }
/** * @see DrugOrderValidator#validate(Object,Errors) */ @Test public void validate_shouldFailValidationIfDrugConceptIsDifferentFromOrderConcept() { DrugOrder order = new DrugOrder(); Drug drug = Context.getConceptService().getDrug(3); Concept concept = Context.getConceptService().getConcept(792); order.setDrug(drug); order.setConcept(concept); // the actual concept which matches with drug is "88" Assert.assertNotEquals(drug.getConcept(), concept); Errors errors = new BindException(order, "order"); new DrugOrderValidator().validate(order, errors); Assert.assertTrue(errors.hasFieldErrors("concept")); Assert.assertTrue(errors.hasFieldErrors("drug")); }
/** * @see DrugOrderValidator#validate(Object, org.springframework.validation.Errors) */ @Test public void validate_shouldPassIfConceptIsNullAndDrugIsSet() { DrugOrder order = new DrugOrder(); order.setPatient(Context.getPatientService().getPatient(7)); order.setCareSetting(Context.getOrderService().getCareSetting(2)); order.setEncounter(Context.getEncounterService().getEncounter(3)); order.setOrderer(Context.getProviderService().getProvider(1)); Drug drug = Context.getConceptService().getDrug(3); order.setDrug(drug); order.setConcept(null); FreeTextDosingInstructions di = new FreeTextDosingInstructions(); di.setInstructions("testing"); di.setDosingInstructions(order); Errors errors = new BindException(order, "order"); new DrugOrderValidator().validate(order, errors); Assert.assertFalse(errors.hasFieldErrors()); }
/** * @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())); }
/** * @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()); }
/** * @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()); }