1 | package gov.hhs.fha.nhinc.document;
|
---|
2 |
|
---|
3 | import gov.hhs.fha.nhinc.nhinclib.NullChecker;
|
---|
4 | import gov.hhs.fha.nhinc.properties.PropertyAccessor;
|
---|
5 | import java.text.SimpleDateFormat;
|
---|
6 | import java.util.ArrayList;
|
---|
7 | import java.util.Date;
|
---|
8 | import java.util.List;
|
---|
9 | import java.util.UUID;
|
---|
10 |
|
---|
11 | import javax.xml.bind.JAXBContext;
|
---|
12 | import javax.xml.bind.JAXBElement;
|
---|
13 | import javax.xml.bind.Marshaller;
|
---|
14 | import javax.xml.bind.Unmarshaller;
|
---|
15 |
|
---|
16 | import org.apache.commons.logging.Log;
|
---|
17 | import org.apache.commons.logging.LogFactory;
|
---|
18 |
|
---|
19 | import gov.hhs.fha.nhinc.repository.model.Document;
|
---|
20 | import gov.hhs.fha.nhinc.repository.model.DocumentQueryParams;
|
---|
21 | import gov.hhs.fha.nhinc.repository.model.EventCode;
|
---|
22 | import gov.hhs.fha.nhinc.repository.service.DocumentService;
|
---|
23 | import gov.hhs.fha.nhinc.repository.util.DocumentLoadUtil;
|
---|
24 | import gov.hhs.fha.nhinc.util.format.PatientIdFormatUtil;
|
---|
25 |
|
---|
26 | import oasis.names.tc.ebxml_regrep.xsd.rim._3.AdhocQueryType;
|
---|
27 | import oasis.names.tc.ebxml_regrep.xsd.rim._3.AssociationType1;
|
---|
28 | import oasis.names.tc.ebxml_regrep.xsd.rim._3.ClassificationType;
|
---|
29 | import oasis.names.tc.ebxml_regrep.xsd.rim._3.ExternalIdentifierType;
|
---|
30 | import oasis.names.tc.ebxml_regrep.xsd.rim._3.ExtrinsicObjectType;
|
---|
31 | import oasis.names.tc.ebxml_regrep.xsd.rim._3.IdentifiableType;
|
---|
32 | import oasis.names.tc.ebxml_regrep.xsd.rim._3.InternationalStringType;
|
---|
33 | import oasis.names.tc.ebxml_regrep.xsd.rim._3.LocalizedStringType;
|
---|
34 | import oasis.names.tc.ebxml_regrep.xsd.rim._3.ObjectRefType;
|
---|
35 | import oasis.names.tc.ebxml_regrep.xsd.rim._3.RegistryObjectListType;
|
---|
36 | import oasis.names.tc.ebxml_regrep.xsd.rim._3.SlotType1;
|
---|
37 | import oasis.names.tc.ebxml_regrep.xsd.rim._3.ValueListType;
|
---|
38 |
|
---|
39 | /**
|
---|
40 | * Helper class for performing document registry operations
|
---|
41 | *
|
---|
42 | * @author Neil Webb
|
---|
43 | */
|
---|
44 | public class DocumentRegistryHelper
|
---|
45 | {
|
---|
46 | private static Log log = LogFactory.getLog(DocumentRegistryHelper.class);
|
---|
47 |
|
---|
48 | private static final String EBXML_DOCENTRY_PATIENT_ID = "$XDSDocumentEntryPatientId";
|
---|
49 | private static final String EBXML_DOCENTRY_CLASS_CODE = "$XDSDocumentEntryClassCode";
|
---|
50 | private static final String EBXML_DOCENTRY_CLASS_CODE_SCHEME = "$XDSDocumentEntryClassCodeScheme";
|
---|
51 | private static final String EBXML_DOCENTRY_CREATION_TIME_FROM = "$XDSDocumentEntryCreationTimeFrom";
|
---|
52 | private static final String EBXML_DOCENTRY_CREATION_TIME_TO = "$XDSDocumentEntryCreationTimeTo";
|
---|
53 | private static final String EBXML_DOCENTRY_SERVICE_START_TIME_FROM = "$XDSDocumentEntryServiceStartTimeFrom";
|
---|
54 | private static final String EBXML_DOCENTRY_SERVICE_START_TIME_TO = "$XDSDocumentEntryServiceStartTimeTo";
|
---|
55 | private static final String EBXML_DOCENTRY_SERVICE_STOP_TIME_FROM = "$XDSDocumentEntryServiceStopTimeFrom";
|
---|
56 | private static final String EBXML_DOCENTRY_SERVICE_STOP_TIME_TO = "$XDSDocumentEntryServiceStopTimeTo";
|
---|
57 | private static final String EBXML_DOCENTRY_STATUS = "$XDSDocumentEntryStatus";
|
---|
58 |
|
---|
59 | // We need to be able to do a search using AdhocQueryRequest parameters, but
|
---|
60 | // XDS.b does not have a search parameter slot name defined for repository ID
|
---|
61 | // and document ID. So we had to create our own custom ones.
|
---|
62 | //----------------------------------------------------------------------------
|
---|
63 | private static final String NHINC_CUSTOM_REPOSITORY_ID = "$NHINCRepositoryId";
|
---|
64 | private static final String NHINC_CUSTOM_DOCUMENT_ID = "$NHINCDocumentId";
|
---|
65 |
|
---|
66 | private static final String EBXML_RESPONSE_REPOSITORY_UNIQUE_ID_SLOTNAME = "repositoryUniqueId";
|
---|
67 | private static final String EBXML_RESPONSE_DOCID_IDENTIFICATION_SCHEME = "urn:uuid:2e82c1f6-a085-4c72-9da3-8640a32e42ab";
|
---|
68 | private static final String EBXML_RESPONSE_DOCID_NAME = "XDSDocumentEntry.uniqueId";
|
---|
69 | private static final String EBXML_RESPONSE_PATIENTID_IDENTIFICATION_SCHEME = "urn:uuid:58a6f841-87b3-4a3e-92fd-a8ffeff98427";
|
---|
70 | private static final String EBXML_RESPONSE_PATIENTID_NAME = "XDSDocumentEntry.patientId";
|
---|
71 | private static final String EBXML_RESPONSE_AUTHOR_CLASS_SCHEME = "urn:uuid:93606bcf-9494-43ec-9b4e-a7748d1a838d";
|
---|
72 | private static final String EBXML_RESPONSE_AUTHOR_PERSON_SLOTNAME = "authorPerson";
|
---|
73 | private static final String EBXML_RESPONSE_AUTHOR_INSTITUTION_SLOTNAME = "authorInstitution";
|
---|
74 | private static final String EBXML_RESPONSE_AUTHOR_ROLE_SLOTNAME = "authorRole";
|
---|
75 | private static final String EBXML_RESPONSE_AUTHOR_SPECIALTY_SLOTNAME = "authorSpecialty";
|
---|
76 | private static final String EBXML_RESPONSE_CLASSCODE_CLASS_SCHEME = "urn:uuid:41a5887f-8865-4c09-adf7-e362475b143a";
|
---|
77 | private static final String EBXML_RESPONSE_CONFIDENTIALITYCODE_CLASS_SCHEME = "urn:uuid:f4f85eac-e6cb-4883-b524-f2705394840f";
|
---|
78 | private static final String EBXML_RESPONSE_EVENTCODE_CLASS_SCHEME = "urn:uuid:2c6b8cb7-8b2a-4051-b291-b1ae6a575ef4";
|
---|
79 | private static final String EBXML_RESPONSE_FORMATCODE_CLASS_SCHEME = "urn:uuid:a09d5840-386c-46f2-b5ad-9c3699a4309d";
|
---|
80 | private static final String EBXML_RESPONSE_HEALTHCAREFACILITYTYPE_CLASS_SCHEME = "urn:uuid:f33fb8ac-18af-42cc-ae0e-ed0b0bdb91e1";
|
---|
81 | private static final String EBXML_RESPONSE_PRACTICESETTING_CLASS_SCHEME = "urn:uuid:cccf5598-8b07-4b77-a05e-ae952c785ead";
|
---|
82 | private static final String EBXML_RESPONSE_TYPECODE_CLASS_SCHEME = "urn:uuid:f0306f51-975f-434e-a61c-c59651d33983";
|
---|
83 | private static final String EBXML_RESPONSE_CODE_CODESCHEME_SLOTNAME = "codingScheme";
|
---|
84 | private static final String EBXML_RESPONSE_CREATIONTIME_SLOTNAME = "creationTime";
|
---|
85 | private static final String EBXML_RESPONSE_HASH_SLOTNAME = "hash";
|
---|
86 | private static final String EBXML_RESPONSE_INTENDEDRECIPIENTS_SLOTNAME = "intendedRecipient";
|
---|
87 | private static final String EBXML_RESPONSE_LANGUAGECODE_SLOTNAME = "languageCode";
|
---|
88 | private static final String EBXML_RESPONSE_LEGALAUTHENTICATOR_SLOTNAME = "legalAuthenticator";
|
---|
89 | private static final String EBXML_RESPONSE_SERVICESTARTTIME_SLOTNAME = "serviceStartTime";
|
---|
90 | private static final String EBXML_RESPONSE_SERVICESTOPTIME_SLOTNAME = "serviceStopTime";
|
---|
91 | private static final String EBXML_RESPONSE_SIZE_SLOTNAME = "size";
|
---|
92 | private static final String EBXML_RESPONSE_SOURCEPATIENTID_SLOTNAME = "sourcePatientId";
|
---|
93 | private static final String EBXML_RESPONSE_SOURCEPATIENTINFO_SLOTNAME = "sourcePatientInfo";
|
---|
94 | private static final String EBXML_RESPONSE_URI_SLOTNAME = "URI";
|
---|
95 | private static final int EBXML_RESPONSE_URI_LINE_LENGTH = 128;
|
---|
96 |
|
---|
97 | private static final String XDS_QUERY_RESPONSE_STATUS_SUCCESS = "urn:oasis:names:tc:ebxml-regrep:ResponseStatusType:Success";
|
---|
98 | private static final String XDS_QUERY_RESPONSE_STATUS_FAILURE = "urn:oasis:names:tc:ebxml-regrep:ResponseStatusType:Failure";
|
---|
99 | private static final String XDS_QUERY_RESPONSE_OPTION_RETURN_TYPE_OBJECT_REF = "ObjectRef";
|
---|
100 | private static final String XDS_QUERY_RESPONSE_OPTION_RETURN_TYPE_LEAF_CLASS = "LeafClass";
|
---|
101 | private static final String XDS_QUERY_RESPONSE_EXTRINSIC_OBJCECT_OBJECT_TYPE = "urn:uuid:7edca82f-054d-47f2-a032-9b2a5b5186c1";
|
---|
102 |
|
---|
103 | private static final String DATE_FORMAT_FULL = "yyyyMMddhhmmssZ";
|
---|
104 | private static final String DATE_FORMAT_CREATION = DATE_FORMAT_FULL;
|
---|
105 | private static final String DATE_FORMAT_SERVICE = "yyyyMMdd";
|
---|
106 |
|
---|
107 | private static final String REPOSITORY_UNIQUE_ID = "1";
|
---|
108 |
|
---|
109 | // Properties file keys
|
---|
110 | private static final String PROPERTY_FILE_NAME_GATEWAY = "gateway";
|
---|
111 | private static final String PROPERTY_FILE_KEY_HOME_COMMUNITY = "localHomeCommunityId";
|
---|
112 |
|
---|
113 | public oasis.names.tc.ebxml_regrep.xsd.query._3.AdhocQueryResponse documentRegistryRegistryStoredQuery(oasis.names.tc.ebxml_regrep.xsd.query._3.AdhocQueryRequest body)
|
---|
114 | {
|
---|
115 | oasis.names.tc.ebxml_regrep.xsd.query._3.ObjectFactory queryObjFact = new oasis.names.tc.ebxml_regrep.xsd.query._3.ObjectFactory();
|
---|
116 | oasis.names.tc.ebxml_regrep.xsd.query._3.AdhocQueryResponse response = queryObjFact.createAdhocQueryResponse();
|
---|
117 |
|
---|
118 | // Collect input values from query.
|
---|
119 | String patientId = null;
|
---|
120 | List<String> classCodeValues = null;
|
---|
121 | String classCodeScheme = null;
|
---|
122 | Date creationTimeFrom = null;
|
---|
123 | Date creationTimeTo = null;
|
---|
124 | Date serviceStartTimeFrom = null;
|
---|
125 | Date serviceStartTimeTo = null;
|
---|
126 | Date serviceStopTimeFrom = null;
|
---|
127 | Date serviceStopTimeTo = null;
|
---|
128 | List<String> statuses = null;
|
---|
129 | List<String> documentUniqueIds = null;
|
---|
130 | String sRepositoryId = null;
|
---|
131 |
|
---|
132 | if(body != null)
|
---|
133 | {
|
---|
134 | AdhocQueryType adhocQuery = body.getAdhocQuery();
|
---|
135 | List<SlotType1> slots = adhocQuery.getSlot();
|
---|
136 |
|
---|
137 | patientId = extractPatientIdentifier(slots);
|
---|
138 | classCodeValues = extractClassCodes(slots);
|
---|
139 | classCodeScheme = extractClassCodeScheme(slots);
|
---|
140 | creationTimeFrom = extractCreationTimeFrom(slots);
|
---|
141 | creationTimeTo = extractCreationTimeTo(slots);
|
---|
142 | serviceStartTimeFrom = extractServiceStartTimeFrom(slots);
|
---|
143 | serviceStartTimeTo = extractServiceStartTimeTo(slots);
|
---|
144 | serviceStopTimeFrom = extractServiceStopTimeFrom(slots);
|
---|
145 | serviceStopTimeTo = extractServiceStopTimeTo(slots);
|
---|
146 | statuses = extractStatuses(slots);
|
---|
147 | documentUniqueIds = extractDocumentId(slots);
|
---|
148 |
|
---|
149 | // We really do not do much with the repository ID - Since
|
---|
150 | // we are not supporting multiple repositories...
|
---|
151 | //---------------------------------------------------------
|
---|
152 | sRepositoryId = extractRepositoryId(slots);
|
---|
153 | }
|
---|
154 |
|
---|
155 | // Perform Query
|
---|
156 | DocumentQueryParams params = new DocumentQueryParams();
|
---|
157 | params.setPatientId(patientId);
|
---|
158 | params.setClassCodes(classCodeValues);
|
---|
159 | params.setClassCodeScheme(classCodeScheme);
|
---|
160 | params.setCreationTimeFrom(creationTimeFrom);
|
---|
161 | params.setCreationTimeTo(creationTimeTo);
|
---|
162 | params.setServiceStartTimeFrom(serviceStartTimeFrom);
|
---|
163 | params.setServiceStartTimeTo(serviceStartTimeTo);
|
---|
164 | params.setServiceStopTimeFrom(serviceStopTimeFrom);
|
---|
165 | params.setServiceStopTimeTo(serviceStopTimeTo);
|
---|
166 | params.setStatuses(statuses);
|
---|
167 | params.setDocumentUniqueId(documentUniqueIds);
|
---|
168 | DocumentService service = new DocumentService();
|
---|
169 | List<Document> docs = service.documentQuery(params);
|
---|
170 |
|
---|
171 | // Create response
|
---|
172 | loadResponseMessage(response, docs);
|
---|
173 |
|
---|
174 | return response;
|
---|
175 | }
|
---|
176 |
|
---|
177 | private String extractPatientIdentifier(List<SlotType1> slots)
|
---|
178 | {
|
---|
179 | String patientId = null;
|
---|
180 | List<String> slotValues = extractSlotValues(slots, EBXML_DOCENTRY_PATIENT_ID);
|
---|
181 | if((slotValues != null) && (!slotValues.isEmpty()))
|
---|
182 | {
|
---|
183 | String formattedPatientId = slotValues.get(0);
|
---|
184 | patientId = PatientIdFormatUtil.parsePatientId(formattedPatientId);
|
---|
185 | }
|
---|
186 | return patientId;
|
---|
187 | }
|
---|
188 |
|
---|
189 | private List<String> extractClassCodes(List<SlotType1> slots)
|
---|
190 | {
|
---|
191 | List<String> classCodes = null;
|
---|
192 | List<String> slotValues = extractSlotValues(slots, EBXML_DOCENTRY_CLASS_CODE);
|
---|
193 | if((slotValues != null) && (!slotValues.isEmpty()))
|
---|
194 | {
|
---|
195 | classCodes = new ArrayList<String>();
|
---|
196 | for(String slotValue : slotValues)
|
---|
197 | {
|
---|
198 | parseParamFormattedString(slotValue, classCodes);
|
---|
199 | }
|
---|
200 | }
|
---|
201 | return classCodes;
|
---|
202 | }
|
---|
203 |
|
---|
204 | private String extractClassCodeScheme(List<SlotType1> slots)
|
---|
205 | {
|
---|
206 | String classCodeScheme = null;
|
---|
207 | List<String> slotValues = extractSlotValues(slots, EBXML_DOCENTRY_CLASS_CODE_SCHEME);
|
---|
208 | if((slotValues != null) && (!slotValues.isEmpty()))
|
---|
209 | {
|
---|
210 | classCodeScheme = slotValues.get(0);
|
---|
211 | }
|
---|
212 | return classCodeScheme;
|
---|
213 | }
|
---|
214 |
|
---|
215 | private Date extractCreationTimeFrom(List<SlotType1> slots)
|
---|
216 | {
|
---|
217 | Date creationTimeFrom = null;
|
---|
218 | List<String> slotValues = extractSlotValues(slots, EBXML_DOCENTRY_CREATION_TIME_FROM);
|
---|
219 | if((slotValues != null) && (!slotValues.isEmpty()))
|
---|
220 | {
|
---|
221 | creationTimeFrom = parseCreationDate(slotValues.get(0));
|
---|
222 | }
|
---|
223 | return creationTimeFrom;
|
---|
224 | }
|
---|
225 |
|
---|
226 | private Date extractCreationTimeTo(List<SlotType1> slots)
|
---|
227 | {
|
---|
228 | Date creationTimeTo = null;
|
---|
229 | List<String> slotValues = extractSlotValues(slots, EBXML_DOCENTRY_CREATION_TIME_TO);
|
---|
230 | if((slotValues != null) && (!slotValues.isEmpty()))
|
---|
231 | {
|
---|
232 | creationTimeTo = parseCreationDate(slotValues.get(0));
|
---|
233 | }
|
---|
234 | return creationTimeTo;
|
---|
235 | }
|
---|
236 |
|
---|
237 | private Date extractServiceStartTimeFrom(List<SlotType1> slots)
|
---|
238 | {
|
---|
239 | Date serviceStartTimeFrom = null;
|
---|
240 | List<String> slotValues = extractSlotValues(slots, EBXML_DOCENTRY_SERVICE_START_TIME_FROM);
|
---|
241 | if((slotValues != null) && (!slotValues.isEmpty()))
|
---|
242 | {
|
---|
243 | serviceStartTimeFrom = parseCreationDate(slotValues.get(0));
|
---|
244 | }
|
---|
245 | return serviceStartTimeFrom;
|
---|
246 | }
|
---|
247 |
|
---|
248 | private Date extractServiceStartTimeTo(List<SlotType1> slots)
|
---|
249 | {
|
---|
250 | Date serviceStartTimeTo = null;
|
---|
251 | List<String> slotValues = extractSlotValues(slots, EBXML_DOCENTRY_SERVICE_START_TIME_TO);
|
---|
252 | if((slotValues != null) && (!slotValues.isEmpty()))
|
---|
253 | {
|
---|
254 | serviceStartTimeTo = parseCreationDate(slotValues.get(0));
|
---|
255 | }
|
---|
256 | return serviceStartTimeTo;
|
---|
257 | }
|
---|
258 |
|
---|
259 | private Date extractServiceStopTimeFrom(List<SlotType1> slots)
|
---|
260 | {
|
---|
261 | Date serviceStopTimeFrom = null;
|
---|
262 | List<String> slotValues = extractSlotValues(slots, EBXML_DOCENTRY_SERVICE_STOP_TIME_FROM);
|
---|
263 | if((slotValues != null) && (!slotValues.isEmpty()))
|
---|
264 | {
|
---|
265 | serviceStopTimeFrom = parseCreationDate(slotValues.get(0));
|
---|
266 | }
|
---|
267 | return serviceStopTimeFrom;
|
---|
268 | }
|
---|
269 |
|
---|
270 | private Date extractServiceStopTimeTo(List<SlotType1> slots)
|
---|
271 | {
|
---|
272 | Date serviceStopTimeTo = null;
|
---|
273 | List<String> slotValues = extractSlotValues(slots, EBXML_DOCENTRY_SERVICE_STOP_TIME_TO);
|
---|
274 | if((slotValues != null) && (!slotValues.isEmpty()))
|
---|
275 | {
|
---|
276 | serviceStopTimeTo = parseCreationDate(slotValues.get(0));
|
---|
277 | }
|
---|
278 | return serviceStopTimeTo;
|
---|
279 | }
|
---|
280 |
|
---|
281 | private List<String> extractStatuses(List<SlotType1> slots)
|
---|
282 | {
|
---|
283 | List<String> statuses = null;
|
---|
284 | List<String> slotValues = extractSlotValues(slots, EBXML_DOCENTRY_STATUS);
|
---|
285 | if((slotValues != null) && (!slotValues.isEmpty()))
|
---|
286 | {
|
---|
287 | statuses = new ArrayList<String>();
|
---|
288 | for(String slotValue : slotValues)
|
---|
289 | {
|
---|
290 | parseParamFormattedString(slotValue, statuses);
|
---|
291 | }
|
---|
292 | }
|
---|
293 | return statuses;
|
---|
294 | }
|
---|
295 |
|
---|
296 | /**
|
---|
297 | * Extract the document ID from the slots, if it exists and put it into
|
---|
298 | * the array.
|
---|
299 | *
|
---|
300 | * @param slots The slots to be searched.
|
---|
301 | * @return The document ID in a list if it is found.
|
---|
302 | */
|
---|
303 | private List<String> extractDocumentId(List<SlotType1> slots)
|
---|
304 | {
|
---|
305 | List<String> documentIds = null;
|
---|
306 | List<String> slotValues = extractSlotValues(slots, NHINC_CUSTOM_DOCUMENT_ID);
|
---|
307 | if((slotValues != null) && (!slotValues.isEmpty()))
|
---|
308 | {
|
---|
309 | // We should only have one - so use the first one.
|
---|
310 | //-------------------------------------------------
|
---|
311 | documentIds = new ArrayList<String>();
|
---|
312 | documentIds.add(slotValues.get(0).trim());
|
---|
313 | }
|
---|
314 | return documentIds;
|
---|
315 | }
|
---|
316 |
|
---|
317 | /**
|
---|
318 | * Extract the repository ID from the slots
|
---|
319 | *
|
---|
320 | * @param slots The slots to be searched.
|
---|
321 | * @return The repository Id.
|
---|
322 | */
|
---|
323 | private String extractRepositoryId(List<SlotType1> slots)
|
---|
324 | {
|
---|
325 | String repositoryId = null;
|
---|
326 | List<String> slotValues = extractSlotValues(slots, NHINC_CUSTOM_REPOSITORY_ID);
|
---|
327 | if((slotValues != null) && (!slotValues.isEmpty()))
|
---|
328 | {
|
---|
329 | // We should only have one - so use the first one.
|
---|
330 | //-------------------------------------------------
|
---|
331 | repositoryId = slotValues.get(0).trim();
|
---|
332 | }
|
---|
333 | return repositoryId;
|
---|
334 | }
|
---|
335 |
|
---|
336 | private void loadResponseMessage(oasis.names.tc.ebxml_regrep.xsd.query._3.AdhocQueryResponse response, List<Document> docs)
|
---|
337 | {
|
---|
338 | response.setStatus(XDS_QUERY_RESPONSE_STATUS_FAILURE);
|
---|
339 | oasis.names.tc.ebxml_regrep.xsd.rim._3.ObjectFactory oRimObjectFactory = new oasis.names.tc.ebxml_regrep.xsd.rim._3.ObjectFactory();
|
---|
340 |
|
---|
341 | RegistryObjectListType regObjList = new RegistryObjectListType();
|
---|
342 | response.setRegistryObjectList(regObjList);
|
---|
343 |
|
---|
344 | // Collect the home community id
|
---|
345 | String homeCommunityId = retrieveHomeCommunityId();
|
---|
346 |
|
---|
347 | if((docs != null) && (!docs.isEmpty()))
|
---|
348 | {
|
---|
349 | List<JAXBElement<? extends IdentifiableType>> olRegObjs = regObjList.getIdentifiable();
|
---|
350 |
|
---|
351 | // Save these so that theyu can be added in later after all of the other items..
|
---|
352 | //------------------------------------------------------------------------------
|
---|
353 | ArrayList<JAXBElement<? extends IdentifiableType>> olObjRef = new ArrayList<JAXBElement<? extends IdentifiableType>>();
|
---|
354 | ArrayList<JAXBElement<? extends IdentifiableType>> olAssoc = new ArrayList<JAXBElement<? extends IdentifiableType>>();
|
---|
355 |
|
---|
356 | for(Document doc : docs)
|
---|
357 | {
|
---|
358 | ExtrinsicObjectType oExtObj = new ExtrinsicObjectType();
|
---|
359 | JAXBElement<? extends IdentifiableType> oJAXBExtObj = oRimObjectFactory.createExtrinsicObject(oExtObj);
|
---|
360 | List<SlotType1> olSlot = oExtObj.getSlot();
|
---|
361 | List<ClassificationType> olClassifications = oExtObj.getClassification();
|
---|
362 | boolean bHaveData = false;
|
---|
363 |
|
---|
364 | oExtObj.setIsOpaque(Boolean.FALSE);
|
---|
365 | oExtObj.setObjectType(XDS_QUERY_RESPONSE_EXTRINSIC_OBJCECT_OBJECT_TYPE);
|
---|
366 |
|
---|
367 | // Generate a UUID for the document
|
---|
368 | UUID oDocumentUUID = UUID.randomUUID();
|
---|
369 | String sDocumentUUID = "urn:uuid:" + oDocumentUUID.toString();
|
---|
370 | oExtObj.setId(sDocumentUUID);
|
---|
371 |
|
---|
372 | //Document Unique ID
|
---|
373 | //------------------
|
---|
374 | String sDocumentId = ""; // need to keep a handle to this to be used later...
|
---|
375 | if(NullChecker.isNotNullish(doc.getDocumentUniqueId()))
|
---|
376 | {
|
---|
377 | sDocumentId = doc.getDocumentUniqueId();
|
---|
378 | ExternalIdentifierType oExtId = new ExternalIdentifierType();
|
---|
379 | oExtId.setId("");
|
---|
380 | oExtObj.getExternalIdentifier().add(oExtId);
|
---|
381 | oExtId.setRegistryObject(sDocumentUUID);
|
---|
382 | oExtId.setValue(sDocumentId);
|
---|
383 | oExtId.setIdentificationScheme(EBXML_RESPONSE_DOCID_IDENTIFICATION_SCHEME);
|
---|
384 | InternationalStringType oName = CreateSingleValueInternationalStringType(EBXML_RESPONSE_DOCID_NAME);
|
---|
385 | oExtId.setName(oName);
|
---|
386 | bHaveData = true;
|
---|
387 | }
|
---|
388 |
|
---|
389 | // Author data
|
---|
390 | boolean bHasAuthorData = false;
|
---|
391 | ClassificationType oClassification = new ClassificationType();
|
---|
392 | oClassification.setId("");
|
---|
393 | oClassification.setClassificationScheme(EBXML_RESPONSE_AUTHOR_CLASS_SCHEME);
|
---|
394 | oClassification.setClassifiedObject(sDocumentUUID);
|
---|
395 | oClassification.setNodeRepresentation("");
|
---|
396 | List<SlotType1> olClassificationSlot = oClassification.getSlot();
|
---|
397 |
|
---|
398 | // AuthorPerson
|
---|
399 | //-------------
|
---|
400 | if(NullChecker.isNotNullish(doc.getAuthorPerson()))
|
---|
401 | {
|
---|
402 | SlotType1 oSlot = CreateSingleValueSlot(EBXML_RESPONSE_AUTHOR_PERSON_SLOTNAME,
|
---|
403 | doc.getAuthorPerson());
|
---|
404 | olClassificationSlot.add(oSlot);
|
---|
405 | bHasAuthorData = true;
|
---|
406 | }
|
---|
407 | // AuthorInstitution
|
---|
408 | //------------------
|
---|
409 | if(NullChecker.isNotNullish(doc.getAuthorInstitution()))
|
---|
410 | {
|
---|
411 | SlotType1 oSlot = CreateSingleValueSlot(EBXML_RESPONSE_AUTHOR_INSTITUTION_SLOTNAME,
|
---|
412 | doc.getAuthorInstitution());
|
---|
413 | olClassificationSlot.add(oSlot);
|
---|
414 | bHasAuthorData = true;
|
---|
415 | }
|
---|
416 |
|
---|
417 | // AuthorRole
|
---|
418 | //------------
|
---|
419 | if(NullChecker.isNotNullish(doc.getAuthorRole()))
|
---|
420 | {
|
---|
421 | SlotType1 oSlot = CreateSingleValueSlot(EBXML_RESPONSE_AUTHOR_ROLE_SLOTNAME,
|
---|
422 | doc.getAuthorRole());
|
---|
423 | olClassificationSlot.add(oSlot);
|
---|
424 | bHasAuthorData = true;
|
---|
425 | }
|
---|
426 |
|
---|
427 | // AuthorSpecialty
|
---|
428 | //----------------
|
---|
429 | if(NullChecker.isNotNullish(doc.getAuthorSpecialty()))
|
---|
430 | {
|
---|
431 | SlotType1 oSlot = CreateSingleValueSlot(EBXML_RESPONSE_AUTHOR_SPECIALTY_SLOTNAME,
|
---|
432 | doc.getAuthorSpecialty());
|
---|
433 | olClassificationSlot.add(oSlot);
|
---|
434 | bHasAuthorData = true;
|
---|
435 | }
|
---|
436 |
|
---|
437 | if (bHasAuthorData)
|
---|
438 | {
|
---|
439 | olClassifications.add(oClassification);
|
---|
440 | bHaveData = true;
|
---|
441 | }
|
---|
442 |
|
---|
443 | // Availability Status
|
---|
444 | //---------------------
|
---|
445 | if(NullChecker.isNotNullish(doc.getAvailablityStatus()))
|
---|
446 | {
|
---|
447 | oExtObj.setStatus(doc.getAvailablityStatus());
|
---|
448 | bHaveData = true;
|
---|
449 | }
|
---|
450 |
|
---|
451 | // Class Code
|
---|
452 | //------------
|
---|
453 | ClassificationType classCodeClassification = createClassificationFromCodedData(doc.getClassCode(), doc.getClassCodeScheme(), doc.getClassCodeDisplayName(),
|
---|
454 | EBXML_RESPONSE_CLASSCODE_CLASS_SCHEME,
|
---|
455 | sDocumentUUID);
|
---|
456 | if (classCodeClassification != null)
|
---|
457 | {
|
---|
458 | olClassifications.add(classCodeClassification);
|
---|
459 | bHaveData = true;
|
---|
460 | }
|
---|
461 |
|
---|
462 | // Comments
|
---|
463 | //---------
|
---|
464 | if(NullChecker.isNotNullish(doc.getComments()))
|
---|
465 | {
|
---|
466 | InternationalStringType oComments = CreateSingleValueInternationalStringType(doc.getComments());
|
---|
467 | oExtObj.setDescription(oComments);
|
---|
468 | bHaveData = true;
|
---|
469 | }
|
---|
470 |
|
---|
471 | // Confidentiality Code
|
---|
472 | //---------------------
|
---|
473 | ClassificationType confidentialityCodeClassification = createClassificationFromCodedData(doc.getConfidentialityCode(), doc.getConfidentialityCodeScheme(), doc.getConfidentialityCodeDisplayName(),
|
---|
474 | EBXML_RESPONSE_CONFIDENTIALITYCODE_CLASS_SCHEME,
|
---|
475 | sDocumentUUID);
|
---|
476 | if (confidentialityCodeClassification != null)
|
---|
477 | {
|
---|
478 | olClassifications.add(confidentialityCodeClassification);
|
---|
479 | bHaveData = true;
|
---|
480 | }
|
---|
481 |
|
---|
482 | // Creation Time
|
---|
483 | //--------------
|
---|
484 | if(doc.getCreationTime() != null)
|
---|
485 | {
|
---|
486 | SlotType1 oSlot = CreateSingleValueSlot(EBXML_RESPONSE_CREATIONTIME_SLOTNAME,
|
---|
487 | formatCreationDate(doc.getCreationTime()));
|
---|
488 | olSlot.add(oSlot);
|
---|
489 | bHaveData = true;
|
---|
490 | }
|
---|
491 |
|
---|
492 | // Event Code List
|
---|
493 | //----------------
|
---|
494 | if((doc.getEventCodes() != null) && (!doc.getEventCodes().isEmpty()))
|
---|
495 | {
|
---|
496 | for(EventCode eventCode : doc.getEventCodes())
|
---|
497 | {
|
---|
498 | ClassificationType eventCodeClassification = createClassificationFromCodedData(eventCode.getEventCode(), eventCode.getEventCodeScheme(), eventCode.getEventCodeDisplayName(),
|
---|
499 | EBXML_RESPONSE_EVENTCODE_CLASS_SCHEME,
|
---|
500 | sDocumentUUID);
|
---|
501 | if (eventCodeClassification != null)
|
---|
502 | {
|
---|
503 | olClassifications.add(eventCodeClassification);
|
---|
504 | bHaveData = true;
|
---|
505 | }
|
---|
506 | }
|
---|
507 | }
|
---|
508 |
|
---|
509 | // Format Code
|
---|
510 | //-------------
|
---|
511 | ClassificationType formatCodeClassification = createClassificationFromCodedData(doc.getFormatCode(), doc.getFormatCodeScheme(), doc.getFormatCodeDisplayName(),
|
---|
512 | EBXML_RESPONSE_FORMATCODE_CLASS_SCHEME,
|
---|
513 | sDocumentUUID);
|
---|
514 | if (formatCodeClassification != null)
|
---|
515 | {
|
---|
516 | olClassifications.add(formatCodeClassification);
|
---|
517 | bHaveData = true;
|
---|
518 | }
|
---|
519 |
|
---|
520 | // Hash Code
|
---|
521 | //----------
|
---|
522 | if(NullChecker.isNotNullish(doc.getHash()))
|
---|
523 | {
|
---|
524 | SlotType1 oSlot = CreateSingleValueSlot(EBXML_RESPONSE_HASH_SLOTNAME,
|
---|
525 | doc.getHash());
|
---|
526 | olSlot.add(oSlot);
|
---|
527 | bHaveData = true;
|
---|
528 | }
|
---|
529 |
|
---|
530 | // Healthcare Facility Type Code
|
---|
531 | //------------------------------
|
---|
532 | ClassificationType healthcareFacilityTypeCodeClassification = createClassificationFromCodedData(doc.getFacilityCode(), doc.getFacilityCodeScheme(), doc.getFacilityCodeDisplayName(),
|
---|
533 | EBXML_RESPONSE_HEALTHCAREFACILITYTYPE_CLASS_SCHEME,
|
---|
534 | sDocumentUUID);
|
---|
535 | if (healthcareFacilityTypeCodeClassification != null)
|
---|
536 | {
|
---|
537 | olClassifications.add(healthcareFacilityTypeCodeClassification);
|
---|
538 | bHaveData = true;
|
---|
539 | }
|
---|
540 |
|
---|
541 | // Intended Recipients
|
---|
542 | //--------------------
|
---|
543 | List<String> intendedRecipients = new ArrayList<String>();
|
---|
544 | if(NullChecker.isNotNullish(doc.getIntendedRecipientPerson()))
|
---|
545 | {
|
---|
546 | intendedRecipients.add(doc.getIntendedRecipientPerson());
|
---|
547 | }
|
---|
548 | else if(NullChecker.isNotNullish(doc.getIntendedRecipientOrganization()))
|
---|
549 | {
|
---|
550 | intendedRecipients.add(doc.getIntendedRecipientOrganization());
|
---|
551 | }
|
---|
552 |
|
---|
553 | if(!intendedRecipients.isEmpty())
|
---|
554 | {
|
---|
555 | String[] intendedRecipientArray = intendedRecipients.toArray(new String[intendedRecipients.size()]);
|
---|
556 | SlotType1 oSlot = CreateMultiValueSlot(EBXML_RESPONSE_INTENDEDRECIPIENTS_SLOTNAME, intendedRecipientArray);
|
---|
557 | olSlot.add(oSlot);
|
---|
558 | bHaveData = true;
|
---|
559 | }
|
---|
560 |
|
---|
561 | // Language Code
|
---|
562 | //---------------
|
---|
563 | if(NullChecker.isNotNullish(doc.getLanguageCode()))
|
---|
564 | {
|
---|
565 | SlotType1 oSlot = CreateSingleValueSlot(EBXML_RESPONSE_LANGUAGECODE_SLOTNAME,
|
---|
566 | doc.getLanguageCode());
|
---|
567 | olSlot.add(oSlot);
|
---|
568 | bHaveData = true;
|
---|
569 | }
|
---|
570 |
|
---|
571 | // LegalAuthenticator Code
|
---|
572 | //------------------------
|
---|
573 | if(NullChecker.isNotNullish(doc.getLegalAuthenticator()))
|
---|
574 | {
|
---|
575 | SlotType1 oSlot = CreateSingleValueSlot(EBXML_RESPONSE_LEGALAUTHENTICATOR_SLOTNAME,
|
---|
576 | doc.getLegalAuthenticator());
|
---|
577 | olSlot.add(oSlot);
|
---|
578 | bHaveData = true;
|
---|
579 | }
|
---|
580 |
|
---|
581 | // Mime Type
|
---|
582 | //----------
|
---|
583 | if(NullChecker.isNotNullish(doc.getMimeType()))
|
---|
584 | {
|
---|
585 | oExtObj.setMimeType(doc.getMimeType());
|
---|
586 | bHaveData = true;
|
---|
587 | }
|
---|
588 |
|
---|
589 | // Patient ID
|
---|
590 | //-----------
|
---|
591 | if(NullChecker.isNotNullish(doc.getPatientId()))
|
---|
592 | {
|
---|
593 | String formattedPatientId = PatientIdFormatUtil.hl7EncodePatientId(doc.getPatientId(), homeCommunityId);
|
---|
594 | ExternalIdentifierType oExtId = new ExternalIdentifierType();
|
---|
595 | oExtId.setId("");
|
---|
596 | oExtId.setIdentificationScheme(EBXML_RESPONSE_PATIENTID_IDENTIFICATION_SCHEME);
|
---|
597 | InternationalStringType oPatIdName = CreateSingleValueInternationalStringType(EBXML_RESPONSE_PATIENTID_NAME);
|
---|
598 | oExtId.setName(oPatIdName);
|
---|
599 | oExtId.setRegistryObject(sDocumentUUID);
|
---|
600 | oExtId.setValue(formattedPatientId);
|
---|
601 | oExtObj.getExternalIdentifier().add(oExtId);
|
---|
602 | bHaveData = true;
|
---|
603 | }
|
---|
604 |
|
---|
605 | // Practice Setting Code
|
---|
606 | //----------------------
|
---|
607 | ClassificationType practiceSettingCodeClassification = createClassificationFromCodedData(doc.getPracticeSetting(), doc.getPracticeSettingScheme(), doc.getPracticeSettingDisplayName(),
|
---|
608 | EBXML_RESPONSE_PRACTICESETTING_CLASS_SCHEME,
|
---|
609 | sDocumentUUID);
|
---|
610 | if (practiceSettingCodeClassification != null)
|
---|
611 | {
|
---|
612 | olClassifications.add(practiceSettingCodeClassification);
|
---|
613 | bHaveData = true;
|
---|
614 | }
|
---|
615 |
|
---|
616 | // Service Start Time
|
---|
617 | //-------------------
|
---|
618 | if(doc.getServiceStartTime() != null)
|
---|
619 | {
|
---|
620 | SlotType1 oSlot = CreateSingleValueSlot(EBXML_RESPONSE_SERVICESTARTTIME_SLOTNAME,
|
---|
621 | formatServiceDate(doc.getServiceStartTime()));
|
---|
622 | olSlot.add(oSlot);
|
---|
623 | bHaveData = true;
|
---|
624 | }
|
---|
625 |
|
---|
626 | // Service Stop Time
|
---|
627 | //------------------
|
---|
628 | if(doc.getServiceStopTime() != null)
|
---|
629 | {
|
---|
630 | SlotType1 oSlot = CreateSingleValueSlot(EBXML_RESPONSE_SERVICESTOPTIME_SLOTNAME,
|
---|
631 | formatServiceDate(doc.getServiceStopTime()));
|
---|
632 | olSlot.add(oSlot);
|
---|
633 | bHaveData = true;
|
---|
634 | }
|
---|
635 |
|
---|
636 | // Size
|
---|
637 | //-----
|
---|
638 | if((doc.getSize() != null) && (doc.getSize().intValue() > 0))
|
---|
639 | {
|
---|
640 | SlotType1 oSlot = CreateSingleValueSlot(EBXML_RESPONSE_SIZE_SLOTNAME,
|
---|
641 | doc.getSize().toString());
|
---|
642 | olSlot.add(oSlot);
|
---|
643 | bHaveData = true;
|
---|
644 | }
|
---|
645 |
|
---|
646 | // Source Patient Id
|
---|
647 | //------------------
|
---|
648 | if(NullChecker.isNotNullish(doc.getSourcePatientId()))
|
---|
649 | {
|
---|
650 | SlotType1 oSlot = CreateSingleValueSlot(EBXML_RESPONSE_SOURCEPATIENTID_SLOTNAME,
|
---|
651 | doc.getSourcePatientId());
|
---|
652 | olSlot.add(oSlot);
|
---|
653 | bHaveData = true;
|
---|
654 | }
|
---|
655 |
|
---|
656 | // Source Patient Info
|
---|
657 | //--------------------
|
---|
658 | List<String> sourcePatientInfoValues = new ArrayList<String>();
|
---|
659 | if(NullChecker.isNotNullish(doc.getPid3()))
|
---|
660 | {
|
---|
661 | sourcePatientInfoValues.add("PID-3|" + doc.getPid3());
|
---|
662 | }
|
---|
663 | if(NullChecker.isNotNullish(doc.getPid5()))
|
---|
664 | {
|
---|
665 | sourcePatientInfoValues.add("PID-5|" + doc.getPid5());
|
---|
666 | }
|
---|
667 | if(NullChecker.isNotNullish(doc.getPid7()))
|
---|
668 | {
|
---|
669 | sourcePatientInfoValues.add("PID-7|" + doc.getPid7());
|
---|
670 | }
|
---|
671 | if(NullChecker.isNotNullish(doc.getPid8()))
|
---|
672 | {
|
---|
673 | sourcePatientInfoValues.add("PID-8|" + doc.getPid8());
|
---|
674 | }
|
---|
675 | if(NullChecker.isNotNullish(doc.getPid11()))
|
---|
676 | {
|
---|
677 | sourcePatientInfoValues.add("PID-11|" + doc.getPid11());
|
---|
678 | }
|
---|
679 |
|
---|
680 | if(!sourcePatientInfoValues.isEmpty())
|
---|
681 | {
|
---|
682 | String[] sourcePatientInfoValuesArray = sourcePatientInfoValues.toArray(new String[sourcePatientInfoValues.size()]);
|
---|
683 | SlotType1 oSlot = CreateMultiValueSlot(EBXML_RESPONSE_SOURCEPATIENTINFO_SLOTNAME,
|
---|
684 | sourcePatientInfoValuesArray);
|
---|
685 | olSlot.add(oSlot);
|
---|
686 | bHaveData = true;
|
---|
687 | }
|
---|
688 |
|
---|
689 | // Title
|
---|
690 | //-------
|
---|
691 | if(NullChecker.isNotNullish(doc.getDocumentTitle()))
|
---|
692 | {
|
---|
693 | InternationalStringType oTitle = CreateSingleValueInternationalStringType(doc.getDocumentTitle());
|
---|
694 | oExtObj.setName(oTitle);
|
---|
695 | bHaveData = true;
|
---|
696 | }
|
---|
697 |
|
---|
698 | // Type Code
|
---|
699 | //----------
|
---|
700 | ClassificationType typeCodeClassification = createClassificationFromCodedData(doc.getTypeCode(), doc.getTypeCodeScheme(), doc.getTypeCodeDisplayName(),
|
---|
701 | EBXML_RESPONSE_TYPECODE_CLASS_SCHEME,
|
---|
702 | sDocumentUUID);
|
---|
703 | if (typeCodeClassification != null)
|
---|
704 | {
|
---|
705 | olClassifications.add(typeCodeClassification);
|
---|
706 | bHaveData = true;
|
---|
707 | }
|
---|
708 |
|
---|
709 | // URI
|
---|
710 | //----
|
---|
711 | if(NullChecker.isNotNullish(doc.getDocumentUri()))
|
---|
712 | {
|
---|
713 | SlotType1 oSlot = null;
|
---|
714 | String documentUri = doc.getDocumentUri();
|
---|
715 | if (documentUri.length() <= EBXML_RESPONSE_URI_LINE_LENGTH)
|
---|
716 | {
|
---|
717 | oSlot = CreateSingleValueSlot(EBXML_RESPONSE_URI_SLOTNAME, documentUri);
|
---|
718 | }
|
---|
719 | else
|
---|
720 | {
|
---|
721 | int iStart = 0;
|
---|
722 | String sURI = documentUri;
|
---|
723 | int iTotalLen = sURI.length();
|
---|
724 | int iIndex = 1;
|
---|
725 | String saURIPart[] = null;
|
---|
726 |
|
---|
727 | if ((iTotalLen % EBXML_RESPONSE_URI_LINE_LENGTH) == 0)
|
---|
728 | {
|
---|
729 | saURIPart = new String[iTotalLen / EBXML_RESPONSE_URI_LINE_LENGTH];
|
---|
730 | }
|
---|
731 | else
|
---|
732 | {
|
---|
733 | saURIPart = new String[iTotalLen / EBXML_RESPONSE_URI_LINE_LENGTH + 1];
|
---|
734 | }
|
---|
735 | while (iStart < iTotalLen)
|
---|
736 | {
|
---|
737 | if ((iStart + EBXML_RESPONSE_URI_LINE_LENGTH) > iTotalLen)
|
---|
738 | {
|
---|
739 | saURIPart[iIndex - 1] = iIndex + "|" + sURI.substring(iStart, iTotalLen);
|
---|
740 | iStart = iTotalLen;
|
---|
741 | }
|
---|
742 | else
|
---|
743 | {
|
---|
744 | saURIPart[iIndex - 1] = iIndex + "|" + sURI.substring(iStart, iStart + EBXML_RESPONSE_URI_LINE_LENGTH);
|
---|
745 | iStart += EBXML_RESPONSE_URI_LINE_LENGTH;
|
---|
746 | }
|
---|
747 | iIndex++;
|
---|
748 | }
|
---|
749 |
|
---|
750 | oSlot = CreateMultiValueSlot(EBXML_RESPONSE_URI_SLOTNAME,
|
---|
751 | saURIPart);
|
---|
752 | } // else
|
---|
753 |
|
---|
754 | if (oSlot != null)
|
---|
755 | {
|
---|
756 | olSlot.add(oSlot);
|
---|
757 | bHaveData = true;
|
---|
758 | }
|
---|
759 | }
|
---|
760 |
|
---|
761 | if(bHaveData)
|
---|
762 | {
|
---|
763 | // Home community ID
|
---|
764 | //------------------
|
---|
765 | oExtObj.setHome(homeCommunityId);
|
---|
766 |
|
---|
767 | // Repository Unique ID
|
---|
768 | //---------------------
|
---|
769 | SlotType1 oSlot = CreateSingleValueSlot(EBXML_RESPONSE_REPOSITORY_UNIQUE_ID_SLOTNAME,
|
---|
770 | REPOSITORY_UNIQUE_ID);
|
---|
771 | olSlot.add(oSlot);
|
---|
772 |
|
---|
773 | olRegObjs.add(oJAXBExtObj);
|
---|
774 |
|
---|
775 | }
|
---|
776 | }
|
---|
777 | // if we have any Object References, add them in now.
|
---|
778 | //---------------------------------------------------
|
---|
779 | if (olObjRef.size() > 0)
|
---|
780 | {
|
---|
781 | olRegObjs.addAll(olObjRef);
|
---|
782 | }
|
---|
783 |
|
---|
784 | // if we have any associations, add them in now.
|
---|
785 | //---------------------------------------------------
|
---|
786 | if (olAssoc.size() > 0)
|
---|
787 | {
|
---|
788 | olRegObjs.addAll(olAssoc);
|
---|
789 | }
|
---|
790 |
|
---|
791 | }
|
---|
792 |
|
---|
793 | }
|
---|
794 |
|
---|
795 | /**
|
---|
796 | * This method creates a classification from a coded item.
|
---|
797 | *
|
---|
798 | * @param oCoded The coded to be transformed.
|
---|
799 | * @param sClassificationScheme The classification scheme value.
|
---|
800 | * @param sDocumentId The document ID for the document associated with this classificaation.
|
---|
801 | * @return The classification created based on the information in the coded.
|
---|
802 | */
|
---|
803 | private ClassificationType createClassificationFromCodedData(String code, String codeScheme, String codeDisplayName, String sClassificationScheme, String sDocumentId)
|
---|
804 | {
|
---|
805 | log.debug("DocumentRegistryHelper.CreateClassificationFromCodedData() -- Begin");
|
---|
806 | ClassificationType oClassification = new ClassificationType();
|
---|
807 | oClassification.setId("");
|
---|
808 | boolean bHasCode = false;
|
---|
809 | oClassification.setClassificationScheme(sClassificationScheme);
|
---|
810 | oClassification.setClassifiedObject(sDocumentId);
|
---|
811 | oClassification.setNodeRepresentation("");
|
---|
812 | List<SlotType1> olClassificationSlot = oClassification.getSlot();
|
---|
813 |
|
---|
814 | // Code
|
---|
815 | //-----
|
---|
816 | if (NullChecker.isNotNullish(code))
|
---|
817 | {
|
---|
818 | oClassification.setNodeRepresentation(code);
|
---|
819 | bHasCode = true;
|
---|
820 | }
|
---|
821 |
|
---|
822 | // Code System
|
---|
823 | //------------
|
---|
824 | if (NullChecker.isNotNullish(codeScheme))
|
---|
825 | {
|
---|
826 | SlotType1 oSlot = CreateSingleValueSlot(EBXML_RESPONSE_CODE_CODESCHEME_SLOTNAME,
|
---|
827 | codeScheme);
|
---|
828 | olClassificationSlot.add(oSlot);
|
---|
829 | bHasCode = true;
|
---|
830 | }
|
---|
831 |
|
---|
832 | // DisplayName
|
---|
833 | //------------
|
---|
834 | if (NullChecker.isNotNullish(codeDisplayName))
|
---|
835 | {
|
---|
836 | InternationalStringType oDisplayName = CreateSingleValueInternationalStringType(codeDisplayName);
|
---|
837 | oClassification.setName(oDisplayName);
|
---|
838 | bHasCode = true;
|
---|
839 | }
|
---|
840 |
|
---|
841 | if (bHasCode)
|
---|
842 | {
|
---|
843 | return oClassification;
|
---|
844 | }
|
---|
845 | else
|
---|
846 | {
|
---|
847 | log.debug("DocumentRegistryHelper.CreateClassificationFromCodedData() -- End");
|
---|
848 | return null;
|
---|
849 | }
|
---|
850 | }
|
---|
851 | private String retrieveHomeCommunityId()
|
---|
852 | {
|
---|
853 | String homeCommunityId = null;
|
---|
854 | try
|
---|
855 | {
|
---|
856 | homeCommunityId = "urn:oid:" + PropertyAccessor.getProperty(PROPERTY_FILE_NAME_GATEWAY, PROPERTY_FILE_KEY_HOME_COMMUNITY);
|
---|
857 | }
|
---|
858 | catch(Throwable t)
|
---|
859 | {
|
---|
860 | log.error("Error retrieving the home community id: " + t.getMessage(), t);
|
---|
861 | }
|
---|
862 | return homeCommunityId;
|
---|
863 | }
|
---|
864 |
|
---|
865 | private List<String> extractSlotValues(List<SlotType1> slots, String slotName)
|
---|
866 | {
|
---|
867 | List<String> returnValues = null;
|
---|
868 | for(SlotType1 slot : slots)
|
---|
869 | {
|
---|
870 | if ((slot.getName() != null) &&
|
---|
871 | (slot.getName().length() > 0) &&
|
---|
872 | (slot.getValueList() != null) &&
|
---|
873 | (slot.getValueList().getValue() != null) &&
|
---|
874 | (slot.getValueList().getValue().size() > 0))
|
---|
875 | {
|
---|
876 |
|
---|
877 | if(slot.getName().equals(slotName))
|
---|
878 | {
|
---|
879 | ValueListType valueListType = slot.getValueList();
|
---|
880 | List<String> slotValues = valueListType.getValue();
|
---|
881 | returnValues = new ArrayList<String>();
|
---|
882 | for(String slotValue : slotValues)
|
---|
883 | {
|
---|
884 | returnValues.add(slotValue);
|
---|
885 | }
|
---|
886 | }
|
---|
887 | }
|
---|
888 |
|
---|
889 | }
|
---|
890 | return returnValues;
|
---|
891 | }
|
---|
892 |
|
---|
893 | public void parseParamFormattedString(String paramFormattedString, List<String> resultCollection)
|
---|
894 | {
|
---|
895 | if((paramFormattedString != null) && (resultCollection != null))
|
---|
896 | {
|
---|
897 | if(paramFormattedString.startsWith("("))
|
---|
898 | {
|
---|
899 | String working = paramFormattedString.substring(1);
|
---|
900 | int endIndex = working.indexOf(")");
|
---|
901 | if(endIndex != -1)
|
---|
902 | {
|
---|
903 | working = working.substring(0, endIndex);
|
---|
904 | }
|
---|
905 | String[] multiValueString = working.split(",");
|
---|
906 | if(multiValueString != null)
|
---|
907 | {
|
---|
908 | for(int i = 0; i < multiValueString.length; i++)
|
---|
909 | {
|
---|
910 | String singleValue = multiValueString[i];
|
---|
911 | if(singleValue != null)
|
---|
912 | {
|
---|
913 | singleValue = singleValue.trim();
|
---|
914 | }
|
---|
915 | if(singleValue.startsWith("'"))
|
---|
916 | {
|
---|
917 | singleValue = singleValue.substring(1);
|
---|
918 | int endTickIndex = singleValue.indexOf("'");
|
---|
919 | if(endTickIndex != -1)
|
---|
920 | {
|
---|
921 | singleValue = singleValue.substring(0, endTickIndex);
|
---|
922 | }
|
---|
923 | }
|
---|
924 | resultCollection.add(singleValue);
|
---|
925 | if(log.isDebugEnabled())
|
---|
926 | {
|
---|
927 | log.debug("Added single value: " + singleValue + " to query parameters");
|
---|
928 | }
|
---|
929 | }
|
---|
930 | }
|
---|
931 | }
|
---|
932 | else
|
---|
933 | {
|
---|
934 | resultCollection.add(paramFormattedString);
|
---|
935 | if(log.isDebugEnabled())
|
---|
936 | {
|
---|
937 | log.debug("No wrapper on status - adding status: " + paramFormattedString + " to query parameters");
|
---|
938 | }
|
---|
939 | }
|
---|
940 | }
|
---|
941 | }
|
---|
942 |
|
---|
943 | protected Date parseCreationDate(String dateString)
|
---|
944 | {
|
---|
945 | return parseDate(dateString, DATE_FORMAT_FULL);
|
---|
946 | }
|
---|
947 |
|
---|
948 | protected Date parseServiceDate(String dateString)
|
---|
949 | {
|
---|
950 | return parseDate(dateString, DATE_FORMAT_FULL);
|
---|
951 | }
|
---|
952 |
|
---|
953 | private Date parseDate(String dateString, String dateFormat)
|
---|
954 | {
|
---|
955 | Date parsed = null;
|
---|
956 | if ((dateString != null) && (dateFormat != null))
|
---|
957 | {
|
---|
958 | try
|
---|
959 | {
|
---|
960 | String formatString = DocumentLoadUtil.prepareDateFormatString(dateFormat, dateString);
|
---|
961 | parsed = new SimpleDateFormat(formatString).parse(dateString);
|
---|
962 | }
|
---|
963 | catch (Throwable t)
|
---|
964 | {
|
---|
965 | log.warn("Error parsing '" + dateString + "' using format: '" + dateFormat + "'", t);
|
---|
966 | }
|
---|
967 | }
|
---|
968 | return parsed;
|
---|
969 | }
|
---|
970 |
|
---|
971 | protected String formatCreationDate(Date sourceDate)
|
---|
972 | {
|
---|
973 | return formatDate(sourceDate, DATE_FORMAT_CREATION);
|
---|
974 | }
|
---|
975 |
|
---|
976 | protected String formatServiceDate(Date sourceDate)
|
---|
977 | {
|
---|
978 | return formatDate(sourceDate, DATE_FORMAT_SERVICE);
|
---|
979 | }
|
---|
980 |
|
---|
981 | private String formatDate(Date sourceDate, String formatString)
|
---|
982 | {
|
---|
983 | String formatted = "";
|
---|
984 | if ((sourceDate != null) && (formatString != null))
|
---|
985 | {
|
---|
986 | try
|
---|
987 | {
|
---|
988 | formatted = new SimpleDateFormat(formatString).format(sourceDate);
|
---|
989 | }
|
---|
990 | catch (Throwable t)
|
---|
991 | {
|
---|
992 | log.warn("Failed to format a date (" + sourceDate.toString() + ") to a formatted string using the format '" + formatString + "': " + t.getMessage(), t);
|
---|
993 | }
|
---|
994 | }
|
---|
995 | return formatted;
|
---|
996 | }
|
---|
997 |
|
---|
998 | /**
|
---|
999 | * This method creates a Slot containing a single value.
|
---|
1000 | *
|
---|
1001 | * @param sSlotName The name of the slot.
|
---|
1002 | * @param sSlotValue The value for the slot.
|
---|
1003 | * @return The SlotType1 object containing the data passed in.
|
---|
1004 | */
|
---|
1005 | private SlotType1 CreateSingleValueSlot(String sSlotName, String sSlotValue)
|
---|
1006 | {
|
---|
1007 | log.debug("DocumentRegistryHelper.CreateSingleValueSlot() -- Begin");
|
---|
1008 | String saSlotValue[] = new String[1];
|
---|
1009 | saSlotValue[0] = sSlotValue;
|
---|
1010 | log.debug("DocumentRegistryHelper.CreateSingleValueSlot() -- End");
|
---|
1011 | return CreateMultiValueSlot(sSlotName, saSlotValue);
|
---|
1012 | }
|
---|
1013 |
|
---|
1014 | /**
|
---|
1015 | * This method creates a Slot containing a single value.
|
---|
1016 | *
|
---|
1017 | * @param sSlotName The name of the slot.
|
---|
1018 | * @param saSlotValue The array of values for the slot.
|
---|
1019 | * @return The SlotType1 object containing the data passed in.
|
---|
1020 | */
|
---|
1021 | private SlotType1 CreateMultiValueSlot(String sSlotName, String[] saSlotValue)
|
---|
1022 | {
|
---|
1023 | log.debug("DocumentRegistryHelper.CreateMultiValueSlot() -- Begin");
|
---|
1024 | SlotType1 oSlot = new SlotType1();
|
---|
1025 | oSlot.setName(sSlotName);
|
---|
1026 | ValueListType oValueList = new ValueListType();
|
---|
1027 | oSlot.setValueList(oValueList);
|
---|
1028 | List<String> olValue = oValueList.getValue();
|
---|
1029 | for (int i = 0; i < saSlotValue.length; i++)
|
---|
1030 | {
|
---|
1031 | olValue.add(saSlotValue[i]);
|
---|
1032 | }
|
---|
1033 | log.debug("DocumentRegistryHelper.CreateMultiValueSlot() -- End");
|
---|
1034 | return oSlot;
|
---|
1035 | }
|
---|
1036 |
|
---|
1037 | /**
|
---|
1038 | * This method creates an InternationalStringType with a single value.
|
---|
1039 | *
|
---|
1040 | * @param sLocStrValue The value to be placed in the string.
|
---|
1041 | * @return The InternationStringType that is being returned.
|
---|
1042 | */
|
---|
1043 | private InternationalStringType CreateSingleValueInternationalStringType(String sLocStrValue)
|
---|
1044 | {
|
---|
1045 | log.debug("DocumentTransforms.CreateSingleValueInternationalStringType() -- Begin");
|
---|
1046 | InternationalStringType oName = new InternationalStringType();
|
---|
1047 | List<LocalizedStringType> olLocStr = oName.getLocalizedString();
|
---|
1048 | LocalizedStringType oNameLocStr = new LocalizedStringType();
|
---|
1049 | olLocStr.add(oNameLocStr);
|
---|
1050 | oNameLocStr.setValue(sLocStrValue);
|
---|
1051 | log.debug("DocumentTransforms.CreateSingleValueInternationalStringType() -- End");
|
---|
1052 | return oName;
|
---|
1053 | }
|
---|
1054 |
|
---|
1055 | }
|
---|