Search in sources :

Example 21 with ModuleApi

use of se.inera.intyg.common.support.modules.support.api.ModuleApi in project webcert by sklintyg.

the class CertificateRevokeProcessor method process.

public void process(@Body String xmlBody, @Header(Constants.INTYGS_ID) String intygsId, @Header(Constants.LOGICAL_ADDRESS) String logicalAddress, @Header(Constants.INTYGS_TYP) String intygsTyp) throws TemporaryException, PermanentException {
    checkArgument(!Strings.isNullOrEmpty(intygsId), "Message of type %s does not have a %s header.", Constants.REVOKE_MESSAGE, Constants.INTYGS_ID);
    checkArgument(!Strings.isNullOrEmpty(logicalAddress), "Message of type %s does not have a %s header.", Constants.REVOKE_MESSAGE, Constants.LOGICAL_ADDRESS);
    checkArgument(!Strings.isNullOrEmpty(intygsTyp), "Message of type %s does not have a %s header.", Constants.REVOKE_MESSAGE, Constants.INTYGS_TYP);
    try {
        ModuleApi moduleApi = registry.getModuleApi(intygsTyp);
        moduleApi.revokeCertificate(xmlBody, logicalAddress);
    } catch (ExternalServiceCallException e) {
        switch(e.getErroIdEnum()) {
            case TECHNICAL_ERROR:
            case APPLICATION_ERROR:
                throw new TemporaryException(e.getMessage());
            default:
                throw new PermanentException(e.getMessage());
        }
    } catch (ModuleException e) {
        throw new PermanentException(e.getMessage());
    } catch (WebServiceException e) {
        throw new TemporaryException(e.getMessage());
    } catch (Exception e) {
        throw new PermanentException(e.getMessage());
    }
}
Also used : ModuleApi(se.inera.intyg.common.support.modules.support.api.ModuleApi) TemporaryException(se.inera.intyg.webcert.common.sender.exception.TemporaryException) WebServiceException(javax.xml.ws.WebServiceException) PermanentException(se.inera.intyg.webcert.common.sender.exception.PermanentException) ModuleException(se.inera.intyg.common.support.modules.support.api.exception.ModuleException) ExternalServiceCallException(se.inera.intyg.common.support.modules.support.api.exception.ExternalServiceCallException) ModuleException(se.inera.intyg.common.support.modules.support.api.exception.ModuleException) TemporaryException(se.inera.intyg.webcert.common.sender.exception.TemporaryException) PermanentException(se.inera.intyg.webcert.common.sender.exception.PermanentException) WebServiceException(javax.xml.ws.WebServiceException) ExternalServiceCallException(se.inera.intyg.common.support.modules.support.api.exception.ExternalServiceCallException)

Example 22 with ModuleApi

use of se.inera.intyg.common.support.modules.support.api.ModuleApi in project webcert by sklintyg.

the class CertificateRevokeProcessorTest method testRevokeCertificateOnApplicationErrorResponse.

@Test(expected = TemporaryException.class)
public void testRevokeCertificateOnApplicationErrorResponse() throws Exception {
    ModuleApi moduleApi = mock(ModuleApi.class);
    when(registry.getModuleApi(eq(INTYGS_TYP))).thenReturn(moduleApi);
    doThrow(new ExternalServiceCallException("message", ExternalServiceCallException.ErrorIdEnum.APPLICATION_ERROR)).when(moduleApi).revokeCertificate(eq(BODY), eq(LOGICAL_ADDRESS1));
    certificateRevokeProcessor.process(BODY, INTYGS_ID1, LOGICAL_ADDRESS1, INTYGS_TYP);
}
Also used : ModuleApi(se.inera.intyg.common.support.modules.support.api.ModuleApi) ExternalServiceCallException(se.inera.intyg.common.support.modules.support.api.exception.ExternalServiceCallException) Test(org.junit.Test)

Example 23 with ModuleApi

use of se.inera.intyg.common.support.modules.support.api.ModuleApi in project webcert by sklintyg.

the class CertificateRevokeProcessorTest method testRevokeCertificateOnTechnicalErrorResponse.

@Test(expected = TemporaryException.class)
public void testRevokeCertificateOnTechnicalErrorResponse() throws Exception {
    ModuleApi moduleApi = mock(ModuleApi.class);
    when(registry.getModuleApi(eq(INTYGS_TYP))).thenReturn(moduleApi);
    doThrow(new ExternalServiceCallException("message", ExternalServiceCallException.ErrorIdEnum.TECHNICAL_ERROR)).when(moduleApi).revokeCertificate(eq(BODY), eq(LOGICAL_ADDRESS1));
    certificateRevokeProcessor.process(BODY, INTYGS_ID1, LOGICAL_ADDRESS1, INTYGS_TYP);
}
Also used : ModuleApi(se.inera.intyg.common.support.modules.support.api.ModuleApi) ExternalServiceCallException(se.inera.intyg.common.support.modules.support.api.exception.ExternalServiceCallException) Test(org.junit.Test)

Example 24 with ModuleApi

use of se.inera.intyg.common.support.modules.support.api.ModuleApi in project webcert by sklintyg.

the class CertificateRevokeProcessorTest method testRevokeCertificate.

@Test
public void testRevokeCertificate() throws Exception {
    ModuleApi moduleApi = mock(ModuleApi.class);
    when(registry.getModuleApi(eq(INTYGS_TYP))).thenReturn(moduleApi);
    certificateRevokeProcessor.process(BODY, INTYGS_ID1, LOGICAL_ADDRESS1, INTYGS_TYP);
    verify(moduleApi).revokeCertificate(eq(BODY), eq(LOGICAL_ADDRESS1));
}
Also used : ModuleApi(se.inera.intyg.common.support.modules.support.api.ModuleApi) Test(org.junit.Test)

Example 25 with ModuleApi

use of se.inera.intyg.common.support.modules.support.api.ModuleApi in project webcert by sklintyg.

the class IntygServiceImpl method listCertificatesForCareWithQA.

@Override
public List<IntygWithNotificationsResponse> listCertificatesForCareWithQA(IntygWithNotificationsRequest request) {
    List<Utkast> utkastList;
    if (request.shouldUseEnhetId()) {
        utkastList = utkastRepository.findDraftsByPatientAndEnhetAndStatus(DaoUtil.formatPnrForPersistence(request.getPersonnummer()), request.getEnhetId(), Arrays.asList(UtkastStatus.values()), moduleRegistry.listAllModules().stream().map(IntygModule::getId).collect(Collectors.toSet()));
    } else {
        utkastList = utkastRepository.findDraftsByPatientAndVardgivareAndStatus(DaoUtil.formatPnrForPersistence(request.getPersonnummer()), request.getVardgivarId(), Arrays.asList(UtkastStatus.values()), moduleRegistry.listAllModules().stream().map(IntygModule::getId).collect(Collectors.toSet()));
    }
    List<IntygWithNotificationsResponse> res = new ArrayList<>();
    for (Utkast utkast : utkastList) {
        List<Handelse> notifications = notificationService.getNotifications(utkast.getIntygsId());
        String ref = referensService.getReferensForIntygsId(utkast.getIntygsId());
        notifications = notifications.stream().filter(handelse -> {
            if (request.getStartDate() != null && handelse.getTimestamp().isBefore(request.getStartDate())) {
                return false;
            }
            if (request.getEndDate() != null && handelse.getTimestamp().isAfter(request.getEndDate())) {
                return false;
            }
            return true;
        }).collect(Collectors.toList());
        // this time span
        if ((request.getStartDate() != null || request.getEndDate() != null) && notifications.isEmpty()) {
            continue;
        }
        try {
            ModuleApi api = moduleRegistry.getModuleApi(utkast.getIntygsTyp());
            Intyg intyg = api.getIntygFromUtlatande(api.getUtlatandeFromJson(utkast.getModel()));
            Pair<ArendeCount, ArendeCount> arenden = fragorOchSvarCreator.createArenden(utkast.getIntygsId(), utkast.getIntygsTyp());
            res.add(new IntygWithNotificationsResponse(intyg, notifications, arenden.getLeft(), arenden.getRight(), ref));
        } catch (ModuleNotFoundException | ModuleException | IOException e) {
            LOG.error("Could not convert intyg {} to external format", utkast.getIntygsId());
        }
    }
    return res;
}
Also used : ModuleApi(se.inera.intyg.common.support.modules.support.api.ModuleApi) ModuleNotFoundException(se.inera.intyg.common.support.modules.registry.ModuleNotFoundException) Intyg(se.riv.clinicalprocess.healthcond.certificate.v3.Intyg) ArendeCount(se.inera.intyg.common.support.modules.support.api.notification.ArendeCount) ArrayList(java.util.ArrayList) IOException(java.io.IOException) Utkast(se.inera.intyg.webcert.persistence.utkast.model.Utkast) IntygWithNotificationsResponse(se.inera.intyg.webcert.web.service.intyg.dto.IntygWithNotificationsResponse) ModuleException(se.inera.intyg.common.support.modules.support.api.exception.ModuleException) Handelse(se.inera.intyg.webcert.persistence.handelse.model.Handelse)

Aggregations

ModuleApi (se.inera.intyg.common.support.modules.support.api.ModuleApi)27 ModuleException (se.inera.intyg.common.support.modules.support.api.exception.ModuleException)13 ModuleNotFoundException (se.inera.intyg.common.support.modules.registry.ModuleNotFoundException)12 Utkast (se.inera.intyg.webcert.persistence.utkast.model.Utkast)11 Test (org.junit.Test)10 IOException (java.io.IOException)8 Utlatande (se.inera.intyg.common.support.model.common.internal.Utlatande)7 WebCertServiceException (se.inera.intyg.webcert.common.service.exception.WebCertServiceException)7 Patient (se.inera.intyg.common.support.model.common.internal.Patient)6 ExternalServiceCallException (se.inera.intyg.common.support.modules.support.api.exception.ExternalServiceCallException)5 Personnummer (se.inera.intyg.schemas.contract.Personnummer)5 ArrayList (java.util.ArrayList)3 WebServiceException (javax.xml.ws.WebServiceException)3 Transactional (org.springframework.transaction.annotation.Transactional)3 UtkastStatus (se.inera.intyg.webcert.common.model.UtkastStatus)3 Intyg (se.riv.clinicalprocess.healthcond.certificate.v3.Intyg)3 LocalDateTime (java.time.LocalDateTime)2 OptimisticLockException (javax.persistence.OptimisticLockException)2 Relation (se.inera.intyg.common.support.model.common.internal.Relation)2 Vardenhet (se.inera.intyg.common.support.model.common.internal.Vardenhet)2