1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.openehealth.ipf.commons.ihe.fhir.support;
18
19 import ca.uhn.fhir.context.FhirContext;
20 import org.hl7.fhir.dstu3.model.Bundle;
21 import org.hl7.fhir.dstu3.model.NamingSystem;
22
23 import java.io.BufferedReader;
24 import java.io.IOException;
25 import java.io.InputStreamReader;
26 import java.io.Reader;
27 import java.net.URL;
28
29
30
31
32
33
34
35
36 public class DefaultNamingSystemServiceImpl extends AbstractNamingSystemServiceImpl {
37
38 private FhirContext fhirContext;
39
40 public DefaultNamingSystemServiceImpl(FhirContext fhirContext) {
41 super();
42 this.fhirContext = fhirContext;
43 }
44
45 public DefaultNamingSystemServiceImpl addNamingSystemsFromXml(Reader reader) {
46 addNamingSystems(fhirContext.newXmlParser().parseResource(Bundle.class, reader));
47 return this;
48 }
49
50 public void setNamingSystemsFromXml(URL... urls) throws IOException {
51 for (URL url : urls) {
52 addNamingSystemsFromXml(new BufferedReader(new InputStreamReader(url.openStream())));
53 }
54 }
55
56 public DefaultNamingSystemServiceImpl addNamingSystemsFromJson(Reader reader) {
57 addNamingSystems(fhirContext.newJsonParser().parseResource(Bundle.class, reader));
58 return this;
59 }
60
61 public void setNamingSystemsFromJson(URL... urls) throws IOException {
62 for (URL url : urls) {
63 addNamingSystemsFromJson(new BufferedReader(new InputStreamReader(url.openStream())));
64 }
65 }
66
67 public DefaultNamingSystemServiceImpl addNamingSystemsFromFhirServer(String url) {
68 addNamingSystems(fhirContext.newRestfulGenericClient(url)
69 .search()
70 .forResource(NamingSystem.class)
71 .returnBundle(Bundle.class)
72 .execute());
73 return this;
74 }
75
76 }