Search in sources :

Example 51 with WebCertServiceException

use of se.inera.intyg.webcert.common.service.exception.WebCertServiceException in project webcert by sklintyg.

the class ArendeServiceImpl method setForwarded.

@Override
@Transactional
public List<ArendeConversationView> setForwarded(String intygsId) {
    WebCertUser user = webcertUserService.getUser();
    List<Arende> arendenToForward = arendeRepository.save(arendeRepository.findByIntygsId(intygsId).stream().filter(isCorrectEnhet(user)).filter(isQuestion()).peek(arende -> authoritiesValidator.given(user, arende.getIntygTyp()).features(AuthoritiesConstants.FEATURE_HANTERA_FRAGOR).privilege(AuthoritiesConstants.PRIVILEGE_VIDAREBEFORDRA_FRAGASVAR).orThrow()).peek(Arende::setArendeToVidareBerordrat).collect(Collectors.toList()));
    if (arendenToForward.isEmpty()) {
        throw new WebCertServiceException(WebCertServiceErrorCodeEnum.DATA_NOT_FOUND, "Could not find any arende related to IntygsId: " + intygsId);
    }
    return getArendeConversationViewList(intygsId, arendenToForward);
}
Also used : Arrays(java.util.Arrays) ArendeDraft(se.inera.intyg.webcert.persistence.arende.model.ArendeDraft) PatientDetailsResolver(se.inera.intyg.webcert.web.service.patient.PatientDetailsResolver) LoggerFactory(org.slf4j.LoggerFactory) Autowired(org.springframework.beans.factory.annotation.Autowired) MonitoringLogService(se.inera.intyg.webcert.web.service.monitoring.MonitoringLogService) Lakare(se.inera.intyg.webcert.web.service.dto.Lakare) WebCertUserService(se.inera.intyg.webcert.web.service.user.WebCertUserService) CertificateSenderService(se.inera.intyg.webcert.web.service.certificatesender.CertificateSenderService) Fk7263EntryPoint(se.inera.intyg.common.fk7263.support.Fk7263EntryPoint) UtkastRepository(se.inera.intyg.webcert.persistence.utkast.repository.UtkastRepository) SendMessageToRecipientTypeConverter(se.inera.intyg.webcert.common.client.converter.SendMessageToRecipientTypeConverter) ArendeAmne(se.inera.intyg.webcert.persistence.arende.model.ArendeAmne) Map(java.util.Map) HsaEmployeeService(se.inera.intyg.infra.integration.hsa.services.HsaEmployeeService) SendMessageToRecipientType(se.riv.clinicalprocess.healthcond.certificate.sendMessageToRecipient.v2.SendMessageToRecipientType) Status(se.inera.intyg.webcert.persistence.model.Status) MedicinsktArende(se.inera.intyg.webcert.persistence.arende.model.MedicinsktArende) AuthoritiesValidator(se.inera.intyg.infra.security.authorities.validation.AuthoritiesValidator) SekretessStatus(se.inera.intyg.webcert.common.model.SekretessStatus) Predicate(java.util.function.Predicate) Personnummer(se.inera.intyg.schemas.contract.Personnummer) Set(java.util.Set) Collectors(java.util.stream.Collectors) JAXBException(javax.xml.bind.JAXBException) Arende(se.inera.intyg.webcert.persistence.arende.model.Arende) Utkast(se.inera.intyg.webcert.persistence.utkast.model.Utkast) Objects(java.util.Objects) QueryFragaSvarParameter(se.inera.intyg.webcert.web.service.fragasvar.dto.QueryFragaSvarParameter) AnsweredWithIntyg(se.inera.intyg.webcert.web.web.controller.api.dto.AnsweredWithIntyg) List(java.util.List) NotificationEvent(se.inera.intyg.webcert.web.service.notification.NotificationEvent) ArendeConversationView(se.inera.intyg.webcert.web.web.controller.api.dto.ArendeConversationView) FrageStallare(se.inera.intyg.webcert.web.service.fragasvar.dto.FrageStallare) NotNull(org.jetbrains.annotations.NotNull) WebCertServiceException(se.inera.intyg.webcert.common.service.exception.WebCertServiceException) Filter(se.inera.intyg.webcert.persistence.model.Filter) FragaSvarService(se.inera.intyg.webcert.web.service.fragasvar.FragaSvarService) SendMessageToRecipientTypeBuilder(se.inera.intyg.webcert.web.integration.builders.SendMessageToRecipientTypeBuilder) CertificateSenderException(se.inera.intyg.webcert.web.service.certificatesender.CertificateSenderException) ArendeListItem(se.inera.intyg.webcert.web.web.controller.api.dto.ArendeListItem) LocalDateTime(java.time.LocalDateTime) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) GroupableItem(se.inera.intyg.webcert.common.model.GroupableItem) Value(org.springframework.beans.factory.annotation.Value) ArendeConverter(se.inera.intyg.webcert.web.converter.ArendeConverter) Strings(com.google.common.base.Strings) ArendeListItemConverter(se.inera.intyg.webcert.web.converter.ArendeListItemConverter) TsBasEntryPoint(se.inera.intyg.common.ts_bas.support.TsBasEntryPoint) Service(org.springframework.stereotype.Service) AuthoritiesHelper(se.inera.intyg.infra.security.authorities.AuthoritiesHelper) AnsweredWithIntygUtil(se.inera.intyg.webcert.web.converter.util.AnsweredWithIntygUtil) StatisticsGroupByUtil(se.inera.intyg.webcert.web.service.util.StatisticsGroupByUtil) ArendeViewConverter(se.inera.intyg.webcert.web.converter.ArendeViewConverter) NotificationService(se.inera.intyg.webcert.web.service.notification.NotificationService) Logger(org.slf4j.Logger) ArendeRepository(se.inera.intyg.webcert.persistence.arende.repository.ArendeRepository) TsDiabetesEntryPoint(se.inera.intyg.common.ts_diabetes.support.TsDiabetesEntryPoint) WebCertServiceErrorCodeEnum(se.inera.intyg.webcert.common.service.exception.WebCertServiceErrorCodeEnum) QueryFragaSvarResponse(se.inera.intyg.webcert.web.service.fragasvar.dto.QueryFragaSvarResponse) WebCertUser(se.inera.intyg.webcert.web.service.user.dto.WebCertUser) Clock(java.time.Clock) FilterConverter(se.inera.intyg.webcert.web.converter.FilterConverter) Preconditions(com.google.common.base.Preconditions) VisibleForTesting(com.google.common.annotations.VisibleForTesting) AuthoritiesConstants(se.inera.intyg.infra.security.common.model.AuthoritiesConstants) Comparator(java.util.Comparator) Transactional(org.springframework.transaction.annotation.Transactional) MedicinsktArende(se.inera.intyg.webcert.persistence.arende.model.MedicinsktArende) Arende(se.inera.intyg.webcert.persistence.arende.model.Arende) WebCertServiceException(se.inera.intyg.webcert.common.service.exception.WebCertServiceException) WebCertUser(se.inera.intyg.webcert.web.service.user.dto.WebCertUser) Transactional(org.springframework.transaction.annotation.Transactional)

Example 52 with WebCertServiceException

use of se.inera.intyg.webcert.common.service.exception.WebCertServiceException in project webcert by sklintyg.

the class ArendeServiceImpl method createMessage.

@Override
public ArendeConversationView createMessage(String intygId, ArendeAmne amne, String rubrik, String meddelande) {
    if (!VALID_VARD_AMNEN.contains(amne)) {
        throw new WebCertServiceException(WebCertServiceErrorCodeEnum.INTERNAL_PROBLEM, "Invalid Amne " + amne + " for new question from vard!");
    }
    Utkast utkast = utkastRepository.findOne(intygId);
    validateArende(intygId, utkast);
    verifyEnhetsAuth(utkast.getEnhetsId(), false);
    Arende arende = ArendeConverter.createArendeFromUtkast(amne, rubrik, meddelande, utkast, LocalDateTime.now(systemClock), webcertUserService.getUser().getNamn(), hsaEmployeeService);
    Arende saved = processOutgoingMessage(arende, NotificationEvent.NEW_QUESTION_FROM_CARE);
    arendeDraftService.delete(intygId, null);
    return arendeViewConverter.convertToArendeConversationView(saved, null, null, new ArrayList<>(), null);
}
Also used : Utkast(se.inera.intyg.webcert.persistence.utkast.model.Utkast) MedicinsktArende(se.inera.intyg.webcert.persistence.arende.model.MedicinsktArende) Arende(se.inera.intyg.webcert.persistence.arende.model.Arende) WebCertServiceException(se.inera.intyg.webcert.common.service.exception.WebCertServiceException)

Example 53 with WebCertServiceException

use of se.inera.intyg.webcert.common.service.exception.WebCertServiceException in project webcert by sklintyg.

the class ArendeServiceImpl method answer.

@Override
public ArendeConversationView answer(String svarPaMeddelandeId, String meddelande) {
    if (Strings.isNullOrEmpty(meddelande)) {
        throw new WebCertServiceException(WebCertServiceErrorCodeEnum.INTERNAL_PROBLEM, "SvarsText cannot be empty!");
    }
    Arende svarPaMeddelande = lookupArende(svarPaMeddelandeId);
    verifyEnhetsAuth(svarPaMeddelande.getEnhetId(), false);
    if (!Status.PENDING_INTERNAL_ACTION.equals(svarPaMeddelande.getStatus())) {
        throw new WebCertServiceException(WebCertServiceErrorCodeEnum.INVALID_STATE, "Arende with id " + svarPaMeddelandeId + " has invalid state for saving answer(" + svarPaMeddelande.getStatus() + ")");
    }
    // Implement Business Rule FS-007
    if (ArendeAmne.PAMINN.equals(svarPaMeddelande.getAmne())) {
        throw new WebCertServiceException(WebCertServiceErrorCodeEnum.INTERNAL_PROBLEM, "Arende with id " + svarPaMeddelandeId + " has invalid Amne(" + svarPaMeddelande.getAmne() + ") for saving answer");
    }
    if (ArendeAmne.KOMPLT.equals(svarPaMeddelande.getAmne())) {
        throw new WebCertServiceException(WebCertServiceErrorCodeEnum.INTERNAL_PROBLEM, "Arende with id " + svarPaMeddelandeId + " has invalid Amne(" + svarPaMeddelande.getAmne() + ") for saving answer");
    }
    Arende arende = ArendeConverter.createAnswerFromArende(meddelande, svarPaMeddelande, LocalDateTime.now(systemClock), webcertUserService.getUser().getNamn());
    Arende saved = processOutgoingMessage(arende, NotificationEvent.NEW_ANSWER_FROM_CARE);
    arendeDraftService.delete(svarPaMeddelande.getIntygsId(), svarPaMeddelandeId);
    return arendeViewConverter.convertToArendeConversationView(svarPaMeddelande, saved, null, arendeRepository.findByPaminnelseMeddelandeId(svarPaMeddelandeId), null);
}
Also used : MedicinsktArende(se.inera.intyg.webcert.persistence.arende.model.MedicinsktArende) Arende(se.inera.intyg.webcert.persistence.arende.model.Arende) WebCertServiceException(se.inera.intyg.webcert.common.service.exception.WebCertServiceException)

Example 54 with WebCertServiceException

use of se.inera.intyg.webcert.common.service.exception.WebCertServiceException in project webcert by sklintyg.

the class ArendeServiceImpl method answerKomplettering.

@Override
@Transactional
public List<ArendeConversationView> answerKomplettering(final String intygsId, final String meddelande) {
    Preconditions.checkArgument(!Strings.isNullOrEmpty(intygsId));
    Preconditions.checkArgument(!Strings.isNullOrEmpty(meddelande));
    WebCertUser user = webcertUserService.getUser();
    List<Arende> allArende = getArendeForIntygId(intygsId, user);
    List<Arende> arendeList = filterKompletteringar(allArende);
    Arende latestKomplArende = getLatestKomplArende(intygsId, arendeList);
    verifyEnhetsAuth(latestKomplArende.getEnhetId(), false);
    boolean verified = authoritiesValidator.given(user, latestKomplArende.getIntygTyp()).privilege(AuthoritiesConstants.PRIVILEGE_BESVARA_KOMPLETTERINGSFRAGA).isVerified();
    if (!verified) {
        throw new WebCertServiceException(WebCertServiceErrorCodeEnum.AUTHORIZATION_PROBLEM, "Arende with id " + latestKomplArende.getId() + " and amne (" + latestKomplArende.getAmne() + ") can only be answered by user that is Lakare");
    }
    Arende answer = ArendeConverter.createAnswerFromArende(meddelande, latestKomplArende, LocalDateTime.now(systemClock), user.getNamn());
    Arende saved = processOutgoingMessage(answer, NotificationEvent.NEW_ANSWER_FROM_CARE);
    arendeList.stream().forEach(this::closeArendeAsHandled);
    allArende.add(saved);
    return getArendeConversationViewList(intygsId, allArende);
}
Also used : MedicinsktArende(se.inera.intyg.webcert.persistence.arende.model.MedicinsktArende) Arende(se.inera.intyg.webcert.persistence.arende.model.Arende) WebCertServiceException(se.inera.intyg.webcert.common.service.exception.WebCertServiceException) WebCertUser(se.inera.intyg.webcert.web.service.user.dto.WebCertUser) Transactional(org.springframework.transaction.annotation.Transactional)

Example 55 with WebCertServiceException

use of se.inera.intyg.webcert.common.service.exception.WebCertServiceException in project webcert by sklintyg.

the class ArendeServiceImpl method processOutgoingMessage.

private Arende processOutgoingMessage(Arende arende, NotificationEvent notificationEvent) {
    Arende saved = arendeRepository.save(arende);
    monitoringLog.logArendeCreated(arende.getIntygsId(), arende.getIntygTyp(), arende.getEnhetId(), arende.getAmne(), arende.getSvarPaId() != null);
    updateRelated(arende);
    SendMessageToRecipientType request = SendMessageToRecipientTypeBuilder.build(arende, webcertUserService.getUser(), sendMessageToFKLogicalAddress);
    // Send to recipient
    try {
        certificateSenderService.sendMessageToRecipient(arende.getIntygsId(), SendMessageToRecipientTypeConverter.toXml(request));
    } catch (JAXBException | CertificateSenderException e) {
        throw new WebCertServiceException(WebCertServiceErrorCodeEnum.INTERNAL_PROBLEM, e.getMessage());
    }
    sendNotification(saved, notificationEvent);
    return saved;
}
Also used : JAXBException(javax.xml.bind.JAXBException) MedicinsktArende(se.inera.intyg.webcert.persistence.arende.model.MedicinsktArende) Arende(se.inera.intyg.webcert.persistence.arende.model.Arende) SendMessageToRecipientType(se.riv.clinicalprocess.healthcond.certificate.sendMessageToRecipient.v2.SendMessageToRecipientType) WebCertServiceException(se.inera.intyg.webcert.common.service.exception.WebCertServiceException) CertificateSenderException(se.inera.intyg.webcert.web.service.certificatesender.CertificateSenderException)

Aggregations

WebCertServiceException (se.inera.intyg.webcert.common.service.exception.WebCertServiceException)85 Utkast (se.inera.intyg.webcert.persistence.utkast.model.Utkast)35 Test (org.junit.Test)16 WebCertUser (se.inera.intyg.webcert.web.service.user.dto.WebCertUser)16 ModuleNotFoundException (se.inera.intyg.common.support.modules.registry.ModuleNotFoundException)14 ModuleException (se.inera.intyg.common.support.modules.support.api.exception.ModuleException)14 Arende (se.inera.intyg.webcert.persistence.arende.model.Arende)13 OptimisticLockException (javax.persistence.OptimisticLockException)12 MedicinsktArende (se.inera.intyg.webcert.persistence.arende.model.MedicinsktArende)11 Personnummer (se.inera.intyg.schemas.contract.Personnummer)10 SignaturTicket (se.inera.intyg.webcert.web.service.signatur.dto.SignaturTicket)10 Path (javax.ws.rs.Path)9 Produces (javax.ws.rs.Produces)9 SekretessStatus (se.inera.intyg.webcert.common.model.SekretessStatus)9 OptimisticLockingFailureException (org.springframework.dao.OptimisticLockingFailureException)7 Transactional (org.springframework.transaction.annotation.Transactional)7 POST (javax.ws.rs.POST)6 ModuleApi (se.inera.intyg.common.support.modules.support.api.ModuleApi)6 Signatur (se.inera.intyg.webcert.persistence.utkast.model.Signatur)6 LocalDateTime (java.time.LocalDateTime)5