use of se.inera.intyg.webcert.web.service.intyg.dto.IntygWithNotificationsResponse in project webcert by sklintyg.
the class ListCertificatesForCareWithQAResponderImplTest method testListCertificatesForCareWithQA.
@Test
public void testListCertificatesForCareWithQA() {
final Personnummer personnummer = Personnummer.createPersonnummer("191212121212").get();
final String enhet = "enhetHsaId";
final LocalDate deadline = LocalDate.of(2017, 1, 1);
final String reference = "ref";
Handelse handelse = new Handelse();
handelse.setCode(HandelsekodEnum.SKAPAT);
handelse.setTimestamp(LocalDateTime.now());
handelse.setAmne(ArendeAmne.AVSTMN);
handelse.setSistaDatumForSvar(deadline);
when(intygService.listCertificatesForCareWithQA(any(IntygWithNotificationsRequest.class))).thenReturn(Arrays.asList(new IntygWithNotificationsResponse(null, Arrays.asList(handelse), new ArendeCount(1, 1, 1, 1), new ArendeCount(2, 2, 2, 2), reference)));
ListCertificatesForCareWithQAType request = new ListCertificatesForCareWithQAType();
PersonId personId = new PersonId();
personId.setExtension(personnummer.getPersonnummer());
request.setPersonId(personId);
HsaId hsaId = new HsaId();
hsaId.setExtension(enhet);
request.getEnhetsId().add(hsaId);
ListCertificatesForCareWithQAResponseType response = responder.listCertificatesForCareWithQA("logicalAdress", request);
assertNotNull(response);
assertNotNull(response.getList());
assertNotNull(response.getList().getItem());
assertEquals(1, response.getList().getItem().size());
assertEquals(1, response.getList().getItem().get(0).getHandelser().getHandelse().size());
assertEquals(reference, response.getList().getItem().get(0).getRef());
assertEquals(deadline, response.getList().getItem().get(0).getHandelser().getHandelse().get(0).getSistaDatumForSvar());
assertEquals(HandelsekodEnum.SKAPAT.name(), response.getList().getItem().get(0).getHandelser().getHandelse().get(0).getHandelsekod().getCode());
assertEquals(ArendeAmne.AVSTMN.name(), response.getList().getItem().get(0).getHandelser().getHandelse().get(0).getAmne().getCode());
}
use of se.inera.intyg.webcert.web.service.intyg.dto.IntygWithNotificationsResponse 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;
}
Aggregations