@Test public void testGetFragaSvarFilteringForIntyg() { List<FragaSvar> fragaSvarList = new ArrayList<>(); fragaSvarList.add(buildFragaSvar(1L, DECEMBER_YEAR_9999, DECEMBER_YEAR_9999)); fragaSvarList.add(buildFragaSvar(2L, LocalDateTime.now(), LocalDateTime.now())); fragaSvarList.add(buildFragaSvar(3L, JANUARY, JANUARY)); fragaSvarList.get(1).getVardperson().setEnhetsId("another unit without my range"); when(fragasvarRepositoryMock.findByIntygsReferensIntygsId("intyg-1")).thenReturn(new ArrayList<>(fragaSvarList)); when(webCertUserService.getUser()).thenReturn(createUser()); when(utkastRepository.findAllByRelationIntygsId(any(String.class))).thenReturn(Collections.emptyList()); List<FragaSvarView> result = service.getFragaSvar("intyg-1"); verify(fragasvarRepositoryMock).findByIntygsReferensIntygsId("intyg-1"); verify(webCertUserService).getUser(); assertEquals(2, result.size()); assertEquals(fragaSvarList.get(0), result.get(0).getFragaSvar()); assertEquals(fragaSvarList.get(2), result.get(1).getFragaSvar()); }
@Override @Transactional(readOnly = true) public List<FragaSvarView> getFragaSvar(String intygId) { List<FragaSvar> fragaSvarList = fragaSvarRepository.findByIntygsReferensIntygsId(intygId); WebCertUser user = webCertUserService.getUser(); validateSekretessmarkering(intygId, fragaSvarList, user); List<String> hsaEnhetIds = user.getIdsOfSelectedVardenhet(); fragaSvarList .removeIf(fragaSvar -> fragaSvar.getVardperson() != null && !hsaEnhetIds.contains(fragaSvar.getVardperson().getEnhetsId())); fragaSvarList.sort(SENASTE_HANDELSE_DATUM_COMPARATOR); List<ArendeDraft> drafts = arendeDraftService.listAnswerDrafts(intygId); List<AnsweredWithIntyg> bmi = AnsweredWithIntygUtil.findAllKomplementForGivenIntyg(intygId, utkastRepository); List<FragaSvarView> fragaSvarWithBesvaratMedIntygInfo = fragaSvarList.stream() .map(fs -> FragaSvarView.create(fs, fs.getFrageSkickadDatum() == null ? null : AnsweredWithIntygUtil.returnOldestKompltOlderThan(fs.getFrageSkickadDatum(), bmi), drafts.stream() .filter(d -> Long.toString(fs.getInternReferens()).equals(d.getQuestionId())) .findAny() .map(ArendeDraft::getText) .orElse(null))) .collect(Collectors.toList()); return fragaSvarWithBesvaratMedIntygInfo; }
FragaSvarServiceImpl implements FragaSvarService { @Override @Transactional(readOnly = true) public List<FragaSvarView> getFragaSvar(String intygId) { List<FragaSvar> fragaSvarList = fragaSvarRepository.findByIntygsReferensIntygsId(intygId); WebCertUser user = webCertUserService.getUser(); validateSekretessmarkering(intygId, fragaSvarList, user); List<String> hsaEnhetIds = user.getIdsOfSelectedVardenhet(); fragaSvarList .removeIf(fragaSvar -> fragaSvar.getVardperson() != null && !hsaEnhetIds.contains(fragaSvar.getVardperson().getEnhetsId())); fragaSvarList.sort(SENASTE_HANDELSE_DATUM_COMPARATOR); List<ArendeDraft> drafts = arendeDraftService.listAnswerDrafts(intygId); List<AnsweredWithIntyg> bmi = AnsweredWithIntygUtil.findAllKomplementForGivenIntyg(intygId, utkastRepository); List<FragaSvarView> fragaSvarWithBesvaratMedIntygInfo = fragaSvarList.stream() .map(fs -> FragaSvarView.create(fs, fs.getFrageSkickadDatum() == null ? null : AnsweredWithIntygUtil.returnOldestKompltOlderThan(fs.getFrageSkickadDatum(), bmi), drafts.stream() .filter(d -> Long.toString(fs.getInternReferens()).equals(d.getQuestionId())) .findAny() .map(ArendeDraft::getText) .orElse(null))) .collect(Collectors.toList()); return fragaSvarWithBesvaratMedIntygInfo; } }
FragaSvarServiceImpl implements FragaSvarService { @Override @Transactional(readOnly = true) public List<FragaSvarView> getFragaSvar(String intygId) { List<FragaSvar> fragaSvarList = fragaSvarRepository.findByIntygsReferensIntygsId(intygId); WebCertUser user = webCertUserService.getUser(); validateSekretessmarkering(intygId, fragaSvarList, user); List<String> hsaEnhetIds = user.getIdsOfSelectedVardenhet(); fragaSvarList .removeIf(fragaSvar -> fragaSvar.getVardperson() != null && !hsaEnhetIds.contains(fragaSvar.getVardperson().getEnhetsId())); fragaSvarList.sort(SENASTE_HANDELSE_DATUM_COMPARATOR); List<ArendeDraft> drafts = arendeDraftService.listAnswerDrafts(intygId); List<AnsweredWithIntyg> bmi = AnsweredWithIntygUtil.findAllKomplementForGivenIntyg(intygId, utkastRepository); List<FragaSvarView> fragaSvarWithBesvaratMedIntygInfo = fragaSvarList.stream() .map(fs -> FragaSvarView.create(fs, fs.getFrageSkickadDatum() == null ? null : AnsweredWithIntygUtil.returnOldestKompltOlderThan(fs.getFrageSkickadDatum(), bmi), drafts.stream() .filter(d -> Long.toString(fs.getInternReferens()).equals(d.getQuestionId())) .findAny() .map(ArendeDraft::getText) .orElse(null))) .collect(Collectors.toList()); return fragaSvarWithBesvaratMedIntygInfo; }  }
FragaSvarServiceImpl implements FragaSvarService { @Override @Transactional(readOnly = true) public List<FragaSvarView> getFragaSvar(String intygId) { List<FragaSvar> fragaSvarList = fragaSvarRepository.findByIntygsReferensIntygsId(intygId); WebCertUser user = webCertUserService.getUser(); validateSekretessmarkering(intygId, fragaSvarList, user); List<String> hsaEnhetIds = user.getIdsOfSelectedVardenhet(); fragaSvarList .removeIf(fragaSvar -> fragaSvar.getVardperson() != null && !hsaEnhetIds.contains(fragaSvar.getVardperson().getEnhetsId())); fragaSvarList.sort(SENASTE_HANDELSE_DATUM_COMPARATOR); List<ArendeDraft> drafts = arendeDraftService.listAnswerDrafts(intygId); List<AnsweredWithIntyg> bmi = AnsweredWithIntygUtil.findAllKomplementForGivenIntyg(intygId, utkastRepository); List<FragaSvarView> fragaSvarWithBesvaratMedIntygInfo = fragaSvarList.stream() .map(fs -> FragaSvarView.create(fs, fs.getFrageSkickadDatum() == null ? null : AnsweredWithIntygUtil.returnOldestKompltOlderThan(fs.getFrageSkickadDatum(), bmi), drafts.stream() .filter(d -> Long.toString(fs.getInternReferens()).equals(d.getQuestionId())) .findAny() .map(ArendeDraft::getText) .orElse(null))) .collect(Collectors.toList()); return fragaSvarWithBesvaratMedIntygInfo; }  @Override FragaSvar processIncomingQuestion(FragaSvar fragaSvar); @Override FragaSvar processIncomingAnswer(Long internId, String svarsText, LocalDateTime svarSigneringsDatum); @Override @Transactional(readOnly = true) List<FragaSvarView> getFragaSvar(String intygId); @Override FragaSvar saveSvar(Long fragaSvarsId, String svarsText); @Override List<FragaSvarView> answerKomplettering(final String intygsId, final String svarsText); @Override FragaSvar saveNewQuestion(String intygId, String typ, Amne amne, String frageText); @Override List<FragaSvar> setVidareBefordrad(final String intygsId); @Override FragaSvar closeQuestionAsHandled(Long frageSvarId); @Override void closeCompletionsAsHandled(String intygId); @Override void closeAllNonClosedQuestions(String intygsId); @Override FragaSvar openQuestionAsUnhandled(Long frageSvarId); @Override @Transactional(readOnly = true) QueryFragaSvarResponse filterFragaSvar(Filter filter); @Override @Transactional(readOnly = true) List<Lakare> getFragaSvarHsaIdByEnhet(String enhetsId); @Override Map<String, Long> getNbrOfUnhandledFragaSvarForCareUnits(List<String> vardenheterIds, Set<String> intygsTyper); }
FragaSvarServiceImpl implements FragaSvarService { @Override @Transactional(readOnly = true) public List<FragaSvarView> getFragaSvar(String intygId) { List<FragaSvar> fragaSvarList = fragaSvarRepository.findByIntygsReferensIntygsId(intygId); WebCertUser user = webCertUserService.getUser(); validateSekretessmarkering(intygId, fragaSvarList, user); List<String> hsaEnhetIds = user.getIdsOfSelectedVardenhet(); fragaSvarList .removeIf(fragaSvar -> fragaSvar.getVardperson() != null && !hsaEnhetIds.contains(fragaSvar.getVardperson().getEnhetsId())); fragaSvarList.sort(SENASTE_HANDELSE_DATUM_COMPARATOR); List<ArendeDraft> drafts = arendeDraftService.listAnswerDrafts(intygId); List<AnsweredWithIntyg> bmi = AnsweredWithIntygUtil.findAllKomplementForGivenIntyg(intygId, utkastRepository); List<FragaSvarView> fragaSvarWithBesvaratMedIntygInfo = fragaSvarList.stream() .map(fs -> FragaSvarView.create(fs, fs.getFrageSkickadDatum() == null ? null : AnsweredWithIntygUtil.returnOldestKompltOlderThan(fs.getFrageSkickadDatum(), bmi), drafts.stream() .filter(d -> Long.toString(fs.getInternReferens()).equals(d.getQuestionId())) .findAny() .map(ArendeDraft::getText) .orElse(null))) .collect(Collectors.toList()); return fragaSvarWithBesvaratMedIntygInfo; }  @Override FragaSvar processIncomingQuestion(FragaSvar fragaSvar); @Override FragaSvar processIncomingAnswer(Long internId, String svarsText, LocalDateTime svarSigneringsDatum); @Override @Transactional(readOnly = true) List<FragaSvarView> getFragaSvar(String intygId); @Override FragaSvar saveSvar(Long fragaSvarsId, String svarsText); @Override List<FragaSvarView> answerKomplettering(final String intygsId, final String svarsText); @Override FragaSvar saveNewQuestion(String intygId, String typ, Amne amne, String frageText); @Override List<FragaSvar> setVidareBefordrad(final String intygsId); @Override FragaSvar closeQuestionAsHandled(Long frageSvarId); @Override void closeCompletionsAsHandled(String intygId); @Override void closeAllNonClosedQuestions(String intygsId); @Override FragaSvar openQuestionAsUnhandled(Long frageSvarId); @Override @Transactional(readOnly = true) QueryFragaSvarResponse filterFragaSvar(Filter filter); @Override @Transactional(readOnly = true) List<Lakare> getFragaSvarHsaIdByEnhet(String enhetsId); @Override Map<String, Long> getNbrOfUnhandledFragaSvarForCareUnits(List<String> vardenheterIds, Set<String> intygsTyper);  }