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.metadata.Hl7v2Based;
20  import org.openehealth.ipf.commons.ihe.xds.core.metadata.Identifiable;
21  import org.openehealth.ipf.commons.ihe.xds.core.requests.query.FetchQuery;
22  
23  import static org.openehealth.ipf.commons.ihe.xds.core.transform.requests.QueryParameter.DOC_ENTRY_PATIENT_ID;
24  
25  /**
26   * Transforms between a {@link FetchQuery} and {@link EbXMLAdhocQueryRequest}.
27   * @author Dmytro Rud
28   */
29  public class FetchQueryTransformer extends DocumentsQueryTransformer<FetchQuery> {
30      @Override
31      public void toEbXML(FetchQuery query, EbXMLAdhocQueryRequest ebXML) {
32          if (query == null || ebXML == null) {
33              return;
34          }
35  
36          super.toEbXML(query, ebXML);
37  
38          QuerySlotHelper slots = new QuerySlotHelper(ebXML);
39          slots.fromString(DOC_ENTRY_PATIENT_ID, Hl7v2Based.render(query.getPatientId()));
40      }
41  
42  
43      public void fromEbXML(FetchQuery query, EbXMLAdhocQueryRequest ebXML) {
44          if (query == null || ebXML == null) {
45              return;
46          }
47  
48          super.fromEbXML(query, ebXML);
49          QuerySlotHelper slots = new QuerySlotHelper(ebXML);
50          String patientId = slots.toString(DOC_ENTRY_PATIENT_ID);
51          query.setPatientId(Hl7v2Based.parse(patientId, Identifiable.class));
52      }
53  }