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