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.slf4j.Logger;
28  import org.slf4j.LoggerFactory;
29  
30  import java.util.Map;
31  
32  import static org.apache.commons.lang3.StringUtils.trim;
33  
34  public class LoincPartLinkHandler implements IRecordHandler {
35  
36  	private static final Logger ourLog = LoggerFactory.getLogger(LoincPartLinkHandler.class);
37  	private final Map<String, TermConcept> myCode2Concept;
38  	private final TermCodeSystemVersion myCodeSystemVersion;
39  	private Long myPartCount;
40  
41  	public LoincPartLinkHandler(TermCodeSystemVersion theCodeSystemVersion, Map<String, TermConcept> theCode2concept) {
42  		myCodeSystemVersion = theCodeSystemVersion;
43  		myCode2Concept = theCode2concept;
44  	}
45  
46  	@Override
47  	public void accept(CSVRecord theRecord) {
48  
49  		String loincNumber = trim(theRecord.get("LoincNumber"));
50  		String longCommonName = trim(theRecord.get("LongCommonName"));
51  		String partNumber = trim(theRecord.get("PartNumber"));
52  
53  		TermConcept loincConcept = myCode2Concept.get(loincNumber);
54  		TermConcept partConcept = myCode2Concept.get(partNumber);
55  
56  		if (loincConcept == null) {
57  			ourLog.warn("No loinc code: {}", loincNumber);
58  			return;
59  		}
60  		if (partConcept == null) {
61  			if (myPartCount == null) {
62  				myPartCount = myCode2Concept
63  					.keySet()
64  					.stream()
65  					.filter(t->t.startsWith("LP"))
66  					.count();
67  			}
68  			ourLog.debug("No part code: {} - Have {} part codes", partNumber, myPartCount);
69  			return;
70  		}
71  
72  		// For now we're ignoring these
73  
74  	}
75  }