@Test(expected = WebCertServiceException.class) public void testSaveFragaNotSentToFK() { FragaSvar fraga = buildFraga(1L, "frageText", Amne.OVRIGT, LocalDateTime.now()); when(intygServiceMock.fetchIntygData(fraga.getIntygsReferens().getIntygsId(), fraga.getIntygsReferens().getIntygsTyp(), false)) .thenReturn( getIntygContentHolder()); when(webCertUserService.getUser()).thenReturn(createUser()); try { service.saveNewQuestion(fraga.getIntygsReferens().getIntygsId(), fraga.getIntygsReferens().getIntygsTyp(), fraga.getAmne(), fraga.getFrageText()); } finally { verifyNoInteractions(fragasvarRepositoryMock); verifyNoInteractions(notificationServiceMock); verifyNoInteractions(certificateEventService); verifyNoInteractions(arendeDraftService); } }
@Override public FragaSvar saveNewQuestion(String intygId, String typ, Amne amne, String frageText) { if (Strings.isNullOrEmpty(frageText)) { throw new WebCertServiceException(WebCertServiceErrorCodeEnum.INTERNAL_PROBLEM, "frageText cannot be empty!"); } if (amne == null) { throw new WebCertServiceException(WebCertServiceErrorCodeEnum.INTERNAL_PROBLEM, "Amne cannot be null!"); } else if (!VALID_VARD_AMNEN.contains(amne)) { throw new WebCertServiceException(WebCertServiceErrorCodeEnum.INTERNAL_PROBLEM, "Invalid Amne " + amne + " for new question from vard!"); } IntygContentHolder intyg = intygService.fetchIntygData(intygId, typ, false); WebCertUser user = webCertUserService.getUser(); verifyEnhetsAuth(intyg.getUtlatande().getGrundData().getSkapadAv().getVardenhet().getEnhetsid(), false); if (!isCertificateSentToFK(intyg.getStatuses())) { throw new WebCertServiceException(WebCertServiceErrorCodeEnum.INTERNAL_PROBLEM, "FS-001: Certificate must be sent to FK first before sending question!"); } if (intyg.isRevoked()) { throw new WebCertServiceException(WebCertServiceErrorCodeEnum.INTERNAL_PROBLEM, "FS-XXX: Cannot save Fraga when certificate is revoked!"); } IntygsReferens intygsReferens = FragaSvarConverter.convertToIntygsReferens(intyg.getUtlatande()); HoSPersonal hoSPersonal = IntygConverterUtil.buildHosPersonalFromWebCertUser(user, null); Vardperson vardPerson = FragaSvarConverter.convert(hoSPersonal); FragaSvar fraga = new FragaSvar(); fraga.setFrageStallare(FrageStallare.WEBCERT.getKod()); fraga.setAmne(amne); fraga.setFrageText(frageText); LocalDateTime now = LocalDateTime.now(); fraga.setFrageSkickadDatum(now); fraga.setFrageSigneringsDatum(now); fraga.setIntygsReferens(intygsReferens); fraga.setVardperson(vardPerson); fraga.setStatus(Status.PENDING_EXTERNAL_ACTION); fraga.setVardAktorHsaId(user.getHsaId()); fraga.setVardAktorNamn(user.getNamn()); FragaSvar saved = fragaSvarRepository.save(fraga); SendMedicalCertificateQuestionType sendType = new SendMedicalCertificateQuestionType(); QuestionToFkType question = FKQuestionConverter.convert(saved); if ("true".equalsIgnoreCase(forceFullstandigtNamn)) { question.getLakarutlatande().getPatient().setFullstandigtNamn("---"); } sendType.setQuestion(question); AttributedURIType logicalAddress = new AttributedURIType(); logicalAddress.setValue(sendQuestionToFkLogicalAddress); SendMedicalCertificateQuestionResponseType response; try { response = sendQuestionToFKClient.sendMedicalCertificateQuestion(logicalAddress, sendType); } catch (SOAPFaultException e) { LOGGER.error("Failed to send question to FK, error was: " + e.getMessage()); throw new WebCertServiceException(WebCertServiceErrorCodeEnum.EXTERNAL_SYSTEM_PROBLEM, e.getMessage()); } if (!response.getResult().getResultCode().equals(ResultCodeEnum.OK)) { LOGGER.error("Failed to send question to FK, result was " + response.getResult().toString()); throw new WebCertServiceException(WebCertServiceErrorCodeEnum.EXTERNAL_SYSTEM_PROBLEM, response.getResult() .getErrorText()); } monitoringService.logQuestionSent(saved.getExternReferens(), saved.getInternReferens(), (saved.getIntygsReferens() == null) ? null : saved.getIntygsReferens().getIntygsId(), saved.getVardperson().getEnhetsId(), saved.getAmne()); sendNotification(saved, NotificationEvent.NEW_QUESTION_FROM_CARE); certificateEventService.createCertificateEvent(intygId, user.getHsaId(), EventCode.NYFRFV, amne.name()); arendeDraftService.delete(intygId, null); return saved; }
FragaSvarServiceImpl implements FragaSvarService { @Override public FragaSvar saveNewQuestion(String intygId, String typ, Amne amne, String frageText) { if (Strings.isNullOrEmpty(frageText)) { throw new WebCertServiceException(WebCertServiceErrorCodeEnum.INTERNAL_PROBLEM, "frageText cannot be empty!"); } if (amne == null) { throw new WebCertServiceException(WebCertServiceErrorCodeEnum.INTERNAL_PROBLEM, "Amne cannot be null!"); } else if (!VALID_VARD_AMNEN.contains(amne)) { throw new WebCertServiceException(WebCertServiceErrorCodeEnum.INTERNAL_PROBLEM, "Invalid Amne " + amne + " for new question from vard!"); } IntygContentHolder intyg = intygService.fetchIntygData(intygId, typ, false); WebCertUser user = webCertUserService.getUser(); verifyEnhetsAuth(intyg.getUtlatande().getGrundData().getSkapadAv().getVardenhet().getEnhetsid(), false); if (!isCertificateSentToFK(intyg.getStatuses())) { throw new WebCertServiceException(WebCertServiceErrorCodeEnum.INTERNAL_PROBLEM, "FS-001: Certificate must be sent to FK first before sending question!"); } if (intyg.isRevoked()) { throw new WebCertServiceException(WebCertServiceErrorCodeEnum.INTERNAL_PROBLEM, "FS-XXX: Cannot save Fraga when certificate is revoked!"); } IntygsReferens intygsReferens = FragaSvarConverter.convertToIntygsReferens(intyg.getUtlatande()); HoSPersonal hoSPersonal = IntygConverterUtil.buildHosPersonalFromWebCertUser(user, null); Vardperson vardPerson = FragaSvarConverter.convert(hoSPersonal); FragaSvar fraga = new FragaSvar(); fraga.setFrageStallare(FrageStallare.WEBCERT.getKod()); fraga.setAmne(amne); fraga.setFrageText(frageText); LocalDateTime now = LocalDateTime.now(); fraga.setFrageSkickadDatum(now); fraga.setFrageSigneringsDatum(now); fraga.setIntygsReferens(intygsReferens); fraga.setVardperson(vardPerson); fraga.setStatus(Status.PENDING_EXTERNAL_ACTION); fraga.setVardAktorHsaId(user.getHsaId()); fraga.setVardAktorNamn(user.getNamn()); FragaSvar saved = fragaSvarRepository.save(fraga); SendMedicalCertificateQuestionType sendType = new SendMedicalCertificateQuestionType(); QuestionToFkType question = FKQuestionConverter.convert(saved); if ("true".equalsIgnoreCase(forceFullstandigtNamn)) { question.getLakarutlatande().getPatient().setFullstandigtNamn("---"); } sendType.setQuestion(question); AttributedURIType logicalAddress = new AttributedURIType(); logicalAddress.setValue(sendQuestionToFkLogicalAddress); SendMedicalCertificateQuestionResponseType response; try { response = sendQuestionToFKClient.sendMedicalCertificateQuestion(logicalAddress, sendType); } catch (SOAPFaultException e) { LOGGER.error("Failed to send question to FK, error was: " + e.getMessage()); throw new WebCertServiceException(WebCertServiceErrorCodeEnum.EXTERNAL_SYSTEM_PROBLEM, e.getMessage()); } if (!response.getResult().getResultCode().equals(ResultCodeEnum.OK)) { LOGGER.error("Failed to send question to FK, result was " + response.getResult().toString()); throw new WebCertServiceException(WebCertServiceErrorCodeEnum.EXTERNAL_SYSTEM_PROBLEM, response.getResult() .getErrorText()); } monitoringService.logQuestionSent(saved.getExternReferens(), saved.getInternReferens(), (saved.getIntygsReferens() == null) ? null : saved.getIntygsReferens().getIntygsId(), saved.getVardperson().getEnhetsId(), saved.getAmne()); sendNotification(saved, NotificationEvent.NEW_QUESTION_FROM_CARE); certificateEventService.createCertificateEvent(intygId, user.getHsaId(), EventCode.NYFRFV, amne.name()); arendeDraftService.delete(intygId, null); return saved; } }
FragaSvarServiceImpl implements FragaSvarService { @Override public FragaSvar saveNewQuestion(String intygId, String typ, Amne amne, String frageText) { if (Strings.isNullOrEmpty(frageText)) { throw new WebCertServiceException(WebCertServiceErrorCodeEnum.INTERNAL_PROBLEM, "frageText cannot be empty!"); } if (amne == null) { throw new WebCertServiceException(WebCertServiceErrorCodeEnum.INTERNAL_PROBLEM, "Amne cannot be null!"); } else if (!VALID_VARD_AMNEN.contains(amne)) { throw new WebCertServiceException(WebCertServiceErrorCodeEnum.INTERNAL_PROBLEM, "Invalid Amne " + amne + " for new question from vard!"); } IntygContentHolder intyg = intygService.fetchIntygData(intygId, typ, false); WebCertUser user = webCertUserService.getUser(); verifyEnhetsAuth(intyg.getUtlatande().getGrundData().getSkapadAv().getVardenhet().getEnhetsid(), false); if (!isCertificateSentToFK(intyg.getStatuses())) { throw new WebCertServiceException(WebCertServiceErrorCodeEnum.INTERNAL_PROBLEM, "FS-001: Certificate must be sent to FK first before sending question!"); } if (intyg.isRevoked()) { throw new WebCertServiceException(WebCertServiceErrorCodeEnum.INTERNAL_PROBLEM, "FS-XXX: Cannot save Fraga when certificate is revoked!"); } IntygsReferens intygsReferens = FragaSvarConverter.convertToIntygsReferens(intyg.getUtlatande()); HoSPersonal hoSPersonal = IntygConverterUtil.buildHosPersonalFromWebCertUser(user, null); Vardperson vardPerson = FragaSvarConverter.convert(hoSPersonal); FragaSvar fraga = new FragaSvar(); fraga.setFrageStallare(FrageStallare.WEBCERT.getKod()); fraga.setAmne(amne); fraga.setFrageText(frageText); LocalDateTime now = LocalDateTime.now(); fraga.setFrageSkickadDatum(now); fraga.setFrageSigneringsDatum(now); fraga.setIntygsReferens(intygsReferens); fraga.setVardperson(vardPerson); fraga.setStatus(Status.PENDING_EXTERNAL_ACTION); fraga.setVardAktorHsaId(user.getHsaId()); fraga.setVardAktorNamn(user.getNamn()); FragaSvar saved = fragaSvarRepository.save(fraga); SendMedicalCertificateQuestionType sendType = new SendMedicalCertificateQuestionType(); QuestionToFkType question = FKQuestionConverter.convert(saved); if ("true".equalsIgnoreCase(forceFullstandigtNamn)) { question.getLakarutlatande().getPatient().setFullstandigtNamn("---"); } sendType.setQuestion(question); AttributedURIType logicalAddress = new AttributedURIType(); logicalAddress.setValue(sendQuestionToFkLogicalAddress); SendMedicalCertificateQuestionResponseType response; try { response = sendQuestionToFKClient.sendMedicalCertificateQuestion(logicalAddress, sendType); } catch (SOAPFaultException e) { LOGGER.error("Failed to send question to FK, error was: " + e.getMessage()); throw new WebCertServiceException(WebCertServiceErrorCodeEnum.EXTERNAL_SYSTEM_PROBLEM, e.getMessage()); } if (!response.getResult().getResultCode().equals(ResultCodeEnum.OK)) { LOGGER.error("Failed to send question to FK, result was " + response.getResult().toString()); throw new WebCertServiceException(WebCertServiceErrorCodeEnum.EXTERNAL_SYSTEM_PROBLEM, response.getResult() .getErrorText()); } monitoringService.logQuestionSent(saved.getExternReferens(), saved.getInternReferens(), (saved.getIntygsReferens() == null) ? null : saved.getIntygsReferens().getIntygsId(), saved.getVardperson().getEnhetsId(), saved.getAmne()); sendNotification(saved, NotificationEvent.NEW_QUESTION_FROM_CARE); certificateEventService.createCertificateEvent(intygId, user.getHsaId(), EventCode.NYFRFV, amne.name()); arendeDraftService.delete(intygId, null); return saved; }  }
FragaSvarServiceImpl implements FragaSvarService { @Override public FragaSvar saveNewQuestion(String intygId, String typ, Amne amne, String frageText) { if (Strings.isNullOrEmpty(frageText)) { throw new WebCertServiceException(WebCertServiceErrorCodeEnum.INTERNAL_PROBLEM, "frageText cannot be empty!"); } if (amne == null) { throw new WebCertServiceException(WebCertServiceErrorCodeEnum.INTERNAL_PROBLEM, "Amne cannot be null!"); } else if (!VALID_VARD_AMNEN.contains(amne)) { throw new WebCertServiceException(WebCertServiceErrorCodeEnum.INTERNAL_PROBLEM, "Invalid Amne " + amne + " for new question from vard!"); } IntygContentHolder intyg = intygService.fetchIntygData(intygId, typ, false); WebCertUser user = webCertUserService.getUser(); verifyEnhetsAuth(intyg.getUtlatande().getGrundData().getSkapadAv().getVardenhet().getEnhetsid(), false); if (!isCertificateSentToFK(intyg.getStatuses())) { throw new WebCertServiceException(WebCertServiceErrorCodeEnum.INTERNAL_PROBLEM, "FS-001: Certificate must be sent to FK first before sending question!"); } if (intyg.isRevoked()) { throw new WebCertServiceException(WebCertServiceErrorCodeEnum.INTERNAL_PROBLEM, "FS-XXX: Cannot save Fraga when certificate is revoked!"); } IntygsReferens intygsReferens = FragaSvarConverter.convertToIntygsReferens(intyg.getUtlatande()); HoSPersonal hoSPersonal = IntygConverterUtil.buildHosPersonalFromWebCertUser(user, null); Vardperson vardPerson = FragaSvarConverter.convert(hoSPersonal); FragaSvar fraga = new FragaSvar(); fraga.setFrageStallare(FrageStallare.WEBCERT.getKod()); fraga.setAmne(amne); fraga.setFrageText(frageText); LocalDateTime now = LocalDateTime.now(); fraga.setFrageSkickadDatum(now); fraga.setFrageSigneringsDatum(now); fraga.setIntygsReferens(intygsReferens); fraga.setVardperson(vardPerson); fraga.setStatus(Status.PENDING_EXTERNAL_ACTION); fraga.setVardAktorHsaId(user.getHsaId()); fraga.setVardAktorNamn(user.getNamn()); FragaSvar saved = fragaSvarRepository.save(fraga); SendMedicalCertificateQuestionType sendType = new SendMedicalCertificateQuestionType(); QuestionToFkType question = FKQuestionConverter.convert(saved); if ("true".equalsIgnoreCase(forceFullstandigtNamn)) { question.getLakarutlatande().getPatient().setFullstandigtNamn("---"); } sendType.setQuestion(question); AttributedURIType logicalAddress = new AttributedURIType(); logicalAddress.setValue(sendQuestionToFkLogicalAddress); SendMedicalCertificateQuestionResponseType response; try { response = sendQuestionToFKClient.sendMedicalCertificateQuestion(logicalAddress, sendType); } catch (SOAPFaultException e) { LOGGER.error("Failed to send question to FK, error was: " + e.getMessage()); throw new WebCertServiceException(WebCertServiceErrorCodeEnum.EXTERNAL_SYSTEM_PROBLEM, e.getMessage()); } if (!response.getResult().getResultCode().equals(ResultCodeEnum.OK)) { LOGGER.error("Failed to send question to FK, result was " + response.getResult().toString()); throw new WebCertServiceException(WebCertServiceErrorCodeEnum.EXTERNAL_SYSTEM_PROBLEM, response.getResult() .getErrorText()); } monitoringService.logQuestionSent(saved.getExternReferens(), saved.getInternReferens(), (saved.getIntygsReferens() == null) ? null : saved.getIntygsReferens().getIntygsId(), saved.getVardperson().getEnhetsId(), saved.getAmne()); sendNotification(saved, NotificationEvent.NEW_QUESTION_FROM_CARE); certificateEventService.createCertificateEvent(intygId, user.getHsaId(), EventCode.NYFRFV, amne.name()); arendeDraftService.delete(intygId, null); return saved; }  @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 FragaSvar saveNewQuestion(String intygId, String typ, Amne amne, String frageText) { if (Strings.isNullOrEmpty(frageText)) { throw new WebCertServiceException(WebCertServiceErrorCodeEnum.INTERNAL_PROBLEM, "frageText cannot be empty!"); } if (amne == null) { throw new WebCertServiceException(WebCertServiceErrorCodeEnum.INTERNAL_PROBLEM, "Amne cannot be null!"); } else if (!VALID_VARD_AMNEN.contains(amne)) { throw new WebCertServiceException(WebCertServiceErrorCodeEnum.INTERNAL_PROBLEM, "Invalid Amne " + amne + " for new question from vard!"); } IntygContentHolder intyg = intygService.fetchIntygData(intygId, typ, false); WebCertUser user = webCertUserService.getUser(); verifyEnhetsAuth(intyg.getUtlatande().getGrundData().getSkapadAv().getVardenhet().getEnhetsid(), false); if (!isCertificateSentToFK(intyg.getStatuses())) { throw new WebCertServiceException(WebCertServiceErrorCodeEnum.INTERNAL_PROBLEM, "FS-001: Certificate must be sent to FK first before sending question!"); } if (intyg.isRevoked()) { throw new WebCertServiceException(WebCertServiceErrorCodeEnum.INTERNAL_PROBLEM, "FS-XXX: Cannot save Fraga when certificate is revoked!"); } IntygsReferens intygsReferens = FragaSvarConverter.convertToIntygsReferens(intyg.getUtlatande()); HoSPersonal hoSPersonal = IntygConverterUtil.buildHosPersonalFromWebCertUser(user, null); Vardperson vardPerson = FragaSvarConverter.convert(hoSPersonal); FragaSvar fraga = new FragaSvar(); fraga.setFrageStallare(FrageStallare.WEBCERT.getKod()); fraga.setAmne(amne); fraga.setFrageText(frageText); LocalDateTime now = LocalDateTime.now(); fraga.setFrageSkickadDatum(now); fraga.setFrageSigneringsDatum(now); fraga.setIntygsReferens(intygsReferens); fraga.setVardperson(vardPerson); fraga.setStatus(Status.PENDING_EXTERNAL_ACTION); fraga.setVardAktorHsaId(user.getHsaId()); fraga.setVardAktorNamn(user.getNamn()); FragaSvar saved = fragaSvarRepository.save(fraga); SendMedicalCertificateQuestionType sendType = new SendMedicalCertificateQuestionType(); QuestionToFkType question = FKQuestionConverter.convert(saved); if ("true".equalsIgnoreCase(forceFullstandigtNamn)) { question.getLakarutlatande().getPatient().setFullstandigtNamn("---"); } sendType.setQuestion(question); AttributedURIType logicalAddress = new AttributedURIType(); logicalAddress.setValue(sendQuestionToFkLogicalAddress); SendMedicalCertificateQuestionResponseType response; try { response = sendQuestionToFKClient.sendMedicalCertificateQuestion(logicalAddress, sendType); } catch (SOAPFaultException e) { LOGGER.error("Failed to send question to FK, error was: " + e.getMessage()); throw new WebCertServiceException(WebCertServiceErrorCodeEnum.EXTERNAL_SYSTEM_PROBLEM, e.getMessage()); } if (!response.getResult().getResultCode().equals(ResultCodeEnum.OK)) { LOGGER.error("Failed to send question to FK, result was " + response.getResult().toString()); throw new WebCertServiceException(WebCertServiceErrorCodeEnum.EXTERNAL_SYSTEM_PROBLEM, response.getResult() .getErrorText()); } monitoringService.logQuestionSent(saved.getExternReferens(), saved.getInternReferens(), (saved.getIntygsReferens() == null) ? null : saved.getIntygsReferens().getIntygsId(), saved.getVardperson().getEnhetsId(), saved.getAmne()); sendNotification(saved, NotificationEvent.NEW_QUESTION_FROM_CARE); certificateEventService.createCertificateEvent(intygId, user.getHsaId(), EventCode.NYFRFV, amne.name()); arendeDraftService.delete(intygId, null); return saved; }  @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);  }