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 static org.openehealth.ipf.commons.ihe.xds.core.metadata.Timestamp.toHL7;
19  import static org.openehealth.ipf.commons.ihe.xds.core.transform.requests.QueryParameter.*;
20  
21  import org.openehealth.ipf.commons.ihe.xds.core.ebxml.EbXMLAdhocQueryRequest;
22  import org.openehealth.ipf.commons.ihe.xds.core.metadata.Hl7v2Based;
23  import org.openehealth.ipf.commons.ihe.xds.core.metadata.Identifiable;
24  import org.openehealth.ipf.commons.ihe.xds.core.requests.query.FindFoldersQuery;
25  
26  /**
27   * Transforms between a {@link FindFoldersQuery} and {@link EbXMLAdhocQueryRequest}.
28   * @author Jens Riemschneider
29   */
30  public class FindFoldersQueryTransformer extends AbstractStoredQueryTransformer<FindFoldersQuery>{
31  
32      /**
33       * Transforms the query into its ebXML representation.
34       * <p>
35       * Does not perform any transformation if one of the parameters is <code>null</code>. 
36       * @param query
37       *          the query. Can be <code>null</code>.
38       * @param ebXML
39       *          the ebXML representation. Can be <code>null</code>.
40       */
41      public void toEbXML(FindFoldersQuery query, EbXMLAdhocQueryRequest ebXML) {
42          if (query == null || ebXML == null) {
43              return;
44          }
45  
46          super.toEbXML(query, ebXML);
47          
48          QuerySlotHelper slots = new QuerySlotHelper(ebXML);
49  
50          slots.fromString(FOLDER_PATIENT_ID, Hl7v2Based.render(query.getPatientId()));
51          
52          slots.fromNumber(FOLDER_LAST_UPDATE_TIME_FROM, toHL7(query.getLastUpdateTime().getFrom()));
53          slots.fromNumber(FOLDER_LAST_UPDATE_TIME_TO, toHL7(query.getLastUpdateTime().getTo()));
54  
55          slots.fromCode(FOLDER_CODES, query.getCodes());
56          
57          slots.fromStatus(FOLDER_STATUS, query.getStatus());
58          slots.fromInteger(METADATA_LEVEL, query.getMetadataLevel());
59      }
60      
61      /**
62       * Transforms the ebXML representation of a query into a query object.
63       * <p>
64       * Does not perform any transformation if one of the parameters is <code>null</code>. 
65       * @param query
66       *          the query. Can be <code>null</code>.
67       * @param ebXML
68       *          the ebXML representation. Can be <code>null</code>.
69       */
70      public void fromEbXML(FindFoldersQuery query, EbXMLAdhocQueryRequest ebXML) {
71          if (query == null || ebXML == null) {
72              return;
73          }
74  
75          super.fromEbXML(query, ebXML);
76  
77          QuerySlotHelper slots = new QuerySlotHelper(ebXML);
78          String patientId = slots.toString(FOLDER_PATIENT_ID);
79          query.setPatientId(Hl7v2Based.parse(patientId, Identifiable.class));
80          
81          query.setCodes(slots.toCodeQueryList(FOLDER_CODES, FOLDER_CODES_SCHEME));
82          
83          query.getLastUpdateTime().setFrom(slots.toNumber(FOLDER_LAST_UPDATE_TIME_FROM));
84          query.getLastUpdateTime().setTo(slots.toNumber(FOLDER_LAST_UPDATE_TIME_TO));
85          
86          query.setStatus(slots.toStatus(FOLDER_STATUS));
87          query.setMetadataLevel(slots.toInteger(METADATA_LEVEL));
88      }
89  }