View Javadoc
1   package ca.uhn.fhir.jpa.term.snomedct;
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 ca.uhn.fhir.jpa.term.TerminologyLoaderSvcImpl;
27  import org.apache.commons.csv.CSVRecord;
28  
29  import java.util.Map;
30  import java.util.Set;
31  
32  public final class SctHandlerDescription implements IRecordHandler {
33     private final Map<String, TermConcept> myCode2concept;
34     private final TermCodeSystemVersion myCodeSystemVersion;
35     private final Map<String, TermConcept> myId2concept;
36     private Set<String> myValidConceptIds;
37  
38     public SctHandlerDescription(Set<String> theValidConceptIds, Map<String, TermConcept> theCode2concept, Map<String, TermConcept> theId2concept, TermCodeSystemVersion theCodeSystemVersion) {
39        myCode2concept = theCode2concept;
40        myId2concept = theId2concept;
41        myCodeSystemVersion = theCodeSystemVersion;
42        myValidConceptIds = theValidConceptIds;
43     }
44  
45     @Override
46     public void accept(CSVRecord theRecord) {
47        String id = theRecord.get("id");
48        boolean active = "1".equals(theRecord.get("active"));
49        if (!active) {
50           return;
51        }
52        String conceptId = theRecord.get("conceptId");
53        if (!myValidConceptIds.contains(conceptId)) {
54           return;
55        }
56  
57        String term = theRecord.get("term");
58  
59        TermConcept concept = TerminologyLoaderSvcImpl.getOrCreateConcept(myCodeSystemVersion, myId2concept, id);
60        concept.setCode(conceptId);
61        concept.setDisplay(term);
62        myCode2concept.put(conceptId, concept);
63     }
64  }