@Override protected Drug getExistingObject() { return conceptService.getDrug(EXISTING_ID); } }
/** * @see ConceptService#getDrugs(String, java.util.Locale, boolean, boolean) */ @Test public void getDrugs_shouldReturnAllDrugsWithAMatchingTermCodeOrDrugNameOrConceptName() { executeDataSet("org/openmrs/api/include/ConceptServiceTest-drugSearch.xml"); List<Drug> drugs = conceptService.getDrugs("XXX", null, false, true); assertThat(drugs, containsInAnyOrder(conceptService.getDrug(3), conceptService.getDrug(11), conceptService .getDrug(444))); }
/** * @see ConceptServiceImpl#getDrug(String) */ @Test public void getDrug_shouldReturnTheMatchingDrugObject() { String drugName = "ASPIRIN"; String drugUuid = "05ec820a-d297-44e3-be6e-698531d9dd3f"; Drug drug = conceptService.getDrugByUuid(drugUuid); assertEquals(drug, conceptService.getDrug(drugName)); }
/** * @see ConceptService#getDrugs(String, java.util.Locale, boolean, boolean) */ @Test public void getDrugs_shouldGetDrugsWithNamesMatchingTheSearchPhrase() { //Should be case insensitive List<Drug> drugs = conceptService.getDrugs("tri", null, false, false); assertThat(drugs, contains(conceptService.getDrug(2))); }
@Override protected Drug getObjectById(Integer id) { return Context.getConceptService().getDrug(id); }
/** * @see ConceptServiceImpl#getDrugs(String, Concept, boolean, boolean, boolean, Integer, * Integer) */ @Test public void getDrugs_shouldReturnListOfMatchingDrugs() { String drugName = "ASPIRIN"; String drugUuid = "05ec820a-d297-44e3-be6e-698531d9dd3f"; Concept concept = conceptService.getConceptByUuid(drugUuid); List<Drug> drugs = conceptService.getDrugs(drugName, concept, true, true, true, 0, 100); assertTrue(drugs.contains(conceptService.getDrug(drugName))); }
public DrugOrderBuilder withDrug(Integer drugID) { drugOrder.setDrug(conceptService.getDrug(drugID)); return this; }
/** * @see ConceptService#getDrugs(String) */ @Test public void getDrugs_shouldReturnDrugsByDrugId() { Integer drugId = 2; Drug drug = Context.getConceptService().getDrug(drugId); List<Drug> drugs = Context.getConceptService().getDrugs(String.valueOf(drugId)); Assert.assertTrue(drugs.contains(drug)); }
/** * Ensures that unique drugs are returned in situations where more than one searched fields * match e.g drug name and linked concept name match the search phrase * * @see ConceptService#getDrugs(String, java.util.Locale, boolean, boolean) */ @Test public void getDrugs_shouldReturnUniqueDrugs() { //sanity check that drug.name and drug.concept.name will both match the search phrase Drug drug = conceptService.getDrug("ASPIRIN"); assertEquals(drug.getName().toLowerCase(), drug.getConcept().getName().getName().toLowerCase()); List<Drug> drugs = conceptService.getDrugs("Asp", null, false, false); assertEquals(1, drugs.size()); assertEquals(3, drugs.get(0).getDrugId().intValue()); }
/** * @see ConceptServiceImpl#getDrug(String) */ @Test public void getDrug_shouldReturnNullIfNoMatchingDrugIsFound() { int drugIdNotPresent = 1234; assertNull(conceptService.getDrug(drugIdNotPresent)); }
/** * @see ConceptService#getDrugs(String) */ @Test public void getDrugs_shouldReturnDrugsByDrugConceptId() { Integer conceptId = 792; Drug drug = Context.getConceptService().getDrug(2); // assert that given drug has concept with tested id Assert.assertNotNull(drug.getConcept()); Assert.assertEquals(drug.getConcept().getConceptId(), conceptId); List<Drug> drugs = Context.getConceptService().getDrugs(String.valueOf(conceptId)); Assert.assertTrue(drugs.contains(drug)); }
/** * @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 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 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 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 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()); }
@Test public void saveOrder_shouldFailDrugOrderWithBothDrugNonCodedAndDrugAreSetForDrugOrder() { 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.setDrug(Context.getConceptService().getDrug(3)); order.setDrugNonCoded("paracetemol drug non coded"); 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.assertTrue(errors.hasFieldErrors()); assertEquals("DrugOrder.error.onlyOneOfDrugOrNonCodedShouldBeSet", errors.getFieldError("concept").getCode()); }