private Obs getObsGroup() { ConceptDatatype datatype = new ConceptDatatype(); datatype.setUuid(ConceptDatatype.CODED_UUID); datatype.setHl7Abbreviation(ConceptDatatype.CODED); Concept concept = new Concept(1); concept.setDatatype(datatype); concept.addName(new ConceptName("MedSet", Locale.ENGLISH)); ConceptSource source = new ConceptSource(); source.setName("LOCAL"); ConceptMap map = new ConceptMap(); map.setSourceCode("100"); map.setSource(source); concept.addConceptMapping(map); Date dateCreated = new Date(213231421890234L); Obs obs = new Obs(1); obs.setConcept(concept); obs.setDateCreated(dateCreated); return obs; }
@Test @Verifies( value = "should return a list consisting of active, not retired, states", method = "getPossibleNextStates") public void getPossibleNextStates_shouldReturnNonRetiredStates() throws Exception { executeDataSet(PROGRAM_NEXT_STATES_XML); Integer patient = 11; Integer workflow = 501; Vector<ListItem> possibleNextStates; /* retire a workflow state */ PatientProgram pp = Context.getProgramWorkflowService().getPatientProgram(patient); ProgramWorkflow pw = pp.getProgram().getWorkflow(workflow); Set<ProgramWorkflowState> pwss = pw.getStates(); for (ProgramWorkflowState pws : pwss) { Concept cp = pws.getConcept(); ConceptName cn = cp.getName(); if (cn != null) { String cnn = cn.getName(); if (cnn.equalsIgnoreCase("Test State 3")) { pws.setRetired(true); } } } possibleNextStates = dwrProgramWorkflowService.getPossibleNextStates(patient, workflow); assertFalse(possibleNextStates.isEmpty()); assertEquals(2, possibleNextStates.size()); }
/** * Builds a coded result from an observation * * @param obs */ public Result(Obs obs) { this( obs.getObsDatetime(), null, obs.getValueAsBoolean(), obs.getValueCoded(), obs.getValueDatetime(), obs.getValueNumeric(), obs.getValueText(), obs); Concept concept = obs.getConcept(); ConceptDatatype conceptDatatype = null; if (concept != null) { conceptDatatype = concept.getDatatype(); if (conceptDatatype == null) { return; } if (conceptDatatype.isCoded()) { this.datatype = Datatype.CODED; } else if (conceptDatatype.isNumeric()) { this.datatype = Datatype.NUMERIC; } else if (conceptDatatype.isDate()) { this.datatype = Datatype.DATETIME; } else if (conceptDatatype.isText()) { this.datatype = Datatype.TEXT; } else if (conceptDatatype.isBoolean()) { this.datatype = Datatype.BOOLEAN; } } }
/** * Gets a concept by an identifier (mapping or UUID) * * @param identifier the identifier * @return the concept * @throws org.openmrs.module.metadatadeploy.MissingMetadataException if the concept could not be * found */ public static Concept getConcept(String identifier) { Concept concept; if (identifier.contains(":")) { String[] tokens = identifier.split(":"); concept = Context.getConceptService().getConceptByMapping(tokens[1].trim(), tokens[0].trim()); } else { // Assume it's a UUID concept = Context.getConceptService().getConceptByUuid(identifier); } if (concept == null) { throw new MissingMetadataException(Concept.class, identifier); } // getConcept doesn't always return ConceptNumeric for numeric concepts if (concept.getDatatype().isNumeric() && !(concept instanceof ConceptNumeric)) { concept = Context.getConceptService().getConceptNumeric(concept.getId()); if (concept == null) { throw new MissingMetadataException(ConceptNumeric.class, identifier); } } return concept; }
/** @param concept the concept to set */ public void setConcept(Concept concept) { this.concept = concept; if (concept != null) { setName(concept.getName().getName()); setDescription(concept.getDisplayString()); } }
private Concept newConcept(ConceptDatatype conceptDatatype, String conceptUuid) { Concept concept = new Concept(); concept.setDatatype(conceptDatatype); concept.setUuid(conceptUuid); when(conceptService.getConceptByUuid(conceptUuid)).thenReturn(concept); return concept; }
/** @see {@link HtmlFormEntryUtil#getConcept(String)} mapping test */ @Test @Verifies(value = "should find a concept by its mapping", method = "getConcept(String)") public void getConcept_shouldFindAConceptByItsMapping() throws Exception { String id = "XYZ:HT"; Concept cpt = HtmlFormEntryUtil.getConcept(id); Assert.assertEquals("XYZ", cpt.getConceptMappings().iterator().next().getSource().getName()); Assert.assertEquals("HT", cpt.getConceptMappings().iterator().next().getSourceCode()); }
/** * @see BaseOpenmrsDatatype#doGetTextSummary(Object) * @should use the name in summary instance */ @Override public Summary doGetTextSummary(Concept concept) { String name = ""; if (concept.getName() != null) { name = concept.getName().getName(); } return new CustomDatatype.Summary(name, true); }
private void assertMappedCorrectly() { Concept concept = Context.getConceptService().getConceptByUuid("23423a2982236623"); if (concept.isNumeric()) { Assert.fail(); } Assert.assertEquals("N/A", concept.getDatatype().getName()); }
private Concept setupConcept(ConceptService mockConceptService, String name, String mappingCode) { Concept concept = new Concept(); concept.addName(new ConceptName(name, Locale.ENGLISH)); concept.addConceptMapping( new ConceptMap(new ConceptReferenceTerm(emrConceptSource, mappingCode, null), sameAs)); when(mockConceptService.getConceptByMapping(mappingCode, emrConceptSource.getName())) .thenReturn(concept); return concept; }
/** * Auto generated method comment * * @param conceptId * @return */ public static String getConceptName(Integer conceptId) { try { if (null == conceptId) return "-"; Concept concept = Context.getConceptService().getConcept(conceptId); return (concept != null) ? concept.getDisplayString() : "-"; } catch (Exception e) { log.info(e.getMessage()); return "-"; } }
public CodeableConceptDt getTRValueSetCodeableConcept( Concept concept, String valueSetURL, CodeableConceptDt codeableConcept) { CodingDt coding = codeableConcept.addCoding(); if (null != idMappingsRepository.findByInternalId(concept.getUuid())) { coding.setCode(getTRValueSetCode(concept)); coding.setSystem(valueSetURL); } coding.setDisplay(concept.getName().getName()); return codeableConcept; }
/** * Auto generated method comment * * @param conceptId * @return */ public static String getConceptNameByIdAsString(String conceptId) { String res = "-"; try { if (conceptId.trim().compareTo("") == 0) return "-"; Concept concept = Context.getConceptService().getConcept(Integer.parseInt(conceptId)); res = (concept != null) ? concept.getDisplayString() : "-"; } catch (Exception e) { log.info(e.getMessage()); } return res; }
public String getTRValueSetCode(Concept concept) { for (ConceptMap mapping : concept.getConceptMappings()) { if (mapping.getConceptMapType().getUuid().equals(ConceptMapType.SAME_AS_MAP_TYPE_UUID)) { return mapping.getConceptReferenceTerm().getCode(); } } for (ConceptName conceptName : concept.getShortNames()) { return conceptName.getName(); } return concept.getName().getName(); }
/** * Auto generated method comment * * @param conceptId * @return */ public static String checkIfConceptExistByIdAsString(String conceptId) { String res = ""; try { if (conceptId.trim().compareTo("") == 0) return res; Concept concept = Context.getConceptService().getConcept(Integer.parseInt(conceptId)); res = (concept != null) ? "" + concept.getConceptId() : ""; } catch (Exception e) { log.info(e.getMessage()); } return res; }
private void addTRCodingForConcept( Concept concept, IdMappingsRepository idMappingsRepository, CodeableConceptDt codeableConcept) { IdMapping idMapping = idMappingsRepository.findByInternalId(concept.getUuid()); if (idMapping != null) { addFHIRCoding( codeableConcept, idMapping.getExternalId(), idMapping.getUri(), concept.getName().getName()); } }
/** Gets or creates a Concept with a given UUID and name. */ public static Concept getConcept(String name, String uuid, String typeUuid) { ConceptService conceptService = Context.getConceptService(); Concept concept = conceptService.getConceptByUuid(uuid); if (concept == null) { concept = new Concept(); concept.setUuid(uuid); concept.setShortName(new ConceptName(name, new Locale("en"))); concept.setDatatype(conceptService.getConceptDatatypeByUuid(typeUuid)); concept.setConceptClass(conceptService.getConceptClassByUuid(ConceptClass.MISC_UUID)); conceptService.saveConcept(concept); } return concept; }
@Test public void addSetMembers() throws Exception { ConceptSetRow conceptRow = new ConceptSetRow(); conceptRow.name = "New concept"; conceptRow.conceptClass = "New Class"; conceptRow.description = "some description"; List<KeyValue> children = new ArrayList<>(); children.add(new KeyValue("1", "Child1")); children.add(new KeyValue("2", "Child2")); conceptRow.children = children; Messages persistErrorMessages = conceptSetPersister.persist(conceptRow); assertTrue(persistErrorMessages.isEmpty()); Context.openSession(); Context.authenticate("admin", "test"); Concept persistedConcept = conceptService.getConceptByName(conceptRow.name); assertNotNull(persistedConcept); assertEquals(conceptRow.name, persistedConcept.getName(Context.getLocale()).getName()); assertEquals(conceptRow.conceptClass, persistedConcept.getConceptClass().getName()); assertEquals("some description", persistedConcept.getDescription().getDescription()); assertEquals(2, persistedConcept.getSetMembers().size()); assertEquals("some description", persistedConcept.getDescription().getDescription()); assertEquals(0, persistedConcept.getSynonyms().size()); assertTrue(persistedConcept.isSet()); Context.flushSession(); Context.closeSession(); }
@Test @Verifies( value = "shouldSetTheValueComplexOfObsIfConceptIsComplex", method = "createObs(Concept concept, Object value, Date datetime, String accessionNumber)") public void createObs_shouldSetTheValueComplexOfObsIfConceptIsComplex() { ComplexData complexData = new ComplexData("test", null); Concept c = new Concept(); ConceptDatatype cd = new ConceptDatatype(); cd.setUuid(HtmlFormEntryConstants.COMPLEX_UUID); c.setDatatype(cd); Obs o = HtmlFormEntryUtil.createObs(c, complexData, null, null); Assert.assertEquals(o.getValueComplex(), complexData.getTitle()); }
/** * @return string representation of the result. For non-text results, this will either be the * overridden text value (if specifically defined) or a string representation of the default * datatype value. If the result is a list, then the string representation of all members a * joined with commas. */ public String toString() { if (isSingleResult()) { if (datatype == null) { return valueText == null ? "" : valueText; } switch (datatype) { case BOOLEAN: return (valueBoolean ? "true" : "false"); case CODED: return (valueCoded == null ? "" : valueCoded.getBestName(Context.getLocale()).getName()); case DATETIME: return (valueDatetime == null ? "" : Context.getDateFormat().format(valueDatetime)); case NUMERIC: return (valueNumeric == null ? "" : String.valueOf(valueNumeric)); case TEXT: return (valueText == null ? "" : valueText); default: return valueText; } } StringBuffer s = new StringBuffer(); for (Result r : this) { if (s.length() > 0) { s.append(","); } s.append(r.toString()); } return s.toString(); }
@Test public void testController_createdProperPriorDiagnoses() throws Exception { EncounterDiagnosesFragmentController controller = new EncounterDiagnosesFragmentController(); ConceptName specificName = new ConceptName("Specific Name", Context.getLocale()); specificName.setId(1); specificName.setLocalePreferred(true); Concept conceptForSpecificName = new Concept(); conceptForSpecificName.setId(2); conceptForSpecificName.addName(specificName); Concept nonSpecificConcept = new Concept(); nonSpecificConcept.setId(3); ConceptName nonSpecificConceptName = new ConceptName("Non-specific concept", Context.getLocale()); nonSpecificConceptName.setId(4); nonSpecificConceptName.setLocalePreferred(true); nonSpecificConcept.addName(nonSpecificConceptName); List<Diagnosis> diagnoses = new ArrayList<Diagnosis>(); diagnoses.add(new Diagnosis(new CodedOrFreeTextAnswer(specificName), Diagnosis.Order.PRIMARY)); diagnoses.add( new Diagnosis(new CodedOrFreeTextAnswer(nonSpecificConcept), Diagnosis.Order.SECONDARY)); diagnoses.add( new Diagnosis(new CodedOrFreeTextAnswer("Unknown Disease"), Diagnosis.Order.SECONDARY)); for (Diagnosis d : diagnoses) { d.setExistingObs(new Obs()); } FragmentModel model = new FragmentModel(); controller.controller(new TestUiUtils(), null, diagnoses, model); assertThat(((List<String>) model.getAttribute("jsForExisting")).size(), is(0)); List<String> jsForPrior = (List<String>) model.getAttribute("jsForPrior"); assertThat( jsForPrior.get(0), is( "{ diagnosis: diagnoses.CodedOrFreeTextConceptAnswer({\"word\":null,\"conceptName\":{\"id\":1,\"uuid\":\"" + specificName.getUuid() + "\",\"conceptNameType\":\"FULLY_SPECIFIED\",\"name\":\"Specific Name\"},\"concept\":{\"id\":2,\"uuid\":\"" + conceptForSpecificName.getUuid() + "\",\"conceptMappings\":[],\"preferredName\":\"Specific Name\"}}), confirmed: false, primary: true, existingObs: null }")); assertThat( jsForPrior.get(1), is( "{ diagnosis: diagnoses.CodedOrFreeTextConceptAnswer({\"word\":null,\"conceptName\":null,\"concept\":{\"id\":3,\"uuid\":\"" + nonSpecificConcept.getUuid() + "\",\"conceptMappings\":[],\"preferredName\":\"Non-specific concept\"}}), confirmed: false, primary: false, existingObs: null }")); assertThat( jsForPrior.get(2), is( "{ diagnosis: diagnoses.CodedOrFreeTextConceptAnswer('Unknown Disease'), confirmed: false, primary: false, existingObs: null }")); }
public CodeableConceptDt addTRCodingOrDisplay(Concept concept) { CodeableConceptDt codeableConceptDt = addTRCoding(concept); if (CollectionUtils.isEmpty(codeableConceptDt.getCoding())) { CodingDt coding = codeableConceptDt.addCoding(); coding.setDisplay(concept.getName().getName()); } return codeableConceptDt; }
public DataObject simplifyConcept(Concept concept, Locale locale) throws Exception { List<Object> propertyNamesAndValues = new ArrayList<Object>(); ConceptName preferredName = concept.getPreferredName(locale); propertyNamesAndValues.add("conceptId"); propertyNamesAndValues.add(Integer.toString((concept.getConceptId()))); if (preferredName != null && preferredName.getName() != null) { propertyNamesAndValues.add("conceptName"); propertyNamesAndValues.add(preferredName.getName()); } else if (preferredName == null && concept.getName() != null) { propertyNamesAndValues.add("conceptName"); propertyNamesAndValues.add(concept.getName().getName()); } DataObject dataObject = DataObject.create(propertyNamesAndValues); return dataObject; }
private Obs findOrCreateObs(Obs diagnosisObs, Concept concept) { for (Obs o : diagnosisObs.getGroupMembers()) { if (concept.equals(o.getConcept())) { return o; } } Obs obs = new Obs(); obs.setConcept(concept); return obs; }
public ConceptSearchResult(Concept con) { this.conceptId = con.getConceptId(); if (con.getName() != null) { this.conceptName = con.getName().getName(); } if (con.getDescription() != null) { this.conceptDescription = con.getDescription().getDescription(); } if (con.getConceptClass() != null) { this.conceptClass = con.getConceptClass().getName(); } if (con.getDatatype() != null) { this.conceptDatatype = con.getDatatype().getName(); } this.otherNames = new Vector<String>(); for (ConceptName cn : con.getNames()) { this.otherNames.add(cn.getName()); } }
@Test public void shouldSaveOrdersToEncounterWithExistingOrders() throws ParseException { EmrOrderServiceImpl_1_10 emrOrderService = new EmrOrderServiceImpl_1_10(openMRSDrugOrderMapper, encounterService, openMRSOrderMapper); EncounterTransaction.Order order1 = new OrderBuilder().withConceptUuid("concept-uuid1").withComment("Comment").build(); EncounterTransaction.Order order2 = new OrderBuilder().withConceptUuid("concept-uuid2").withComment("Comment").build(); Order mappedOrder1 = new Order(); Concept concept = new Concept(); concept.setUuid("concept-uuid1"); mappedOrder1.setConcept(concept); mappedOrder1.setCommentToFulfiller("Comment"); Order mappedOrder2 = new Order(); concept = new Concept(); concept.setUuid("concept-uuid2"); mappedOrder2.setConcept(concept); mappedOrder2.setCommentToFulfiller("Comment"); Order existingOrder1 = new Order(); Order existingOrder2 = new Order(); Encounter encounter = new Encounter(); encounter.addOrder(existingOrder1); encounter.addOrder(existingOrder2); when(openMRSOrderMapper.map(order1, encounter)).thenReturn(mappedOrder1); when(openMRSOrderMapper.map(order2, encounter)).thenReturn(mappedOrder2); emrOrderService.saveOrders(Arrays.asList(order1, order2), encounter); ArgumentCaptor<Encounter> encounterArgumentCaptor = ArgumentCaptor.forClass(Encounter.class); verify(encounterService).saveEncounter(encounterArgumentCaptor.capture()); Encounter savedEncounter = encounterArgumentCaptor.getValue(); ArrayList<org.openmrs.Order> savedOrders = new ArrayList<org.openmrs.Order>(savedEncounter.getOrders()); assertThat(savedOrders.size(), is(4)); assertTrue(existsInOrdersList(mappedOrder1, savedOrders)); assertTrue(existsInOrdersList(mappedOrder2, savedOrders)); }
/** * @return true if result contains a coded value with the given concept id (if the result is a * list, then returns true if <em>any</em> member has a matching coded value) */ public boolean containsConcept(Integer conceptId) { if (isSingleResult()) { return (valueCoded != null && valueCoded.getConceptId().equals(conceptId)); } for (Result r : this) { if (r.containsConcept(conceptId)) { return true; } } return false; }
public CodeableConceptDt addTRCoding(Concept concept) { CodeableConceptDt codeableConcept = new CodeableConceptDt(); Collection<ConceptMap> conceptMappings = concept.getConceptMappings(); for (ConceptMap mapping : conceptMappings) { if (mapping.getConceptMapType().getUuid().equals(ConceptMapType.SAME_AS_MAP_TYPE_UUID)) { addTRCodingsForReferenceTerms(concept, idMappingsRepository, codeableConcept, mapping); } } addTRCodingForConcept(concept, idMappingsRepository, codeableConcept); return codeableConcept; }
@Test public void setPreferredConceptName_shouldSetPreferredName() throws Exception { metadataDeployService.installBundles(Arrays.<MetadataBundle>asList(ebolaMetadata)); ConceptNameTag nameTag = MetadataUtils.existing(ConceptNameTag.class, EbolaMetadata._ConceptNameTag.PREFERRED); String uuid = "c607c80f-1ea9-4da3-bb88-6276ce8868dd"; Concept weight = conceptService.getConceptByUuid(uuid); weight.addName(new ConceptName("Weight", Locale.ENGLISH)); conceptService.saveConcept(weight); assertThat( conceptService.getConceptByUuid(uuid).getPreferredName(Locale.ENGLISH).getName(), is("WEIGHT (KG)")); new EbolaExampleActivator().setPreferredConceptName(conceptService, uuid, "Weight"); assertThat( conceptService.getConceptByUuid(uuid).getPreferredName(Locale.ENGLISH).getName(), is("Weight")); assertThat( conceptService.getConceptByUuid(uuid).findNameTaggedWith(nameTag).getName(), is("Weight")); }
/** @see java.lang.Object#equals(java.lang.Object) */ @Override public boolean equals(Object obj) { if (obj == null || !(obj instanceof Result)) { return false; } Result r = (Result) obj; if (EmptyResult.class.isAssignableFrom(r.getClass()) && this.isEmpty()) { return true; } if (EmptyResult.class.isAssignableFrom(this.getClass()) && r.isEmpty()) { return true; } if (isSingleResult() && r.isSingleResult()) { if (datatype == null) { return false; } // both are single results switch (datatype) { case BOOLEAN: return (valueBoolean.equals(r.valueBoolean)); case CODED: return (valueCoded.equals(r.valueCoded)); case DATETIME: return (valueDatetime.equals(r.valueDatetime)); case NUMERIC: return (valueNumeric.equals(r.valueNumeric)); case TEXT: return (valueText.equals(r.valueText)); default: return false; } } if (isSingleResult() || r.isSingleResult()) { // we already know they're not both single results, so if one is // single, it's not a match return false; } if (this.size() != r.size()) { return false; } // at this point, we have two results that are lists, so members must // match exactly for (int i = 0; i < this.size(); i++) { if (!this.get(i).equals(r.get(i))) { return false; } } return true; }