source: ccr/trunk/nhin-vista/projects/NHINC/Current/Product/Production/Gateway/SubscriptionDteEjb/src/java/gov/hhs/fha/nhinc/subscription/dte/DocumentMetadataHelper.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: 5.3 KB
Line 
1/*
2 * To change this template, choose Tools | Templates
3 * and open the template in the editor.
4 */
5package gov.hhs.fha.nhinc.subscription.dte;
6
7//import gov.hhs.fha.nhinc.NHINCLib.NullChecker;
8//import gov.hhs.fha.nhinc.subscription.*;
9//import gov.hhs.fha.nhinc.subscriptiondte.*;
10//import gov.hhs.fha.nhinc.util.format.PatientIdFormatUtil;
11//import ihe.iti.xds_b._2007.RetrieveDocumentSetRequestType.DocumentRequest;
12//import java.util.List;
13//import java.util.logging.Level;
14//import java.util.logging.Logger;
15//import javax.xml.bind.JAXBElement;
16import gov.hhs.fha.nhinc.common.nhinccommon.QualifiedSubjectIdentifierType;
17import gov.hhs.fha.nhinc.nhinclib.NullChecker;
18import gov.hhs.fha.nhinc.util.format.PatientIdFormatUtil;
19import ihe.iti.xds_b._2007.RetrieveDocumentSetRequestType.DocumentRequest;
20import java.util.List;
21import oasis.names.tc.ebxml_regrep.xsd.rim._3.ClassificationType;
22import oasis.names.tc.ebxml_regrep.xsd.rim._3.ExternalIdentifierType;
23import oasis.names.tc.ebxml_regrep.xsd.rim._3.ExtrinsicObjectType;
24import oasis.names.tc.ebxml_regrep.xsd.rim._3.IdentifiableType;
25import oasis.names.tc.ebxml_regrep.xsd.rim._3.RegistryObjectListType;
26import oasis.names.tc.ebxml_regrep.xsd.rim._3.SlotType1;
27//import org.netbeans.xml.schema.homecommunity.HomeCommunity;
28//import org.netbeans.xml.schema.QualifiedSubjectIdentifierType.QualifiedSubjectIdentifierType;
29/**
30 *
31 * @author rayj
32 */
33public class DocumentMetadataHelper {
34
35 private static org.apache.commons.logging.Log log = org.apache.commons.logging.LogFactory.getLog(DocumentMetadataHelper.class);
36
37 public static ExtrinsicObjectType findMatchingDocumentMetadata(RegistryObjectListType documentMetadatas, DocumentRequest document) {
38 ExtrinsicObjectType matchingDocumentMetadata = null;
39
40 for (int i = 0; i < documentMetadatas.getIdentifiable().size(); i++) {
41 IdentifiableType identifiable = documentMetadatas.getIdentifiable().get(i).getValue();
42 ExtrinsicObjectType documentmetadata = (ExtrinsicObjectType) identifiable;
43 if (areDocumentsMatching(document, documentmetadata)) {
44 matchingDocumentMetadata = documentmetadata;
45 }
46 }
47 return matchingDocumentMetadata;
48 }
49
50 private static boolean areDocumentsMatching(DocumentRequest document, ExtrinsicObjectType documentMetadata) {
51 boolean match = false;
52 String documentMetadataDocumentId = findDocumentId(documentMetadata);
53 String documentMetadataRepositoryId = findRepositoryId(documentMetadata);
54
55 if (((NullChecker.isNotNullish(documentMetadataDocumentId)) && (NullChecker.isNotNullish(documentMetadataRepositoryId))) && ((document.getDocumentUniqueId().contentEquals(documentMetadataDocumentId)) && (document.getRepositoryUniqueId().contentEquals(documentMetadataRepositoryId)))) {
56 match = true;
57 }
58 return match;
59 }
60
61 public static String findDocumentId(ExtrinsicObjectType documentMetadata) {
62 return findExternalIdentifierByIdentificationSchema(documentMetadata, Constants.DocumentIdIdentificationScheme);
63 }
64
65 public static String findRepositoryId(ExtrinsicObjectType documentMetadata) {
66 String repositoryId = null;
67 try {
68 repositoryId = AdhocQueryHelper.findSlotValue(documentMetadata.getSlot(), Constants.RepositoryIdSlotName);
69 } catch (MultipleSlotValuesFoundException ex) {
70 log.error(ex);
71 }
72 return repositoryId;
73 }
74
75 public static QualifiedSubjectIdentifierType getPatient(ExtrinsicObjectType documentMetaData) {
76 QualifiedSubjectIdentifierType patient = new QualifiedSubjectIdentifierType();
77 String formattedPatientId = findExternalIdentifierByIdentificationSchema(documentMetaData, Constants.PatientIdIdentificationScheme);
78 patient.setSubjectIdentifier(PatientIdFormatUtil.parsePatientId(formattedPatientId));
79 patient.setAssigningAuthorityIdentifier(PatientIdFormatUtil.parseCommunityId(formattedPatientId));
80 return patient;
81 }
82
83 public static String findExternalIdentifierByIdentificationSchema(ExtrinsicObjectType documentMetaData, String identificationScheme) {
84 String value = null;
85 List<ExternalIdentifierType> externalIdentifierList = documentMetaData.getExternalIdentifier();
86 for (ExternalIdentifierType externalIdentifier : externalIdentifierList) {
87 if (externalIdentifier.getIdentificationScheme().contentEquals(identificationScheme)) {
88 value = externalIdentifier.getValue();
89 }
90 }
91 return value;
92 }
93
94 public static String findClassificationByClassificationSchema(ExtrinsicObjectType documentMetaData, String classificationScheme) {
95 String value = null;
96 List<ClassificationType> classificationList = documentMetaData.getClassification();
97 for (ClassificationType classification : classificationList) {
98 if (classification.getClassificationScheme().contentEquals(classificationScheme)) {
99 value = classification.getNodeRepresentation();
100 }
101 }
102 return value;
103 }
104
105 public static String getDocumentClassCode(ExtrinsicObjectType documentMetaData) {
106 return findClassificationByClassificationSchema(documentMetaData, Constants.DocumentClassCodeClassificationScheme);
107 }
108}
Note: See TracBrowser for help on using the repository browser.