use of se.inera.intyg.webcert.web.service.intyg.dto.IntygContentHolder in project webcert by sklintyg.
the class AbstractUtkastBuilder method populateCopyUtkastFromSignedIntyg.
/*
* (non-Javadoc)
*
* @see
* se.inera.intyg.webcert.web.service.utkast.CopyUtkastBuilder#populateCopyUtkastFromSignedIntyg(se.inera.intyg.
* webcert.web.service.utkast.dto.CreateNewDraftCopyRequest, se.inera.intyg.webcert.integration.pu.model.Person)
*/
@Override
public CopyUtkastBuilderResponse populateCopyUtkastFromSignedIntyg(T copyRequest, Person patientDetails, boolean addRelation, boolean coherentJournaling, boolean enforceEnhet) throws ModuleNotFoundException, ModuleException {
String orignalIntygsId = copyRequest.getOriginalIntygId();
String originalIntygsTyp = copyRequest.getOriginalIntygTyp();
String intygsTyp = copyRequest.getTyp();
IntygContentHolder signedIntygHolder = intygService.fetchIntygData(orignalIntygsId, originalIntygsTyp, coherentJournaling);
ModuleApi orgModuleApi = moduleRegistry.getModuleApi(originalIntygsTyp);
Utlatande orgUtlatande;
try {
orgUtlatande = orgModuleApi.getUtlatandeFromJson(signedIntygHolder.getContents());
} catch (IOException e) {
throw new ModuleException("Could not convert orignal certificate to Utlatande", e);
}
GrundData grundData = signedIntygHolder.getUtlatande().getGrundData();
se.inera.intyg.common.support.model.common.internal.Vardenhet vardenhet = grundData.getSkapadAv().getVardenhet();
if (coherentJournaling && enforceEnhet) {
verifyEnhetsAuth(vardenhet.getVardgivare().getVardgivarid(), vardenhet.getEnhetsid(), true);
}
LOG.debug("Populating copy with details from signed Intyg '{}'", orignalIntygsId);
CopyUtkastBuilderResponse builderResponse = new CopyUtkastBuilderResponse();
builderResponse.setOrginalEnhetsId(vardenhet.getEnhetsid());
builderResponse.setOrginalEnhetsNamn(vardenhet.getEnhetsnamn());
builderResponse.setOrginalVardgivarId(vardenhet.getVardgivare().getVardgivarid());
builderResponse.setOrginalVardgivarNamn(vardenhet.getVardgivare().getVardgivarnamn());
ModuleApi moduleApi = moduleRegistry.getModuleApi(intygsTyp);
// Set relation to null if not applicable
Relation relation = createRelation(copyRequest);
String newDraftCopyId = intygsIdStrategy.createId();
String draftCopyJson = getInternalModel(orgUtlatande, moduleApi, copyRequest, patientDetails, relation, newDraftCopyId);
UtkastStatus utkastStatus = validateDraft(moduleApi, draftCopyJson);
Utkast utkast = buildUtkastCopy(copyRequest, newDraftCopyId, intygsTyp, addRelation, relation, draftCopyJson, utkastStatus);
if (patientDetails != null) {
populatePatientDetailsFromPerson(utkast, patientDetails);
} else {
se.inera.intyg.common.support.model.common.internal.Patient patient = signedIntygHolder.getUtlatande().getGrundData().getPatient();
populatePatientDetailsFromPatient(utkast, patient);
}
replacePatientPersonnummerWithNew(utkast, copyRequest);
builderResponse.setUtkastCopy(utkast);
return builderResponse;
}
use of se.inera.intyg.webcert.web.service.intyg.dto.IntygContentHolder in project webcert by sklintyg.
the class IntygServiceTest method testFetchIntygDataHasSentAndRevokedStatusesWhenIntygstjanstIsUnavailableAndDraftHadSentDateAndRevokedDate.
@SuppressWarnings("unchecked")
@Test
public void testFetchIntygDataHasSentAndRevokedStatusesWhenIntygstjanstIsUnavailableAndDraftHadSentDateAndRevokedDate() throws Exception {
when(moduleFacade.getCertificate(CERTIFICATE_ID, CERTIFICATE_TYPE)).thenThrow(WebServiceException.class);
when(utkastRepository.findOneByIntygsIdAndIntygsTyp(CERTIFICATE_ID, CERTIFICATE_TYPE)).thenReturn(getIntyg(CERTIFICATE_ID, LocalDateTime.now(), LocalDateTime.now()));
IntygContentHolder intygContentHolder = intygService.fetchIntygData(CERTIFICATE_ID, CERTIFICATE_TYPE, false);
assertEquals(intygContentHolder.getStatuses().size(), 3);
assertEquals(intygContentHolder.getStatuses().get(0).getType(), CertificateState.SENT);
assertEquals(intygContentHolder.getStatuses().get(1).getType(), CertificateState.CANCELLED);
assertEquals(intygContentHolder.getStatuses().get(2).getType(), CertificateState.RECEIVED);
assertNotNull(intygContentHolder.getUtlatande());
// ensure that correct call is made to moduleFacade
verify(moduleFacade).getCertificate(CERTIFICATE_ID, CERTIFICATE_TYPE);
// Assert pdl log
verify(logservice).logReadIntyg(any(LogRequest.class));
}
use of se.inera.intyg.webcert.web.service.intyg.dto.IntygContentHolder in project webcert by sklintyg.
the class IntygServiceTest method testFetchIntygDataWithRelationNotFoundInIT.
@Test
public void testFetchIntygDataWithRelationNotFoundInIT() throws Exception {
when(moduleFacade.getCertificate(any(String.class), any(String.class))).thenThrow(new IntygModuleFacadeException(""));
when(utkastRepository.findOneByIntygsIdAndIntygsTyp(CERTIFICATE_ID, CERTIFICATE_TYPE)).thenReturn(getIntyg(CERTIFICATE_ID, null, null));
IntygContentHolder res = intygService.fetchIntygDataWithRelations(CERTIFICATE_ID, CERTIFICATE_TYPE, false);
assertNotNull(res);
assertNotNull(res.getRelations());
verify(moduleFacade).getCertificate(CERTIFICATE_ID, CERTIFICATE_TYPE);
verify(utkastRepository).findOneByIntygsIdAndIntygsTyp(CERTIFICATE_ID, CERTIFICATE_TYPE);
verify(logservice).logReadIntyg(any(LogRequest.class));
verify(mockMonitoringService).logIntygRead(CERTIFICATE_ID, CERTIFICATE_TYPE);
verify(certificateRelationService).getRelations(eq(CERTIFICATE_ID));
}
use of se.inera.intyg.webcert.web.service.intyg.dto.IntygContentHolder in project webcert by sklintyg.
the class IntygServiceTest method testDeceasedIsSetForDeadPatientDjupintegration.
@Test
public void testDeceasedIsSetForDeadPatientDjupintegration() {
when(webcertUser.getOrigin()).thenReturn(UserOriginType.DJUPINTEGRATION.name());
when(webcertUser.getParameters()).thenReturn(new IntegrationParameters("", "", "", "", "", "", "", "", "", false, true, false, true));
when(patientDetailsResolver.resolvePatient(any(Personnummer.class), anyString())).thenReturn(buildPatient(false, true));
IntygContentHolder intygData = intygService.fetchIntygData(CERTIFICATE_ID, CERTIFICATE_TYPE, false);
assertTrue(intygData.isDeceased());
}
use of se.inera.intyg.webcert.web.service.intyg.dto.IntygContentHolder in project webcert by sklintyg.
the class IntygServiceTest method testThatIncompletePatientAddressIsNotUsed.
@Test
public void testThatIncompletePatientAddressIsNotUsed() throws Exception {
// Given
String postadress = "ttipafpinu-postadress";
String postort = null;
String postnummer = null;
Patient patientWithIncompleteAddress = buildPatient(false, false);
patientWithIncompleteAddress.setPostadress(postadress);
patientWithIncompleteAddress.setPostort(postort);
patientWithIncompleteAddress.setPostnummer(postnummer);
when(patientDetailsResolver.resolvePatient(any(Personnummer.class), anyString())).thenReturn(patientWithIncompleteAddress);
// When
IntygContentHolder intygData = intygService.fetchIntygData(CERTIFICATE_ID, CERTIFICATE_TYPE, false);
// Then
ArgumentCaptor<Patient> argumentCaptor = ArgumentCaptor.forClass(Patient.class);
verify(moduleApi).updateBeforeSave(anyString(), argumentCaptor.capture());
assertNotEquals(postadress, argumentCaptor.getValue().getPostadress());
}
Aggregations