1 | /*
|
---|
2 | * To change this template, choose Tools | Templates
|
---|
3 | * and open the template in the editor.
|
---|
4 | */
|
---|
5 | package gov.hhs.fha.nhinc.patientcorrelationservice.parsers.PRPAIN201309UV;
|
---|
6 |
|
---|
7 | import gov.hhs.fha.nhinc.patientcorrelationservice.parsers.helpers.CDHelper;
|
---|
8 | import gov.hhs.fha.nhinc.patientcorrelationservice.parsers.helpers.CSHelper;
|
---|
9 | import gov.hhs.fha.nhinc.patientcorrelationservice.parsers.helpers.Configuration;
|
---|
10 | import gov.hhs.fha.nhinc.patientcorrelationservice.parsers.helpers.Constants;
|
---|
11 | import gov.hhs.fha.nhinc.patientcorrelationservice.parsers.helpers.CreationTimeHelper;
|
---|
12 | import gov.hhs.fha.nhinc.patientcorrelationservice.parsers.helpers.IIHelper;
|
---|
13 | import gov.hhs.fha.nhinc.patientcorrelationservice.parsers.helpers.InteractionIdHelper;
|
---|
14 | import gov.hhs.fha.nhinc.patientcorrelationservice.parsers.helpers.SenderReceiverHelperMCCIMT000100UV01;
|
---|
15 | import gov.hhs.fha.nhinc.patientcorrelationservice.parsers.helpers.SenderReceiverHelperMCCIMT000300UV01;
|
---|
16 | import gov.hhs.fha.nhinc.patientcorrelationservice.parsers.helpers.UniqueIdHelper;
|
---|
17 | import java.util.List;
|
---|
18 | import org.hl7.v3.*;
|
---|
19 | import javax.xml.bind.JAXBElement;
|
---|
20 | import org.apache.commons.logging.Log;
|
---|
21 | import org.apache.commons.logging.LogFactory;
|
---|
22 |
|
---|
23 | /**
|
---|
24 | *
|
---|
25 | * @author rayj
|
---|
26 | */
|
---|
27 | public class PixRetrieveResponseBuilder {
|
---|
28 |
|
---|
29 | private static Log log = LogFactory.getLog(PixRetrieveResponseBuilder.class);
|
---|
30 | private static String CODE = "CA";
|
---|
31 | private static String MoodCode = "EVN";
|
---|
32 | private static String ControlActProcessCode = "PRPA_TE201310UV";
|
---|
33 | private static String SubjectTypeCode = "SUBJ";
|
---|
34 | private static String StatusCodeValue = "active";
|
---|
35 | private static String PatientClassCode = "PAT";
|
---|
36 | private static String PATIENTPERSON_CLASSCODE = "PSN";
|
---|
37 | private static String QUERY_RESPONSE = "OK";
|
---|
38 | private static final String AcceptAckCodeValue = "AL";
|
---|
39 | private static final String InteractionIdExtension = "PRPA_IN201310";
|
---|
40 | private static final String ProcessingCodeValue = "P";
|
---|
41 | private static final String ProcessingModeCode = "T";
|
---|
42 | private static final String ITSVersion = "XML_1.0";
|
---|
43 |
|
---|
44 | public static PRPAIN201310UV createPixRetrieveResponse(PRPAIN201309UV retrievePatientCorrelationsRequest, List<II> resultListII) {
|
---|
45 | PRPAIN201310UV message = createTransmissionWrapper(IIHelper.IIFactory(Configuration.getMyCommunityId(), null), IIHelper.IIFactoryCreateNull());
|
---|
46 | message.getAcknowledgement().add(createAck());
|
---|
47 | message.setControlActProcess(createControlActProcess(resultListII, retrievePatientCorrelationsRequest));
|
---|
48 | return message;
|
---|
49 | }
|
---|
50 |
|
---|
51 | private static MFMIMT700711UV01QueryAck createQueryAck(PRPAIN201310UVMFMIMT700711UV01Subject2 subject1) {
|
---|
52 |
|
---|
53 | MFMIMT700711UV01QueryAck queryAck = new MFMIMT700711UV01QueryAck();
|
---|
54 | queryAck.setQueryId(subject1.getQueryByParameter().getQueryId());
|
---|
55 | queryAck.setQueryResponseCode(CSHelper.buildCS(QUERY_RESPONSE));
|
---|
56 |
|
---|
57 | return queryAck;
|
---|
58 | }
|
---|
59 |
|
---|
60 | private static PRPAIN201310UVMFMIMT700711UV01RegistrationEvent createRegistrationEvent(List<II> patientIds, PRPAIN201309UV originalRetrievePatientCorrelationsRequest) {
|
---|
61 |
|
---|
62 | PRPAIN201310UVMFMIMT700711UV01RegistrationEvent registrationEvent = new PRPAIN201310UVMFMIMT700711UV01RegistrationEvent();
|
---|
63 | registrationEvent.getId().add(IIHelper.IIFactoryCreateNull());
|
---|
64 | registrationEvent.setStatusCode(CSHelper.buildCS(StatusCodeValue));
|
---|
65 | PRPAIN201310UVMFMIMT700711UV01Subject2 subject1 = createSubject1(patientIds, originalRetrievePatientCorrelationsRequest);
|
---|
66 |
|
---|
67 | registrationEvent.setSubject1(subject1);
|
---|
68 |
|
---|
69 | registrationEvent.setCustodian(createCustodian());
|
---|
70 | return registrationEvent;
|
---|
71 | }
|
---|
72 |
|
---|
73 | private static PRPAIN201310UVMFMIMT700711UV01Subject1 createSubject(List<II> patientIds, PRPAIN201309UV originalRetrievePatientCorrelationsRequest) {
|
---|
74 |
|
---|
75 | PRPAIN201310UVMFMIMT700711UV01Subject1 subject = new PRPAIN201310UVMFMIMT700711UV01Subject1();
|
---|
76 | subject.getTypeCode().add(SubjectTypeCode);
|
---|
77 | PRPAIN201310UVMFMIMT700711UV01RegistrationEvent registrationEvent = createRegistrationEvent(patientIds, originalRetrievePatientCorrelationsRequest);
|
---|
78 |
|
---|
79 | subject.setRegistrationEvent(registrationEvent);
|
---|
80 |
|
---|
81 |
|
---|
82 | return subject;
|
---|
83 | }
|
---|
84 |
|
---|
85 | private static PRPAIN201310UVMFMIMT700711UV01Subject2 createSubject1(List<II> patientIds, PRPAIN201309UV originalRetrievePatientCorrelationsRequest) {
|
---|
86 |
|
---|
87 | PRPAIN201310UVMFMIMT700711UV01Subject2 subject1 = new PRPAIN201310UVMFMIMT700711UV01Subject2();
|
---|
88 | PRPAMT201304UVPatient patient = createPatient(patientIds);
|
---|
89 | subject1.setPatient(patient);
|
---|
90 |
|
---|
91 | //TODO: add provider organization
|
---|
92 |
|
---|
93 | PRPAMT201307UVQueryByParameter queryByParameter = PRPAIN201309UVParser.ExtractQueryId(originalRetrievePatientCorrelationsRequest);
|
---|
94 | subject1.setQueryByParameter(queryByParameter);
|
---|
95 |
|
---|
96 | return subject1;
|
---|
97 | }
|
---|
98 |
|
---|
99 | private static MCCIMT000300UV01Acknowledgement createAck() {
|
---|
100 | MCCIMT000300UV01Acknowledgement ack = new MCCIMT000300UV01Acknowledgement();
|
---|
101 | ack.setTypeCode(CSHelper.buildCS(CODE));
|
---|
102 | return ack;
|
---|
103 | }
|
---|
104 |
|
---|
105 | private static PRPAIN201310UVMFMIMT700711UV01ControlActProcess createControlActProcess(List<II> patientIds, PRPAIN201309UV originalRetrievePatientCorrelationsRequest) {
|
---|
106 | PRPAIN201310UVMFMIMT700711UV01ControlActProcess controlActProcess = new PRPAIN201310UVMFMIMT700711UV01ControlActProcess();
|
---|
107 | controlActProcess.setMoodCode(MoodCode);
|
---|
108 | controlActProcess.setCode(CDHelper.CDFactory(ControlActProcessCode, Constants.HL7_OID));
|
---|
109 |
|
---|
110 | PRPAIN201310UVMFMIMT700711UV01Subject1 subject = createSubject(patientIds, originalRetrievePatientCorrelationsRequest);
|
---|
111 | controlActProcess.getSubject().add(subject);
|
---|
112 |
|
---|
113 | controlActProcess.setQueryAck(createQueryAck(subject.getRegistrationEvent().getSubject1()));
|
---|
114 |
|
---|
115 | return controlActProcess;
|
---|
116 | }
|
---|
117 |
|
---|
118 | private static MFMIMT700711UV01Custodian createCustodian() {
|
---|
119 |
|
---|
120 | MFMIMT700711UV01Custodian custodian = new MFMIMT700711UV01Custodian();
|
---|
121 | COCTMT090003UVAssignedEntity assignedEntity = new COCTMT090003UVAssignedEntity();
|
---|
122 | assignedEntity.getId().add(IIHelper.IIFactoryCreateNull());
|
---|
123 | custodian.setAssignedEntity(assignedEntity);
|
---|
124 | return custodian;
|
---|
125 | }
|
---|
126 |
|
---|
127 | private static PRPAMT201304UVPatient createPatient(List<II> patientIds) {
|
---|
128 | PRPAMT201304UVPatient patient = new PRPAMT201304UVPatient();
|
---|
129 | patient.setClassCode(PatientClassCode);
|
---|
130 | for (II patientId : patientIds) {
|
---|
131 | patient.getId().add(patientId);
|
---|
132 | }
|
---|
133 |
|
---|
134 | patient.setStatusCode(CSHelper.buildCS(StatusCodeValue));
|
---|
135 |
|
---|
136 | PRPAMT201304UVPerson patientPerson = new PRPAMT201304UVPerson();
|
---|
137 | // create patient person element
|
---|
138 | javax.xml.namespace.QName xmlqname = new javax.xml.namespace.QName("urn:hl7-org:v3", "patientPerson");
|
---|
139 | JAXBElement<PRPAMT201304UVPerson> patientPersonElement = new JAXBElement<PRPAMT201304UVPerson>(xmlqname, PRPAMT201304UVPerson.class, patientPerson);
|
---|
140 | patient.setPatientPerson(patientPersonElement);
|
---|
141 | patientPerson.setClassCode(PATIENTPERSON_CLASSCODE);
|
---|
142 |
|
---|
143 | patientPerson.setDeterminerCode("INSTANCE");
|
---|
144 |
|
---|
145 | PNExplicit patientName = new PNExplicit();
|
---|
146 | patientName.getNullFlavor().add("NA");
|
---|
147 | patientPerson.getName().add(patientName);
|
---|
148 | return patient;
|
---|
149 | }
|
---|
150 |
|
---|
151 | private static PRPAIN201310UV createTransmissionWrapper(II senderId, II receiverId) {
|
---|
152 | PRPAIN201310UV message = new PRPAIN201310UV();
|
---|
153 |
|
---|
154 | message.setITSVersion(ITSVersion);
|
---|
155 | message.setId(UniqueIdHelper.createUniqueId());
|
---|
156 | message.setCreationTime(CreationTimeHelper.getCreationTime());
|
---|
157 | message.setInteractionId(InteractionIdHelper.createInteractionId(InteractionIdExtension));
|
---|
158 |
|
---|
159 | message.setProcessingCode(CSHelper.buildCS(ProcessingCodeValue));
|
---|
160 | message.setProcessingModeCode(CSHelper.buildCS(ProcessingModeCode));
|
---|
161 | message.setAcceptAckCode(CSHelper.buildCS(AcceptAckCodeValue));
|
---|
162 |
|
---|
163 | message.getReceiver().add(SenderReceiverHelperMCCIMT000300UV01.CreateReceiver(receiverId));
|
---|
164 | message.setSender(SenderReceiverHelperMCCIMT000300UV01.CreateSender(senderId));
|
---|
165 |
|
---|
166 | return message;
|
---|
167 | }
|
---|
168 | }
|
---|