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.commons.ihe.xds.core.transform.requests.query;
17  
18  import org.openehealth.ipf.commons.ihe.xds.core.ebxml.EbXMLAdhocQueryRequest;
19  import org.openehealth.ipf.commons.ihe.xds.core.metadata.Hl7v2Based;
20  import org.openehealth.ipf.commons.ihe.xds.core.metadata.Identifiable;
21  import org.openehealth.ipf.commons.ihe.xds.core.requests.query.FindDocumentsQuery;
22  
23  import static org.openehealth.ipf.commons.ihe.xds.core.transform.requests.QueryParameter.*;
24  
25  /**
26   * Transforms between a {@link FindDocumentsQuery} and {@link EbXMLAdhocQueryRequest}.
27   * @author Jens Riemschneider
28   */
29  public class FindDocumentsQueryTransformer<T extends FindDocumentsQuery> extends DocumentsQueryTransformer<T> {
30  
31      @Override
32      public void toEbXML(T query, EbXMLAdhocQueryRequest ebXML) {
33          if (query == null || ebXML == null) {
34              return;
35          }
36  
37          super.toEbXML(query, ebXML);
38  
39          QuerySlotHelper slots = new QuerySlotHelper(ebXML);
40          slots.fromString(DOC_ENTRY_PATIENT_ID, Hl7v2Based.render(query.getPatientId()));
41          slots.fromDocumentEntryType(DOC_ENTRY_TYPE, query.getDocumentEntryTypes());
42          slots.fromStatus(DOC_ENTRY_STATUS, query.getStatus());
43          slots.fromDocumentAvailability(DOC_ENTRY_DOCUMENT_AVAILABILITY, query.getDocumentAvailability());
44          slots.fromInteger(METADATA_LEVEL, query.getMetadataLevel());
45      }
46  
47  
48      public void fromEbXML(T query, EbXMLAdhocQueryRequest ebXML) {
49          if (query == null || ebXML == null) {
50              return;
51          }
52  
53          super.fromEbXML(query, ebXML);
54          QuerySlotHelper slots = new QuerySlotHelper(ebXML);
55          String patientId = slots.toString(DOC_ENTRY_PATIENT_ID);
56          query.setPatientId(Hl7v2Based.parse(patientId, Identifiable.class));
57          query.setDocumentEntryTypes(slots.toDocumentEntryType(DOC_ENTRY_TYPE));
58          query.setStatus(slots.toStatus(DOC_ENTRY_STATUS));
59          query.setDocumentAvailability(slots.toDocumentAvailability(DOC_ENTRY_DOCUMENT_AVAILABILITY));
60          query.setMetadataLevel(slots.toInteger(METADATA_LEVEL));
61      }
62  }