use of se.inera.intyg.common.support.modules.support.api.exception.ModuleException 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.exception.ModuleException in project webcert by sklintyg.
the class IntygModuleFacadeImpl method convertFromInternalToPdfDocument.
@Override
public IntygPdf convertFromInternalToPdfDocument(String intygType, String internalIntygJsonModel, List<Status> statuses, boolean isEmployer) throws IntygModuleFacadeException {
boolean isUtkast = isUtkast(statuses);
try {
ModuleApi moduleApi = moduleRegistry.getModuleApi(intygType);
PdfResponse pdfResponse;
if (!isEmployer) {
pdfResponse = moduleApi.pdf(internalIntygJsonModel, statuses, ApplicationOrigin.WEBCERT, isUtkast);
} else {
pdfResponse = moduleApi.pdfEmployer(internalIntygJsonModel, statuses, ApplicationOrigin.WEBCERT, Collections.emptyList(), isUtkast);
}
return new IntygPdf(pdfResponse.getPdfData(), pdfResponse.getFilename());
} catch (ModuleException me) {
LOG.error("ModuleException occured when when generating PDF document from internal");
throw new IntygModuleFacadeException("ModuleException occured when generating PDF document from internal", me);
} catch (ModuleNotFoundException e) {
LOG.error("ModuleNotFoundException occured for intygstyp '{}' when generating PDF document from internal", intygType);
throw new IntygModuleFacadeException("ModuleNotFoundException occured when registering certificate", e);
}
}
Aggregations