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.*;
030
031import static ca.uhn.fhir.jpa.term.loinc.LoincUploadPropertiesEnum.LOINC_CODESYSTEM_VERSION;
032import static org.apache.commons.lang3.StringUtils.trim;
033
034public class LoincUniversalOrderSetHandler extends BaseLoincHandler implements IZipContentsHandlerCsv {
035
036        public static final String VS_ID_BASE = "loinc-universal-order-set";
037        public static final String VS_URI = "http://loinc.org/vs/loinc-universal-order-set";
038        public static final String VS_NAME = "LOINC Universal Order Set";
039
040        public LoincUniversalOrderSetHandler(
041                        Map<String, TermConcept> theCode2concept,
042                        List<ValueSet> theValueSets,
043                        List<ConceptMap> theConceptMaps,
044                        Properties theUploadProperties) {
045                super(theCode2concept, theValueSets, theConceptMaps, theUploadProperties);
046        }
047
048        @Override
049        public void accept(CSVRecord theRecord) {
050                String loincNumber = trim(theRecord.get("LOINC_NUM"));
051                String displayName = trim(theRecord.get("LONG_COMMON_NAME"));
052                String orderObs = trim(theRecord.get("ORDER_OBS"));
053
054                String codeSystemVersionId = myUploadProperties.getProperty(LOINC_CODESYSTEM_VERSION.getCode());
055                String valueSetId;
056                if (codeSystemVersionId != null) {
057                        valueSetId = VS_ID_BASE + "-" + codeSystemVersionId;
058                } else {
059                        valueSetId = VS_ID_BASE;
060                }
061
062                ValueSet valueSet = getValueSet(valueSetId, VS_URI, VS_NAME, null);
063                addCodeAsIncludeToValueSet(valueSet, ITermLoaderSvc.LOINC_URI, loincNumber, displayName);
064        }
065}