VerifyMode implements ResponseMode { protected II patientExistsLocally(List<II> localPatientIds, AssertionType assertion, PRPAIN201306UV02 response, NhinTargetSystemType target) { II patId = null; PRPAIN201305UV02 mpiQuery; List<II> mpiIds = new ArrayList<>(); mpiQuery = convert201306to201305(response); if (CollectionUtils.isNotEmpty(localPatientIds)) { PRPAIN201306UV02 mpiResult = queryMpi(mpiQuery, assertion, target); if (mpiResult != null) { try { LOG.debug("Received result from mpi."); if (mpiResult.getControlActProcess() != null && NullChecker.isNotNullish(mpiResult.getControlActProcess().getSubject())) { for (PRPAIN201306UV02MFMIMT700711UV01Subject1 subj1 : mpiResult.getControlActProcess() .getSubject()) { if (subj1.getRegistrationEvent() != null && subj1.getRegistrationEvent().getSubject1() != null && subj1.getRegistrationEvent().getSubject1().getPatient() != null && subj1.getRegistrationEvent().getSubject1().getPatient().getId() != null) { mpiIds.add(subj1.getRegistrationEvent().getSubject1().getPatient().getId().get(0)); } } } LOG.debug("mpiIds size: " + mpiIds.size()); requestIdsSearch: for (II id : localPatientIds) { for (II mpiId : mpiIds) { if (compareId(mpiId, id)) { patId = mpiId; break requestIdsSearch; } } } } catch (Exception ex) { LOG.error(ex.getMessage(), ex); patId = null; } } } return patId; } VerifyMode(); @Override PRPAIN201306UV02 processResponse(ResponseParams params); @Override PRPAIN201306UV02 processResponse(PRPAIN201306UV02 response, AssertionType assertion, II localPatientId); PRPAIN201306UV02 processResponse(PRPAIN201305UV02 requestMsg, PRPAIN201306UV02 response,
        AssertionType assertion, NhinTargetSystemType target);  }
@Test public void testPatientExistsLocally() { List<II> localPatientIds = new ArrayList<>(); II patientId = new II(); patientId.setExtension("1234"); patientId.setRoot("1.1.1"); localPatientIds.add(patientId); VerifyMode verifyMode = new VerifyMode() { @Override protected TrustMode getTrustMode() { return mockTrustMode; } @Override protected PRPAIN201305UV02 convert201306to201305(PRPAIN201306UV02 response) { return null; } @Override protected PRPAIN201306UV02 queryMpi(PRPAIN201305UV02 query, AssertionType assertion, NhinTargetSystemType target) { JAXBElement<PRPAMT201301UV02Person> person = HL7PatientTransforms.create201301PatientPerson("Joe", "Smith", "M", null, null); PRPAMT201301UV02Patient patient = HL7PatientTransforms.create201301Patient(person, "1234", "1.1.1"); PRPAIN201305UV02 request = HL7PRPA201305Transforms.createPRPA201305(patient, "1.1", "2.2", "1.1.1"); return HL7PRPA201306Transforms.createPRPA201306(patient, "2.2", "1.1.1", "1.1", "2.2.2", request); } }; context.checking(new Expectations() { { exactly(1).of(mockTrustMode).processResponse(with(any(PRPAIN201306UV02.class)), with(any(AssertionType.class)), with(any(II.class))); } }); II patId = verifyMode.patientExistsLocally(localPatientIds, null, null, null); assertEquals("1234", patId.getExtension()); }