Search in sources :

Example 1 with CertificateSenderException

use of se.inera.intyg.webcert.web.service.certificatesender.CertificateSenderException in project webcert by sklintyg.

the class ArendeServiceTest method answerKompltQuestionClosesAllCompletionsAsHandled.

@Test
public void answerKompltQuestionClosesAllCompletionsAsHandled() throws CertificateSenderException {
    final String svarPaMeddelandeId = "svarPaMeddelandeId";
    Arende fraga = buildArende(svarPaMeddelandeId, ENHET_ID);
    fraga.setStatus(Status.PENDING_INTERNAL_ACTION);
    fraga.setAmne(ArendeAmne.KOMPLT);
    fraga.setPatientPersonId(PERSON_ID);
    Arende komplt1 = buildArende(UUID.randomUUID().toString(), ENHET_ID);
    komplt1.setStatus(Status.PENDING_INTERNAL_ACTION);
    komplt1.setAmne(ArendeAmne.KOMPLT);
    komplt1.setPatientPersonId(PERSON_ID);
    Arende komplt2 = buildArende(UUID.randomUUID().toString(), ENHET_ID);
    komplt2.setStatus(Status.PENDING_INTERNAL_ACTION);
    komplt2.setAmne(ArendeAmne.KOMPLT);
    komplt2.setPatientPersonId(PERSON_ID);
    Arende otherSubject = buildArende(UUID.randomUUID().toString(), ENHET_ID);
    otherSubject.setStatus(Status.PENDING_INTERNAL_ACTION);
    otherSubject.setAmne(ArendeAmne.AVSTMN);
    otherSubject.setPatientPersonId(PERSON_ID);
    when(arendeRepository.findByIntygsId(INTYG_ID)).thenReturn(Arrays.asList(fraga, komplt1, otherSubject, komplt2));
    when(webcertUserService.isAuthorizedForUnit(anyString(), anyBoolean())).thenReturn(true);
    WebCertUser webcertUser = createUser();
    when(webcertUserService.getUser()).thenReturn(webcertUser);
    List<ArendeConversationView> result = service.answerKomplettering(INTYG_ID, "svarstext");
    verify(notificationService).sendNotificationForQAs(INTYG_ID, NotificationEvent.NEW_ANSWER_FROM_CARE);
    verify(arendeRepository).findByIntygsId(INTYG_ID);
    verify(arendeDraftService, times(3)).delete(eq(INTYG_ID), anyString());
    assertTrue(result.stream().map(ArendeConversationView::getFraga).filter(f -> f.getAmne() == ArendeAmne.KOMPLT).allMatch(f -> f.getStatus() == Status.CLOSED));
    assertNotNull(result.stream().map(ArendeConversationView::getSvar).filter(Objects::nonNull).map(ArendeView::getInternReferens).collect(MoreCollectors.onlyElement()));
}
Also used : PatientDetailsResolver(se.inera.intyg.webcert.web.service.patient.PatientDetailsResolver) 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) Matchers.anySet(org.mockito.Matchers.anySet) ArendeView(se.inera.intyg.webcert.web.web.controller.api.dto.ArendeView) Matchers.anyBoolean(org.mockito.Matchers.anyBoolean) UtkastRepository(se.inera.intyg.webcert.persistence.utkast.repository.UtkastRepository) ArendeAmne(se.inera.intyg.webcert.persistence.arende.model.ArendeAmne) Matchers.eq(org.mockito.Matchers.eq) Status(se.inera.intyg.webcert.persistence.model.Status) MedicinsktArende(se.inera.intyg.webcert.persistence.arende.model.MedicinsktArende) org.mockito(org.mockito) SekretessStatus(se.inera.intyg.webcert.common.model.SekretessStatus) ImmutableMap(com.google.common.collect.ImmutableMap) MoreCollectors(com.google.common.collect.MoreCollectors) Personnummer(se.inera.intyg.schemas.contract.Personnummer) Signatur(se.inera.intyg.webcert.persistence.utkast.model.Signatur) Instant(java.time.Instant) Collectors(java.util.stream.Collectors) Arende(se.inera.intyg.webcert.persistence.arende.model.Arende) Utkast(se.inera.intyg.webcert.persistence.utkast.model.Utkast) ZoneId(java.time.ZoneId) QueryFragaSvarParameter(se.inera.intyg.webcert.web.service.fragasvar.dto.QueryFragaSvarParameter) Matchers.any(org.mockito.Matchers.any) NotificationEvent(se.inera.intyg.webcert.web.service.notification.NotificationEvent) Stream(java.util.stream.Stream) ArendeConversationView(se.inera.intyg.webcert.web.web.controller.api.dto.ArendeConversationView) FrageStallare(se.inera.intyg.webcert.web.service.fragasvar.dto.FrageStallare) MockitoJUnitRunner(org.mockito.junit.MockitoJUnitRunner) se.inera.intyg.infra.security.common.model(se.inera.intyg.infra.security.common.model) 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) java.util(java.util) CertificateSenderException(se.inera.intyg.webcert.web.service.certificatesender.CertificateSenderException) ArendeListItem(se.inera.intyg.webcert.web.web.controller.api.dto.ArendeListItem) RunWith(org.junit.runner.RunWith) LocalDateTime(java.time.LocalDateTime) Matchers.anyString(org.mockito.Matchers.anyString) GroupableItem(se.inera.intyg.webcert.common.model.GroupableItem) VardpersonReferens(se.inera.intyg.webcert.persistence.utkast.model.VardpersonReferens) ImmutableList(com.google.common.collect.ImmutableList) Matchers.anyLong(org.mockito.Matchers.anyLong) AuthoritiesHelper(se.inera.intyg.infra.security.authorities.AuthoritiesHelper) Before(org.junit.Before) StatisticsGroupByUtil(se.inera.intyg.webcert.web.service.util.StatisticsGroupByUtil) ArgumentMatchers.isNull(org.mockito.ArgumentMatchers.isNull) ArendeViewConverter(se.inera.intyg.webcert.web.converter.ArendeViewConverter) NotificationService(se.inera.intyg.webcert.web.service.notification.NotificationService) Test(org.junit.Test) ArendeRepository(se.inera.intyg.webcert.persistence.arende.repository.ArendeRepository) AuthoritiesConfigurationTestSetup(se.inera.intyg.webcert.web.auth.bootstrap.AuthoritiesConfigurationTestSetup) Mockito(org.mockito.Mockito) AuthoritiesResolverUtil(se.inera.intyg.infra.security.authorities.AuthoritiesResolverUtil) Vardgivare(se.inera.intyg.infra.integration.hsa.model.Vardgivare) 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) Matchers.anyList(org.mockito.Matchers.anyList) Assert(org.junit.Assert) Vardenhet(se.inera.intyg.infra.integration.hsa.model.Vardenhet) ArendeConversationView(se.inera.intyg.webcert.web.web.controller.api.dto.ArendeConversationView) MedicinsktArende(se.inera.intyg.webcert.persistence.arende.model.MedicinsktArende) Arende(se.inera.intyg.webcert.persistence.arende.model.Arende) Matchers.anyString(org.mockito.Matchers.anyString) WebCertUser(se.inera.intyg.webcert.web.service.user.dto.WebCertUser) ArendeView(se.inera.intyg.webcert.web.web.controller.api.dto.ArendeView) Test(org.junit.Test)

Example 2 with CertificateSenderException

use of se.inera.intyg.webcert.web.service.certificatesender.CertificateSenderException in project webcert by sklintyg.

the class IntygServiceImpl method revokeIntyg.

/*
     * (non-Javadoc)
     *
     * @see se.inera.intyg.webcert.web.service.intyg.IntygService#revokeIntyg(java.lang.String, java.lang.String)
     */
@Override
public IntygServiceResult revokeIntyg(String intygsId, String intygsTyp, String revokeMessage, String reason) {
    LOG.debug("Attempting to revoke intyg {}", intygsId);
    IntygContentHolder intyg = getIntygData(intygsId, intygsTyp, false);
    verifyEnhetsAuth(intyg.getUtlatande(), true);
    verifyIsSigned(intyg.getStatuses());
    if (intyg.isRevoked()) {
        LOG.debug("Certificate with id '{}' is already revoked", intygsId);
        throw new WebCertServiceException(WebCertServiceErrorCodeEnum.INVALID_STATE, "Certificate is already revoked");
    }
    try {
        certificateSenderService.revokeCertificate(intygsId, modelFacade.getRevokeCertificateRequest(intygsTyp, intyg.getUtlatande(), IntygConverterUtil.buildHosPersonalFromWebCertUser(webCertUserService.getUser(), null), revokeMessage), intygsTyp);
        whenSuccessfulRevoke(intyg.getUtlatande(), reason);
        return IntygServiceResult.OK;
    } catch (CertificateSenderException | ModuleException | IntygModuleFacadeException e) {
        throw new WebCertServiceException(WebCertServiceErrorCodeEnum.UNKNOWN_INTERNAL_PROBLEM, e.getMessage());
    }
}
Also used : IntygContentHolder(se.inera.intyg.webcert.web.service.intyg.dto.IntygContentHolder) ModuleException(se.inera.intyg.common.support.modules.support.api.exception.ModuleException) IntygModuleFacadeException(se.inera.intyg.webcert.web.service.intyg.converter.IntygModuleFacadeException) WebCertServiceException(se.inera.intyg.webcert.common.service.exception.WebCertServiceException) CertificateSenderException(se.inera.intyg.webcert.web.service.certificatesender.CertificateSenderException)

Example 3 with CertificateSenderException

use of se.inera.intyg.webcert.web.service.certificatesender.CertificateSenderException 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)

Example 4 with CertificateSenderException

use of se.inera.intyg.webcert.web.service.certificatesender.CertificateSenderException in project webcert by sklintyg.

the class IntygServiceStoreTest method testStoreIntygThrowsCertificateSenderException.

@Test(expected = WebCertServiceException.class)
public void testStoreIntygThrowsCertificateSenderException() throws Exception {
    doThrow(new CertificateSenderException("")).when(certificateSenderService).storeCertificate(eq(INTYG_ID), eq(INTYG_TYP_FK), anyString());
    intygService.storeIntyg(createUtkast());
}
Also used : CertificateSenderException(se.inera.intyg.webcert.web.service.certificatesender.CertificateSenderException) Test(org.junit.Test)

Example 5 with CertificateSenderException

use of se.inera.intyg.webcert.web.service.certificatesender.CertificateSenderException in project webcert by sklintyg.

the class IntygServiceImpl method sendIntygToCertificateSender.

protected IntygServiceResult sendIntygToCertificateSender(SendIntygConfiguration sendConfig, Utlatande intyg, boolean delay) {
    String intygsId = intyg.getId();
    String recipient = sendConfig.getRecipient();
    String intygsTyp = intyg.getTyp();
    HoSPersonal skickatAv = IntygConverterUtil.buildHosPersonalFromWebCertUser(webCertUserService.getUser(), null);
    try {
        LOG.debug("Sending intyg {} of type {} to recipient {}", intygsId, intygsTyp, recipient);
        // Ask the certificateSenderService to post a 'send' message onto the queue.
        certificateSenderService.sendCertificate(intygsId, intyg.getGrundData().getPatient().getPersonId(), objectMapper.writeValueAsString(skickatAv), recipient, delay);
        // Notify stakeholders when a certificate is sent
        notificationService.sendNotificationForIntygSent(intygsId);
        return IntygServiceResult.OK;
    } catch (WebServiceException wse) {
        LOG.error("An WebServiceException occured when trying to send intyg: " + intygsId, wse);
        return IntygServiceResult.FAILED;
    } catch (RuntimeException e) {
        LOG.error("Module problems occured when trying to send intyg " + intygsId, e);
        throw new WebCertServiceException(WebCertServiceErrorCodeEnum.MODULE_PROBLEM, e);
    } catch (JsonProcessingException e) {
        LOG.error("Error writing skickatAv as string when trying to send intyg " + intygsId, e);
        throw new WebCertServiceException(WebCertServiceErrorCodeEnum.MODULE_PROBLEM, e);
    } catch (CertificateSenderException e) {
        throw new WebCertServiceException(WebCertServiceErrorCodeEnum.MODULE_PROBLEM, e);
    }
}
Also used : HoSPersonal(se.inera.intyg.common.support.model.common.internal.HoSPersonal) WebServiceException(javax.xml.ws.WebServiceException) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException) WebCertServiceException(se.inera.intyg.webcert.common.service.exception.WebCertServiceException) CertificateSenderException(se.inera.intyg.webcert.web.service.certificatesender.CertificateSenderException)

Aggregations

CertificateSenderException (se.inera.intyg.webcert.web.service.certificatesender.CertificateSenderException)5 WebCertServiceException (se.inera.intyg.webcert.common.service.exception.WebCertServiceException)4 Test (org.junit.Test)2 Arende (se.inera.intyg.webcert.persistence.arende.model.Arende)2 MedicinsktArende (se.inera.intyg.webcert.persistence.arende.model.MedicinsktArende)2 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)1 ImmutableList (com.google.common.collect.ImmutableList)1 ImmutableMap (com.google.common.collect.ImmutableMap)1 MoreCollectors (com.google.common.collect.MoreCollectors)1 Clock (java.time.Clock)1 Instant (java.time.Instant)1 LocalDateTime (java.time.LocalDateTime)1 ZoneId (java.time.ZoneId)1 java.util (java.util)1 Collectors (java.util.stream.Collectors)1 Stream (java.util.stream.Stream)1 JAXBException (javax.xml.bind.JAXBException)1 WebServiceException (javax.xml.ws.WebServiceException)1 Assert (org.junit.Assert)1 Before (org.junit.Before)1