/** * Returns the boolean value if the concept of this obs is of boolean datatype * * @return true or false if value is set otherwise null * @should return true if value coded answer concept is true concept * @should return false if value coded answer concept is false concept */ public Boolean getValueBoolean() { if (getConcept() != null && valueCoded != null && getConcept().getDatatype().isBoolean()) { Concept trueConcept = Context.getConceptService().getTrueConcept(); return trueConcept != null && valueCoded.getId().equals(trueConcept.getId()); } return null; }
/** * @see ConceptService#getConceptsByMapping(String,String,Boolean) */ @Test public void getConceptsByMapping_shouldSortNonRetiredConceptsFirst() { List<Concept> concepts = conceptService.getConceptsByMapping("766554", "SSTRM", true); Assert.assertEquals(16, concepts.get(0).getId().intValue()); }
/** * @see ConceptService#getConceptByMapping(String,String) */ @Test public void getConceptByMapping_shouldGetConceptWithGivenCodeAndSourceName() { Concept concept = conceptService.getConceptByMapping("WGT234", "Some Standardized Terminology"); Assert.assertEquals(5089, concept.getId().intValue()); }
List<Integer> ids = new ArrayList<>(); for (ConceptAnswer conceptAnswer : answersToConcept.getAnswers(false)) { ids.add(conceptAnswer.getAnswerConcept().getId());
/** * @see ConceptService#getConceptsByMapping(String,String) */ @Test public void getConceptByMapping_shouldReturnRetiredConceptByDefaultIfOnlyMatch() { Concept concept = conceptService.getConceptByMapping("454545", "SSTRM"); Assert.assertEquals(24, concept.getId().intValue()); }
/** * @see ConceptService#getConceptByMapping(String,String) */ @Test public void getConceptByMapping_shouldIgnoreCase() { Concept concept = conceptService.getConceptByMapping("wgt234", "sstrm"); Assert.assertEquals(5089, concept.getId().intValue()); }
/** * @see ConceptService#getConceptByMapping(String,String) */ @Test public void getConceptByMapping_shouldGetConceptWithGivenCodeAndSourceHl7Code() { Concept concept = conceptService.getConceptByMapping("WGT234", "SSTRM"); Assert.assertEquals(5089, concept.getId().intValue()); }
/** * @see ConceptService#getConceptsByMapping(String,String,Boolean) */ @Test public void getConceptByMapping_shouldReturnRetiredConceptIfOnlyMatch() { Concept concept = conceptService.getConceptByMapping("454545", "SSTRM", true); Assert.assertEquals(24, concept.getId().intValue()); }
/** * Utility method to check if the concept is already attached to an observation (including * voided ones) and if the datatype of the concept has changed, an exception indicating that the * datatype cannot be modified will be reported if the concept is attached to an observation. * This method will only allow changing boolean concepts to coded. * * @param concept * @throws ConceptInUseException */ private void checkIfDatatypeCanBeChanged(Concept concept) { if (concept.getId() != null && hasAnyObservation(concept) && hasDatatypeChanged(concept)) { // allow boolean concepts to be converted to coded if (!(dao.getSavedConceptDatatype(concept).isBoolean() && concept.getDatatype().isCoded())) { throw new ConceptInUseException(); } if (log.isDebugEnabled()) { log.debug("Converting datatype of concept with id " + concept.getConceptId() + " from Boolean to Coded"); } } }
/** * @see ConceptService#getConcepts(String, List, boolean, List, List, List, List, Concept, Integer, Integer) */ @Test public void getConcepts_shouldReturnConceptSearchResultsThatMatchUniqueConceptsEvenIfDifferentMatchingWords() { executeDataSet("org/openmrs/api/include/ConceptServiceTest-names.xml"); List<ConceptSearchResult> searchResults = conceptService.getConcepts("now", Collections .singletonList(Locale.ENGLISH), false, null, null, null, null, null, null, null); // "now matches both concept names "TRUST NOW" and "TRUST NOWHERE", but these are for the same concept (4000), so there should only be one item in the result set Assert.assertEquals(1, searchResults.size()); Assert.assertEquals(new Integer(4000), searchResults.get(0).getConcept().getId()); }
/** * @see ConceptService#getConceptByName(String) */ @Test public void getConceptByName_shouldGetConceptByName() { String nameToFetch = "Some non numeric concept name"; executeDataSet(INITIAL_CONCEPTS_XML); Concept conceptByName = conceptService.getConceptByName(nameToFetch); assertEquals("Unable to fetch concept by name", 1, conceptByName.getId().intValue()); }
/** * @see ORUR01Handler#getConcept(String,String) */ @Test public void getConcept_shouldReturnAMappedConceptIfGivenAValidMapping() throws Exception { Assert.assertEquals(5089, new ORUR01Handler().getConcept("WGT234", "SSTRM", "23498343sdnm3").getId().intValue()); }
/** * @see ORUR01Handler#getConcept(String,String) */ @Test public void getConcept_shouldReturnAConceptIfGivenLocalCodingSystem() throws Exception { Assert.assertEquals(5089, new ORUR01Handler().getConcept("5089", "99DCT", "xj39bnj4k34nmf").getId().intValue()); }
/** * @see ConceptService#getConceptsByAnswer(ConceptClass) */ @Test public void getConceptsByAnswer_shouldFindAnswersForConcept() { Concept concept = conceptService.getConcept(7); Assert.assertNotNull(concept); List<Concept> concepts = conceptService.getConceptsByAnswer(concept); Assert.assertEquals(1, concepts.size()); Assert.assertEquals(21, concepts.get(0).getId().intValue()); }
/** * @see ObsService#getObs(Integer) */ @Test public void getObs_shouldGetObsMatchingGivenObsId() { ObsService obsService = Context.getObsService(); Obs obs = obsService.getObs(7); Assert.assertEquals(5089, obs.getConcept().getId().intValue()); }
/** * @see ConceptService#getUnknownConcept() */ @Test public void getUnknownConcept_shouldReturnTheUnknownConcept() { createUnknownConceptGlobalProperty(); Assert.assertNotNull(conceptService.getUnknownConcept()); Assert.assertEquals(9, conceptService.getUnknownConcept().getId().intValue()); }
/** * @see ConceptService#getFalseConcept() */ @Test public void getFalse_shouldReturnTheFalseConcept() { createTrueFalseGlobalProperties(); Assert.assertNotNull(conceptService.getFalseConcept()); Assert.assertEquals(8, conceptService.getFalseConcept().getId().intValue()); }
/** * @see ConceptService#getTrueConcept() */ @Test public void getTrue_shouldReturnTheTrueConcept() { createTrueFalseGlobalProperties(); Assert.assertNotNull(conceptService.getTrueConcept()); Assert.assertEquals(7, conceptService.getTrueConcept().getId().intValue()); }
@Test public void saveProgram_shouldAlsoSaveOutcomesConcept() { Concept outcomesConcept = Context.getConceptService().getConcept(3); Program program = createProgram(); program.setOutcomesConcept(outcomesConcept); int id = dao.saveProgram(program).getId(); clearHibernateCache(); Program savedProgram = dao.getProgram(id); Assert.assertEquals(3, savedProgram.getOutcomesConcept().getId().intValue()); }
/** * @see ConceptService#saveConcept(Concept) */ @Test public void saveConcept_shouldCreateAReferenceTermForAConceptMappingOnTheFlyWhenCreatingAConcept() { int initialTermCount = conceptService.getAllConceptReferenceTerms().size(); Concept concept = new Concept(); concept.addName(new ConceptName("test name", Context.getLocale())); concept.setDatatype(new ConceptDatatype(1)); concept.setConceptClass(new ConceptClass(1)); ConceptMap map = new ConceptMap(); map.getConceptReferenceTerm().setCode("unique code"); map.getConceptReferenceTerm().setConceptSource(conceptService.getConceptSource(1)); concept.addDescription(new ConceptDescription("some description",null)); concept.addConceptMapping(map); conceptService.saveConcept(concept); Assert.assertNotNull(concept.getId()); Assert.assertEquals(initialTermCount + 1, conceptService.getAllConceptReferenceTerms().size()); }