001package ca.uhn.fhir.jpa.term.loinc;
002
003/*-
004 * #%L
005 * HAPI FHIR JPA Server
006 * %%
007 * Copyright (C) 2014 - 2021 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.ValueSet;
029
030import java.util.List;
031import java.util.Map;
032import java.util.Properties;
033
034import static ca.uhn.fhir.jpa.term.loinc.LoincUploadPropertiesEnum.LOINC_CODESYSTEM_VERSION;
035import static org.apache.commons.lang3.StringUtils.trim;
036
037public class BaseLoincTop2000LabResultsHandler extends BaseLoincHandler implements IZipContentsHandlerCsv {
038
039        private String myValueSetId;
040        private String myValueSetUri;
041        private String myValueSetName;
042
043        public BaseLoincTop2000LabResultsHandler(Map<String, TermConcept> theCode2concept, List<ValueSet> theValueSets, String theValueSetId, String theValueSetUri, String theValueSetName, List<ConceptMap> theConceptMaps, Properties theUploadProperties) {
044                super(theCode2concept, theValueSets, theConceptMaps, theUploadProperties);
045                String versionId = myUploadProperties.getProperty(LOINC_CODESYSTEM_VERSION.getCode());
046                if (versionId != null) {
047                        myValueSetId = theValueSetId + "-" + versionId;
048                } else {
049                        myValueSetId = theValueSetId;
050                }
051                myValueSetUri = theValueSetUri;
052                myValueSetName = theValueSetName;
053        }
054
055        @Override
056        public void accept(CSVRecord theRecord) {
057                String loincNumber = trim(theRecord.get("LOINC #"));
058                String displayName = trim(theRecord.get("Long Common Name"));
059
060                ValueSet valueSet = getValueSet(myValueSetId, myValueSetUri, myValueSetName, null);
061                addCodeAsIncludeToValueSet(valueSet, ITermLoaderSvc.LOINC_URI, loincNumber, displayName);
062        }
063
064}