1 | /*
|
---|
2 | * To change this template, choose Tools | Templates
|
---|
3 | * and open the template in the editor.
|
---|
4 | */
|
---|
5 | package gov.hhs.fha.nhinc.common.patientcorrelationfacade.dte;
|
---|
6 |
|
---|
7 | import gov.hhs.fha.nhinc.common.nhinccommon.QualifiedSubjectIdentifierType;
|
---|
8 | import gov.hhs.fha.nhinc.common.patientcorrelationfacade.RemovePatientCorrelationRequestType;
|
---|
9 | import gov.hhs.fha.nhinc.common.patientcorrelationfacade.dte.helpers.CSHelper;
|
---|
10 | import gov.hhs.fha.nhinc.common.patientcorrelationfacade.dte.helpers.Configuration;
|
---|
11 | import gov.hhs.fha.nhinc.common.patientcorrelationfacade.dte.helpers.CreationTimeHelper;
|
---|
12 | import gov.hhs.fha.nhinc.common.patientcorrelationfacade.dte.helpers.IIHelper;
|
---|
13 | import gov.hhs.fha.nhinc.common.patientcorrelationfacade.dte.helpers.InteractionIdHelper;
|
---|
14 | import gov.hhs.fha.nhinc.common.patientcorrelationfacade.dte.helpers.SenderReceiverHelper;
|
---|
15 | import gov.hhs.fha.nhinc.common.patientcorrelationfacade.dte.helpers.UniqueIdHelper;
|
---|
16 | import java.util.List;
|
---|
17 | import javax.xml.bind.JAXBElement;
|
---|
18 | import javax.xml.namespace.QName;
|
---|
19 | import org.hl7.v3.CreatePixRevokeRequestType;
|
---|
20 | import org.hl7.v3.CreatePixRevokeResponseType;
|
---|
21 | import org.hl7.v3.II;
|
---|
22 | import org.hl7.v3.PNExplicit;
|
---|
23 | import org.hl7.v3.PRPAIN201303UV;
|
---|
24 | import org.hl7.v3.PRPAIN201303UVMFMIMT700701UV01ControlActProcess;
|
---|
25 | import org.hl7.v3.PRPAIN201303UVMFMIMT700701UV01RegistrationEvent;
|
---|
26 | import org.hl7.v3.PRPAIN201303UVMFMIMT700701UV01Subject1;
|
---|
27 | import org.hl7.v3.PRPAIN201303UVMFMIMT700701UV01Subject2;
|
---|
28 | import org.hl7.v3.PRPAMT201303UVPerson;
|
---|
29 | import org.hl7.v3.PRPAMT201305UVPatient;
|
---|
30 | import org.hl7.v3.PRPAMT201305UVPerson;
|
---|
31 |
|
---|
32 | /**
|
---|
33 | *
|
---|
34 | * @author jhoppesc
|
---|
35 | */
|
---|
36 | public class PixRevokeBuilder {
|
---|
37 |
|
---|
38 | private static final String AcceptAckCodeValue = "AL";
|
---|
39 | private static final String ITSVersion = "XML_1.0";
|
---|
40 | private static final String InteractionIdExtension = "PRPA_IN201303UV";
|
---|
41 | private static final String MoodCodeValue = "EVN";
|
---|
42 | private static final String PatientClassCode = "PAT";
|
---|
43 | private static final String PatientStatusCode = "active";
|
---|
44 | private static final String ProcessingCodeValue = "T";
|
---|
45 | private static final String ProcessingModeCode = "T";
|
---|
46 | private static final String SubjectTypeCode = "SUBJ";
|
---|
47 | private static org.apache.commons.logging.Log log = org.apache.commons.logging.LogFactory.getLog(PixRevokeBuilder.class);
|
---|
48 |
|
---|
49 | public static CreatePixRevokeResponseType createPixRevoke(CreatePixRevokeRequestType createPixRevokeRequest) {
|
---|
50 | CreatePixRevokeResponseType createPixRevokeResponse = new CreatePixRevokeResponseType();
|
---|
51 | createPixRevokeResponse.setPRPAIN201303UV(createPixRevoke(createPixRevokeRequest.getRemovePatientCorrelationRequest()));
|
---|
52 | return createPixRevokeResponse;
|
---|
53 | }
|
---|
54 |
|
---|
55 | public static PRPAIN201303UV createPixRevoke(RemovePatientCorrelationRequestType revokePatientCorrelationRequest) {
|
---|
56 | log.info("begin createPixAdd");
|
---|
57 | PRPAIN201303UV message = null;
|
---|
58 |
|
---|
59 | List<QualifiedSubjectIdentifierType> qualifiedIds = revokePatientCorrelationRequest.getQualifiedPatientIdentifier();
|
---|
60 | log.info("qualifiedIds is null? -> " + (qualifiedIds == null));
|
---|
61 | log.info("qualifiedIds.size()=" + (qualifiedIds.size()));
|
---|
62 |
|
---|
63 | message = createTransmissionWrapper(Configuration.getMyCommunityId(), null);
|
---|
64 | message.setControlActProcess(buildControlActProcess(qualifiedIds));
|
---|
65 |
|
---|
66 | log.info("end createPixRevoke");
|
---|
67 | return message;
|
---|
68 | }
|
---|
69 |
|
---|
70 | private static PRPAIN201303UV createTransmissionWrapper(String senderId, String receiverId) {
|
---|
71 | PRPAIN201303UV message = new PRPAIN201303UV();
|
---|
72 |
|
---|
73 | message.setITSVersion(ITSVersion);
|
---|
74 | message.setId(UniqueIdHelper.createUniqueId());
|
---|
75 | message.setCreationTime(CreationTimeHelper.getCreationTime());
|
---|
76 | message.setInteractionId(InteractionIdHelper.createInteractionId(InteractionIdExtension));
|
---|
77 |
|
---|
78 | message.setProcessingCode(CSHelper.buildCS(ProcessingCodeValue));
|
---|
79 | message.setProcessingModeCode(CSHelper.buildCS(ProcessingModeCode));
|
---|
80 | message.setAcceptAckCode(CSHelper.buildCS(AcceptAckCodeValue));
|
---|
81 |
|
---|
82 | message.getReceiver().add(SenderReceiverHelper.CreateReceiver(receiverId));
|
---|
83 | message.setSender(SenderReceiverHelper.CreateSender(senderId));
|
---|
84 |
|
---|
85 | return message;
|
---|
86 | }
|
---|
87 |
|
---|
88 | private static PRPAIN201303UVMFMIMT700701UV01ControlActProcess buildControlActProcess(List<QualifiedSubjectIdentifierType> qualifiedIds) {
|
---|
89 | log.info("begin buildControlActProcess");
|
---|
90 |
|
---|
91 | PRPAIN201303UVMFMIMT700701UV01ControlActProcess controlActProcess = new PRPAIN201303UVMFMIMT700701UV01ControlActProcess();
|
---|
92 | controlActProcess.setMoodCode(MoodCodeValue);
|
---|
93 |
|
---|
94 | PRPAIN201303UVMFMIMT700701UV01Subject1 subject = new PRPAIN201303UVMFMIMT700701UV01Subject1();
|
---|
95 | subject.getTypeCode().add(SubjectTypeCode);
|
---|
96 | PRPAIN201303UVMFMIMT700701UV01RegistrationEvent registrationEvent = buildRegistrationEvent(qualifiedIds);
|
---|
97 | subject.setRegistrationEvent(registrationEvent);
|
---|
98 |
|
---|
99 | controlActProcess.getSubject().add(subject);
|
---|
100 |
|
---|
101 | log.info("end buildControlActProcess");
|
---|
102 | log.info("controlActProcess.getSubject().get(0).getRegistrationEvent().getSubject1().getPatient().getId().size()=" + controlActProcess.getSubject().get(0).getRegistrationEvent().getSubject1().getPatient().getId().size());
|
---|
103 |
|
---|
104 | return controlActProcess;
|
---|
105 | }
|
---|
106 |
|
---|
107 | private static PRPAIN201303UVMFMIMT700701UV01RegistrationEvent buildRegistrationEvent(List<QualifiedSubjectIdentifierType> qualifiedIds) {
|
---|
108 | log.info("begin buildRegistrationEvent");
|
---|
109 |
|
---|
110 | PRPAIN201303UVMFMIMT700701UV01RegistrationEvent registrationEvent = new PRPAIN201303UVMFMIMT700701UV01RegistrationEvent();
|
---|
111 | registrationEvent.getId().add(IIHelper.IIFactoryCreateNull());
|
---|
112 | registrationEvent.setStatusCode(CSHelper.buildCS("active"));
|
---|
113 |
|
---|
114 | PRPAIN201303UVMFMIMT700701UV01Subject2 subject1 = new PRPAIN201303UVMFMIMT700701UV01Subject2();
|
---|
115 | PRPAMT201305UVPatient patient = new PRPAMT201305UVPatient();
|
---|
116 | patient.setClassCode(PatientClassCode);
|
---|
117 | patient.setStatusCode(CSHelper.buildCS(PatientStatusCode));
|
---|
118 |
|
---|
119 | log.info("adding qualifiedSubjectIdentifiers");
|
---|
120 | for (QualifiedSubjectIdentifierType qualifiedId : qualifiedIds) {
|
---|
121 | II ii = IIHelper.IIFactory(qualifiedId);
|
---|
122 | patient.getId().add(ii);
|
---|
123 | log.info("adding a qualifiedSubjectIdentifier");
|
---|
124 | }
|
---|
125 | log.info("patient.getId().size()=" + patient.getId().size());
|
---|
126 |
|
---|
127 | log.info("building patientPerson");
|
---|
128 | JAXBElement<PRPAMT201305UVPerson> patientPersonElement;
|
---|
129 | PRPAMT201305UVPerson patientPerson = new PRPAMT201305UVPerson();
|
---|
130 |
|
---|
131 | PNExplicit patientName = new PNExplicit();
|
---|
132 | patientName.getNullFlavor().add("NA");
|
---|
133 | patientPerson.getName().add(patientName);
|
---|
134 |
|
---|
135 | QName xmlqname = new QName("urn:hl7-org:v3", "patientPerson");
|
---|
136 | patientPersonElement = new JAXBElement<PRPAMT201305UVPerson>(xmlqname, PRPAMT201305UVPerson.class, patientPerson);
|
---|
137 |
|
---|
138 | patient.setPatientPerson(patientPersonElement);
|
---|
139 | subject1.setPatient(patient);
|
---|
140 | registrationEvent.setSubject1(subject1);
|
---|
141 |
|
---|
142 | log.info("end buildRegistrationEvent");
|
---|
143 | log.info("registrationEvent.getSubject1().getPatient().getId().size()=" + registrationEvent.getSubject1().getPatient().getId().size());
|
---|
144 |
|
---|
145 | return registrationEvent;
|
---|
146 | }
|
---|
147 | }
|
---|