Search in sources :

Example 1 with IntygWithNotificationsResponse

use of se.inera.intyg.webcert.web.service.intyg.dto.IntygWithNotificationsResponse in project webcert by sklintyg.

the class ListCertificatesForCareWithQAResponderImpl method listCertificatesForCareWithQA.

@Override
public ListCertificatesForCareWithQAResponseType listCertificatesForCareWithQA(String s, ListCertificatesForCareWithQAType request) {
    Objects.requireNonNull(request.getEnhetsId());
    if (!validate(request)) {
        throw new IllegalArgumentException();
    }
    ListCertificatesForCareWithQAResponseType response = new ListCertificatesForCareWithQAResponseType();
    List list = new List();
    IntygWithNotificationsRequest.Builder builder = new IntygWithNotificationsRequest.Builder().setPersonnummer(Personnummer.createPersonnummer(request.getPersonId().getExtension()).get());
    if (!request.getEnhetsId().isEmpty()) {
        builder = builder.setEnhetId(request.getEnhetsId().stream().map(HsaId::getExtension).collect(Collectors.toList()));
    }
    if (request.getVardgivarId() != null) {
        builder = builder.setVardgivarId(request.getVardgivarId().getExtension());
    }
    if (request.getFromTidpunkt() != null) {
        builder = builder.setStartDate(request.getFromTidpunkt());
    }
    if (request.getTomTidpunkt() != null) {
        builder = builder.setEndDate(request.getTomTidpunkt());
    }
    java.util.List<IntygWithNotificationsResponse> intygWithNotifications = intygService.listCertificatesForCareWithQA(builder.build());
    for (IntygWithNotificationsResponse intygHolder : intygWithNotifications) {
        ListItem item = new ListItem();
        item.setIntyg(intygHolder.getIntyg());
        HandelseList handelseList = new HandelseList();
        handelseList.getHandelse().addAll(intygHolder.getNotifications().stream().map(ListCertificatesForCareWithQAResponderImpl::toHandelse).collect(Collectors.toList()));
        item.setHandelser(handelseList);
        item.setSkickadeFragor(toArenden(intygHolder.getSentQuestions()));
        item.setMottagnaFragor(toArenden(intygHolder.getReceivedQuestions()));
        item.setRef(intygHolder.getRef());
        list.getItem().add(item);
    }
    response.setList(list);
    return response;
}
Also used : IntygWithNotificationsResponse(se.inera.intyg.webcert.web.service.intyg.dto.IntygWithNotificationsResponse) IntygWithNotificationsRequest(se.inera.intyg.webcert.web.service.intyg.dto.IntygWithNotificationsRequest)

Example 2 with IntygWithNotificationsResponse

use of se.inera.intyg.webcert.web.service.intyg.dto.IntygWithNotificationsResponse 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 3 with IntygWithNotificationsResponse

use of se.inera.intyg.webcert.web.service.intyg.dto.IntygWithNotificationsResponse 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 4 with IntygWithNotificationsResponse

use of se.inera.intyg.webcert.web.service.intyg.dto.IntygWithNotificationsResponse in project webcert by sklintyg.

the class IntygServiceTest method testListCertificatesForCareWithQANoNotifications.

@Test
public void testListCertificatesForCareWithQANoNotifications() throws Exception {
    final List<String> enhetList = Arrays.asList("enhet");
    final String intygType = "intygType";
    final String intygId = "intygId";
    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(Collections.emptyList());
    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());
    assertTrue(res.get(0).getNotifications().isEmpty());
    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 : 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) Test(org.junit.Test)

Example 5 with IntygWithNotificationsResponse

use of se.inera.intyg.webcert.web.service.intyg.dto.IntygWithNotificationsResponse in project webcert by sklintyg.

the class IntygServiceTest method testListCertificatesForCareWithQANoNotificationsTrim.

@Test
public void testListCertificatesForCareWithQANoNotificationsTrim() throws Exception {
    final LocalDateTime start = LocalDateTime.of(2017, Month.APRIL, 1, 1, 1);
    final LocalDateTime end = LocalDateTime.of(2018, Month.APRIL, 1, 1, 1);
    final String vardgivarId = "vardgivarId";
    final String intygType = "intygType";
    final String intygId = "intygId";
    when(moduleRegistry.listAllModules()).thenReturn(Collections.singletonList(new IntygModule(intygType, "", "", "", "", "", "", "", "", false)));
    when(utkastRepository.findDraftsByPatientAndVardgivareAndStatus(eq(PERSON_ID), eq(vardgivarId), eq(Arrays.asList(UtkastStatus.values())), eq(Collections.singleton(intygType)))).thenReturn(Collections.singletonList(getDraft(intygId)));
    when(notificationService.getNotifications(eq(intygId))).thenReturn(Collections.emptyList());
    List<IntygWithNotificationsResponse> res = intygService.listCertificatesForCareWithQA(new IntygWithNotificationsRequest.Builder().setPersonnummer(PERSNR).setVardgivarId(vardgivarId).setStartDate(start).setEndDate(end).build());
    assertNotNull(res);
    assertEquals(0, res.size());
}
Also used : LocalDateTime(java.time.LocalDateTime) IntygModule(se.inera.intyg.common.support.modules.registry.IntygModule) IntygWithNotificationsResponse(se.inera.intyg.webcert.web.service.intyg.dto.IntygWithNotificationsResponse) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) Test(org.junit.Test)

Aggregations

IntygWithNotificationsResponse (se.inera.intyg.webcert.web.service.intyg.dto.IntygWithNotificationsResponse)7 Test (org.junit.Test)5 ArendeCount (se.inera.intyg.common.support.modules.support.api.notification.ArendeCount)5 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)4 IntygModule (se.inera.intyg.common.support.modules.registry.IntygModule)4 Handelse (se.inera.intyg.webcert.persistence.handelse.model.Handelse)4 LocalDateTime (java.time.LocalDateTime)3 Fk7263Utlatande (se.inera.intyg.common.fk7263.model.internal.Fk7263Utlatande)3 IntygWithNotificationsRequest (se.inera.intyg.webcert.web.service.intyg.dto.IntygWithNotificationsRequest)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 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