View Javadoc
1   /*
2    * Copyright 2009 the original author or authors.
3    * 
4    * Licensed under the Apache License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    *     http://www.apache.org/licenses/LICENSE-2.0
9    *     
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
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   * @author Stefan Ivanov
34   */
35  public class CDAR2Parser implements Parser<ClinicalDocument> {
36  
37  
38      /* (non-Javadoc)
39       * @see org.openehealth.ipf.commons.core.modules.api.Parser#parse(java.lang.String, java.lang.Object[])
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      /* (non-Javadoc)
50       * @see org.openehealth.ipf.commons.core.modules.api.Parser#parse(java.io.InputStream, java.lang.Object[])
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       * (non-Javadoc)
67       * @see org.openehealth.ipf.commons.core.modules.api.Parser#parse(javax.xml.transform.Source, java.lang.Object[])
68       */
69      public ClinicalDocument parse(Source source, Object... options) throws IOException {
70          throw new UnsupportedOperationException("Not implemented yet");
71      }
72  
73      /*
74       * (non-Javadoc)
75       * @see org.openehealth.ipf.commons.core.modules.api.Parser#parse(java.io.Reader, java.lang.Object[])
76       */
77      public ClinicalDocument parse(Reader reader, Object... options) throws IOException {
78          throw new UnsupportedOperationException("Not implemented yet");
79      }
80  
81  }