001package ca.uhn.fhir.jpa.term.loinc;
002
003/*-
004 * #%L
005 * HAPI FHIR JPA Server
006 * %%
007 * Copyright (C) 2014 - 2022 Smile CDR, Inc.
008 * %%
009 * Licensed under the Apache License, Version 2.0 (the "License");
010 * you may not use this file except in compliance with the License.
011 * You may obtain a copy of the License at
012 *
013 *      http://www.apache.org/licenses/LICENSE-2.0
014 *
015 * Unless required by applicable law or agreed to in writing, software
016 * distributed under the License is distributed on an "AS IS" BASIS,
017 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
018 * See the License for the specific language governing permissions and
019 * limitations under the License.
020 * #L%
021 */
022
023import ca.uhn.fhir.jpa.entity.TermConcept;
024import ca.uhn.fhir.jpa.term.api.ITermLoaderSvc;
025import ca.uhn.fhir.jpa.term.IZipContentsHandlerCsv;
026import org.apache.commons.csv.CSVRecord;
027import org.hl7.fhir.r4.model.ConceptMap;
028import org.hl7.fhir.r4.model.Enumerations;
029import org.hl7.fhir.r4.model.ValueSet;
030
031import java.util.List;
032import java.util.Map;
033import java.util.Properties;
034
035import static ca.uhn.fhir.jpa.term.loinc.LoincUploadPropertiesEnum.LOINC_CODESYSTEM_VERSION;
036import static ca.uhn.fhir.jpa.term.loinc.LoincUploadPropertiesEnum.LOINC_CONCEPTMAP_VERSION;
037import static org.apache.commons.lang3.StringUtils.trim;
038
039public class LoincIeeeMedicalDeviceCodeHandler extends BaseLoincHandler implements IZipContentsHandlerCsv {
040
041        public static final String LOINC_IEEE_CM_ID = "loinc-to-ieee-11073-10101";
042        public static final String LOINC_IEEE_CM_URI = "http://loinc.org/cm/loinc-to-ieee-11073-10101";
043        public static final String LOINC_IEEE_CM_NAME = "LOINC/IEEE Device Code Mappings";
044        private static final String CM_COPYRIGHT = "The LOINC/IEEE Medical Device Code Mapping Table contains content from IEEE (http://ieee.org), copyright  2017 IEEE.";
045
046        /**
047         * Constructor
048         */
049        public LoincIeeeMedicalDeviceCodeHandler(Map<String, TermConcept> theCode2concept, List<ValueSet> theValueSets,
050                        List<ConceptMap> theConceptMaps, Properties theUploadProperties, String theCopyrightStatement) {
051                super(theCode2concept, theValueSets, theConceptMaps, theUploadProperties, theCopyrightStatement);
052        }
053
054        @Override
055        public void accept(CSVRecord theRecord) {
056
057                String codeSystemVersionId = myUploadProperties.getProperty(LOINC_CODESYSTEM_VERSION.getCode());
058                String loincIeeeCmVersion;
059                if (codeSystemVersionId != null) {
060                        loincIeeeCmVersion =  myUploadProperties.getProperty(LOINC_CONCEPTMAP_VERSION.getCode()) + "-" + codeSystemVersionId;
061                } else {
062                        loincIeeeCmVersion = myUploadProperties.getProperty(LOINC_CONCEPTMAP_VERSION.getCode());
063                }
064                String loincNumber = trim(theRecord.get("LOINC_NUM"));
065                String longCommonName = trim(theRecord.get("LOINC_LONG_COMMON_NAME"));
066                String ieeeCode = trim(theRecord.get("IEEE_CF_CODE10"));
067                String ieeeDisplayName = trim(theRecord.get("IEEE_REFID"));
068
069                // LOINC Part -> IEEE 11073:10101 Mappings
070                String sourceCodeSystemUri = ITermLoaderSvc.LOINC_URI;
071                String targetCodeSystemUri = ITermLoaderSvc.IEEE_11073_10101_URI;
072                String conceptMapId;
073                if (codeSystemVersionId != null) {
074                        conceptMapId = LOINC_IEEE_CM_ID + "-" + codeSystemVersionId;
075                } else {
076                        conceptMapId = LOINC_IEEE_CM_ID;
077                }
078                addConceptMapEntry(
079                        new ConceptMapping()
080                                .setConceptMapId(conceptMapId)
081                                .setConceptMapUri(LOINC_IEEE_CM_URI)
082                                .setConceptMapVersion(loincIeeeCmVersion)
083                                .setConceptMapName(LOINC_IEEE_CM_NAME)
084                                .setSourceCodeSystem(sourceCodeSystemUri)
085                                .setSourceCodeSystemVersion(codeSystemVersionId)
086                                .setSourceCode(loincNumber)
087                                .setSourceDisplay(longCommonName)
088                                .setTargetCodeSystem(targetCodeSystemUri)
089                                .setTargetCode(ieeeCode)
090                                .setTargetDisplay(ieeeDisplayName)
091                                .setEquivalence(Enumerations.ConceptMapEquivalence.EQUAL),
092                        myLoincCopyrightStatement + " " + CM_COPYRIGHT);
093        }
094
095
096}