1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.openehealth.ipf.modules.cda;
17
18 import java.io.ByteArrayInputStream;
19 import java.io.IOException;
20 import java.io.InputStream;
21 import java.io.Reader;
22 import java.util.Map;
23 import javax.xml.transform.Source;
24
25 import org.eclipse.emf.common.util.URI;
26 import org.openehealth.ipf.commons.core.modules.api.ParseException;
27 import org.openehealth.ipf.commons.core.modules.api.Parser;
28 import org.openhealthtools.mdht.uml.cda.CDAPackage;
29 import org.openhealthtools.mdht.uml.cda.ClinicalDocument;
30 import org.openhealthtools.mdht.uml.cda.DocumentRoot;
31 import org.openhealthtools.mdht.uml.cda.internal.resource.CDAResource;
32
33
34
35 public class CDAR2Parser implements Parser<ClinicalDocument> {
36
37
38
39
40
41 public ClinicalDocument parse(String s, Object... options) {
42 try {
43 return parse(new ByteArrayInputStream(s.getBytes()), options);
44 } catch (IOException e) {
45 throw new ParseException(e);
46 }
47 }
48
49
50
51
52 public ClinicalDocument parse(InputStream is, Object... options)
53 throws IOException {
54 CDAResource resource = (CDAResource) CDAResource.Factory.INSTANCE.createResource(URI
55 .createURI(CDAPackage.eNS_URI));
56 if (options != null && options.length > 0 && options[0] instanceof Map<?, ?>) {
57 resource.load(is, (Map<?, ?>) options[0]);
58 } else {
59 resource.load(is, null);
60 }
61 DocumentRoot root = (DocumentRoot) resource.getContents().get(0);
62 return root.getClinicalDocument();
63 }
64
65
66
67
68
69 public ClinicalDocument parse(Source source, Object... options) throws IOException {
70 throw new UnsupportedOperationException("Not implemented yet");
71 }
72
73
74
75
76
77 public ClinicalDocument parse(Reader reader, Object... options) throws IOException {
78 throw new UnsupportedOperationException("Not implemented yet");
79 }
80
81 }