@Test public void getCandidateMetaDataWhenMissingCopyFromCriteria() { String utkastType = "ag7804"; Patient patient = createPatient("Lilltolvan", "Tolvansson", createPnr("20121212-1212")); when(ag7804ModuleApiV1Mock.getCopyFromCriteria()).thenReturn(Optional.empty()); assertFalse(utkastCandidateService.getCandidateMetaData(ag7804ModuleApiV1Mock, utkastType, patient, false).isPresent()); verify(logService, times(0)).logReadIntyg(any(LogRequest.class)); }
public Optional<UtkastCandidateMetaData> getCandidateMetaData( ModuleApi moduleApi, String intygType, Patient patient, boolean isCoherentJournaling) { UtkastCandidateMetaData metaData = null; final Optional<GetCopyFromCriteria> copyFromCriteria = moduleApi.getCopyFromCriteria(); if (!copyFromCriteria.isPresent()) { return Optional.empty(); } AccessResult accessResult = draftAccessService.allowToCopyFromCandidate(intygType, patient.getPersonId()); if (accessResult.isDenied()) { return Optional.empty(); } if (!getUser().isLakare() && patient.isSekretessmarkering()) { return Optional.empty(); } try { Optional<Utkast> candidate = findCandidate(copyFromCriteria.get(), patient); if (candidate.isPresent()) { Utkast utkast = candidate.get(); boolean sameVardenhet = webCertUserService.isUserAllowedAccessToUnit(utkast.getEnhetsId()); metaData = new UtkastCandidateMetaData.Builder() .with(builder -> { builder.intygId = utkast.getIntygsId(); builder.intygType = utkast.getIntygsTyp(); builder.intygTypeVersion = utkast.getIntygTypeVersion(); builder.intygCreated = utkast.getSkapad(); builder.signedByHsaId = utkast.getSkapadAv().getHsaId(); builder.enhetHsaId = utkast.getEnhetsId(); builder.enhetName = utkast.getEnhetsNamn(); builder.sameVardenhet = sameVardenhet; }) .create(); logService.logReadIntyg( logRequestFactory.createLogRequestFromUtkast( utkast, isCoherentJournaling), LogUtil.getLogUser(getUser())); } return Optional.ofNullable(metaData); } catch (Exception e) { throw new WebCertServiceException(WebCertServiceErrorCodeEnum.MODULE_PROBLEM, "Failed to lookup a candidate to copy certificate information from", e); } }
UtkastCandidateServiceImpl { public Optional<UtkastCandidateMetaData> getCandidateMetaData( ModuleApi moduleApi, String intygType, Patient patient, boolean isCoherentJournaling) { UtkastCandidateMetaData metaData = null; final Optional<GetCopyFromCriteria> copyFromCriteria = moduleApi.getCopyFromCriteria(); if (!copyFromCriteria.isPresent()) { return Optional.empty(); } AccessResult accessResult = draftAccessService.allowToCopyFromCandidate(intygType, patient.getPersonId()); if (accessResult.isDenied()) { return Optional.empty(); } if (!getUser().isLakare() && patient.isSekretessmarkering()) { return Optional.empty(); } try { Optional<Utkast> candidate = findCandidate(copyFromCriteria.get(), patient); if (candidate.isPresent()) { Utkast utkast = candidate.get(); boolean sameVardenhet = webCertUserService.isUserAllowedAccessToUnit(utkast.getEnhetsId()); metaData = new UtkastCandidateMetaData.Builder() .with(builder -> { builder.intygId = utkast.getIntygsId(); builder.intygType = utkast.getIntygsTyp(); builder.intygTypeVersion = utkast.getIntygTypeVersion(); builder.intygCreated = utkast.getSkapad(); builder.signedByHsaId = utkast.getSkapadAv().getHsaId(); builder.enhetHsaId = utkast.getEnhetsId(); builder.enhetName = utkast.getEnhetsNamn(); builder.sameVardenhet = sameVardenhet; }) .create(); logService.logReadIntyg( logRequestFactory.createLogRequestFromUtkast( utkast, isCoherentJournaling), LogUtil.getLogUser(getUser())); } return Optional.ofNullable(metaData); } catch (Exception e) { throw new WebCertServiceException(WebCertServiceErrorCodeEnum.MODULE_PROBLEM, "Failed to lookup a candidate to copy certificate information from", e); } } }
UtkastCandidateServiceImpl { public Optional<UtkastCandidateMetaData> getCandidateMetaData( ModuleApi moduleApi, String intygType, Patient patient, boolean isCoherentJournaling) { UtkastCandidateMetaData metaData = null; final Optional<GetCopyFromCriteria> copyFromCriteria = moduleApi.getCopyFromCriteria(); if (!copyFromCriteria.isPresent()) { return Optional.empty(); } AccessResult accessResult = draftAccessService.allowToCopyFromCandidate(intygType, patient.getPersonId()); if (accessResult.isDenied()) { return Optional.empty(); } if (!getUser().isLakare() && patient.isSekretessmarkering()) { return Optional.empty(); } try { Optional<Utkast> candidate = findCandidate(copyFromCriteria.get(), patient); if (candidate.isPresent()) { Utkast utkast = candidate.get(); boolean sameVardenhet = webCertUserService.isUserAllowedAccessToUnit(utkast.getEnhetsId()); metaData = new UtkastCandidateMetaData.Builder() .with(builder -> { builder.intygId = utkast.getIntygsId(); builder.intygType = utkast.getIntygsTyp(); builder.intygTypeVersion = utkast.getIntygTypeVersion(); builder.intygCreated = utkast.getSkapad(); builder.signedByHsaId = utkast.getSkapadAv().getHsaId(); builder.enhetHsaId = utkast.getEnhetsId(); builder.enhetName = utkast.getEnhetsNamn(); builder.sameVardenhet = sameVardenhet; }) .create(); logService.logReadIntyg( logRequestFactory.createLogRequestFromUtkast( utkast, isCoherentJournaling), LogUtil.getLogUser(getUser())); } return Optional.ofNullable(metaData); } catch (Exception e) { throw new WebCertServiceException(WebCertServiceErrorCodeEnum.MODULE_PROBLEM, "Failed to lookup a candidate to copy certificate information from", e); } }  }
UtkastCandidateServiceImpl { public Optional<UtkastCandidateMetaData> getCandidateMetaData( ModuleApi moduleApi, String intygType, Patient patient, boolean isCoherentJournaling) { UtkastCandidateMetaData metaData = null; final Optional<GetCopyFromCriteria> copyFromCriteria = moduleApi.getCopyFromCriteria(); if (!copyFromCriteria.isPresent()) { return Optional.empty(); } AccessResult accessResult = draftAccessService.allowToCopyFromCandidate(intygType, patient.getPersonId()); if (accessResult.isDenied()) { return Optional.empty(); } if (!getUser().isLakare() && patient.isSekretessmarkering()) { return Optional.empty(); } try { Optional<Utkast> candidate = findCandidate(copyFromCriteria.get(), patient); if (candidate.isPresent()) { Utkast utkast = candidate.get(); boolean sameVardenhet = webCertUserService.isUserAllowedAccessToUnit(utkast.getEnhetsId()); metaData = new UtkastCandidateMetaData.Builder() .with(builder -> { builder.intygId = utkast.getIntygsId(); builder.intygType = utkast.getIntygsTyp(); builder.intygTypeVersion = utkast.getIntygTypeVersion(); builder.intygCreated = utkast.getSkapad(); builder.signedByHsaId = utkast.getSkapadAv().getHsaId(); builder.enhetHsaId = utkast.getEnhetsId(); builder.enhetName = utkast.getEnhetsNamn(); builder.sameVardenhet = sameVardenhet; }) .create(); logService.logReadIntyg( logRequestFactory.createLogRequestFromUtkast( utkast, isCoherentJournaling), LogUtil.getLogUser(getUser())); } return Optional.ofNullable(metaData); } catch (Exception e) { throw new WebCertServiceException(WebCertServiceErrorCodeEnum.MODULE_PROBLEM, "Failed to lookup a candidate to copy certificate information from", e); } }  Optional<UtkastCandidateMetaData> getCandidateMetaData(
        ModuleApi moduleApi, String intygType, Patient patient, boolean isCoherentJournaling); }
UtkastCandidateServiceImpl { public Optional<UtkastCandidateMetaData> getCandidateMetaData( ModuleApi moduleApi, String intygType, Patient patient, boolean isCoherentJournaling) { UtkastCandidateMetaData metaData = null; final Optional<GetCopyFromCriteria> copyFromCriteria = moduleApi.getCopyFromCriteria(); if (!copyFromCriteria.isPresent()) { return Optional.empty(); } AccessResult accessResult = draftAccessService.allowToCopyFromCandidate(intygType, patient.getPersonId()); if (accessResult.isDenied()) { return Optional.empty(); } if (!getUser().isLakare() && patient.isSekretessmarkering()) { return Optional.empty(); } try { Optional<Utkast> candidate = findCandidate(copyFromCriteria.get(), patient); if (candidate.isPresent()) { Utkast utkast = candidate.get(); boolean sameVardenhet = webCertUserService.isUserAllowedAccessToUnit(utkast.getEnhetsId()); metaData = new UtkastCandidateMetaData.Builder() .with(builder -> { builder.intygId = utkast.getIntygsId(); builder.intygType = utkast.getIntygsTyp(); builder.intygTypeVersion = utkast.getIntygTypeVersion(); builder.intygCreated = utkast.getSkapad(); builder.signedByHsaId = utkast.getSkapadAv().getHsaId(); builder.enhetHsaId = utkast.getEnhetsId(); builder.enhetName = utkast.getEnhetsNamn(); builder.sameVardenhet = sameVardenhet; }) .create(); logService.logReadIntyg( logRequestFactory.createLogRequestFromUtkast( utkast, isCoherentJournaling), LogUtil.getLogUser(getUser())); } return Optional.ofNullable(metaData); } catch (Exception e) { throw new WebCertServiceException(WebCertServiceErrorCodeEnum.MODULE_PROBLEM, "Failed to lookup a candidate to copy certificate information from", e); } }  Optional<UtkastCandidateMetaData> getCandidateMetaData(
        ModuleApi moduleApi, String intygType, Patient patient, boolean isCoherentJournaling);  }