public static Concept createUnits(String source, String code, String mapTypeUuid) { Concept doseUnits = new Concept(); doseUnits.addConceptMapping(getConceptMap(source, code, mapTypeUuid)); return doseUnits; }
@Test public void validate_shouldNotFailIfATermHasTwoNewMappingsOnIt() { concept.addName(new ConceptName("my name", Context.getLocale())); ConceptReferenceTerm newTerm = new ConceptReferenceTerm(conceptService.getConceptSource(1), "1234", "term one two three four"); ConceptMap map1 = new ConceptMap(newTerm, conceptService.getConceptMapType(1)); concept.addConceptMapping(map1); ConceptReferenceTerm newTermTwo = new ConceptReferenceTerm(conceptService.getConceptSource(1), "12345", "term one two three four five"); ConceptMap map2 = new ConceptMap(newTermTwo, conceptService.getConceptMapType(1)); concept.addConceptMapping(map2); validator.validate(concept, errors); assertThat(errors, not(hasFieldErrors("conceptMappings[1]"))); }
/** * @see Concept#removeConceptMapping(ContentMap) */ @Test public void removeConceptMapping_shouldRemoveConceptMapPassedFromListOfMappings() { Concept c = new Concept(); ConceptMap c1 = new ConceptMap(1); c1.setConceptMapType(new ConceptMapType(1)); ConceptMap c2 = new ConceptMap(2); c2.setConceptMapType(new ConceptMapType(2)); c.addConceptMapping(c1); c.addConceptMapping(c2); Collection<ConceptMap> mappings = c.getConceptMappings(); Assert.assertEquals(2, mappings.size()); c.removeConceptMapping(c1); mappings = c.getConceptMappings(); Assert.assertTrue(mappings.contains(c2)); Assert.assertEquals(1, mappings.size()); }
/** * @see ConceptService#saveConcept(Concept) */ @Test public void saveConcept_shouldCreateAReferenceTermForAConceptMappingOnTheFlyWhenEditingAConcept() { int initialTermCount = conceptService.getAllConceptReferenceTerms().size(); Concept concept = conceptService.getConcept(5497); ConceptMap map = new ConceptMap(); map.getConceptReferenceTerm().setCode("unique code"); map.getConceptReferenceTerm().setConceptSource(conceptService.getConceptSource(1)); concept.addConceptMapping(map); conceptService.saveConcept(concept); Assert.assertEquals(initialTermCount + 1, conceptService.getAllConceptReferenceTerms().size()); }
@Test public void validate_shouldFailIfATermIsMappedMultipleTimesToTheSameConcept() { concept.setConceptClass(new ConceptClass()); concept.setDatatype(new ConceptDatatype()); concept.addName(new ConceptName("my name", Context.getLocale())); concept.addDescription(new ConceptDescription("some description",null)); ConceptMap map1 = new ConceptMap(conceptService.getConceptReferenceTerm(1), conceptService.getConceptMapType(1)); concept.addConceptMapping(map1); ConceptMap map2 = new ConceptMap(conceptService.getConceptReferenceTerm(1), conceptService.getConceptMapType(1)); concept.addConceptMapping(map2); validator.validate(concept, errors); assertThat(errors, hasFieldErrors("conceptMappings[1]")); }
@Test public void validate_shouldPassForAnEditedConceptWithAMapCreatedWithDeprecatedConceptMapMethods() { Concept concept = cd4Count; ConceptMap map = new ConceptMap(); map.getConceptReferenceTerm().setCode("unique code"); map.getConceptReferenceTerm().setConceptSource(conceptService.getConceptSource(1)); concept.addConceptMapping(map); ValidateUtil.validate(concept); }
/** * It's needed, because of ConversionException: Don't know how to handle collection class: * interface java.util.Collection * * @param instance * @param mappings */ @PropertySetter("mappings") public static void setMappings(Concept instance, List<ConceptMap> mappings) { instance.getConceptMappings().clear(); for (ConceptMap map : mappings) { instance.addConceptMapping(map); } }
/** * @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()); }
@Test public void validate_shouldPassForANewConceptWithAMapCreatedWithDeprecatedConceptMapMethods() { concept.addName(new ConceptName("test name", Context.getLocale())); concept.addDescription(new ConceptDescription("some description",null)); concept.setConceptClass(new ConceptClass()); concept.setDatatype(new ConceptDatatype()); ConceptMap map = new ConceptMap(); map.getConceptReferenceTerm().setCode("unique code"); map.getConceptReferenceTerm().setConceptSource(conceptService.getConceptSource(1)); concept.addConceptMapping(map); ValidateUtil.validate(concept); }
/** * @see org.openmrs.module.webservices.rest.web.resource.impl.DelegatingResourceHandler#save(java.lang.Object) */ @Override public ConceptMap save(ConceptMap newMap) { newMap.getConcept().addConceptMapping(newMap); Context.getConceptService().saveConcept(newMap.getConcept()); return newMap; }
@Test public void testGetByUniqueIdWorksWithConceptMappings() throws Exception { ConceptSource snomed = conceptService.getConceptSource(2); ConceptReferenceTerm term = new ConceptReferenceTerm(snomed, "307486002", null); conceptService.saveConceptReferenceTerm(term); Concept concept = conceptService.getConcept(113); concept.addConceptMapping(new ConceptMap(term, conceptService.getConceptMapType(2))); conceptService.saveConcept(concept); OrderFrequency orderFrequency = getResource().getByUniqueId("SNOMED CT:307486002"); assertThat(orderFrequency.getConcept(), is(concept)); } }