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.IRecordHandler;
26  import org.apache.commons.csv.CSVRecord;
27  import org.apache.commons.lang3.Validate;
28  import org.hl7.fhir.r4.model.ValueSet;
29  
30  import java.util.HashMap;
31  import java.util.Map;
32  
33  import static org.apache.commons.lang3.StringUtils.isNotBlank;
34  import static org.apache.commons.lang3.StringUtils.trim;
35  
36  public class LoincPartHandler implements IRecordHandler {
37  
38  	private final Map<String, TermConcept> myCode2Concept;
39  	private final TermCodeSystemVersion myCodeSystemVersion;
40  	private final Map<String, ValueSet> myIdToValueSet = new HashMap<>();
41  	private final Map<PartTypeAndPartName, String> myPartTypeAndPartNameToPartNumber = new HashMap<>();
42  
43  	public LoincPartHandler(TermCodeSystemVersion theCodeSystemVersion, Map<String, TermConcept> theCode2concept) {
44  		myCodeSystemVersion = theCodeSystemVersion;
45  		myCode2Concept = theCode2concept;
46  	}
47  
48  	@Override
49  	public void accept(CSVRecord theRecord) {
50  
51  		// this is the code for the list (will repeat)
52  		String partNumber = trim(theRecord.get("PartNumber"));
53  		String partTypeName = trim(theRecord.get("PartTypeName"));
54  		String partName = trim(theRecord.get("PartName"));
55  		String partDisplayName = trim(theRecord.get("PartDisplayName"));
56  
57  		// Per Dan's note, we include deprecated parts
58  //		String status = trim(theRecord.get("Status"));
59  //		if (!"ACTIVE".equals(status)) {
60  //			return;
61  //		}
62  
63  		PartTypeAndPartName partTypeAndPartName = new PartTypeAndPartName(partTypeName, partName);
64  		String previousValue = myPartTypeAndPartNameToPartNumber.put(partTypeAndPartName, partNumber);
65  		Validate.isTrue(previousValue == null, "Already had part: " + partTypeAndPartName);
66  
67  		TermConcept concept = myCode2Concept.get(partNumber);
68  		if (concept == null) {
69  			concept = new TermConcept(myCodeSystemVersion, partNumber);
70  			concept.setDisplay(partName);
71  			myCode2Concept.put(partNumber, concept);
72  		}
73  
74  		if (isNotBlank(partDisplayName)) {
75  			concept.addDesignation()
76  				.setConcept(concept)
77  				.setUseDisplay("PartDisplayName")
78  				.setValue(partDisplayName);
79  		}
80  
81  	}
82  
83  	public Map<PartTypeAndPartName, String> getPartTypeAndPartNameToPartNumber() {
84  		return myPartTypeAndPartNameToPartNumber;
85  	}
86  
87  
88  }