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.TermConcept;
24  import ca.uhn.fhir.jpa.term.IHapiTerminologyLoaderSvc;
25  import ca.uhn.fhir.jpa.term.IRecordHandler;
26  import ca.uhn.fhir.rest.server.exceptions.InternalErrorException;
27  import org.apache.commons.csv.CSVRecord;
28  import org.hl7.fhir.r4.model.CodeSystem;
29  import org.hl7.fhir.r4.model.ConceptMap;
30  import org.hl7.fhir.r4.model.ValueSet;
31  
32  import java.util.List;
33  import java.util.Map;
34  import java.util.Properties;
35  
36  import static org.apache.commons.lang3.StringUtils.trim;
37  
38  public class LoincDocumentOntologyHandler extends BaseLoincHandler implements IRecordHandler {
39  
40  	public static final String DOCUMENT_ONTOLOGY_CODES_VS_ID = "loinc-document-ontology";
41  	public static final String DOCUMENT_ONTOLOGY_CODES_VS_URI = "http://loinc.org/vs/loinc-document-ontology";
42  	public static final String DOCUMENT_ONTOLOGY_CODES_VS_NAME = "LOINC Document Ontology Codes";
43  	private final Map<String, TermConcept> myCode2Concept;
44  
45  	public LoincDocumentOntologyHandler(Map<String, TermConcept> theCode2concept, Map<String, CodeSystem.PropertyType> thePropertyNames, List<ValueSet> theValueSets, List<ConceptMap> theConceptMaps, Properties theUploadProperties) {
46  		super(theCode2concept, theValueSets, theConceptMaps, theUploadProperties);
47  		myCode2Concept = theCode2concept;
48  	}
49  
50  	@Override
51  	public void accept(CSVRecord theRecord) {
52  
53  		String loincNumber = trim(theRecord.get("LoincNumber"));
54  		String partNumber = trim(theRecord.get("PartNumber"));
55  		String partTypeName = trim(theRecord.get("PartTypeName"));
56  		String partSequenceOrder = trim(theRecord.get("PartSequenceOrder"));
57  		String partName = trim(theRecord.get("PartName"));
58  
59  		// RSNA Codes VS
60  		ValueSet vs = getValueSet(DOCUMENT_ONTOLOGY_CODES_VS_ID, DOCUMENT_ONTOLOGY_CODES_VS_URI, DOCUMENT_ONTOLOGY_CODES_VS_NAME, null);
61  		addCodeAsIncludeToValueSet(vs, IHapiTerminologyLoaderSvc.LOINC_URI, loincNumber, null);
62  
63  		// Part Properties
64  		String loincCodePropName;
65  		switch (partTypeName) {
66  			case "Document.Kind":
67  				loincCodePropName = "document-kind";
68  				break;
69  			case "Document.Role":
70  				loincCodePropName = "document-role";
71  				break;
72  			case "Document.Setting":
73  				loincCodePropName = "document-setting";
74  				break;
75  			case "Document.SubjectMatterDomain":
76  				loincCodePropName = "document-subject-matter-domain";
77  				break;
78  			case "Document.TypeOfService":
79  				loincCodePropName = "document-type-of-service";
80  				break;
81  			default:
82  				throw new InternalErrorException("Unknown PartTypeName: " + partTypeName);
83  		}
84  
85  		TermConcept code = myCode2Concept.get(loincNumber);
86  		if (code != null) {
87  			code.addPropertyCoding(loincCodePropName, IHapiTerminologyLoaderSvc.LOINC_URI, partNumber, partName);
88  		}
89  
90  	}
91  
92  
93  
94  }