View Javadoc
1   package ca.uhn.fhir.jpa.term.loinc;
2   
3   /*-
4    * #%L
5    * HAPI FHIR JPA Server
6    * %%
7    * Copyright (C) 2014 - 2018 University Health Network
8    * %%
9    * Licensed under the Apache License, Version 2.0 (the "License");
10   * you may not use this file except in compliance with the License.
11   * You may obtain a copy of the License at
12   * 
13   *      http://www.apache.org/licenses/LICENSE-2.0
14   * 
15   * Unless required by applicable law or agreed to in writing, software
16   * distributed under the License is distributed on an "AS IS" BASIS,
17   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18   * See the License for the specific language governing permissions and
19   * limitations under the License.
20   * #L%
21   */
22  
23  import ca.uhn.fhir.jpa.entity.TermConcept;
24  import ca.uhn.fhir.jpa.term.IHapiTerminologyLoaderSvc;
25  import ca.uhn.fhir.jpa.term.IRecordHandler;
26  import ca.uhn.fhir.rest.server.exceptions.InternalErrorException;
27  import org.apache.commons.csv.CSVRecord;
28  import org.hl7.fhir.r4.model.ConceptMap;
29  import org.hl7.fhir.r4.model.Enumerations;
30  import org.hl7.fhir.r4.model.ValueSet;
31  
32  import java.util.List;
33  import java.util.Map;
34  import java.util.Properties;
35  
36  import static org.apache.commons.lang3.StringUtils.defaultString;
37  import static org.apache.commons.lang3.StringUtils.trim;
38  
39  public class LoincPartRelatedCodeMappingHandler extends BaseLoincHandler implements IRecordHandler {
40  
41  	public static final String LOINC_SCT_PART_MAP_ID = "loinc-parts-to-snomed-ct";
42  	public static final String LOINC_SCT_PART_MAP_URI = "http://loinc.org/cm/loinc-parts-to-snomed-ct";
43  	public static final String LOINC_TERM_TO_RPID_PART_MAP_ID = "loinc-term-to-rpids";
44  	public static final String LOINC_TERM_TO_RPID_PART_MAP_URI = "http://loinc.org/cm/loinc-to-rpids";
45  	public static final String LOINC_TERM_TO_RPID_PART_MAP_NAME = "LOINC Terms to RadLex RPIDs";
46  	public static final String LOINC_PART_TO_RID_PART_MAP_ID = "loinc-part-to-rids";
47  	public static final String LOINC_PART_TO_RID_PART_MAP_URI = "http://loinc.org/cm/loinc-to-rids";
48  	public static final String LOINC_PART_TO_RID_PART_MAP_NAME = "LOINC Parts to RadLex RIDs";
49  	private static final String LOINC_SCT_PART_MAP_NAME = "LOINC Part Map to SNOMED CT";
50  	private static final String LOINC_RXNORM_PART_MAP_ID = "loinc-parts-to-rxnorm";
51  	private static final String LOINC_RXNORM_PART_MAP_URI = "http://loinc.org/cm/loinc-parts-to-rxnorm";
52  	private static final String LOINC_RXNORM_PART_MAP_NAME = "LOINC Part Map to RxNORM";
53  	private static final String CM_COPYRIGHT = "This content from LOINC® is copyright © 1995 Regenstrief Institute, Inc. and the LOINC Committee, and available at no cost under the license at https://loinc.org/license/. The LOINC Part File, LOINC/SNOMED CT Expression Association and Map Sets File, RELMA database and associated search index files include SNOMED Clinical Terms (SNOMED CT®) which is used by permission of the International Health Terminology Standards Development Organisation (IHTSDO) under license. All rights are reserved. SNOMED CT® was originally created by The College of American Pathologists. “SNOMED” and “SNOMED CT” are registered trademarks of the IHTSDO. Use of SNOMED CT content is subject to the terms and conditions set forth in the SNOMED CT Affiliate License Agreement.  It is the responsibility of those implementing this product to ensure they are appropriately licensed and for more information on the license, including how to register as an Affiliate Licensee, please refer to http://www.snomed.org/snomed-ct/get-snomed-ct or info@snomed.org. Under the terms of the Affiliate License, use of SNOMED CT in countries that are not IHTSDO Members is subject to reporting and fee payment obligations. However, IHTSDO agrees to waive the requirements to report and pay fees for use of SNOMED CT content included in the LOINC Part Mapping and LOINC Term Associations for purposes that support or enable more effective use of LOINC. This material includes content from the US Edition to SNOMED CT, which is developed and maintained by the U.S. National Library of Medicine and is available to authorized UMLS Metathesaurus Licensees from the UTS Downloads site at https://uts.nlm.nih.gov.";
54  	private static final String LOINC_PUBCHEM_PART_MAP_URI = "http://loinc.org/cm/loinc-parts-to-pubchem";
55  	private static final String LOINC_PUBCHEM_PART_MAP_ID = "loinc-parts-to-pubchem";
56  	private static final String LOINC_PUBCHEM_PART_MAP_NAME = "LOINC Part Map to PubChem";
57  
58  	public LoincPartRelatedCodeMappingHandler(Map<String, TermConcept> theCode2concept, List<ValueSet> theValueSets, List<ConceptMap> theConceptMaps, Properties theUploadProperties) {
59  		super(theCode2concept, theValueSets, theConceptMaps, theUploadProperties);
60  	}
61  
62  	@Override
63  	public void accept(CSVRecord theRecord) {
64  
65  		String partNumber = trim(theRecord.get("PartNumber"));
66  		String partName = trim(theRecord.get("PartName"));
67  		String partTypeName = trim(theRecord.get("PartTypeName"));
68  		String extCodeId = trim(theRecord.get("ExtCodeId"));
69  		// TODO: use hex code for ascii 160
70  		extCodeId = extCodeId.replace(" ", "");
71  		String extCodeDisplayName = trim(theRecord.get("ExtCodeDisplayName"));
72  		String extCodeSystem = trim(theRecord.get("ExtCodeSystem"));
73  		String mapType = trim(theRecord.get("MapType"));
74  		String contentOrigin = trim(theRecord.get("ContentOrigin"));
75  		String extCodeSystemVersion = trim(theRecord.get("ExtCodeSystemVersion"));
76  		String extCodeSystemCopyrightNotice = trim(theRecord.get("ExtCodeSystemCopyrightNotice"));
77  
78  		Enumerations.ConceptMapEquivalence equivalence;
79  		switch (trim(defaultString(mapType))) {
80  			case "":
81  			case "Exact":
82  				// 'equal' is more exact than 'equivalent' in the equivalence codes
83  				equivalence = Enumerations.ConceptMapEquivalence.EQUAL;
84  				break;
85  			case "LOINC broader":
86  				equivalence = Enumerations.ConceptMapEquivalence.NARROWER;
87  				break;
88  			case "LOINC narrower":
89  				equivalence = Enumerations.ConceptMapEquivalence.WIDER;
90  				break;
91  			default:
92  				throw new InternalErrorException("Unknown MapType '" + mapType + "' for PartNumber: " + partNumber);
93  		}
94  
95  		String loincPartMapId;
96  		String loincPartMapUri;
97  		String loincPartMapName;
98  		switch (extCodeSystem) {
99  			case IHapiTerminologyLoaderSvc.SCT_URI:
100 				loincPartMapId = LOINC_SCT_PART_MAP_ID;
101 				loincPartMapUri = LOINC_SCT_PART_MAP_URI;
102 				loincPartMapName = LOINC_SCT_PART_MAP_NAME;
103 				break;
104 			case "http://www.nlm.nih.gov/research/umls/rxnorm":
105 				loincPartMapId = LOINC_RXNORM_PART_MAP_ID;
106 				loincPartMapUri = LOINC_RXNORM_PART_MAP_URI;
107 				loincPartMapName = LOINC_RXNORM_PART_MAP_NAME;
108 				break;
109 			case "http://www.radlex.org":
110 				loincPartMapId = LOINC_PART_TO_RID_PART_MAP_ID;
111 				loincPartMapUri = LOINC_PART_TO_RID_PART_MAP_URI;
112 				loincPartMapName = LOINC_PART_TO_RID_PART_MAP_NAME;
113 				break;
114 			case "http://pubchem.ncbi.nlm.nih.gov":
115 				loincPartMapId = LOINC_PUBCHEM_PART_MAP_ID;
116 				loincPartMapUri = LOINC_PUBCHEM_PART_MAP_URI;
117 				loincPartMapName = LOINC_PUBCHEM_PART_MAP_NAME;
118 				break;
119 			default:
120 				loincPartMapId = extCodeSystem.replaceAll("[^a-zA-Z]", "");
121 				loincPartMapUri = extCodeSystem;
122 				loincPartMapName = "Unknown Mapping";
123 				break;
124 		}
125 
126 		addConceptMapEntry(
127 			new ConceptMapping()
128 				.setConceptMapId(loincPartMapId)
129 				.setConceptMapUri(loincPartMapUri)
130 				.setConceptMapName(loincPartMapName)
131 				.setSourceCodeSystem(IHapiTerminologyLoaderSvc.LOINC_URI)
132 				.setSourceCode(partNumber)
133 				.setSourceDisplay(partName)
134 				.setTargetCodeSystem(extCodeSystem)
135 				.setTargetCode(extCodeId)
136 				.setTargetDisplay(extCodeDisplayName)
137 				.setTargetCodeSystemVersion(extCodeSystemVersion)
138 				.setEquivalence(equivalence)
139 				.setCopyright(extCodeSystemCopyrightNotice),
140 			CM_COPYRIGHT
141 		);
142 
143 	}
144 
145 }