@Test public void testCreateUtkastFromTemplate() throws Exception { final String reference = "ref"; WebCertUser user = new WebCertUser(); user.setParameters(new IntegrationParameters(reference, "", "", "", "", "", "", "", "", false, false, false, true)); when(userService.getUser()).thenReturn(user); UtkastBuilderResponse resp = createCopyUtkastBuilderResponse(); when(createUtkastFromTemplateBuilder.populateCopyUtkastFromSignedIntyg(any(CreateUtkastFromTemplateRequest.class), any(Person.class), any(boolean.class), any(boolean.class))).thenReturn(resp); CreateUtkastFromTemplateRequest copyReq = buildUtkastFromTemplateRequest(); setupMockForGettingUtlatande(true); CreateUtkastFromTemplateResponse utkastCopyResponse = copyService.createUtkastFromSignedTemplate(copyReq); assertNotNull(utkastCopyResponse); assertEquals(INTYG_COPY_ID, utkastCopyResponse.getNewDraftIntygId()); assertEquals(INTYG_TYPE, utkastCopyResponse.getNewDraftIntygType()); assertEquals(INTYG_ID, utkastCopyResponse.getOriginalIntygId()); verify(mockPUService).getPerson(PATIENT_SSN); verify(createUtkastFromTemplateBuilder).populateCopyUtkastFromSignedIntyg(any(CreateUtkastFromTemplateRequest.class), any(Person.class), any(boolean.class), eq(false)); verify(mockUtkastRepository).save(any(Utkast.class)); verify(referensService).saveReferens(eq(INTYG_COPY_ID), eq(reference)); verify(mockNotificationService).sendNotificationForDraftCreated(any(Utkast.class)); verify(certificateEventService) .createCertificateEventFromCopyUtkast(resp.getUtkast(), user.getHsaId(), EventCode.SKAPATFRAN, INTYG_ID); verify(intygService).isRevoked(INTYG_ID, INTYG_TYPE_2, false); }
@Override public CreateUtkastFromTemplateResponse createUtkastFromSignedTemplate(CreateUtkastFromTemplateRequest templateRequest) { String originalIntygId = templateRequest.getOriginalIntygId(); LOG.debug("Creating utkast from template (certificate). Certificate = '{}'", originalIntygId); WebCertUser user = userService.getUser(); boolean coherentJournaling = isCoherentJournaling(user); try { if (intygService.isRevoked(templateRequest.getOriginalIntygId(), templateRequest.getOriginalIntygTyp(), coherentJournaling)) { LOG.debug("Cannot create utkast from template. The certificate is revoked. Certificate id = '{}'", originalIntygId); throw new WebCertServiceException(WebCertServiceErrorCodeEnum.INVALID_STATE, "Original certificate is revoked"); } Person patientDetails = updatePatientDetails(templateRequest, false); draftAccessServiceHelper.validateAllowToCreateUtkast(templateRequest.getTyp(), patientDetails.getPersonnummer()); final Utlatande utlatande = utkastServiceHelper.getUtlatande(templateRequest.getOriginalIntygId(), templateRequest.getOriginalIntygTyp(), false, false); addTestIntygFlagIfNecessaryToCopyRequest(templateRequest, utlatande.getGrundData().isTestIntyg()); verifyNotReplacedWithSigned(templateRequest.getOriginalIntygId(), "create utkast from template"); UtkastBuilderResponse builderResponse = buildUtkastFromSignedTemplateBuilderResponse(templateRequest, patientDetails, true, coherentJournaling); Utkast savedUtkast = saveAndNotify(builderResponse, user, EventCode.SKAPATFRAN, originalIntygId); monitoringService.logUtkastCreatedTemplateManual(savedUtkast.getIntygsId(), savedUtkast.getIntygsTyp(), savedUtkast.getSkapadAv().getHsaId(), savedUtkast.getEnhetsId(), originalIntygId, templateRequest.getOriginalIntygTyp()); if (templateRequest.isDjupintegrerad()) { checkIntegreradEnhet(builderResponse); } return new CreateUtkastFromTemplateResponse(savedUtkast.getIntygsTyp(), savedUtkast.getIntygTypeVersion(), savedUtkast.getIntygsId(), originalIntygId); } catch (ModuleException | ModuleNotFoundException me) { LOG.error("Module exception occured when trying to make a copy of " + originalIntygId); throw new WebCertServiceException(WebCertServiceErrorCodeEnum.MODULE_PROBLEM, me); } }
CopyUtkastServiceImpl implements CopyUtkastService { @Override public CreateUtkastFromTemplateResponse createUtkastFromSignedTemplate(CreateUtkastFromTemplateRequest templateRequest) { String originalIntygId = templateRequest.getOriginalIntygId(); LOG.debug("Creating utkast from template (certificate). Certificate = '{}'", originalIntygId); WebCertUser user = userService.getUser(); boolean coherentJournaling = isCoherentJournaling(user); try { if (intygService.isRevoked(templateRequest.getOriginalIntygId(), templateRequest.getOriginalIntygTyp(), coherentJournaling)) { LOG.debug("Cannot create utkast from template. The certificate is revoked. Certificate id = '{}'", originalIntygId); throw new WebCertServiceException(WebCertServiceErrorCodeEnum.INVALID_STATE, "Original certificate is revoked"); } Person patientDetails = updatePatientDetails(templateRequest, false); draftAccessServiceHelper.validateAllowToCreateUtkast(templateRequest.getTyp(), patientDetails.getPersonnummer()); final Utlatande utlatande = utkastServiceHelper.getUtlatande(templateRequest.getOriginalIntygId(), templateRequest.getOriginalIntygTyp(), false, false); addTestIntygFlagIfNecessaryToCopyRequest(templateRequest, utlatande.getGrundData().isTestIntyg()); verifyNotReplacedWithSigned(templateRequest.getOriginalIntygId(), "create utkast from template"); UtkastBuilderResponse builderResponse = buildUtkastFromSignedTemplateBuilderResponse(templateRequest, patientDetails, true, coherentJournaling); Utkast savedUtkast = saveAndNotify(builderResponse, user, EventCode.SKAPATFRAN, originalIntygId); monitoringService.logUtkastCreatedTemplateManual(savedUtkast.getIntygsId(), savedUtkast.getIntygsTyp(), savedUtkast.getSkapadAv().getHsaId(), savedUtkast.getEnhetsId(), originalIntygId, templateRequest.getOriginalIntygTyp()); if (templateRequest.isDjupintegrerad()) { checkIntegreradEnhet(builderResponse); } return new CreateUtkastFromTemplateResponse(savedUtkast.getIntygsTyp(), savedUtkast.getIntygTypeVersion(), savedUtkast.getIntygsId(), originalIntygId); } catch (ModuleException | ModuleNotFoundException me) { LOG.error("Module exception occured when trying to make a copy of " + originalIntygId); throw new WebCertServiceException(WebCertServiceErrorCodeEnum.MODULE_PROBLEM, me); } } }
CopyUtkastServiceImpl implements CopyUtkastService { @Override public CreateUtkastFromTemplateResponse createUtkastFromSignedTemplate(CreateUtkastFromTemplateRequest templateRequest) { String originalIntygId = templateRequest.getOriginalIntygId(); LOG.debug("Creating utkast from template (certificate). Certificate = '{}'", originalIntygId); WebCertUser user = userService.getUser(); boolean coherentJournaling = isCoherentJournaling(user); try { if (intygService.isRevoked(templateRequest.getOriginalIntygId(), templateRequest.getOriginalIntygTyp(), coherentJournaling)) { LOG.debug("Cannot create utkast from template. The certificate is revoked. Certificate id = '{}'", originalIntygId); throw new WebCertServiceException(WebCertServiceErrorCodeEnum.INVALID_STATE, "Original certificate is revoked"); } Person patientDetails = updatePatientDetails(templateRequest, false); draftAccessServiceHelper.validateAllowToCreateUtkast(templateRequest.getTyp(), patientDetails.getPersonnummer()); final Utlatande utlatande = utkastServiceHelper.getUtlatande(templateRequest.getOriginalIntygId(), templateRequest.getOriginalIntygTyp(), false, false); addTestIntygFlagIfNecessaryToCopyRequest(templateRequest, utlatande.getGrundData().isTestIntyg()); verifyNotReplacedWithSigned(templateRequest.getOriginalIntygId(), "create utkast from template"); UtkastBuilderResponse builderResponse = buildUtkastFromSignedTemplateBuilderResponse(templateRequest, patientDetails, true, coherentJournaling); Utkast savedUtkast = saveAndNotify(builderResponse, user, EventCode.SKAPATFRAN, originalIntygId); monitoringService.logUtkastCreatedTemplateManual(savedUtkast.getIntygsId(), savedUtkast.getIntygsTyp(), savedUtkast.getSkapadAv().getHsaId(), savedUtkast.getEnhetsId(), originalIntygId, templateRequest.getOriginalIntygTyp()); if (templateRequest.isDjupintegrerad()) { checkIntegreradEnhet(builderResponse); } return new CreateUtkastFromTemplateResponse(savedUtkast.getIntygsTyp(), savedUtkast.getIntygTypeVersion(), savedUtkast.getIntygsId(), originalIntygId); } catch (ModuleException | ModuleNotFoundException me) { LOG.error("Module exception occured when trying to make a copy of " + originalIntygId); throw new WebCertServiceException(WebCertServiceErrorCodeEnum.MODULE_PROBLEM, me); } }  }
CopyUtkastServiceImpl implements CopyUtkastService { @Override public CreateUtkastFromTemplateResponse createUtkastFromSignedTemplate(CreateUtkastFromTemplateRequest templateRequest) { String originalIntygId = templateRequest.getOriginalIntygId(); LOG.debug("Creating utkast from template (certificate). Certificate = '{}'", originalIntygId); WebCertUser user = userService.getUser(); boolean coherentJournaling = isCoherentJournaling(user); try { if (intygService.isRevoked(templateRequest.getOriginalIntygId(), templateRequest.getOriginalIntygTyp(), coherentJournaling)) { LOG.debug("Cannot create utkast from template. The certificate is revoked. Certificate id = '{}'", originalIntygId); throw new WebCertServiceException(WebCertServiceErrorCodeEnum.INVALID_STATE, "Original certificate is revoked"); } Person patientDetails = updatePatientDetails(templateRequest, false); draftAccessServiceHelper.validateAllowToCreateUtkast(templateRequest.getTyp(), patientDetails.getPersonnummer()); final Utlatande utlatande = utkastServiceHelper.getUtlatande(templateRequest.getOriginalIntygId(), templateRequest.getOriginalIntygTyp(), false, false); addTestIntygFlagIfNecessaryToCopyRequest(templateRequest, utlatande.getGrundData().isTestIntyg()); verifyNotReplacedWithSigned(templateRequest.getOriginalIntygId(), "create utkast from template"); UtkastBuilderResponse builderResponse = buildUtkastFromSignedTemplateBuilderResponse(templateRequest, patientDetails, true, coherentJournaling); Utkast savedUtkast = saveAndNotify(builderResponse, user, EventCode.SKAPATFRAN, originalIntygId); monitoringService.logUtkastCreatedTemplateManual(savedUtkast.getIntygsId(), savedUtkast.getIntygsTyp(), savedUtkast.getSkapadAv().getHsaId(), savedUtkast.getEnhetsId(), originalIntygId, templateRequest.getOriginalIntygTyp()); if (templateRequest.isDjupintegrerad()) { checkIntegreradEnhet(builderResponse); } return new CreateUtkastFromTemplateResponse(savedUtkast.getIntygsTyp(), savedUtkast.getIntygTypeVersion(), savedUtkast.getIntygsId(), originalIntygId); } catch (ModuleException | ModuleNotFoundException me) { LOG.error("Module exception occured when trying to make a copy of " + originalIntygId); throw new WebCertServiceException(WebCertServiceErrorCodeEnum.MODULE_PROBLEM, me); } }  @Override CreateCompletionCopyResponse createCompletion(CreateCompletionCopyRequest copyRequest); @Override CreateRenewalCopyResponse createRenewalCopy(CreateRenewalCopyRequest copyRequest); @Override @Transactional CreateReplacementCopyResponse createReplacementCopy(CreateReplacementCopyRequest replacementRequest); @Override CreateUtkastFromTemplateResponse createUtkastFromSignedTemplate(CreateUtkastFromTemplateRequest templateRequest); @Override CreateUtkastFromTemplateResponse createUtkastCopy(CreateUtkastFromTemplateRequest copyRequest); }
CopyUtkastServiceImpl implements CopyUtkastService { @Override public CreateUtkastFromTemplateResponse createUtkastFromSignedTemplate(CreateUtkastFromTemplateRequest templateRequest) { String originalIntygId = templateRequest.getOriginalIntygId(); LOG.debug("Creating utkast from template (certificate). Certificate = '{}'", originalIntygId); WebCertUser user = userService.getUser(); boolean coherentJournaling = isCoherentJournaling(user); try { if (intygService.isRevoked(templateRequest.getOriginalIntygId(), templateRequest.getOriginalIntygTyp(), coherentJournaling)) { LOG.debug("Cannot create utkast from template. The certificate is revoked. Certificate id = '{}'", originalIntygId); throw new WebCertServiceException(WebCertServiceErrorCodeEnum.INVALID_STATE, "Original certificate is revoked"); } Person patientDetails = updatePatientDetails(templateRequest, false); draftAccessServiceHelper.validateAllowToCreateUtkast(templateRequest.getTyp(), patientDetails.getPersonnummer()); final Utlatande utlatande = utkastServiceHelper.getUtlatande(templateRequest.getOriginalIntygId(), templateRequest.getOriginalIntygTyp(), false, false); addTestIntygFlagIfNecessaryToCopyRequest(templateRequest, utlatande.getGrundData().isTestIntyg()); verifyNotReplacedWithSigned(templateRequest.getOriginalIntygId(), "create utkast from template"); UtkastBuilderResponse builderResponse = buildUtkastFromSignedTemplateBuilderResponse(templateRequest, patientDetails, true, coherentJournaling); Utkast savedUtkast = saveAndNotify(builderResponse, user, EventCode.SKAPATFRAN, originalIntygId); monitoringService.logUtkastCreatedTemplateManual(savedUtkast.getIntygsId(), savedUtkast.getIntygsTyp(), savedUtkast.getSkapadAv().getHsaId(), savedUtkast.getEnhetsId(), originalIntygId, templateRequest.getOriginalIntygTyp()); if (templateRequest.isDjupintegrerad()) { checkIntegreradEnhet(builderResponse); } return new CreateUtkastFromTemplateResponse(savedUtkast.getIntygsTyp(), savedUtkast.getIntygTypeVersion(), savedUtkast.getIntygsId(), originalIntygId); } catch (ModuleException | ModuleNotFoundException me) { LOG.error("Module exception occured when trying to make a copy of " + originalIntygId); throw new WebCertServiceException(WebCertServiceErrorCodeEnum.MODULE_PROBLEM, me); } }  @Override CreateCompletionCopyResponse createCompletion(CreateCompletionCopyRequest copyRequest); @Override CreateRenewalCopyResponse createRenewalCopy(CreateRenewalCopyRequest copyRequest); @Override @Transactional CreateReplacementCopyResponse createReplacementCopy(CreateReplacementCopyRequest replacementRequest); @Override CreateUtkastFromTemplateResponse createUtkastFromSignedTemplate(CreateUtkastFromTemplateRequest templateRequest); @Override CreateUtkastFromTemplateResponse createUtkastCopy(CreateUtkastFromTemplateRequest copyRequest);  }