source: ccr/trunk/nhin-vista/projects/NHINC/Current/Product/Production/Adapters/General/DocumentRepositoryEJB/src/java/gov/hhs/fha/nhinc/document/DocumentRepositoryHelper.java@ 507

Last change on this file since 507 was 507, checked in by George Lilly, 15 years ago

NHIN gateway and adaptor for use on linux with VistA EHR and RPMS

File size: 7.3 KB
Line 
1package gov.hhs.fha.nhinc.document;
2
3import gov.hhs.fha.nhinc.nhinclib.NullChecker;
4import gov.hhs.fha.nhinc.repository.model.Document;
5import gov.hhs.fha.nhinc.repository.model.DocumentQueryParams;
6import gov.hhs.fha.nhinc.repository.service.DocumentService;
7import java.util.ArrayList;
8import java.util.Iterator;
9import java.util.List;
10
11import org.apache.commons.logging.Log;
12import org.apache.commons.logging.LogFactory;
13
14import ihe.iti.xds_b._2007.RetrieveDocumentSetRequestType.DocumentRequest;
15import ihe.iti.xds_b._2007.RetrieveDocumentSetResponseType.DocumentResponse;
16import oasis.names.tc.ebxml_regrep.xsd.rs._3.RegistryResponseType;
17
18/**
19 * Helper class for the document repository service.
20 *
21 * @author Neil Webb
22 */
23public class DocumentRepositoryHelper
24{
25 public static final String XDS_RETRIEVE_RESPONSE_STATUS_FAILURE = "urn:oasis:names:tc:ebxml-regrep:ResponseStatusType:Failure";
26 public static final String XDS_RETRIEVE_RESPONSE_STATUS_SUCCESS = "urn:oasis:names:tc:ebxml-regrep:ResponseStatusType:Success";
27
28 private static Log log = LogFactory.getLog(DocumentRepositoryHelper.class);
29
30 private static final String REPOSITORY_UNIQUE_ID = "1";
31
32 /**
33 * Perform a document retrieve on the document repository.
34 *
35 * @param body Message containing docurment retrieve parameters
36 * @return Document retrieve response message.
37 */
38 public ihe.iti.xds_b._2007.RetrieveDocumentSetResponseType documentRepositoryRetrieveDocumentSet(ihe.iti.xds_b._2007.RetrieveDocumentSetRequestType body)
39 {
40 ihe.iti.xds_b._2007.RetrieveDocumentSetResponseType response = new ihe.iti.xds_b._2007.RetrieveDocumentSetResponseType();
41 if((body != null) &&
42 (body.getDocumentRequest() != null) &&
43 (!body.getDocumentRequest().isEmpty()))
44 {
45 String homeCommunityId = null;
46 List<String> documentUniqueIds = new ArrayList<String>();
47 List<String> repositoryUniqueIds = new ArrayList<String>();
48 List<DocumentRequest> olDocRequest = body.getDocumentRequest();
49 Iterator<DocumentRequest> iterDocRequest = olDocRequest.iterator();
50
51 while (iterDocRequest.hasNext())
52 {
53 DocumentRequest oDocRequest = iterDocRequest.next();
54
55
56 // Home Community
57 //----------------
58 if ((homeCommunityId == null) &&
59 (oDocRequest.getHomeCommunityId() != null) &&
60 (oDocRequest.getHomeCommunityId().length() > 0))
61 {
62 homeCommunityId = oDocRequest.getHomeCommunityId();
63 }
64
65 // Document Uniqiue ID
66 //--------------------
67 if ((oDocRequest.getDocumentUniqueId() != null) &&
68 (oDocRequest.getDocumentUniqueId().length() > 0))
69 {
70 documentUniqueIds.add(oDocRequest.getDocumentUniqueId());
71 }
72
73 // Repository Unique ID
74 //----------------------
75 if ((oDocRequest.getRepositoryUniqueId() != null) &&
76 (oDocRequest.getRepositoryUniqueId().length() > 0))
77 {
78 repositoryUniqueIds.add(oDocRequest.getRepositoryUniqueId());
79 }
80
81 } // while (iterDocRequest.hasNext())
82
83 if((!documentUniqueIds.isEmpty()) && (!repositoryUniqueIds.isEmpty()))
84 {
85 boolean repositoryIdMatched = true;
86 for(String repositoryUniqueId : repositoryUniqueIds)
87 {
88 if(!REPOSITORY_UNIQUE_ID.equals(repositoryUniqueId))
89 {
90 repositoryIdMatched = false;
91 log.warn("Document repository message not processed due to repository " +
92 " unique id mismatch. Expected: " + REPOSITORY_UNIQUE_ID + ", found: " +
93 repositoryUniqueId);
94 }
95 }
96
97 if(repositoryIdMatched)
98 {
99 DocumentQueryParams params = new DocumentQueryParams();
100 params.setDocumentUniqueId(documentUniqueIds);
101 DocumentService service = new DocumentService();
102 List<Document> docs = service.documentQuery(params);
103 loadDocumentResponses(response, docs, homeCommunityId);
104 }
105 }
106
107 }
108 return response;
109 }
110
111 private void loadDocumentResponses(ihe.iti.xds_b._2007.RetrieveDocumentSetResponseType response, List<Document> docs, String homeCommunityId)
112 {
113 if(response != null)
114 {
115 String responseStatus = XDS_RETRIEVE_RESPONSE_STATUS_FAILURE;
116 List<DocumentResponse> olDocResponse = response.getDocumentResponse();
117 RegistryResponseType registryResponse = new oasis.names.tc.ebxml_regrep.xsd.rs._3.ObjectFactory().createRegistryResponseType();
118 response.setRegistryResponse(registryResponse);
119
120 if((docs != null) && (!docs.isEmpty()))
121 {
122 for(Document doc : docs)
123 {
124 DocumentResponse oDocResponse = new DocumentResponse();
125 boolean bHasData = false;
126
127 // Home Community Id
128 //-------------------
129 oDocResponse.setHomeCommunityId(homeCommunityId);
130
131 // Repository Unique Id
132 //----------------------
133 oDocResponse.setRepositoryUniqueId(REPOSITORY_UNIQUE_ID);
134
135 // Document Unique ID
136 //--------------------
137 if(NullChecker.isNotNullish(doc.getDocumentUniqueId()))
138 {
139 oDocResponse.setDocumentUniqueId(doc.getDocumentUniqueId());
140 log.info("Document unique id: " + doc.getDocumentUniqueId());
141 bHasData = true;
142 }
143
144 // Mime Type
145 //----------
146 if(NullChecker.isNotNullish(doc.getMimeType()))
147 {
148 oDocResponse.setMimeType(doc.getMimeType());
149 log.info("Mime type: " + doc.getMimeType());
150 bHasData = true;
151 }
152
153 // Document
154 //---------
155 if((doc.getRawData() != null) && (doc.getRawData().length > 0))
156 {
157 oDocResponse.setDocument(doc.getRawData());
158 log.info("Document data: " + doc.getRawData());
159 bHasData = true;
160 }
161
162 if (bHasData)
163 {
164 olDocResponse.add(oDocResponse);
165 responseStatus = XDS_RETRIEVE_RESPONSE_STATUS_SUCCESS;
166 }
167 }
168 }
169 else
170 {
171 log.info("loadDocumentResponses - no response messages returned.");
172 }
173
174 registryResponse.setStatus(responseStatus);
175 }
176 else
177 {
178 log.info("loadDocumentResponses - response object was null");
179 }
180 }
181
182}
Note: See TracBrowser for help on using the repository browser.