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