/** * Sets the drug * * @param drug */ public void setDrug(Drug drug) { this.drug = drug; if (drug != null && getConcept() == null) { setConcept(drug.getConcept()); } }
public DrugOrderBuilder withConcept(Integer conceptID) { drugOrder.setConcept(conceptService.getConcept(conceptID)); return this; }
private void ensureConceptIsSet(Order order) { Concept concept = order.getConcept(); if (concept == null && isDrugOrder(order)) { DrugOrder drugOrder = (DrugOrder) order; if (drugOrder.getDrug() != null) { concept = drugOrder.getDrug().getConcept(); drugOrder.setConcept(concept); } } if (concept == null) { throw new MissingRequiredPropertyException("Order.concept.required"); } }
/** * @see DrugOrder#hasSameOrderableAs(Order) */ @Test public void hasSameOrderableAs_shouldReturnTrueIfBothDrugsAreNullAndTheConceptsMatch() { DrugOrder order = new DrugOrder(); Concept concept = new Concept(); order.setConcept(concept); DrugOrder otherOrder = new DrugOrder(); otherOrder.setConcept(concept); assertTrue(order.hasSameOrderableAs(otherOrder)); }
/** * @see DrugOrder#hasSameOrderableAs(Order) */ @Test public void hasSameOrderableAs_shouldReturnTrueIfTheConceptsMatchAndBothDrugNonCodedIsNull() { DrugOrder order = new DrugOrder(); Concept concept = new Concept(); order.setConcept(concept); DrugOrder otherOrder = new DrugOrder(); otherOrder.setConcept(concept); assertTrue(order.hasSameOrderableAs(otherOrder)); } }
/** * @see DrugOrder#hasSameOrderableAs(Order) */ @Test public void hasSameOrderableAs_shouldReturnFalseIfBothDrugsAreNullAndTheConceptsAreDifferent() { DrugOrder order = new DrugOrder(); order.setConcept(new Concept()); DrugOrder otherOrder = new DrugOrder(); otherOrder.setConcept(new Concept()); assertFalse(order.hasSameOrderableAs(otherOrder)); }
/** * @see DrugOrder#hasSameOrderableAs(Order) */ @Test public void hasSameOrderableAs_shouldReturnFalseIfTheConceptsMatchAndEitherOfDrugNonCodedIsNull() { DrugOrder order = new DrugOrder(); Concept concept = new Concept(); order.setConcept(concept); order.setDrugNonCoded("Chrocine"); DrugOrder otherOrder = new DrugOrder(); otherOrder.setConcept(concept); assertFalse(order.hasSameOrderableAs(otherOrder)); }
/** * @see DrugOrder#hasSameOrderableAs(Order) */ @Test public void hasSameOrderableAs_shouldReturnTrueIfTheConceptsMatchAndHaveSameDrugNonCodedTrimmingSpaces() { DrugOrder order = new DrugOrder(); Concept concept = new Concept(); order.setConcept(concept); order.setDrugNonCoded("Chrocine"); DrugOrder otherOrder = new DrugOrder(); otherOrder.setConcept(concept); otherOrder.setDrugNonCoded(" Chrocine "); assertTrue(order.hasSameOrderableAs(otherOrder)); }
/** * @see DrugOrder#hasSameOrderableAs(Order) */ @Test public void hasSameOrderableAs_shouldReturnTrueIfTheConceptsMatchAndHaveSameDrugNonCoded() { DrugOrder order = new DrugOrder(); Concept concept = new Concept(); order.setConcept(concept); order.setDrugNonCoded("Chrocine"); DrugOrder otherOrder = new DrugOrder(); otherOrder.setConcept(concept); otherOrder.setDrugNonCoded("chrocine"); assertTrue(order.hasSameOrderableAs(otherOrder)); }
/** * @see DrugOrder#hasSameOrderableAs(Order) */ @Test public void hasSameOrderableAs_shouldReturnFalseIfTheConceptsMatchAndHaveDifferentDrugNonCoded() { DrugOrder order = new DrugOrder(); Concept concept = new Concept(); order.setConcept(concept); order.setDrugNonCoded("Chrocine"); DrugOrder otherOrder = new DrugOrder(); otherOrder.setConcept(concept); otherOrder.setDrugNonCoded("paracetemol"); assertFalse(order.hasSameOrderableAs(otherOrder)); }
/** * @see DrugOrder#hasSameOrderableAs(Order) */ @Test public void hasSameOrderableAs_shouldReturnFalseIfTheOtherOrderIsNull() { DrugOrder order = new DrugOrder(); order.setConcept(new Concept()); assertFalse(order.hasSameOrderableAs(null)); }
/** * @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_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 OrderServiceImpl#discontinueExistingOrdersIfNecessary() */ @Test(expected = AmbiguousOrderException.class) public void saveOrder_shouldThrowAmbiguousOrderExceptionIfDisconnectingMultipleActiveOrdersForTheGivenConcepts() { executeDataSet("org/openmrs/api/include/OrderServiceTest-discontinueAmbiguousOrderByConcept.xml"); DrugOrder order = new DrugOrder(); order.setAction(Order.Action.DISCONTINUE); order.setOrderReasonNonCoded("Discontinue this"); order.setConcept(conceptService.getConcept(88)); 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 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()); }
@Test public void saveOrder_shouldPassDrugOrderWithNeitherDrugNonCodedNorDrugAreSetForDrugOrderWhenDrugRequiredISNotSet() { executeDataSet("org/openmrs/api/include/OrderServiceTest-nonCodedDrugs.xml");Patient patient = Context.getPatientService().getPatient(7); CareSetting careSetting = Context.getOrderService().getCareSetting(2); OrderType orderType = Context.getOrderService().getOrderTypeByName("Drug order"); GlobalProperty gp = new GlobalProperty(OpenmrsConstants.GLOBAL_PROPERTY_DRUG_ORDER_REQUIRE_DRUG, "false"); Context.getAdministrationService().saveGlobalProperty(gp); //place drug order DrugOrder order = new DrugOrder(); Encounter encounter = Context.getEncounterService().getEncounter(3); order.setEncounter(encounter); order.setPatient(patient); order.setCareSetting(careSetting); order.setConcept(Context.getOrderService().getNonCodedDrugConcept()); order.setOrderer(Context.getProviderService().getProvider(1)); order.setDateActivated(encounter.getEncounterDatetime()); order.setOrderType(orderType); order.setDosingType(FreeTextDosingInstructions.class); order.setInstructions("None"); order.setDosingInstructions("Test Instruction"); Errors errors = new BindException(order, "order"); new DrugOrderValidator().validate(order, errors); Assert.assertFalse(errors.hasFieldErrors()); } }
@Test public void saveOrder_shouldPassDrugOrderWithADrugNonCodedWhenDrugOrderIsNonCoded() { executeDataSet("org/openmrs/api/include/OrderServiceTest-nonCodedDrugs.xml"); Patient patient = Context.getPatientService().getPatient(7); CareSetting careSetting = Context.getOrderService().getCareSetting(2); OrderType orderType = Context.getOrderService().getOrderTypeByName("Drug order"); GlobalProperty gp = new GlobalProperty(OpenmrsConstants.GLOBAL_PROPERTY_DRUG_ORDER_REQUIRE_DRUG, "true"); Context.getAdministrationService().saveGlobalProperty(gp); //place drug order DrugOrder order = new DrugOrder(); Encounter encounter = Context.getEncounterService().getEncounter(3); order.setEncounter(encounter); order.setConcept(Context.getOrderService().getNonCodedDrugConcept()); order.setDrugNonCoded("Non coded drug"); order.setPatient(patient); 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"); Errors errors = new BindException(order, "order"); new DrugOrderValidator().validate(order, errors); Assert.assertFalse(errors.hasFieldErrors()); }