View Javadoc
1   package ca.uhn.fhir.jpa.term.loinc;
2   
3   /*-
4    * #%L
5    * HAPI FHIR JPA Server
6    * %%
7    * Copyright (C) 2014 - 2018 University Health Network
8    * %%
9    * Licensed under the Apache License, Version 2.0 (the "License");
10   * you may not use this file except in compliance with the License.
11   * You may obtain a copy of the License at
12   * 
13   *      http://www.apache.org/licenses/LICENSE-2.0
14   * 
15   * Unless required by applicable law or agreed to in writing, software
16   * distributed under the License is distributed on an "AS IS" BASIS,
17   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18   * See the License for the specific language governing permissions and
19   * limitations under the License.
20   * #L%
21   */
22  
23  import ca.uhn.fhir.jpa.entity.TermCodeSystemVersion;
24  import ca.uhn.fhir.jpa.entity.TermConcept;
25  import ca.uhn.fhir.jpa.term.IHapiTerminologyLoaderSvc;
26  import ca.uhn.fhir.jpa.term.IRecordHandler;
27  import org.apache.commons.csv.CSVRecord;
28  import org.hl7.fhir.r4.model.Enumerations;
29  import org.hl7.fhir.r4.model.ValueSet;
30  
31  import java.util.HashMap;
32  import java.util.List;
33  import java.util.Map;
34  import java.util.Set;
35  
36  import static org.apache.commons.lang3.StringUtils.isBlank;
37  import static org.apache.commons.lang3.StringUtils.isNotBlank;
38  import static org.apache.commons.lang3.StringUtils.trim;
39  
40  public class LoincAnswerListLinkHandler implements IRecordHandler {
41  
42  	private final Map<String, TermConcept> myCode2Concept;
43  	private final Map<String, ValueSet> myIdToValueSet = new HashMap<>();
44  
45  	public LoincAnswerListLinkHandler(Map<String, TermConcept> theCode2concept, List<ValueSet> theValueSets) {
46  		myCode2Concept = theCode2concept;
47  		for (ValueSet next : theValueSets) {
48  			myIdToValueSet.put(next.getId(), next);
49  		}
50  	}
51  
52  	@Override
53  	public void accept(CSVRecord theRecord) {
54  		String applicableContext = trim(theRecord.get("ApplicableContext"));
55  
56  		/*
57  		 * Per Dan V's Notes:
58  		 *
59  		 * Note: in our current format, we support binding of the same
60  		 * LOINC term to different answer lists depending on the panel
61  		 * context. I don’t believe there’s a way to handle that in
62  		 * the current FHIR spec, so I might suggest we discuss either
63  		 * only binding the “default” (non-context specific) list or
64  		 * if multiple bindings could be supported.
65  		 */
66  		if (isNotBlank(applicableContext)) {
67  			return;
68  		}
69  
70  		String answerListId = trim(theRecord.get("AnswerListId"));
71  		if (isBlank(answerListId)) {
72  			return;
73  		}
74  
75  		String loincNumber = trim(theRecord.get("LoincNumber"));
76  		if (isBlank(loincNumber)) {
77  			return;
78  		}
79  
80  		TermConcept loincCode = myCode2Concept.get(loincNumber);
81  		if (loincCode != null) {
82  			loincCode.addPropertyString("answer-list", answerListId);
83  		}
84  
85  		TermConcept answerListCode = myCode2Concept.get(answerListId);
86  		if (answerListCode != null) {
87  			answerListCode.addPropertyString("answers-for", loincNumber);
88  		}
89  
90  	}
91  
92  }