/** * Returns concept reference term code of the mapping to the SNOMED CT concept source * * @param durationUnits * @return a string which is reference term code * @should return null if the concept has no mapping to the SNOMED CT source * @should return the code for the term of the mapping to the SNOMED CT source */ public static String getCode(Concept durationUnits) { for (ConceptMap conceptMapping : durationUnits.getConceptMappings()) { ConceptReferenceTerm conceptReferenceTerm = conceptMapping.getConceptReferenceTerm(); if (ConceptMapType.SAME_AS_MAP_TYPE_UUID.equals(conceptMapping.getConceptMapType().getUuid()) && Duration.SNOMED_CT_CONCEPT_SOURCE_HL7_CODE.equals(conceptReferenceTerm.getConceptSource() .getHl7Code())) { return conceptReferenceTerm.getCode(); } } return null; } }
@Test public void shouldCreateConceptReferenceTermMap() throws Exception { String termA = RestTestConstants1_9.CONCEPT_REFERENCE_TERM_UUID; String termB = RestTestConstants1_9.CONCEPT_REFERENCE_TERM2_UUID; String json = "{\"termA\": \"" + termA + "\", " + "\"termB\": \"" + termB + "\", " + "\"conceptMapType\": \"" + RestTestConstants1_9.CONCEPT_MAP_TYPE_UUID + "\"}"; SimpleObject result = deserialize(handle(newPostRequest(getURI(), json))); String uuid = (String) result.get("uuid"); ConceptReferenceTermMap termMap = service.getObjectByUuid(ConceptReferenceTermMap.class, uuid); assertThat(termMap.getTermA().getUuid(), is(termA)); assertThat(termMap.getTermB().getUuid(), is(termB)); assertThat(termMap.getConceptMapType().getUuid(), is(RestTestConstants1_9.CONCEPT_MAP_TYPE_UUID)); }
@Test public void shouldGetAConceptMapTypeByName() throws Exception { final String name = "related-to"; MockHttpServletRequest req = request(RequestMethod.GET, getURI() + "/" + name); SimpleObject result = deserialize(handle(req)); ConceptMapType conceptMapTypeType = service.getConceptMapTypeByName(name); assertEquals(conceptMapTypeType.getUuid(), PropertyUtils.getProperty(result, "uuid")); assertEquals(conceptMapTypeType.getName(), PropertyUtils.getProperty(result, "name")); }
@Test public void shouldGetAnConceptMapTypeByUuid() throws Exception { MockHttpServletRequest req = request(RequestMethod.GET, getURI() + "/" + getUuid()); SimpleObject result = deserialize(handle(req)); ConceptMapType conceptMapTypeType = service.getConceptMapTypeByUuid(getUuid()); assertEquals(conceptMapTypeType.getUuid(), PropertyUtils.getProperty(result, "uuid")); assertEquals(conceptMapTypeType.getName(), PropertyUtils.getProperty(result, "name")); assertEquals(conceptMapTypeType.isHidden(), PropertyUtils.getProperty(result, "isHidden")); assertEquals(conceptMapTypeType.getDescription(), PropertyUtils.getProperty(result, "description")); }
@Test public void shouldCreateConceptMap() throws Exception { String json = "{\"conceptReferenceTerm\": \"" + RestTestConstants1_9.CONCEPT_REFERENCE_TERM_UUID + "\", \"conceptMapType\": \"" + RestTestConstants1_9.CONCEPT_MAP_TYPE_UUID + "\"}"; SimpleObject newConceptMap = deserialize(handle(newPostRequest(getURI(), json))); String uuid = (String) newConceptMap.get("uuid"); ConceptMap conceptMap = restHelperService.getObjectByUuid(ConceptMap.class, uuid); assertThat(conceptMap.getConcept().getUuid(), is(RestTestConstants1_9.CONCEPT_UUID)); assertThat(conceptMap.getConceptMapType().getUuid(), is(RestTestConstants1_9.CONCEPT_MAP_TYPE_UUID)); assertThat(conceptMap.getConceptReferenceTerm().getUuid(), is(RestTestConstants1_9.CONCEPT_REFERENCE_TERM_UUID)); }
@Test public void shouldSetMappingsOnConcept() throws Exception { //before adding Concept concept = service.getConceptByUuid(getUuid()); assertThat(concept.getConceptMappings().size(), is(0)); //add one mapping MockHttpServletRequest request = request(RequestMethod.POST, getURI() + "/" + getUuid()); ConceptReferenceTerm referenceTerm = service.getAllConceptReferenceTerms().get(0); String mapTypeUuid = service.getDefaultConceptMapType().getUuid(); String json = "{ \"mappings\": [{\"conceptReferenceTerm\":\"" + referenceTerm.getUuid() + "\",\"conceptMapType\":\"" + mapTypeUuid + "\"}]}"; request.setContent(json.getBytes()); handle(request); concept = service.getConceptByUuid(getUuid()); assertThat(concept.getConceptMappings().size(), is(1)); assertThat(concept.getConceptMappings(), hasItem(hasTerm(referenceTerm))); //set mappings to empty MockHttpServletRequest requestEmpty = request(RequestMethod.POST, getURI() + "/" + getUuid()); String jsonEmpty = "{ \"mappings\": []}"; requestEmpty.setContent(jsonEmpty.getBytes()); handle(requestEmpty); assertThat(concept.getConceptMappings().size(), is(0)); }
@Test public void getDrugByMapping_shouldReturnADrugThatMatchesTheCodeAndSourceAndTheBestMapType() throws Exception { executeDataSet(DRUG_MAPPINGS); final String sourceUuid = conceptService.getConceptSource(2).getUuid(); String mapTypeUuids = conceptService.getConceptMapType(1).getUuid() + "," + conceptService.getConceptMapType(2).getUuid(); SimpleObject results = deserialize(handle(newGetRequest(getURI(), new Parameter("s", "getDrugByMapping"), new Parameter("code", "WGT234"), new Parameter("source", sourceUuid), new Parameter("preferredMapTypes", mapTypeUuids)))); assertEquals(getUuid(), PropertyUtils.getProperty(Util.getResultsList(results).get(0), "uuid")); //Lets switch the order of the map types in the list to make sure that //if there is no match on the first map type, the logic matches on the second //sanity check that actually there will be no match on the first map type in the list mapTypeUuids = conceptService.getConceptMapType(2).getUuid(); results = deserialize(handle(newGetRequest(getURI(), new Parameter("s", "getDrugByMapping"), new Parameter("code", "WGT234"), new Parameter("source", sourceUuid), new Parameter("preferredMapTypes", mapTypeUuids)))); assertEquals(0, Util.getResultsSize(results)); mapTypeUuids = conceptService.getConceptMapType(1).getUuid(); results = deserialize(handle(newGetRequest(getURI(), new Parameter("s", "getDrugByMapping"), new Parameter("code", "WGT234"), new Parameter("source", sourceUuid), new Parameter("preferredMapTypes", mapTypeUuids)))); assertEquals(1, Util.getResultsSize(results)); assertEquals(getUuid(), PropertyUtils.getProperty(Util.getResultsList(results).get(0), "uuid")); }
@Test public void getDrugsByMapping_shouldReturnADrugThatMatchesTheCodeAndSourceAndTheBestMapType() throws Exception { executeDataSet(DRUG_MAPPINGS); final String sourceUuid = conceptService.getConceptSource(1).getUuid(); String expectedDrugUuid = conceptService.getDrug(3).getUuid(); String mapTypeUuids = conceptService.getConceptMapType(3).getUuid(); SimpleObject results = deserialize(handle(newGetRequest(getURI(), new Parameter("s", "getDrugsByMapping"), new Parameter("code", "CD41003"), new Parameter("source", sourceUuid), new Parameter("preferredMapTypes", mapTypeUuids)))); assertEquals(0, Util.getResultsSize(results)); mapTypeUuids = conceptService.getConceptMapType(2).getUuid(); results = deserialize(handle(newGetRequest(getURI(), new Parameter("s", "getDrugsByMapping"), new Parameter("code", "CD41003"), new Parameter("source", sourceUuid), new Parameter("preferredMapTypes", mapTypeUuids)))); assertEquals(expectedDrugUuid, PropertyUtils.getProperty(Util.getResultsList(results).get(1), "uuid")); }