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 LoincGroupTermsFileHandler extends BaseLoincHandler implements IZipContentsHandlerCsv {
037
038        public LoincGroupTermsFileHandler(
039                        Map<String, TermConcept> theCode2concept,
040                        List<ValueSet> theValueSets,
041                        List<ConceptMap> theConceptMaps,
042                        Properties theUploadProperties) {
043                super(theCode2concept, theValueSets, theConceptMaps, theUploadProperties);
044        }
045
046        @Override
047        public void accept(CSVRecord theRecord) {
048                // "Category","GroupId","Archetype","LoincNumber","LongCommonName"
049                String groupId = trim(theRecord.get("GroupId"));
050                String codeSystemVersionId = myUploadProperties.getProperty(LOINC_CODESYSTEM_VERSION.getCode());
051                String valueSetId;
052                if (codeSystemVersionId != null) {
053                        valueSetId = groupId + "-" + codeSystemVersionId;
054                } else {
055                        valueSetId = groupId;
056                }
057                String loincNumber = trim(theRecord.get("LoincNumber"));
058
059                ValueSet valueSet = getValueSet(valueSetId, LoincGroupFileHandler.VS_URI_PREFIX + groupId, null, null);
060                addCodeAsIncludeToValueSet(valueSet, ITermLoaderSvc.LOINC_URI, loincNumber, null);
061        }
062}