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 com.sun.org.apache.bcel.internal.classfile.ConstantString;
|
---|
8 | import gov.hhs.fha.nhinc.common.nhinccommon.QualifiedSubjectIdentifierType;
|
---|
9 | import gov.hhs.fha.nhinc.common.patientcorrelationfacade.RetrievePatientCorrelationsRequestType;
|
---|
10 | import gov.hhs.fha.nhinc.common.patientcorrelationfacade.dte.helpers.AssigningAuthorityHomeCommunityMappingHelper;
|
---|
11 | import gov.hhs.fha.nhinc.common.patientcorrelationfacade.dte.helpers.CDHelper;
|
---|
12 | import gov.hhs.fha.nhinc.common.patientcorrelationfacade.dte.helpers.CSHelper;
|
---|
13 | import gov.hhs.fha.nhinc.common.patientcorrelationfacade.dte.helpers.Configuration;
|
---|
14 | import gov.hhs.fha.nhinc.common.patientcorrelationfacade.dte.helpers.Constants;
|
---|
15 | import gov.hhs.fha.nhinc.common.patientcorrelationfacade.dte.helpers.CreationTimeHelper;
|
---|
16 | import gov.hhs.fha.nhinc.common.patientcorrelationfacade.dte.helpers.IIHelper;
|
---|
17 | import gov.hhs.fha.nhinc.common.patientcorrelationfacade.dte.helpers.InteractionIdHelper;
|
---|
18 | import gov.hhs.fha.nhinc.common.patientcorrelationfacade.dte.helpers.SemanticsTextHelper;
|
---|
19 | import gov.hhs.fha.nhinc.common.patientcorrelationfacade.dte.helpers.UniqueIdHelper;
|
---|
20 | import gov.hhs.fha.nhinc.common.patientcorrelationfacade.dte.helpers.SenderReceiverHelper;
|
---|
21 | import gov.hhs.fha.nhinc.nhinclib.NullChecker;
|
---|
22 | import java.util.List;
|
---|
23 | import org.hl7.v3.*;
|
---|
24 | import java.util.Calendar;
|
---|
25 | import java.text.SimpleDateFormat;
|
---|
26 | import java.util.ArrayList;
|
---|
27 | import java.util.Date;
|
---|
28 | import javax.xml.bind.JAXBElement;
|
---|
29 |
|
---|
30 | /**
|
---|
31 | *
|
---|
32 | * @author rayj
|
---|
33 | */
|
---|
34 | public class PixRetrieveBuilder {
|
---|
35 |
|
---|
36 | public static final String ControlActProcessCode = "PRPA_TE201309UV";
|
---|
37 | private static final String AcceptAckCodeValue = "AL";
|
---|
38 | private static final String InteractionIdExtension = "PRPA_IN201309";
|
---|
39 | private static final String ProcessingCodeValue = "P";
|
---|
40 | private static final String ProcessingModeCode = "T";
|
---|
41 | private static final String ITSVersion = "XML_1.0";
|
---|
42 | private static final String MoodCodeValue = "EVN";
|
---|
43 |
|
---|
44 | public static CreatePixRetrieveResponseType createPixRetrieve(CreatePixRetrieveRequestType createPixRetrieveRequest) {
|
---|
45 | PRPAIN201309UV pixRetrieve = createPixRetrieve(createPixRetrieveRequest.getRetrievePatientCorrelationsRequest());
|
---|
46 | CreatePixRetrieveResponseType response = new CreatePixRetrieveResponseType();
|
---|
47 | response.setPRPAIN201309UV(pixRetrieve);
|
---|
48 | return response;
|
---|
49 | }
|
---|
50 |
|
---|
51 | public static PRPAIN201309UV createPixRetrieve(RetrievePatientCorrelationsRequestType retrievePatientCorrelationsRequest) {
|
---|
52 | List<String> targetAssigningAuthorities = extractTargetAssigningAuthorities(retrievePatientCorrelationsRequest);
|
---|
53 | PRPAIN201309UV pixRetrieve = createTransmissionWrapper(Configuration.getMyCommunityId(), null);
|
---|
54 |
|
---|
55 | PRPAIN201309UVQUQIMT021001UV01ControlActProcess controlActProcess = createBaseControlActProcess();
|
---|
56 |
|
---|
57 | PRPAMT201307UVQueryByParameter queryByParameter = createQueryByParameter(retrievePatientCorrelationsRequest.getQualifiedPatientIdentifier(), targetAssigningAuthorities);
|
---|
58 | JAXBElement<PRPAMT201307UVQueryByParameter> createQueryByParameterElement = createQueryByParameterElement(queryByParameter);
|
---|
59 | controlActProcess.setQueryByParameter(createQueryByParameterElement);
|
---|
60 |
|
---|
61 | pixRetrieve.setControlActProcess(controlActProcess);
|
---|
62 |
|
---|
63 | return pixRetrieve;
|
---|
64 | }
|
---|
65 |
|
---|
66 | private static List<String> extractTargetAssigningAuthorities(RetrievePatientCorrelationsRequestType retrievePatientCorrelationsRequest) {
|
---|
67 | //if assigning authorities are present, use those. If not, convert home community to assigning authority
|
---|
68 | List<String> targetAssigningAuthorities = retrievePatientCorrelationsRequest.getTargetAssigningAuthority();
|
---|
69 |
|
---|
70 | if (NullChecker.isNullish(targetAssigningAuthorities)) {
|
---|
71 | List<String> targetHomeCommunities = retrievePatientCorrelationsRequest.getTargetHomeCommunity();
|
---|
72 | if (NullChecker.isNotNullish(targetHomeCommunities)) {
|
---|
73 | targetAssigningAuthorities = AssigningAuthorityHomeCommunityMappingHelper.lookupAssigningAuthorities(targetHomeCommunities);
|
---|
74 | }
|
---|
75 | }
|
---|
76 |
|
---|
77 | return targetAssigningAuthorities;
|
---|
78 | }
|
---|
79 |
|
---|
80 | private static JAXBElement<COCTMT090100UV01AssignedPerson> createAssignedPersonElement() {
|
---|
81 |
|
---|
82 | COCTMT090100UV01AssignedPerson assignedPerson = new COCTMT090100UV01AssignedPerson();
|
---|
83 | assignedPerson.getId().add(IIHelper.IIFactoryCreateNull());
|
---|
84 |
|
---|
85 | JAXBElement<COCTMT090100UV01AssignedPerson> assignedPersonElement;
|
---|
86 | javax.xml.namespace.QName xmlqname = new javax.xml.namespace.QName("urn:hl7-org:v3", "assignedPerson");
|
---|
87 | assignedPersonElement = new JAXBElement<COCTMT090100UV01AssignedPerson>(xmlqname, COCTMT090100UV01AssignedPerson.class, assignedPerson);
|
---|
88 |
|
---|
89 | return assignedPersonElement;
|
---|
90 | }
|
---|
91 |
|
---|
92 | private static QUQIMT021001UV01AuthorOrPerformer createAuthor() {
|
---|
93 |
|
---|
94 | QUQIMT021001UV01AuthorOrPerformer author = new QUQIMT021001UV01AuthorOrPerformer();
|
---|
95 | XParticipationAuthorPerformer xAuthor = XParticipationAuthorPerformer.AUT;
|
---|
96 | author.setTypeCode(xAuthor);
|
---|
97 | author.setAssignedPerson(createAssignedPersonElement());
|
---|
98 |
|
---|
99 | return author;
|
---|
100 | }
|
---|
101 |
|
---|
102 | private static PRPAMT201307UVParameterList createParameterList(QualifiedSubjectIdentifierType qualifiedSubjectIdentifier, List<String> targetAssigningAuthorities) {
|
---|
103 | PRPAMT201307UVParameterList parameterList = new PRPAMT201307UVParameterList();
|
---|
104 | PRPAMT201307UVPatientIdentifier patId = createPatientIdentifier(qualifiedSubjectIdentifier);
|
---|
105 | parameterList.getPatientIdentifier().add(patId);
|
---|
106 |
|
---|
107 | if (targetAssigningAuthorities != null) {
|
---|
108 | for (String targetAssigningAuthority : targetAssigningAuthorities) {
|
---|
109 | PRPAMT201307UVDataSource dataSourceItem = new PRPAMT201307UVDataSource();
|
---|
110 | II dataSourceValue = new II();
|
---|
111 | dataSourceValue.setRoot(targetAssigningAuthority);
|
---|
112 | dataSourceItem.getValue().add(dataSourceValue);
|
---|
113 | parameterList.getDataSource().add(dataSourceItem);
|
---|
114 | }
|
---|
115 | }
|
---|
116 |
|
---|
117 | return parameterList;
|
---|
118 | }
|
---|
119 |
|
---|
120 | private static PRPAIN201309UV createTransmissionWrapper(String senderId, String receiverId) {
|
---|
121 | PRPAIN201309UV message = new PRPAIN201309UV();
|
---|
122 |
|
---|
123 | message.setITSVersion(ITSVersion);
|
---|
124 | message.setId(UniqueIdHelper.createUniqueId());
|
---|
125 | message.setCreationTime(CreationTimeHelper.getCreationTime());
|
---|
126 | message.setInteractionId(InteractionIdHelper.createInteractionId(InteractionIdExtension));
|
---|
127 |
|
---|
128 | message.setProcessingCode(CSHelper.buildCS(ProcessingCodeValue));
|
---|
129 | message.setProcessingModeCode(CSHelper.buildCS(ProcessingModeCode));
|
---|
130 | message.setAcceptAckCode(CSHelper.buildCS(AcceptAckCodeValue));
|
---|
131 |
|
---|
132 | message.getReceiver().add(SenderReceiverHelper.CreateReceiver(receiverId));
|
---|
133 | message.setSender(SenderReceiverHelper.CreateSender(senderId));
|
---|
134 |
|
---|
135 | return message;
|
---|
136 | }
|
---|
137 |
|
---|
138 | private static PRPAIN201309UVQUQIMT021001UV01ControlActProcess createBaseControlActProcess() {
|
---|
139 | PRPAIN201309UVQUQIMT021001UV01ControlActProcess controlActProcess = new PRPAIN201309UVQUQIMT021001UV01ControlActProcess();
|
---|
140 |
|
---|
141 | controlActProcess.setMoodCode(MoodCodeValue);
|
---|
142 | controlActProcess.setCode(CDHelper.CDFactory(ControlActProcessCode, Constants.HL7_OID));
|
---|
143 | controlActProcess.getAuthorOrPerformer().add(createAuthor());
|
---|
144 |
|
---|
145 | return controlActProcess;
|
---|
146 | }
|
---|
147 |
|
---|
148 | private static PRPAMT201307UVQueryByParameter createQueryByParameter(QualifiedSubjectIdentifierType qualifiedSubjectIdentifier, List<String> targetAssigningAuthorities) {
|
---|
149 | PRPAMT201307UVQueryByParameter queryByParameter = new PRPAMT201307UVQueryByParameter();
|
---|
150 | queryByParameter.setQueryId(UniqueIdHelper.createUniqueId(Configuration.getMyCommunityId()));
|
---|
151 | queryByParameter.setStatusCode(CSHelper.buildCS("new"));
|
---|
152 | queryByParameter.setResponsePriorityCode(CSHelper.buildCS("I"));
|
---|
153 | queryByParameter.setParameterList(createParameterList(qualifiedSubjectIdentifier, targetAssigningAuthorities));
|
---|
154 | return queryByParameter;
|
---|
155 | }
|
---|
156 |
|
---|
157 | private static JAXBElement<PRPAMT201307UVQueryByParameter> createQueryByParameterElement(PRPAMT201307UVQueryByParameter queryByParameter) {
|
---|
158 | JAXBElement<PRPAMT201307UVQueryByParameter> queryByParameterElement;
|
---|
159 | javax.xml.namespace.QName xmlqname = new javax.xml.namespace.QName("urn:hl7-org:v3", "queryByParameter");
|
---|
160 | queryByParameterElement = new JAXBElement<PRPAMT201307UVQueryByParameter>(xmlqname, PRPAMT201307UVQueryByParameter.class, new PRPAMT201307UVQueryByParameter());
|
---|
161 | queryByParameterElement.setValue(queryByParameter);
|
---|
162 | return queryByParameterElement;
|
---|
163 | }
|
---|
164 |
|
---|
165 | private static II getII(String assignAuth, String root, String ext) {
|
---|
166 | II val = new II();
|
---|
167 |
|
---|
168 | val.setAssigningAuthorityName(assignAuth);
|
---|
169 | val.setExtension(ext);
|
---|
170 | val.setRoot(root);
|
---|
171 |
|
---|
172 | return val;
|
---|
173 | }
|
---|
174 |
|
---|
175 | private static PRPAMT201307UVPatientIdentifier createPatientIdentifier(QualifiedSubjectIdentifierType qualifiedSubjectIdentifier) {
|
---|
176 | PRPAMT201307UVPatientIdentifier patientIdentifier = new PRPAMT201307UVPatientIdentifier();
|
---|
177 | patientIdentifier.getValue().add(IIHelper.IIFactory(qualifiedSubjectIdentifier));
|
---|
178 | patientIdentifier.setSemanticsText(SemanticsTextHelper.CreateSemanticsText("Patient.Id"));
|
---|
179 | return patientIdentifier;
|
---|
180 | }
|
---|
181 | }
|
---|