@Test public void saveConcept_shouldUpdateConceptAlreadyExistingInDatabase() { executeDataSet(INITIAL_CONCEPTS_XML); // using isSet() as a value to check and change assertFalse(conceptService.getConcept(2).getSet()); Concept concept = conceptService.getConcept(2); // change a value concept.setSet(true); // save the concept conceptService.saveConcept(concept); // see if the value was updated in the database assertTrue(conceptService.getConcept(2).getSet()); }
@Override protected Concept getObjectByUuid(String uuid) { return Context.getConceptService().getConceptByUuid(uuid); } }
@Override protected Drug getObjectByUuid(String uuid) { return Context.getConceptService().getDrugByUuid(uuid); } }
/** * @see ConceptService#getConcept(Integer) */ @Test(expected = APIException.class) public void changeConceptFromBooleanToCoded_shouldFailIfTheDatatypeOfTheConceptIsNotBoolean() { Concept concept = conceptService.getConcept(5497); conceptService.convertBooleanConceptToCoded(concept); }
/** * @see ConceptServiceImpl#getPrevConcept(Concept) */ @Test public void getPrevConcept_shouldReturnTheConceptPreviousToTheGivenConcept() { Integer conceptId = 4; Integer prevConceptId = 3; Concept returnedConcept = conceptService.getPrevConcept(conceptService.getConcept(conceptId)); assertEquals(returnedConcept, conceptService.getConcept(prevConceptId)); }
/** * @see ConceptServiceImpl#getNextConcept(Concept) */ @Test public void getNextConcept_shouldReturnTheConceptNextToTheGivenConcept() { Integer conceptId = 3; Integer nextConceptId = 4; Concept returnedConcept = conceptService.getNextConcept(conceptService.getConcept(conceptId)); assertEquals(returnedConcept, conceptService.getConcept(nextConceptId)); }
/** * @see ConceptService#saveConcept(Concept) */ @Test public void saveConcept_shouldKeepIdForNewConceptIfOneIsSpecified() { Integer conceptId = 343434; // a nonexistent concept id; Assert.assertNull(conceptService.getConcept(conceptId)); // sanity check Concept concept = new Concept(); ConceptName cn = new ConceptName("Weight", Context.getLocale()); concept.addName(cn); concept.addDescription(new ConceptDescription("some description",null)); concept.setConceptId(conceptId); concept.setDatatype(Context.getConceptService().getConceptDatatypeByName("Numeric")); concept.setConceptClass(Context.getConceptService().getConceptClassByName("Finding")); concept = Context.getConceptService().saveConcept(concept); assertTrue(concept.getConceptId().equals(conceptId)); }
/** * @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))); }
@Test(expected = ConceptInUseException.class) public void saveConcept_shouldNotUpdateConceptDataTypeIfConceptIsAttachedToAnObservation() { executeDataSet(INITIAL_CONCEPTS_XML); Concept concept = conceptService.getConcept(2); assertNotNull(concept); ObsService obsService = Context.getObsService(); Obs obs = new Obs(Context.getPersonService().getPerson(1), concept, new Date(), Context.getLocationService() .getLocation(1)); obs.setValueCoded(Context.getConceptService().getConcept(7)); obsService.saveObs(obs, "Creating a new observation with a concept"); ConceptDatatype newDatatype = conceptService.getConceptDatatypeByName("Text"); concept.setDatatype(newDatatype); conceptService.saveConcept(concept); }
/** * @see ConceptService#saveConcept(Concept) */ @Test public void saveConcept_shouldGenerateIdForNewConceptIfNoneIsSpecified() { Concept concept = new Concept(); ConceptName cn = new ConceptName("Weight", Context.getLocale()); concept.addName(cn); concept.addDescription(new ConceptDescription("some description",null)); concept.setConceptId(null); concept.setDatatype(Context.getConceptService().getConceptDatatypeByName("Numeric")); concept.setConceptClass(Context.getConceptService().getConceptClassByName("Finding")); concept = Context.getConceptService().saveConcept(concept); assertFalse(concept.getConceptId().equals(5089)); }
/** * @see FormService#getFormsContainingConcept(Concept) */ @Test public void getFormsContainingConcept_shouldGetAllFormsForConcept() { Concept concept = Context.getConceptService().getConcept(3); assertEquals(1, Context.getFormService().getFormsContainingConcept(concept).size()); }
/** * @see ConceptService#getConcepts(String, List, boolean, List, List, List, List, Concept, Integer, Integer) */ @Test public void getConcepts_shouldReturnConceptsWithSpecifiedClasses() { executeDataSet("org/openmrs/api/include/ConceptServiceTest-names.xml"); List<ConceptClass> classes = new ArrayList<>(); classes.add(Context.getConceptService().getConceptClassByName("Finding")); classes.add(Context.getConceptService().getConceptClassByName("LabSet")); List<ConceptSearchResult> searchResults = conceptService.getConcepts(null, null, false, classes, null, null, null, null, null, null); Assert.assertEquals(2, searchResults.size()); }
@Override protected ConceptSource getObjectByUuid(String uuid) { return Context.getConceptService().getConceptSourceByUuid(uuid); } }
/** * @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)); }
@Test public void setValue_shouldReturnDrug() throws Exception { Obs obs = new Obs(); Concept concept = Context.getConceptService().getConceptByUuid("89ca642a-dab6-4f20-b712-e12ca4fc6d36"); obs.setConcept(concept); // drug String drugUuid = "3cfcf118-931c-46f7-8ff6-7b876f0d4202"; Drug drug = Context.getConceptService().getDrugByUuid(drugUuid); ObsResource1_8.setValue(obs, drugUuid); assertEquals(drug, ObsResource1_8.getValue(obs)); }
/** * @see ConceptServiceImpl#purgeConcept(Concept) */ @Test public void purgeConcept_shouldPurgeTheConceptIfNotBeingUsedByAnObs() { int conceptId = 88; conceptService.purgeConcept(conceptService.getConcept(conceptId)); assertNull(conceptService.getConcept(conceptId)); }
/** * @see ConceptServiceImpl#getAllConceptSources(boolean) */ @Test public void getAllConceptSources_shouldReturnAllConceptSourcesIncludingRetiredOnesWhenGivenTrue() { int conceptSourcesInDataset = 5; List<ConceptSource> conceptSources = conceptService.getAllConceptSources(true); assertEquals(conceptSourcesInDataset, conceptSources.size()); }
/** * @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#getAllConceptDatatypes() */ @Test public void getAllConceptDatatypes_shouldGiveAListOfAllConceptDataypes() { int resultSize = 12; String uuid = "8d4a4488-c2cc-11de-8d13-0010c6dffd0f"; List<ConceptDatatype> conceptDatatypes = conceptService.getAllConceptDatatypes(); assertEquals(resultSize, conceptDatatypes.size()); assertTrue(conceptDatatypes.contains(conceptService.getConceptDatatypeByUuid(uuid))); }
/** * @see ConceptServiceImpl#getSetsContainingConcept(Concept) */ @Test public void getSetsContainingConcept_shouldGiveAnEmptyListIfNoMatchingConceptSetIsFound() { String uuid = "0cbe2ed3-cd5f-4f46-9459-26127c9265ab"; Concept concept = conceptService.getConceptByUuid(uuid); List<ConceptSet> conceptSets = conceptService.getSetsContainingConcept(concept); assertEquals(conceptSets, Collections.emptyList()); }