Search in sources :

Example 11 with ArendeCount

use of se.inera.intyg.common.support.modules.support.api.notification.ArendeCount 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)

Example 12 with ArendeCount

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

the class FragorOchSvarCreatorImpl method performArendeCount.

private Pair<ArendeCount, ArendeCount> performArendeCount(List<Arende> arenden) {
    int skickadeFragorTotalt = 0;
    int skickadeFragorBesvarade = 0;
    int skickadeFragorEjBesvarade = 0;
    int skickadeFragorHanterade = 0;
    int mottagnaFragorTotalt = 0;
    int mottagnaFragorBesvarade = 0;
    int mottagnaFragorEjBesvarade = 0;
    int mottagnaFragorHanterade = 0;
    Set<String> isAnswered = new HashSet<>();
    for (Arende arende : arenden) {
        if (!Strings.nullToEmpty(arende.getSvarPaId()).trim().isEmpty()) {
            isAnswered.add(arende.getSvarPaId());
        }
    }
    for (Arende arende : arenden) {
        if (ArendeAmne.PAMINN == arende.getAmne() || !Strings.nullToEmpty(arende.getSvarPaId()).trim().isEmpty()) {
            // skip answers and reminders
            continue;
        }
        if (FRAGESTALLARE_WEBCERT.equalsIgnoreCase(arende.getSkickatAv())) {
            skickadeFragorTotalt++;
            if (Status.CLOSED.equals(arende.getStatus())) {
                skickadeFragorHanterade++;
            } else if (isAnswered.contains(arende.getMeddelandeId())) {
                skickadeFragorBesvarade++;
            } else {
                skickadeFragorEjBesvarade++;
            }
        } else if (FRAGESTALLARE_FK.equalsIgnoreCase(arende.getSkickatAv())) {
            mottagnaFragorTotalt++;
            if (Status.CLOSED.equals(arende.getStatus())) {
                mottagnaFragorHanterade++;
            } else if (isAnswered.contains(arende.getMeddelandeId())) {
                mottagnaFragorBesvarade++;
            } else {
                mottagnaFragorEjBesvarade++;
            }
        }
    }
    return Pair.of(new ArendeCount(skickadeFragorTotalt, skickadeFragorEjBesvarade, skickadeFragorBesvarade, skickadeFragorHanterade), new ArendeCount(mottagnaFragorTotalt, mottagnaFragorEjBesvarade, mottagnaFragorBesvarade, mottagnaFragorHanterade));
}
Also used : ArendeCount(se.inera.intyg.common.support.modules.support.api.notification.ArendeCount) Arende(se.inera.intyg.webcert.persistence.arende.model.Arende) Fk7263EntryPoint(se.inera.intyg.common.fk7263.support.Fk7263EntryPoint) HashSet(java.util.HashSet)

Aggregations

ArendeCount (se.inera.intyg.common.support.modules.support.api.notification.ArendeCount)12 Test (org.junit.Test)8 LocalDateTime (java.time.LocalDateTime)6 NotificationMessage (se.inera.intyg.common.support.modules.support.api.notification.NotificationMessage)5 IntygWithNotificationsResponse (se.inera.intyg.webcert.web.service.intyg.dto.IntygWithNotificationsResponse)5 Handelse (se.inera.intyg.webcert.persistence.handelse.model.Handelse)4 Intyg (se.riv.clinicalprocess.healthcond.certificate.v3.Intyg)4 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)3 Fk7263Utlatande (se.inera.intyg.common.fk7263.model.internal.Fk7263Utlatande)3 HandelsekodEnum (se.inera.intyg.common.support.common.enumerations.HandelsekodEnum)3 IntygModule (se.inera.intyg.common.support.modules.registry.IntygModule)3 CertificateStatusUpdateForCareType (se.riv.clinicalprocess.healthcond.certificate.certificatestatusupdateforcareresponder.v3.CertificateStatusUpdateForCareType)3 LocalDate (java.time.LocalDate)2 Fk7263EntryPoint (se.inera.intyg.common.fk7263.support.Fk7263EntryPoint)2 Utkast (se.inera.intyg.webcert.persistence.utkast.model.Utkast)2 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 HashSet (java.util.HashSet)1 ModuleNotFoundException (se.inera.intyg.common.support.modules.registry.ModuleNotFoundException)1 ModuleApi (se.inera.intyg.common.support.modules.support.api.ModuleApi)1