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;
}
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));
}
Aggregations