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