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.impl;
|
---|
6 |
|
---|
7 | import java.util.ArrayList;
|
---|
8 | import java.util.List;
|
---|
9 | import javax.xml.bind.JAXBElement;
|
---|
10 | import org.hl7.v3.CD;
|
---|
11 | import org.hl7.v3.CS;
|
---|
12 | import org.hl7.v3.II;
|
---|
13 | import org.hl7.v3.MCCIIN000002UV01;
|
---|
14 | import org.hl7.v3.PRPAIN201301UV;
|
---|
15 | import org.hl7.v3.PRPAIN201301UVMFMIMT700701UV01ControlActProcess;
|
---|
16 | import org.hl7.v3.PRPAIN201301UVMFMIMT700701UV01RegistrationEvent;
|
---|
17 | import org.hl7.v3.PRPAIN201301UVMFMIMT700701UV01Subject1;
|
---|
18 | import org.hl7.v3.PRPAIN201301UVMFMIMT700701UV01Subject2;
|
---|
19 | import org.hl7.v3.PRPAIN201309UV;
|
---|
20 | import org.hl7.v3.PRPAIN201309UVQUQIMT021001UV01ControlActProcess;
|
---|
21 | import org.hl7.v3.PRPAMT201307UVParameterList;
|
---|
22 | import org.hl7.v3.PRPAMT201307UVPatientIdentifier;
|
---|
23 | import org.hl7.v3.PRPAMT201307UVQueryByParameter;
|
---|
24 | import org.hl7.v3.QUQIMT021001UV01AuthorOrPerformer;
|
---|
25 | import org.hl7.v3.PRPAIN201310UV;
|
---|
26 | import org.hl7.v3.PRPAMT201301UVPatient;
|
---|
27 | import org.hl7.v3.XParticipationAuthorPerformer;
|
---|
28 | import org.junit.After;
|
---|
29 | import org.junit.AfterClass;
|
---|
30 | import org.junit.Before;
|
---|
31 | import org.junit.BeforeClass;
|
---|
32 | import org.junit.Test;
|
---|
33 | import static org.junit.Assert.*;
|
---|
34 | import org.hl7.v3.*;
|
---|
35 |
|
---|
36 | /**
|
---|
37 | *
|
---|
38 | * @author svalluripalli
|
---|
39 | */
|
---|
40 | public class PatientCorrelationServiceImplTest {
|
---|
41 |
|
---|
42 | private static org.apache.commons.logging.Log log = org.apache.commons.logging.LogFactory.getLog(PatientCorrelationServiceImplTest.class);
|
---|
43 |
|
---|
44 | public PatientCorrelationServiceImplTest() {
|
---|
45 | }
|
---|
46 |
|
---|
47 | @BeforeClass
|
---|
48 | public static void setUpClass() throws Exception {
|
---|
49 | }
|
---|
50 |
|
---|
51 | @AfterClass
|
---|
52 | public static void tearDownClass() throws Exception {
|
---|
53 | }
|
---|
54 |
|
---|
55 | @Before
|
---|
56 | public void setUp() {
|
---|
57 | RemoveExistingCorrelations();
|
---|
58 | }
|
---|
59 |
|
---|
60 | @After
|
---|
61 | public void tearDown() {
|
---|
62 | }
|
---|
63 |
|
---|
64 | private PRPAIN201309UV createRetrieveMessage(II correlation) {
|
---|
65 | PRPAIN201309UV requestMessage = new PRPAIN201309UV();
|
---|
66 | II interactionId = new II();
|
---|
67 | interactionId.setExtension("PRPA_IN201309");
|
---|
68 | requestMessage.setInteractionId(interactionId);
|
---|
69 | PRPAIN201309UVQUQIMT021001UV01ControlActProcess cntlAccess = new PRPAIN201309UVQUQIMT021001UV01ControlActProcess();
|
---|
70 | requestMessage.setControlActProcess(cntlAccess);
|
---|
71 | cntlAccess.setMoodCode("RQO");
|
---|
72 | CD code = new CD();
|
---|
73 | code.setCode("PRPA_TE201309UV");
|
---|
74 | code.setCodeSystem("2.16.840.1.113883.1.6");
|
---|
75 | cntlAccess.setCode(code);
|
---|
76 | QUQIMT021001UV01AuthorOrPerformer authPerformer = new QUQIMT021001UV01AuthorOrPerformer();
|
---|
77 | authPerformer.setTypeCode(XParticipationAuthorPerformer.AUT);
|
---|
78 | cntlAccess.getAuthorOrPerformer().add(authPerformer);
|
---|
79 | PRPAMT201307UVQueryByParameter qParam = new PRPAMT201307UVQueryByParameter();
|
---|
80 | CS csValue = new CS();
|
---|
81 | csValue.setCode("new");
|
---|
82 | qParam.setStatusCode(csValue);
|
---|
83 | CS resValue = new CS();
|
---|
84 | resValue.setCode("I");
|
---|
85 | qParam.setResponsePriorityCode(csValue);
|
---|
86 | PRPAMT201307UVParameterList paramsList = new PRPAMT201307UVParameterList();
|
---|
87 | PRPAMT201307UVPatientIdentifier patId = new PRPAMT201307UVPatientIdentifier();
|
---|
88 | patId.getValue().add(correlation);
|
---|
89 | paramsList.getPatientIdentifier().add(patId);
|
---|
90 | qParam.setParameterList(paramsList);
|
---|
91 | javax.xml.namespace.QName xmlqname = new javax.xml.namespace.QName("urn:hl7-org:v3", "PRPAMT201307UVQueryByParameter");
|
---|
92 | JAXBElement<PRPAMT201307UVQueryByParameter> qP = new JAXBElement<PRPAMT201307UVQueryByParameter>(xmlqname, PRPAMT201307UVQueryByParameter.class, qParam);
|
---|
93 | cntlAccess.setQueryByParameter(qP);
|
---|
94 | return requestMessage;
|
---|
95 | }
|
---|
96 |
|
---|
97 | private PRPAIN201301UV createAddRequestMessage(II corr1, II corr2) {
|
---|
98 | PRPAIN201301UV addRequest = new PRPAIN201301UV();
|
---|
99 | II interactionId = new II();
|
---|
100 | interactionId.setExtension("PRPA_IN201301UV");
|
---|
101 | addRequest.setInteractionId(interactionId);
|
---|
102 | PRPAIN201301UVMFMIMT700701UV01ControlActProcess cntrlAccess = new PRPAIN201301UVMFMIMT700701UV01ControlActProcess();
|
---|
103 | addRequest.setControlActProcess(cntrlAccess);
|
---|
104 | cntrlAccess.setMoodCode("EVN");
|
---|
105 |
|
---|
106 | PRPAIN201301UVMFMIMT700701UV01Subject1 subj = new PRPAIN201301UVMFMIMT700701UV01Subject1();
|
---|
107 | cntrlAccess.getSubject().add(subj);
|
---|
108 | subj.getTypeCode().add("SUBJ");
|
---|
109 | PRPAIN201301UVMFMIMT700701UV01RegistrationEvent regEvent = new PRPAIN201301UVMFMIMT700701UV01RegistrationEvent();
|
---|
110 | subj.setRegistrationEvent(regEvent);
|
---|
111 | CS csValue = new CS();
|
---|
112 | csValue.setCode("active");
|
---|
113 | regEvent.setStatusCode(csValue);
|
---|
114 | PRPAIN201301UVMFMIMT700701UV01Subject2 subj1 = new PRPAIN201301UVMFMIMT700701UV01Subject2();
|
---|
115 | regEvent.setSubject1(subj1);
|
---|
116 | PRPAMT201301UVPatient pat = new PRPAMT201301UVPatient();
|
---|
117 | subj1.setPatient(pat);
|
---|
118 | pat.setClassCode("PAT");
|
---|
119 | pat.getId().add(corr1);
|
---|
120 | pat.getId().add(corr2);
|
---|
121 |
|
---|
122 | return addRequest;
|
---|
123 | }
|
---|
124 |
|
---|
125 | private List<II> extractIdsFromRetrieveResult(PRPAIN201310UV retrieveResult) {
|
---|
126 | return retrieveResult.getControlActProcess().getSubject().get(0).getRegistrationEvent().getSubject1().getPatient().getId();
|
---|
127 | }
|
---|
128 |
|
---|
129 | private boolean isIdInList(List<II> list, II id) {
|
---|
130 | boolean found = false;
|
---|
131 |
|
---|
132 | if (id != null) {
|
---|
133 | for (II idInList : list) {
|
---|
134 | if (areEqual(id, idInList)) {
|
---|
135 | found = true;
|
---|
136 | break;
|
---|
137 | }
|
---|
138 | }
|
---|
139 | }
|
---|
140 |
|
---|
141 | return found;
|
---|
142 | }
|
---|
143 |
|
---|
144 | private boolean areEqual(II a, II b) {
|
---|
145 | return ((a.getExtension().equals(b.getExtension())) && (a.getRoot().equals(b.getRoot())));
|
---|
146 | }
|
---|
147 |
|
---|
148 | private II IIFactory(String root, String extension) {
|
---|
149 | II id = new II();
|
---|
150 | id.setRoot(root);
|
---|
151 | id.setExtension(extension);
|
---|
152 | return id;
|
---|
153 | }
|
---|
154 |
|
---|
155 | private void RemoveExistingCorrelations() {
|
---|
156 | log.info("RemoveExistingCorrelations is not yet implemented, therefore test is not fully conclusive");
|
---|
157 | //todo - determine method for removing existing correlations
|
---|
158 | }
|
---|
159 |
|
---|
160 | @Test
|
---|
161 | public void testSimpleAddRetrieveCorrelation() {
|
---|
162 | log.debug("begin testSimpleAddRetrieveCorrelation");
|
---|
163 | II corr1 = IIFactory("AA1", "MRN-1");
|
---|
164 | II corr2 = IIFactory("AA2", "MRN-2");
|
---|
165 |
|
---|
166 | //clear db
|
---|
167 | //create message
|
---|
168 | PRPAIN201301UV addRequest = createAddRequestMessage(corr1, corr2);
|
---|
169 |
|
---|
170 | //send
|
---|
171 | AddPatientCorrelationRequestType addPatientCorrelationRequest = new AddPatientCorrelationRequestType();
|
---|
172 | addPatientCorrelationRequest.setPRPAIN201301UV(addRequest);
|
---|
173 | PatientCorrelationServiceImpl.addPatientCorrelation(addPatientCorrelationRequest);
|
---|
174 |
|
---|
175 | //build retrieve
|
---|
176 | PRPAIN201309UV retrieveRequest = createRetrieveMessage(corr1);
|
---|
177 | RetrievePatientCorrelationsRequestType retrievePatientCorrelationsRequest = new RetrievePatientCorrelationsRequestType();
|
---|
178 | retrievePatientCorrelationsRequest.setPRPAIN201309UV(retrieveRequest);
|
---|
179 | RetrievePatientCorrelationsResponseType retrievePatientCorrelationsResponse = PatientCorrelationServiceImpl.retrievePatientCorrelations(retrievePatientCorrelationsRequest);
|
---|
180 | PRPAIN201310UV retrieveResult = retrievePatientCorrelationsResponse.getPRPAIN201310UV();
|
---|
181 | List<II> resultsIds = extractIdsFromRetrieveResult(retrieveResult);
|
---|
182 | assertTrue(isIdInList(resultsIds, corr2));
|
---|
183 |
|
---|
184 | retrieveRequest = createRetrieveMessage(corr2);
|
---|
185 | retrievePatientCorrelationsRequest = new RetrievePatientCorrelationsRequestType();
|
---|
186 | retrievePatientCorrelationsRequest.setPRPAIN201309UV(retrieveRequest);
|
---|
187 | retrievePatientCorrelationsResponse = PatientCorrelationServiceImpl.retrievePatientCorrelations(retrievePatientCorrelationsRequest);
|
---|
188 | retrieveResult = retrievePatientCorrelationsResponse.getPRPAIN201310UV();
|
---|
189 | resultsIds = extractIdsFromRetrieveResult(retrieveResult);
|
---|
190 | assertTrue(isIdInList(resultsIds, corr1));
|
---|
191 | }
|
---|
192 |
|
---|
193 | @Test
|
---|
194 | public void testRetrieveDoesNotReturnInputId() {
|
---|
195 | log.debug("begin testRetrieveDoesNotReturnInputId");
|
---|
196 |
|
---|
197 | II corr1 = IIFactory("MRN-1", "AA1");
|
---|
198 | II corr2 = IIFactory("MRN-2", "AA2");
|
---|
199 |
|
---|
200 | //clear db
|
---|
201 | //create message
|
---|
202 | PRPAIN201301UV addRequest = createAddRequestMessage(corr1, corr2);
|
---|
203 | AddPatientCorrelationRequestType addReq = new AddPatientCorrelationRequestType();
|
---|
204 | addReq.setPRPAIN201301UV(addRequest);
|
---|
205 | //send
|
---|
206 | PatientCorrelationServiceImpl.addPatientCorrelation(addReq);
|
---|
207 |
|
---|
208 | //build retrieve
|
---|
209 | PRPAIN201309UV retrieveRequest = createRetrieveMessage(corr1);
|
---|
210 | RetrievePatientCorrelationsRequestType retrRequest = new RetrievePatientCorrelationsRequestType();
|
---|
211 | retrRequest.setPRPAIN201309UV(retrieveRequest);
|
---|
212 | PRPAIN201310UV retrieveResult = PatientCorrelationServiceImpl.retrievePatientCorrelations(retrRequest).getPRPAIN201310UV();
|
---|
213 | List<II> resultsIds = extractIdsFromRetrieveResult(retrieveResult);
|
---|
214 | for(II aII : resultsIds)
|
---|
215 | {
|
---|
216 | System.out.println(aII.getExtension()+" <----------------> "+aII.getRoot());
|
---|
217 | }
|
---|
218 | assertFalse(isIdInList(resultsIds, corr1));
|
---|
219 | assertEquals(1, resultsIds.size());
|
---|
220 | }
|
---|
221 | }
|
---|