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.transform.requests.QueryParameter.*;
19  import static org.openehealth.ipf.commons.ihe.xds.core.metadata.Timestamp.toHL7;
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.FindSubmissionSetsQuery;
25  
26  /**
27   * Transforms between {@link FindSubmissionSetsQuery} and {@link EbXMLAdhocQueryRequest}.
28   * @author Jens Riemschneider
29   */
30  public class FindSubmissionSetsQueryTransformer extends AbstractStoredQueryTransformer<FindSubmissionSetsQuery> {
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 to transform.
38       * @param ebXML
39       *          the EbXML representation.
40       */
41      public void toEbXML(FindSubmissionSetsQuery 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(SUBMISSION_SET_PATIENT_ID, Hl7v2Based.render(query.getPatientId()));
51          
52          slots.fromStringList(SUBMISSION_SET_SOURCE_ID, query.getSourceIds());
53          
54          slots.fromNumber(SUBMISSION_SET_SUBMISSION_TIME_FROM, toHL7(query.getSubmissionTime().getFrom()));
55          slots.fromNumber(SUBMISSION_SET_SUBMISSION_TIME_TO, toHL7(query.getSubmissionTime().getTo()));
56  
57          slots.fromString(SUBMISSION_SET_AUTHOR_PERSON, query.getAuthorPerson());
58          
59          slots.fromCode(SUBMISSION_SET_CONTENT_TYPE_CODE, query.getContentTypeCodes());
60          
61          slots.fromStatus(SUBMISSION_SET_STATUS, query.getStatus());
62      }
63      
64      /**
65       * Transforms the ebXML representation of a query into a query object.
66       * <p>
67       * Does not perform any transformation if one of the parameters is <code>null</code>. 
68       * @param query
69       *          the query. Can be <code>null</code>.
70       * @param ebXML
71       *          the ebXML representation. Can be <code>null</code>.
72       */
73      public void fromEbXML(FindSubmissionSetsQuery query, EbXMLAdhocQueryRequest ebXML) {
74          if (query == null || ebXML == null) {
75              return;
76          }
77  
78          super.fromEbXML(query, ebXML);
79  
80          QuerySlotHelper slots = new QuerySlotHelper(ebXML);
81          
82          String patientId = slots.toString(SUBMISSION_SET_PATIENT_ID);
83          query.setPatientId(Hl7v2Based.parse(patientId, Identifiable.class));
84          
85          query.setSourceIds(slots.toStringList(SUBMISSION_SET_SOURCE_ID));
86          
87          query.getSubmissionTime().setFrom(slots.toNumber(SUBMISSION_SET_SUBMISSION_TIME_FROM));
88          query.getSubmissionTime().setTo(slots.toNumber(SUBMISSION_SET_SUBMISSION_TIME_TO));
89          
90          query.setAuthorPerson(slots.toString(SUBMISSION_SET_AUTHOR_PERSON));
91          
92          query.setContentTypeCodes(slots.toCodeList(SUBMISSION_SET_CONTENT_TYPE_CODE));
93          
94          query.setStatus(slots.toStatus(SUBMISSION_SET_STATUS));
95      }
96  }