Search in sources :

Example 1 with Handelse

use of se.inera.intyg.webcert.persistence.handelse.model.Handelse in project webcert by sklintyg.

the class IntygServiceTest method testListCertificatesForCareWithQAOk.

@Test
public void testListCertificatesForCareWithQAOk() throws Exception {
    final List<String> enhetList = Arrays.asList("enhet");
    final String intygType = "intygType";
    final String intygId = "intygId";
    final LocalDateTime localDateTime = LocalDateTime.of(2017, Month.JANUARY, 1, 1, 1);
    Handelse handelse = new Handelse();
    handelse.setTimestamp(localDateTime);
    handelse.setCode(HandelsekodEnum.SKAPAT);
    Fk7263Utlatande utlatande = objectMapper.readValue(json, Fk7263Utlatande.class);
    ArendeCount sent = new ArendeCount(1, 2, 3, 4);
    ArendeCount received = new ArendeCount(5, 6, 7, 8);
    when(moduleRegistry.listAllModules()).thenReturn(Arrays.asList(new IntygModule(intygType, "", "", "", "", "", "", "", "", false)));
    when(utkastRepository.findDraftsByPatientAndEnhetAndStatus(eq(PERSON_ID), eq(enhetList), eq(Arrays.asList(UtkastStatus.values())), eq(Collections.singleton(intygType)))).thenReturn(Arrays.asList(getDraft(intygId)));
    when(notificationService.getNotifications(eq(intygId))).thenReturn(Arrays.asList(handelse));
    when(moduleRegistry.getModuleApi(any(String.class))).thenReturn(moduleApi);
    when(moduleApi.getUtlatandeFromJson(anyString())).thenReturn(utlatande);
    when(fragorOchSvarCreator.createArenden(eq(intygId), anyString())).thenReturn(Pair.of(sent, received));
    List<IntygWithNotificationsResponse> res = intygService.listCertificatesForCareWithQA(new IntygWithNotificationsRequest.Builder().setPersonnummer(PERSNR).setEnhetId(enhetList).build());
    assertNotNull(res);
    assertEquals(1, res.size());
    assertEquals(1, res.get(0).getNotifications().size());
    assertEquals(HandelsekodEnum.SKAPAT, res.get(0).getNotifications().get(0).getCode());
    assertEquals(localDateTime, res.get(0).getNotifications().get(0).getTimestamp());
    assertEquals(1, res.get(0).getSentQuestions().getTotalt());
    assertEquals(2, res.get(0).getSentQuestions().getEjBesvarade());
    assertEquals(3, res.get(0).getSentQuestions().getBesvarade());
    assertEquals(4, res.get(0).getSentQuestions().getHanterade());
    assertEquals(5, res.get(0).getReceivedQuestions().getTotalt());
    assertEquals(6, res.get(0).getReceivedQuestions().getEjBesvarade());
    assertEquals(7, res.get(0).getReceivedQuestions().getBesvarade());
    assertEquals(8, res.get(0).getReceivedQuestions().getHanterade());
    assertEquals(REFERENCE, res.get(0).getRef());
}
Also used : LocalDateTime(java.time.LocalDateTime) IntygModule(se.inera.intyg.common.support.modules.registry.IntygModule) Fk7263Utlatande(se.inera.intyg.common.fk7263.model.internal.Fk7263Utlatande) ArendeCount(se.inera.intyg.common.support.modules.support.api.notification.ArendeCount) IntygWithNotificationsResponse(se.inera.intyg.webcert.web.service.intyg.dto.IntygWithNotificationsResponse) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) Handelse(se.inera.intyg.webcert.persistence.handelse.model.Handelse) Test(org.junit.Test)

Example 2 with Handelse

use of se.inera.intyg.webcert.persistence.handelse.model.Handelse in project webcert by sklintyg.

the class IntygServiceTest method testListCertificatesForCareWithQAVardgivare.

@Test
public void testListCertificatesForCareWithQAVardgivare() throws Exception {
    final String vardgivarId = "vardgivarId";
    final String intygType = "intygType";
    final String intygId = "intygId";
    final LocalDateTime localDateTime = LocalDateTime.of(2017, Month.JANUARY, 1, 1, 1);
    Handelse handelse = new Handelse();
    handelse.setTimestamp(localDateTime);
    handelse.setCode(HandelsekodEnum.SKAPAT);
    Fk7263Utlatande utlatande = objectMapper.readValue(json, Fk7263Utlatande.class);
    ArendeCount sent = new ArendeCount(1, 2, 3, 4);
    ArendeCount received = new ArendeCount(5, 6, 7, 8);
    when(moduleRegistry.listAllModules()).thenReturn(Arrays.asList(new IntygModule(intygType, "", "", "", "", "", "", "", "", false)));
    when(utkastRepository.findDraftsByPatientAndVardgivareAndStatus(eq(PERSON_ID), eq(vardgivarId), eq(Arrays.asList(UtkastStatus.values())), eq(Collections.singleton(intygType)))).thenReturn(Arrays.asList(getDraft(intygId)));
    when(notificationService.getNotifications(eq(intygId))).thenReturn(Arrays.asList(handelse));
    when(moduleRegistry.getModuleApi(any(String.class))).thenReturn(moduleApi);
    when(moduleApi.getUtlatandeFromJson(anyString())).thenReturn(utlatande);
    when(fragorOchSvarCreator.createArenden(eq(intygId), anyString())).thenReturn(Pair.of(sent, received));
    List<IntygWithNotificationsResponse> res = intygService.listCertificatesForCareWithQA(new IntygWithNotificationsRequest.Builder().setPersonnummer(PERSNR).setVardgivarId(vardgivarId).build());
    assertNotNull(res);
    assertEquals(1, res.size());
    assertEquals(1, res.get(0).getNotifications().size());
    assertEquals(HandelsekodEnum.SKAPAT, res.get(0).getNotifications().get(0).getCode());
    assertEquals(localDateTime, res.get(0).getNotifications().get(0).getTimestamp());
    assertEquals(1, res.get(0).getSentQuestions().getTotalt());
    assertEquals(2, res.get(0).getSentQuestions().getEjBesvarade());
    assertEquals(3, res.get(0).getSentQuestions().getBesvarade());
    assertEquals(4, res.get(0).getSentQuestions().getHanterade());
    assertEquals(5, res.get(0).getReceivedQuestions().getTotalt());
    assertEquals(6, res.get(0).getReceivedQuestions().getEjBesvarade());
    assertEquals(7, res.get(0).getReceivedQuestions().getBesvarade());
    assertEquals(8, res.get(0).getReceivedQuestions().getHanterade());
}
Also used : LocalDateTime(java.time.LocalDateTime) IntygModule(se.inera.intyg.common.support.modules.registry.IntygModule) Fk7263Utlatande(se.inera.intyg.common.fk7263.model.internal.Fk7263Utlatande) ArendeCount(se.inera.intyg.common.support.modules.support.api.notification.ArendeCount) IntygWithNotificationsResponse(se.inera.intyg.webcert.web.service.intyg.dto.IntygWithNotificationsResponse) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) Handelse(se.inera.intyg.webcert.persistence.handelse.model.Handelse) Test(org.junit.Test)

Example 3 with Handelse

use of se.inera.intyg.webcert.persistence.handelse.model.Handelse in project webcert by sklintyg.

the class NotificationServiceImpl method save.

private void save(NotificationMessage notificationMessage, String enhetsId, String vardgivarId, String personnummer, ArendeAmne amne, LocalDate sistaDatumForSvar) {
    Handelse handelse = new Handelse();
    handelse.setCode(notificationMessage.getHandelse());
    handelse.setEnhetsId(enhetsId);
    handelse.setIntygsId(notificationMessage.getIntygsId());
    handelse.setPersonnummer(personnummer);
    handelse.setTimestamp(notificationMessage.getHandelseTid());
    handelse.setVardgivarId(vardgivarId);
    handelse.setAmne(amne);
    handelse.setSistaDatumForSvar(sistaDatumForSvar);
    handelseRepo.save(handelse);
}
Also used : Handelse(se.inera.intyg.webcert.persistence.handelse.model.Handelse)

Example 4 with Handelse

use of se.inera.intyg.webcert.persistence.handelse.model.Handelse 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());
}
Also used : Personnummer(se.inera.intyg.schemas.contract.Personnummer) ListCertificatesForCareWithQAResponseType(se.riv.clinicalprocess.healthcond.certificate.listCertificatesForCareWithQA.v3.ListCertificatesForCareWithQAResponseType) PersonId(se.riv.clinicalprocess.healthcond.certificate.types.v3.PersonId) ArendeCount(se.inera.intyg.common.support.modules.support.api.notification.ArendeCount) IntygWithNotificationsResponse(se.inera.intyg.webcert.web.service.intyg.dto.IntygWithNotificationsResponse) IntygWithNotificationsRequest(se.inera.intyg.webcert.web.service.intyg.dto.IntygWithNotificationsRequest) ListCertificatesForCareWithQAType(se.riv.clinicalprocess.healthcond.certificate.listCertificatesForCareWithQA.v3.ListCertificatesForCareWithQAType) LocalDate(java.time.LocalDate) HsaId(se.riv.clinicalprocess.healthcond.certificate.types.v3.HsaId) Handelse(se.inera.intyg.webcert.persistence.handelse.model.Handelse) Test(org.junit.Test)

Example 5 with Handelse

use of se.inera.intyg.webcert.persistence.handelse.model.Handelse 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

Handelse (se.inera.intyg.webcert.persistence.handelse.model.Handelse)5 ArendeCount (se.inera.intyg.common.support.modules.support.api.notification.ArendeCount)4 IntygWithNotificationsResponse (se.inera.intyg.webcert.web.service.intyg.dto.IntygWithNotificationsResponse)4 Test (org.junit.Test)3 LocalDateTime (java.time.LocalDateTime)2 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)2 Fk7263Utlatande (se.inera.intyg.common.fk7263.model.internal.Fk7263Utlatande)2 IntygModule (se.inera.intyg.common.support.modules.registry.IntygModule)2 IOException (java.io.IOException)1 LocalDate (java.time.LocalDate)1 ArrayList (java.util.ArrayList)1 ModuleNotFoundException (se.inera.intyg.common.support.modules.registry.ModuleNotFoundException)1 ModuleApi (se.inera.intyg.common.support.modules.support.api.ModuleApi)1 ModuleException (se.inera.intyg.common.support.modules.support.api.exception.ModuleException)1 Personnummer (se.inera.intyg.schemas.contract.Personnummer)1 Utkast (se.inera.intyg.webcert.persistence.utkast.model.Utkast)1 IntygWithNotificationsRequest (se.inera.intyg.webcert.web.service.intyg.dto.IntygWithNotificationsRequest)1 ListCertificatesForCareWithQAResponseType (se.riv.clinicalprocess.healthcond.certificate.listCertificatesForCareWithQA.v3.ListCertificatesForCareWithQAResponseType)1 ListCertificatesForCareWithQAType (se.riv.clinicalprocess.healthcond.certificate.listCertificatesForCareWithQA.v3.ListCertificatesForCareWithQAType)1 HsaId (se.riv.clinicalprocess.healthcond.certificate.types.v3.HsaId)1