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