@Test public void testNumberOfUnsignedDraftsByCareUnits() { List<GroupableItem> queryResult = new ArrayList<>(); when(userService.getUser()).thenReturn(createUser()); when(utkastRepository.getIntygWithStatusesByEnhetsId(anyList(), anySet(), anySet())).thenReturn(queryResult); Map<String, Long> resultMap = new HashMap<>(); resultMap.put("HSA1", 2L); when(statisticsGroupByUtil.toSekretessFilteredMap(queryResult)).thenReturn(resultMap); Map<String, Long> result = utkastService.getNbrOfUnsignedDraftsByCareUnits(Arrays.asList("HSA1", "HSA2")); verify(utkastRepository, times(1)).getIntygWithStatusesByEnhetsId(anyList(), anySet(), anySet()); verify(statisticsGroupByUtil, times(1)).toSekretessFilteredMap(queryResult); assertEquals(1, result.size()); assertEquals(2L, result.get("HSA1").longValue()); }
@Override @Transactional(readOnly = true) public Map<String, Long> getNbrOfUnsignedDraftsByCareUnits(List<String> careUnitIds) { Map<String, Long> resultsMap = new HashMap<>(); if (careUnitIds == null || careUnitIds.isEmpty()) { LOG.warn("No ids for Vardenheter was supplied"); return resultsMap; } WebCertUser user = webCertUserService.getUser(); Set<String> intygsTyper = authoritiesHelper.getIntygstyperForPrivilege(user, AuthoritiesConstants.PRIVILEGE_SKRIVA_INTYG); List<GroupableItem> resultArr = utkastRepository.getIntygWithStatusesByEnhetsId(careUnitIds, ALL_DRAFT_STATUSES_INCLUDE_LOCKED, intygsTyper); return statisticsGroupByUtil.toSekretessFilteredMap(resultArr); }
UtkastServiceImpl implements UtkastService { @Override @Transactional(readOnly = true) public Map<String, Long> getNbrOfUnsignedDraftsByCareUnits(List<String> careUnitIds) { Map<String, Long> resultsMap = new HashMap<>(); if (careUnitIds == null || careUnitIds.isEmpty()) { LOG.warn("No ids for Vardenheter was supplied"); return resultsMap; } WebCertUser user = webCertUserService.getUser(); Set<String> intygsTyper = authoritiesHelper.getIntygstyperForPrivilege(user, AuthoritiesConstants.PRIVILEGE_SKRIVA_INTYG); List<GroupableItem> resultArr = utkastRepository.getIntygWithStatusesByEnhetsId(careUnitIds, ALL_DRAFT_STATUSES_INCLUDE_LOCKED, intygsTyper); return statisticsGroupByUtil.toSekretessFilteredMap(resultArr); } }
UtkastServiceImpl implements UtkastService { @Override @Transactional(readOnly = true) public Map<String, Long> getNbrOfUnsignedDraftsByCareUnits(List<String> careUnitIds) { Map<String, Long> resultsMap = new HashMap<>(); if (careUnitIds == null || careUnitIds.isEmpty()) { LOG.warn("No ids for Vardenheter was supplied"); return resultsMap; } WebCertUser user = webCertUserService.getUser(); Set<String> intygsTyper = authoritiesHelper.getIntygstyperForPrivilege(user, AuthoritiesConstants.PRIVILEGE_SKRIVA_INTYG); List<GroupableItem> resultArr = utkastRepository.getIntygWithStatusesByEnhetsId(careUnitIds, ALL_DRAFT_STATUSES_INCLUDE_LOCKED, intygsTyper); return statisticsGroupByUtil.toSekretessFilteredMap(resultArr); }  }
UtkastServiceImpl implements UtkastService { @Override @Transactional(readOnly = true) public Map<String, Long> getNbrOfUnsignedDraftsByCareUnits(List<String> careUnitIds) { Map<String, Long> resultsMap = new HashMap<>(); if (careUnitIds == null || careUnitIds.isEmpty()) { LOG.warn("No ids for Vardenheter was supplied"); return resultsMap; } WebCertUser user = webCertUserService.getUser(); Set<String> intygsTyper = authoritiesHelper.getIntygstyperForPrivilege(user, AuthoritiesConstants.PRIVILEGE_SKRIVA_INTYG); List<GroupableItem> resultArr = utkastRepository.getIntygWithStatusesByEnhetsId(careUnitIds, ALL_DRAFT_STATUSES_INCLUDE_LOCKED, intygsTyper); return statisticsGroupByUtil.toSekretessFilteredMap(resultArr); }  static boolean isUtkast(Utkast utkast); static boolean isEditableUtkast(Utkast utkast); @Override @Transactional() // , readOnly=true int countFilterIntyg(UtkastFilter filter); @Override Utkast createNewDraft(CreateNewDraftRequest request); @Override SaveDraftResponse updateDraftFromCandidate(String fromIntygId, String fromIntygType, String toUtkastId, String toUtkastType); @Override SaveDraftResponse updateDraftFromCandidate(String fromIntygId, String fromIntygType, Utkast toUtkast); @Override String getQuestions(String intygsTyp, String version); @Override @Transactional void setKlarForSigneraAndSendStatusMessage(String intygsId, String intygType); @Override Map<String, Map<String, PreviousIntyg>> checkIfPersonHasExistingIntyg(final Personnummer personnummer,
                                                                                 final IntygUser user,
                                                                                 final String currentDraftId); @Override @Transactional void deleteUnsignedDraft(String intygId, long version); @Override @Transactional(readOnly = true) List<Utkast> filterIntyg(UtkastFilter filter); @Override @Transactional(readOnly = true) Utkast getDraft(String intygId, String intygType); @Override @Transactional(readOnly = true) Utkast getDraft(String intygId, String intygType, boolean createPdlLogEvent); @Override @Transactional(readOnly = true) List<Lakare> getLakareWithDraftsByEnhet(String enhetsId); @Override @Transactional(readOnly = true) Map<String, Long> getNbrOfUnsignedDraftsByCareUnits(List<String> careUnitIds); @Override @Transactional SaveDraftResponse saveDraft(String intygId, long version, String draftAsJson, boolean createPdlLogEvent); @Override void updatePatientOnDraft(UpdatePatientOnDraftRequest request); @Override @Transactional Utkast setNotifiedOnDraft(String intygsId, long version, Boolean notified); @Override DraftValidation validateDraft(String intygId, String intygType, String draftAsJson); @Override @Transactional int lockOldDrafts(int lockedAfterDay, LocalDate today); @Override void revokeLockedDraft(String intygId, String intygTyp, String revokeMessage, String reason); @Override boolean isDraftCreatedFromReplacement(String certificateId); }
UtkastServiceImpl implements UtkastService { @Override @Transactional(readOnly = true) public Map<String, Long> getNbrOfUnsignedDraftsByCareUnits(List<String> careUnitIds) { Map<String, Long> resultsMap = new HashMap<>(); if (careUnitIds == null || careUnitIds.isEmpty()) { LOG.warn("No ids for Vardenheter was supplied"); return resultsMap; } WebCertUser user = webCertUserService.getUser(); Set<String> intygsTyper = authoritiesHelper.getIntygstyperForPrivilege(user, AuthoritiesConstants.PRIVILEGE_SKRIVA_INTYG); List<GroupableItem> resultArr = utkastRepository.getIntygWithStatusesByEnhetsId(careUnitIds, ALL_DRAFT_STATUSES_INCLUDE_LOCKED, intygsTyper); return statisticsGroupByUtil.toSekretessFilteredMap(resultArr); }  static boolean isUtkast(Utkast utkast); static boolean isEditableUtkast(Utkast utkast); @Override @Transactional() // , readOnly=true int countFilterIntyg(UtkastFilter filter); @Override Utkast createNewDraft(CreateNewDraftRequest request); @Override SaveDraftResponse updateDraftFromCandidate(String fromIntygId, String fromIntygType, String toUtkastId, String toUtkastType); @Override SaveDraftResponse updateDraftFromCandidate(String fromIntygId, String fromIntygType, Utkast toUtkast); @Override String getQuestions(String intygsTyp, String version); @Override @Transactional void setKlarForSigneraAndSendStatusMessage(String intygsId, String intygType); @Override Map<String, Map<String, PreviousIntyg>> checkIfPersonHasExistingIntyg(final Personnummer personnummer,
                                                                                 final IntygUser user,
                                                                                 final String currentDraftId); @Override @Transactional void deleteUnsignedDraft(String intygId, long version); @Override @Transactional(readOnly = true) List<Utkast> filterIntyg(UtkastFilter filter); @Override @Transactional(readOnly = true) Utkast getDraft(String intygId, String intygType); @Override @Transactional(readOnly = true) Utkast getDraft(String intygId, String intygType, boolean createPdlLogEvent); @Override @Transactional(readOnly = true) List<Lakare> getLakareWithDraftsByEnhet(String enhetsId); @Override @Transactional(readOnly = true) Map<String, Long> getNbrOfUnsignedDraftsByCareUnits(List<String> careUnitIds); @Override @Transactional SaveDraftResponse saveDraft(String intygId, long version, String draftAsJson, boolean createPdlLogEvent); @Override void updatePatientOnDraft(UpdatePatientOnDraftRequest request); @Override @Transactional Utkast setNotifiedOnDraft(String intygsId, long version, Boolean notified); @Override DraftValidation validateDraft(String intygId, String intygType, String draftAsJson); @Override @Transactional int lockOldDrafts(int lockedAfterDay, LocalDate today); @Override void revokeLockedDraft(String intygId, String intygTyp, String revokeMessage, String reason); @Override boolean isDraftCreatedFromReplacement(String certificateId);  }