SpiritAdapterImpl implements SpiritAdapter { @Override public PatientDto updatePatientByLocId(PatientDto patientDto) throws SpiritAdapterException { logger.info("updatePatientByLocId: START"); String patientId = null; String xdsId = null; List<EhrPatientClientDto> pClientDtos = null; String stateId = login(); EhrPatientClientListDto ehrPatientClientListDto = queryPatientsWithPids( patientDto.getLocalPatientId(), stateId); pClientDtos = ehrPatientClientListDto.getEhrPatientClientListDto(); EhrPatientClientDto ehrPatientClientDto = getC2SPClientDto(pClientDtos); if (null == pClientDtos) { logger.debug("Updating a C2S Patient that is not available in HIE with c2s local identifier."); throw new SpiritAdapterException( "Updating a C2S Patient that is not available in HIE for C2S domain."); } else { EhrPatientRq patientRequest = createEhrPatientRq(patientDto, stateId, false, pClientDtos.get(0)); logger.info("updatePatientByLocId: Looking for: " + patientDto); EhrPatientRsp patientResponse = null; try { patientResponse = webService.updatePatient(patientRequest); logger.debug("updatePatient: Updated patient: " + patientResponse.getResponseData().get(0) .getFamilyName() + " / " + patientResponse.getResponseData().get(0) .getGivenName()); patientId = getC2SPatientId(patientResponse); xdsId = getXDSPatientId(patientResponse); } catch (EhrException_Exception e) { logger.error("updatePatient: FAILED", e.getMessage()); throw new SpiritAdapterException(e.getMessage()); } catch (Exception e) { logger.error("updatePatient: FAILED", e.getMessage()); throw new SpiritAdapterException(e.getClass().toString() +" "+ e.getMessage()); } logger.info("updatePatientByLocId: SUCCESS"); } patientDto.setLocalPatientId(patientId); patientDto.setPatientId(xdsId); logout(stateId); return patientDto; } SpiritAdapterImpl(String endpointUrl, String org, String pwd,
			String rol, String user, String domainId, String c2sDomainId,
			String c2sDomainType, String c2sEnvType);  SpiritAdapterImpl(String endpointUrl, String org, String pwd,
			String rol, String user, String domainId, String c2sDomainId,
			String c2sDomainType, String c2sEnvType,
			SpiritEhrWsClientRqRspInterface webService); @Override SpiritUserResponse usrOrgRoleLogin(); @Override String login(); @Override void logout(String stateId); @Override PatientDto createPatientByPDQ(PatientDto patientDto); @Override PatientDto updatePatientByLocId(PatientDto patientDto); @Override XdsSrcSubmitRsp submitSignedConsent(byte[] xacmlPolicy,
			byte[] signedConsentPdf, byte[] pdfConsentFromXacml,
			byte[] pdfConsentToXacml, String xacmlPolicyId, String patientId,
			String country); @Override EhrPatientClientListDto queryPatientsWithPids(String patientId,
			String stateId); EhrPatientRsp insertPatient(EhrPatientRq arg0); @Override XdsSrcSubmitRsp submitDocument(EhrPatientClientDto submitForPatient,
			SourceSubmissionClientDto sourceSubmission, Boolean withFolder,
			String stateId); @Override XdsSrcSubmitRsp submitDocument(EhrPatientClientDto submitForPatient,
			SourceSubmissionClientDto sourceSubmission, Boolean withFolder); @Override EhrXdsQRsp queryPatientContent(EhrPatientClientDto patient,
			String stateId); @Override EhrXdsRetrRsp retrieveDocument(DocumentClientDto wantedDocument); @Override EhrPatientClientDto updateDocument(
			XdsSrcUpdateReq xdsSrcUpdateRequest); @Override SourceSubmissionClientDto generatePolicyMetadata(String document); @Override DocumentClientDto queryDocumentsByUid(String patientId,
			String documentUniqueId, String stateId); @Override XdsSrcSubmitRsp deprecateDocument(String documentUniqueId,
			String patientId, String stateId); @Override XdsSrcSubmitRsp deprecateDocuments(
			List<String> documentUniqueIdList, String patientId, String stateId); @Override XdsSrcSubmitRsp deprecateDocuments(
			List<String> documentUniqueIdList, EhrPatientClientDto patient,
			PatientContentClientDto patientContentClientDto, String stateId); @Override String deleteDocuments(FolderClientDto folder,
			List<DocumentClientDto> documentList, EhrPatientClientDto patient,
			String stateId); @Override XdsSrcSubmitRsp deleteDocument(FolderClientDto folder,
			DocumentClientDto document, EhrPatientClientDto patient,
			String stateId); @Override XdsSrcSubmitRsp deprecatePolicy(String documentUniqueId,
			String patientId, byte[] revokedPdfConsent); XdsSrcSubmitRsp appendDocument(EhrPatientClientDto patient,
			DocumentClientDto oldDocument, DocumentClientDto documentToAppend,
			String stateId); @Override EhrPolicySubmitRsp submitPolicy(byte[] policy); @Override EhrPolicySubmitRsp submitPolicies(List<byte[]> policyList); @Override EhrPolicySubmitOrUpdateRsp submitOrUpdatePolicy(byte[] policy,
			String stateId); @Override EhrPolicySubmitOrUpdateRsp submitOrUpdatePolicies(
			List<byte[]> policyList, String stateId); @Override EhrPolicyUpdateRsp updatePolicy(byte[] policy); @Override EhrPolicyUpdateRsp updatePolicies(List<byte[]> policyList); @Override byte[] retrievePolicy(String policyId); @Override List<byte[]> retrievePolicies(List<String> listPolicySetIds,
			List<String> listPolicyIds); @Override EhrPolicyDiscardRsp discardPolicy(String policyId, String stateId); @Override EhrPolicyDiscardRsp discardPolicies(List<String> listPolicySetIds,
			List<String> listPolicyIds, String stateId); EhrPapCfgRsp loadPapConfiguration(); @Override XdsSrcSubmitRsp submitC32(byte[] c32file); @Override SourceSubmissionClientDto generateC32Metadata(String document);  }
@Test public void testUpdatePatientIdByLocalId() throws SpiritAdapterException, EhrException_Exception { SpiritUserResponse spiritUserResponse = mock(SpiritUserResponse.class); when(webService.usrLogin(any(SpiritSimpleLoginRequest.class))) .thenReturn(spiritUserResponse); when(spiritUserResponse.getStateID()).thenReturn("stateID"); PatientDto patientDto = mock(PatientDto.class); when(patientDto.getBirthDate()).thenReturn("19070707"); List<EhrPatientClientDto> ehrPatientClientDtos = new LinkedList<EhrPatientClientDto>(); EhrPatientClientDto ehrPatientClientDto = mock(EhrPatientClientDto.class); ehrPatientClientDtos.add(ehrPatientClientDto); EhrPatientRsp patientResponse = mock(EhrPatientRsp.class); when(webService.queryPatients(any(EhrPatientRq.class))).thenReturn( patientResponse); when(patientResponse.getResponseData()) .thenReturn(ehrPatientClientDtos); EhrPatientRsp patientResponse2 = mock(EhrPatientRsp.class); when(webService.updatePatient(any(EhrPatientRq.class))).thenReturn( patientResponse2); when(patientResponse2.getResponseData()).thenReturn( ehrPatientClientDtos); when(patientResponse2.getResponseData().get(0).getFamilyName()) .thenReturn("albert"); when(patientResponse2.getResponseData().get(0).getGivenName()) .thenReturn("smith"); EhrPatientClientDto ehrDto = mock(EhrPatientClientDto.class); when( sHelper.convertFromPatientDto(any(PatientDto.class), anyBoolean(), any(EhrPatientClientDto.class))) .thenReturn(ehrDto); sat.updatePatientByLocId(patientDto); }
@SuppressWarnings("unchecked") @Test(expected = SpiritAdapterException.class) public void testUpdatePatientIdByPDQ_throw_exceptions() throws SpiritAdapterException, EhrException_Exception { SpiritUserResponse spiritUserResponse = mock(SpiritUserResponse.class); when(webService.usrLogin(any(SpiritSimpleLoginRequest.class))) .thenReturn(spiritUserResponse); when(spiritUserResponse.getStateID()).thenReturn("stateID"); PatientDto patientDto = mock(PatientDto.class); when(patientDto.getBirthDate()).thenReturn("19070707"); List<EhrPatientClientDto> ehrPatientClientDtos = new LinkedList<EhrPatientClientDto>(); EhrPatientClientDto ehrPatientClientDto = mock(EhrPatientClientDto.class); ehrPatientClientDtos.add(ehrPatientClientDto); EhrPatientRsp patientResponse = mock(EhrPatientRsp.class); when(webService.queryPatients(any(EhrPatientRq.class))).thenReturn( patientResponse); when(patientResponse.getResponseData()) .thenReturn(ehrPatientClientDtos); EhrPatientRsp patientResponse2 = mock(EhrPatientRsp.class); when(webService.updatePatient(any(EhrPatientRq.class))).thenThrow( EhrException_Exception.class); when(patientResponse2.getResponseData()).thenReturn( ehrPatientClientDtos); when(patientResponse2.getResponseData().get(0).getFamilyName()) .thenReturn("albert"); when(patientResponse2.getResponseData().get(0).getGivenName()) .thenReturn("smith"); EhrPatientClientDto ehrDto = mock(EhrPatientClientDto.class); when( sHelper.convertFromPatientDto(any(PatientDto.class), anyBoolean(), any(EhrPatientClientDto.class))) .thenReturn(ehrDto); sat.updatePatientByLocId(patientDto); }
@SuppressWarnings("unchecked") @Test(expected = SpiritAdapterException.class) public void testUpdatePatientIdByPDQ_2() throws SpiritAdapterException, EhrException_Exception { SpiritUserResponse spiritUserResponse = mock(SpiritUserResponse.class); when(webService.usrLogin(any(SpiritSimpleLoginRequest.class))) .thenReturn(spiritUserResponse); when(spiritUserResponse.getStateID()).thenReturn("stateID"); PatientDto patientDto = mock(PatientDto.class); when(patientDto.getBirthDate()).thenReturn("19070707"); List<EhrPatientClientDto> ehrPatientClientDtos = new LinkedList<EhrPatientClientDto>(); EhrPatientClientDto ehrPatientClientDto = mock(EhrPatientClientDto.class); ehrPatientClientDtos.add(ehrPatientClientDto); EhrPatientRsp patientResponse = mock(EhrPatientRsp.class); when(webService.queryPatients(any(EhrPatientRq.class))).thenReturn( patientResponse); when(patientResponse.getResponseData()).thenReturn(null); EhrPatientRsp patientResponse2 = mock(EhrPatientRsp.class); when(webService.updatePatient(any(EhrPatientRq.class))).thenThrow( EhrException_Exception.class); when(patientResponse2.getResponseData()).thenReturn( ehrPatientClientDtos); when(patientResponse2.getResponseData().get(0).getFamilyName()) .thenReturn("albert"); when(patientResponse2.getResponseData().get(0).getGivenName()) .thenReturn("smith"); EhrPatientClientDto ehrDto = mock(EhrPatientClientDto.class); when( sHelper.convertFromPatientDto(any(PatientDto.class), anyBoolean(), any(EhrPatientClientDto.class))) .thenReturn(ehrDto); sat.updatePatientByLocId(patientDto); }