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  
20  import org.openehealth.ipf.commons.ihe.xds.core.ebxml.EbXMLAdhocQueryRequest;
21  import org.openehealth.ipf.commons.ihe.xds.core.metadata.Hl7v2Based;
22  import org.openehealth.ipf.commons.ihe.xds.core.metadata.Identifiable;
23  import org.openehealth.ipf.commons.ihe.xds.core.requests.query.GetAllQuery;
24  
25  /**
26   * Transforms between a {@link GetAllQuery} and {@link EbXMLAdhocQueryRequest}.
27   * @author Jens Riemschneider
28   */
29  public class GetAllQueryTransformer extends AbstractStoredQueryTransformer<GetAllQuery> {
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(GetAllQuery 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.fromString(PATIENT_ID, Hl7v2Based.render(query.getPatientId()));
50          
51          slots.fromStatus(DOC_ENTRY_STATUS, query.getStatusDocuments());
52          slots.fromStatus(SUBMISSION_SET_STATUS, query.getStatusSubmissionSets());
53          slots.fromStatus(FOLDER_STATUS, query.getStatusFolders());
54          
55          slots.fromCode(DOC_ENTRY_FORMAT_CODE, query.getFormatCodes());
56          slots.fromCode(DOC_ENTRY_CONFIDENTIALITY_CODE, query.getConfidentialityCodes());
57  
58          slots.fromDocumentEntryType(DOC_ENTRY_TYPE, query.getDocumentEntryTypes());
59          slots.fromStatus(ASSOCIATION_STATUS, query.getAssociationStatuses());
60          slots.fromInteger(METADATA_LEVEL, query.getMetadataLevel());
61      }
62      
63      /**
64       * Transforms the ebXML representation of a query into a query object.
65       * <p>
66       * Does not perform any transformation if one of the parameters is <code>null</code>. 
67       * @param query
68       *          the query. Can be <code>null</code>.
69       * @param ebXML
70       *          the ebXML representation. Can be <code>null</code>.
71       */
72      public void fromEbXML(GetAllQuery query, EbXMLAdhocQueryRequest ebXML) {
73          if (query == null || ebXML == null) {
74              return;
75          }
76  
77          super.fromEbXML(query, ebXML);
78  
79          QuerySlotHelper slots = new QuerySlotHelper(ebXML);
80          String patientId = slots.toString(PATIENT_ID);
81          query.setPatientId(Hl7v2Based.parse(patientId, Identifiable.class));
82  
83          query.setStatusDocuments(slots.toStatus(DOC_ENTRY_STATUS));
84          query.setStatusFolders(slots.toStatus(FOLDER_STATUS));
85          query.setStatusSubmissionSets(slots.toStatus(SUBMISSION_SET_STATUS));
86          
87          query.setConfidentialityCodes(slots.toCodeQueryList(DOC_ENTRY_CONFIDENTIALITY_CODE, DOC_ENTRY_CONFIDENTIALITY_CODE_SCHEME));
88          query.setFormatCodes(slots.toCodeList(DOC_ENTRY_FORMAT_CODE));
89  
90          query.setDocumentEntryTypes(slots.toDocumentEntryType(DOC_ENTRY_TYPE));
91          query.setAssociationStatuses(slots.toStatus(ASSOCIATION_STATUS));
92          query.setMetadataLevel(slots.toInteger(METADATA_LEVEL));
93      }
94  }