
001package ca.uhn.fhir.jpa.term.loinc; 002 003import ca.uhn.fhir.jpa.term.IZipContentsHandlerCsv; 004import org.apache.commons.csv.CSVRecord; 005 006import javax.annotation.Nonnull; 007import java.util.List; 008 009import static org.apache.commons.lang3.StringUtils.isBlank; 010import static org.apache.commons.lang3.StringUtils.trim; 011 012/*- 013 * #%L 014 * HAPI FHIR JPA Server 015 * %% 016 * Copyright (C) 2014 - 2022 Smile CDR, Inc. 017 * %% 018 * Licensed under the Apache License, Version 2.0 (the "License"); 019 * you may not use this file except in compliance with the License. 020 * You may obtain a copy of the License at 021 * 022 * http://www.apache.org/licenses/LICENSE-2.0 023 * 024 * Unless required by applicable law or agreed to in writing, software 025 * distributed under the License is distributed on an "AS IS" BASIS, 026 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 027 * See the License for the specific language governing permissions and 028 * limitations under the License. 029 * #L% 030 */ 031 032public class LoincLinguisticVariantsHandler implements IZipContentsHandlerCsv { 033 034 private final List<LinguisticVariant> myLinguisticVariants; 035 036 public LoincLinguisticVariantsHandler(List<LinguisticVariant> thelinguisticVariants) { 037 myLinguisticVariants = thelinguisticVariants; 038 } 039 040 @Override 041 public void accept(CSVRecord theRecord) { 042 043 String id = trim(theRecord.get("ID")); 044 if (isBlank(id)) { 045 return; 046 } 047 048 String isoLanguage = trim(theRecord.get("ISO_LANGUAGE")); 049 if (isBlank(isoLanguage)) { 050 return; 051 } 052 053 String isoCountry = trim(theRecord.get("ISO_COUNTRY")); 054 if (isBlank(isoCountry)) { 055 return; 056 } 057 058 String languageName = trim(theRecord.get("LANGUAGE_NAME")); 059 if (isBlank(languageName)) { 060 return; 061 } 062 063 LinguisticVariant linguisticVariant = new LinguisticVariant(id, isoLanguage, isoCountry, languageName); 064 myLinguisticVariants.add(linguisticVariant); 065 } 066 067 public static class LinguisticVariant { 068 069 private String myId; 070 private String myIsoLanguage; 071 private String myIsoCountry; 072 private String myLanguageName; 073 074 public LinguisticVariant(@Nonnull String theId, @Nonnull String theIsoLanguage, @Nonnull String theIsoCountry, @Nonnull String theLanguageName) { 075 this.myId = theId; 076 this.myIsoLanguage = theIsoLanguage; 077 this.myIsoCountry = theIsoCountry; 078 this.myLanguageName = theLanguageName; 079 } 080 081 public String getLinguisticVariantFileName() { 082 return myIsoLanguage + myIsoCountry + myId + "LinguisticVariant.csv"; 083 } 084 085 public String getLanguageName() { 086 return myLanguageName; 087 } 088 089 public String getLanguageCode() { 090 return myIsoLanguage + "-" + myIsoCountry; 091 } 092 } 093 094}