001/*-
002 * #%L
003 * HAPI FHIR JPA Server
004 * %%
005 * Copyright (C) 2014 - 2024 Smile CDR, Inc.
006 * %%
007 * Licensed under the Apache License, Version 2.0 (the "License");
008 * you may not use this file except in compliance with the License.
009 * You may obtain a copy of the License at
010 *
011 *      http://www.apache.org/licenses/LICENSE-2.0
012 *
013 * Unless required by applicable law or agreed to in writing, software
014 * distributed under the License is distributed on an "AS IS" BASIS,
015 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
016 * See the License for the specific language governing permissions and
017 * limitations under the License.
018 * #L%
019 */
020package ca.uhn.fhir.jpa.term.loinc;
021
022import ca.uhn.fhir.jpa.entity.TermConcept;
023import ca.uhn.fhir.jpa.term.IZipContentsHandlerCsv;
024import ca.uhn.fhir.jpa.term.api.ITermLoaderSvc;
025import org.apache.commons.csv.CSVRecord;
026import org.hl7.fhir.r4.model.ConceptMap;
027import org.hl7.fhir.r4.model.ValueSet;
028
029import java.util.List;
030import java.util.Map;
031import java.util.Properties;
032
033import static ca.uhn.fhir.jpa.term.loinc.LoincUploadPropertiesEnum.LOINC_CODESYSTEM_VERSION;
034import static org.apache.commons.lang3.StringUtils.trim;
035
036public class BaseLoincTop2000LabResultsHandler extends BaseLoincHandler implements IZipContentsHandlerCsv {
037
038        private String myValueSetId;
039        private String myValueSetUri;
040        private String myValueSetName;
041
042        public BaseLoincTop2000LabResultsHandler(
043                        Map<String, TermConcept> theCode2concept,
044                        List<ValueSet> theValueSets,
045                        String theValueSetId,
046                        String theValueSetUri,
047                        String theValueSetName,
048                        List<ConceptMap> theConceptMaps,
049                        Properties theUploadProperties,
050                        String theCopyrightStatement) {
051                super(theCode2concept, theValueSets, theConceptMaps, theUploadProperties, theCopyrightStatement);
052                String versionId = myUploadProperties.getProperty(LOINC_CODESYSTEM_VERSION.getCode());
053                if (versionId != null) {
054                        myValueSetId = theValueSetId + "-" + versionId;
055                } else {
056                        myValueSetId = theValueSetId;
057                }
058                myValueSetUri = theValueSetUri;
059                myValueSetName = theValueSetName;
060        }
061
062        @Override
063        public void accept(CSVRecord theRecord) {
064                String loincNumber = trim(theRecord.get("LOINC #"));
065                String displayName = trim(theRecord.get("Long Common Name"));
066
067                ValueSet valueSet = getValueSet(myValueSetId, myValueSetUri, myValueSetName, null);
068                addCodeAsIncludeToValueSet(valueSet, ITermLoaderSvc.LOINC_URI, loincNumber, displayName);
069        }
070}