@Test public void testAnswerKomplOK() { final LocalDateTime date = LocalDateTime.of(2017, 5, 22, 5, 20); final String svarsText = "bra text"; FragaSvar komplFragaSvar = buildFragaSvar(1L, date, date); komplFragaSvar.setAmne(Amne.KOMPLETTERING_AV_LAKARINTYG); komplFragaSvar.setFrageStallare(FrageStallare.FORSAKRINGSKASSAN.getKod()); FragaSvar ovrigtFragaSvar = buildFragaSvar(2L, date.minusDays(1), date.minusDays(1)); ovrigtFragaSvar.setFrageStallare(FrageStallare.FORSAKRINGSKASSAN.getKod()); komplFragaSvar.setStatus(Status.CLOSED); ResultOfCall resultOfCall = new ResultOfCall(); resultOfCall.setResultCode(ResultCodeEnum.OK); SendMedicalCertificateAnswerResponseType sendMedicalResponse = new SendMedicalCertificateAnswerResponseType(); sendMedicalResponse.setResult(resultOfCall); doReturn(createUser()) .when(webCertUserService) .getUser(); doReturn(Lists.newArrayList(komplFragaSvar, ovrigtFragaSvar)) .when(fragasvarRepositoryMock) .findByIntygsReferensIntygsId(eq(INTYG_ID)); doReturn(komplFragaSvar) .when(fragasvarRepositoryMock) .save(komplFragaSvar); doReturn(sendMedicalResponse) .when(sendAnswerToFKClientMock) .sendMedicalCertificateAnswer( any(AttributedURIType.class), any(SendMedicalCertificateAnswerType.class) ); final List<FragaSvarView> fragaSvarViews = service.answerKomplettering(INTYG_ID, svarsText); assertEquals(2, fragaSvarViews.size()); FragaSvar komplResult = fragaSvarViews.stream() .map(FragaSvarView::getFragaSvar) .filter(fs -> fs.getAmne() == Amne.KOMPLETTERING_AV_LAKARINTYG) .collect(MoreCollectors.onlyElement()); FragaSvar otherResult = fragaSvarViews.stream() .map(FragaSvarView::getFragaSvar) .filter(fs -> fs.getAmne() == Amne.OVRIGT) .collect(MoreCollectors.onlyElement()); assertEquals(Status.CLOSED, komplResult.getStatus()); assertEquals(Status.PENDING_INTERNAL_ACTION, otherResult.getStatus()); }
@Override public List<FragaSvarView> answerKomplettering(final String intygsId, final String svarsText) { Preconditions.checkArgument(!Strings.isNullOrEmpty(intygsId), "intygsId may not be null or empty"); Preconditions.checkArgument(!Strings.isNullOrEmpty(svarsText), "svarsText may not be null or empty"); final List<FragaSvar> fragaSvarList = fragaSvarRepository.findByIntygsReferensIntygsId(intygsId); final FragaSvar komplFragaSvar = fragaSvarList.stream() .filter(isCorrectAmne(Amne.KOMPLETTERING_AV_LAKARINTYG)) .max(SENASTE_HANDELSE_DATUM_COMPARATOR) .orElseThrow(() -> new IllegalArgumentException("No fragasvar of type KOMPLT exist for intyg: " + intygsId)); WebCertUser user = webCertUserService.getUser(); if (!authoritiesValidator.given(user).privilege(AuthoritiesConstants.PRIVILEGE_BESVARA_KOMPLETTERINGSFRAGA).isVerified()) { throw new WebCertServiceException(WebCertServiceErrorCodeEnum.AUTHORIZATION_PROBLEM, "FragaSvar with id " + komplFragaSvar.getInternReferens().toString() + " and amne (" + Amne.KOMPLETTERING_AV_LAKARINTYG + ") can only be answered by user that is Lakare"); } createSvar(user, svarsText, komplFragaSvar); FragaSvar saved = fragaSvarRepository.save(komplFragaSvar); sendFragaSvarToExternalParty(saved); arendeDraftService.delete(komplFragaSvar.getIntygsReferens().getIntygsId(), Long.toString(komplFragaSvar.getInternReferens())); closeCompletionsAsHandled(intygsId); return getFragaSvar(intygsId); }
FragaSvarServiceImpl implements FragaSvarService { @Override public List<FragaSvarView> answerKomplettering(final String intygsId, final String svarsText) { Preconditions.checkArgument(!Strings.isNullOrEmpty(intygsId), "intygsId may not be null or empty"); Preconditions.checkArgument(!Strings.isNullOrEmpty(svarsText), "svarsText may not be null or empty"); final List<FragaSvar> fragaSvarList = fragaSvarRepository.findByIntygsReferensIntygsId(intygsId); final FragaSvar komplFragaSvar = fragaSvarList.stream() .filter(isCorrectAmne(Amne.KOMPLETTERING_AV_LAKARINTYG)) .max(SENASTE_HANDELSE_DATUM_COMPARATOR) .orElseThrow(() -> new IllegalArgumentException("No fragasvar of type KOMPLT exist for intyg: " + intygsId)); WebCertUser user = webCertUserService.getUser(); if (!authoritiesValidator.given(user).privilege(AuthoritiesConstants.PRIVILEGE_BESVARA_KOMPLETTERINGSFRAGA).isVerified()) { throw new WebCertServiceException(WebCertServiceErrorCodeEnum.AUTHORIZATION_PROBLEM, "FragaSvar with id " + komplFragaSvar.getInternReferens().toString() + " and amne (" + Amne.KOMPLETTERING_AV_LAKARINTYG + ") can only be answered by user that is Lakare"); } createSvar(user, svarsText, komplFragaSvar); FragaSvar saved = fragaSvarRepository.save(komplFragaSvar); sendFragaSvarToExternalParty(saved); arendeDraftService.delete(komplFragaSvar.getIntygsReferens().getIntygsId(), Long.toString(komplFragaSvar.getInternReferens())); closeCompletionsAsHandled(intygsId); return getFragaSvar(intygsId); } }
FragaSvarServiceImpl implements FragaSvarService { @Override public List<FragaSvarView> answerKomplettering(final String intygsId, final String svarsText) { Preconditions.checkArgument(!Strings.isNullOrEmpty(intygsId), "intygsId may not be null or empty"); Preconditions.checkArgument(!Strings.isNullOrEmpty(svarsText), "svarsText may not be null or empty"); final List<FragaSvar> fragaSvarList = fragaSvarRepository.findByIntygsReferensIntygsId(intygsId); final FragaSvar komplFragaSvar = fragaSvarList.stream() .filter(isCorrectAmne(Amne.KOMPLETTERING_AV_LAKARINTYG)) .max(SENASTE_HANDELSE_DATUM_COMPARATOR) .orElseThrow(() -> new IllegalArgumentException("No fragasvar of type KOMPLT exist for intyg: " + intygsId)); WebCertUser user = webCertUserService.getUser(); if (!authoritiesValidator.given(user).privilege(AuthoritiesConstants.PRIVILEGE_BESVARA_KOMPLETTERINGSFRAGA).isVerified()) { throw new WebCertServiceException(WebCertServiceErrorCodeEnum.AUTHORIZATION_PROBLEM, "FragaSvar with id " + komplFragaSvar.getInternReferens().toString() + " and amne (" + Amne.KOMPLETTERING_AV_LAKARINTYG + ") can only be answered by user that is Lakare"); } createSvar(user, svarsText, komplFragaSvar); FragaSvar saved = fragaSvarRepository.save(komplFragaSvar); sendFragaSvarToExternalParty(saved); arendeDraftService.delete(komplFragaSvar.getIntygsReferens().getIntygsId(), Long.toString(komplFragaSvar.getInternReferens())); closeCompletionsAsHandled(intygsId); return getFragaSvar(intygsId); }  }
FragaSvarServiceImpl implements FragaSvarService { @Override public List<FragaSvarView> answerKomplettering(final String intygsId, final String svarsText) { Preconditions.checkArgument(!Strings.isNullOrEmpty(intygsId), "intygsId may not be null or empty"); Preconditions.checkArgument(!Strings.isNullOrEmpty(svarsText), "svarsText may not be null or empty"); final List<FragaSvar> fragaSvarList = fragaSvarRepository.findByIntygsReferensIntygsId(intygsId); final FragaSvar komplFragaSvar = fragaSvarList.stream() .filter(isCorrectAmne(Amne.KOMPLETTERING_AV_LAKARINTYG)) .max(SENASTE_HANDELSE_DATUM_COMPARATOR) .orElseThrow(() -> new IllegalArgumentException("No fragasvar of type KOMPLT exist for intyg: " + intygsId)); WebCertUser user = webCertUserService.getUser(); if (!authoritiesValidator.given(user).privilege(AuthoritiesConstants.PRIVILEGE_BESVARA_KOMPLETTERINGSFRAGA).isVerified()) { throw new WebCertServiceException(WebCertServiceErrorCodeEnum.AUTHORIZATION_PROBLEM, "FragaSvar with id " + komplFragaSvar.getInternReferens().toString() + " and amne (" + Amne.KOMPLETTERING_AV_LAKARINTYG + ") can only be answered by user that is Lakare"); } createSvar(user, svarsText, komplFragaSvar); FragaSvar saved = fragaSvarRepository.save(komplFragaSvar); sendFragaSvarToExternalParty(saved); arendeDraftService.delete(komplFragaSvar.getIntygsReferens().getIntygsId(), Long.toString(komplFragaSvar.getInternReferens())); closeCompletionsAsHandled(intygsId); return getFragaSvar(intygsId); }  @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 public List<FragaSvarView> answerKomplettering(final String intygsId, final String svarsText) { Preconditions.checkArgument(!Strings.isNullOrEmpty(intygsId), "intygsId may not be null or empty"); Preconditions.checkArgument(!Strings.isNullOrEmpty(svarsText), "svarsText may not be null or empty"); final List<FragaSvar> fragaSvarList = fragaSvarRepository.findByIntygsReferensIntygsId(intygsId); final FragaSvar komplFragaSvar = fragaSvarList.stream() .filter(isCorrectAmne(Amne.KOMPLETTERING_AV_LAKARINTYG)) .max(SENASTE_HANDELSE_DATUM_COMPARATOR) .orElseThrow(() -> new IllegalArgumentException("No fragasvar of type KOMPLT exist for intyg: " + intygsId)); WebCertUser user = webCertUserService.getUser(); if (!authoritiesValidator.given(user).privilege(AuthoritiesConstants.PRIVILEGE_BESVARA_KOMPLETTERINGSFRAGA).isVerified()) { throw new WebCertServiceException(WebCertServiceErrorCodeEnum.AUTHORIZATION_PROBLEM, "FragaSvar with id " + komplFragaSvar.getInternReferens().toString() + " and amne (" + Amne.KOMPLETTERING_AV_LAKARINTYG + ") can only be answered by user that is Lakare"); } createSvar(user, svarsText, komplFragaSvar); FragaSvar saved = fragaSvarRepository.save(komplFragaSvar); sendFragaSvarToExternalParty(saved); arendeDraftService.delete(komplFragaSvar.getIntygsReferens().getIntygsId(), Long.toString(komplFragaSvar.getInternReferens())); closeCompletionsAsHandled(intygsId); return getFragaSvar(intygsId); }  @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);  }