Search in sources :

Example 1 with ArendeConversationView

use of se.inera.intyg.webcert.web.web.controller.api.dto.ArendeConversationView in project webcert by sklintyg.

the class ArendeServiceTest method setForwardedTrueTest.

@Test
public void setForwardedTrueTest() {
    final Arende arende = buildArende(MEDDELANDE_ID, ENHET_ID);
    final Arende vidareBefordrat = arende;
    arende.setArendeToVidareBerordrat();
    when(arendeRepository.findByIntygsId(INTYG_ID)).thenReturn(ImmutableList.of(arende));
    when(webcertUserService.getUser()).thenReturn(createUser());
    when(arendeRepository.save(anyList())).thenReturn(ImmutableList.of(vidareBefordrat));
    final List<ArendeConversationView> arendeConversationViews = service.setForwarded(INTYG_ID);
    assertTrue(arendeConversationViews.stream().allMatch(arendeConversationView -> arendeConversationView.getFraga().getVidarebefordrad()));
    verifyZeroInteractions(notificationService);
}
Also used : PatientDetailsResolver(se.inera.intyg.webcert.web.service.patient.PatientDetailsResolver) MonitoringLogService(se.inera.intyg.webcert.web.service.monitoring.MonitoringLogService) Lakare(se.inera.intyg.webcert.web.service.dto.Lakare) WebCertUserService(se.inera.intyg.webcert.web.service.user.WebCertUserService) CertificateSenderService(se.inera.intyg.webcert.web.service.certificatesender.CertificateSenderService) Matchers.anySet(org.mockito.Matchers.anySet) ArendeView(se.inera.intyg.webcert.web.web.controller.api.dto.ArendeView) Matchers.anyBoolean(org.mockito.Matchers.anyBoolean) UtkastRepository(se.inera.intyg.webcert.persistence.utkast.repository.UtkastRepository) ArendeAmne(se.inera.intyg.webcert.persistence.arende.model.ArendeAmne) Matchers.eq(org.mockito.Matchers.eq) Status(se.inera.intyg.webcert.persistence.model.Status) MedicinsktArende(se.inera.intyg.webcert.persistence.arende.model.MedicinsktArende) org.mockito(org.mockito) SekretessStatus(se.inera.intyg.webcert.common.model.SekretessStatus) ImmutableMap(com.google.common.collect.ImmutableMap) MoreCollectors(com.google.common.collect.MoreCollectors) Personnummer(se.inera.intyg.schemas.contract.Personnummer) Signatur(se.inera.intyg.webcert.persistence.utkast.model.Signatur) Instant(java.time.Instant) Collectors(java.util.stream.Collectors) Arende(se.inera.intyg.webcert.persistence.arende.model.Arende) Utkast(se.inera.intyg.webcert.persistence.utkast.model.Utkast) ZoneId(java.time.ZoneId) QueryFragaSvarParameter(se.inera.intyg.webcert.web.service.fragasvar.dto.QueryFragaSvarParameter) Matchers.any(org.mockito.Matchers.any) NotificationEvent(se.inera.intyg.webcert.web.service.notification.NotificationEvent) Stream(java.util.stream.Stream) ArendeConversationView(se.inera.intyg.webcert.web.web.controller.api.dto.ArendeConversationView) FrageStallare(se.inera.intyg.webcert.web.service.fragasvar.dto.FrageStallare) MockitoJUnitRunner(org.mockito.junit.MockitoJUnitRunner) se.inera.intyg.infra.security.common.model(se.inera.intyg.infra.security.common.model) WebCertServiceException(se.inera.intyg.webcert.common.service.exception.WebCertServiceException) Filter(se.inera.intyg.webcert.persistence.model.Filter) FragaSvarService(se.inera.intyg.webcert.web.service.fragasvar.FragaSvarService) java.util(java.util) CertificateSenderException(se.inera.intyg.webcert.web.service.certificatesender.CertificateSenderException) ArendeListItem(se.inera.intyg.webcert.web.web.controller.api.dto.ArendeListItem) RunWith(org.junit.runner.RunWith) LocalDateTime(java.time.LocalDateTime) Matchers.anyString(org.mockito.Matchers.anyString) GroupableItem(se.inera.intyg.webcert.common.model.GroupableItem) VardpersonReferens(se.inera.intyg.webcert.persistence.utkast.model.VardpersonReferens) ImmutableList(com.google.common.collect.ImmutableList) Matchers.anyLong(org.mockito.Matchers.anyLong) AuthoritiesHelper(se.inera.intyg.infra.security.authorities.AuthoritiesHelper) Before(org.junit.Before) StatisticsGroupByUtil(se.inera.intyg.webcert.web.service.util.StatisticsGroupByUtil) ArgumentMatchers.isNull(org.mockito.ArgumentMatchers.isNull) ArendeViewConverter(se.inera.intyg.webcert.web.converter.ArendeViewConverter) NotificationService(se.inera.intyg.webcert.web.service.notification.NotificationService) Test(org.junit.Test) ArendeRepository(se.inera.intyg.webcert.persistence.arende.repository.ArendeRepository) AuthoritiesConfigurationTestSetup(se.inera.intyg.webcert.web.auth.bootstrap.AuthoritiesConfigurationTestSetup) Mockito(org.mockito.Mockito) AuthoritiesResolverUtil(se.inera.intyg.infra.security.authorities.AuthoritiesResolverUtil) Vardgivare(se.inera.intyg.infra.integration.hsa.model.Vardgivare) WebCertServiceErrorCodeEnum(se.inera.intyg.webcert.common.service.exception.WebCertServiceErrorCodeEnum) QueryFragaSvarResponse(se.inera.intyg.webcert.web.service.fragasvar.dto.QueryFragaSvarResponse) WebCertUser(se.inera.intyg.webcert.web.service.user.dto.WebCertUser) Clock(java.time.Clock) Matchers.anyList(org.mockito.Matchers.anyList) Assert(org.junit.Assert) Vardenhet(se.inera.intyg.infra.integration.hsa.model.Vardenhet) ArendeConversationView(se.inera.intyg.webcert.web.web.controller.api.dto.ArendeConversationView) MedicinsktArende(se.inera.intyg.webcert.persistence.arende.model.MedicinsktArende) Arende(se.inera.intyg.webcert.persistence.arende.model.Arende) Test(org.junit.Test)

Example 2 with ArendeConversationView

use of se.inera.intyg.webcert.web.web.controller.api.dto.ArendeConversationView in project webcert by sklintyg.

the class ArendeServiceTest method answerKompltQuestionClosesAllCompletionsAsHandled.

@Test
public void answerKompltQuestionClosesAllCompletionsAsHandled() throws CertificateSenderException {
    final String svarPaMeddelandeId = "svarPaMeddelandeId";
    Arende fraga = buildArende(svarPaMeddelandeId, ENHET_ID);
    fraga.setStatus(Status.PENDING_INTERNAL_ACTION);
    fraga.setAmne(ArendeAmne.KOMPLT);
    fraga.setPatientPersonId(PERSON_ID);
    Arende komplt1 = buildArende(UUID.randomUUID().toString(), ENHET_ID);
    komplt1.setStatus(Status.PENDING_INTERNAL_ACTION);
    komplt1.setAmne(ArendeAmne.KOMPLT);
    komplt1.setPatientPersonId(PERSON_ID);
    Arende komplt2 = buildArende(UUID.randomUUID().toString(), ENHET_ID);
    komplt2.setStatus(Status.PENDING_INTERNAL_ACTION);
    komplt2.setAmne(ArendeAmne.KOMPLT);
    komplt2.setPatientPersonId(PERSON_ID);
    Arende otherSubject = buildArende(UUID.randomUUID().toString(), ENHET_ID);
    otherSubject.setStatus(Status.PENDING_INTERNAL_ACTION);
    otherSubject.setAmne(ArendeAmne.AVSTMN);
    otherSubject.setPatientPersonId(PERSON_ID);
    when(arendeRepository.findByIntygsId(INTYG_ID)).thenReturn(Arrays.asList(fraga, komplt1, otherSubject, komplt2));
    when(webcertUserService.isAuthorizedForUnit(anyString(), anyBoolean())).thenReturn(true);
    WebCertUser webcertUser = createUser();
    when(webcertUserService.getUser()).thenReturn(webcertUser);
    List<ArendeConversationView> result = service.answerKomplettering(INTYG_ID, "svarstext");
    verify(notificationService).sendNotificationForQAs(INTYG_ID, NotificationEvent.NEW_ANSWER_FROM_CARE);
    verify(arendeRepository).findByIntygsId(INTYG_ID);
    verify(arendeDraftService, times(3)).delete(eq(INTYG_ID), anyString());
    assertTrue(result.stream().map(ArendeConversationView::getFraga).filter(f -> f.getAmne() == ArendeAmne.KOMPLT).allMatch(f -> f.getStatus() == Status.CLOSED));
    assertNotNull(result.stream().map(ArendeConversationView::getSvar).filter(Objects::nonNull).map(ArendeView::getInternReferens).collect(MoreCollectors.onlyElement()));
}
Also used : PatientDetailsResolver(se.inera.intyg.webcert.web.service.patient.PatientDetailsResolver) MonitoringLogService(se.inera.intyg.webcert.web.service.monitoring.MonitoringLogService) Lakare(se.inera.intyg.webcert.web.service.dto.Lakare) WebCertUserService(se.inera.intyg.webcert.web.service.user.WebCertUserService) CertificateSenderService(se.inera.intyg.webcert.web.service.certificatesender.CertificateSenderService) Matchers.anySet(org.mockito.Matchers.anySet) ArendeView(se.inera.intyg.webcert.web.web.controller.api.dto.ArendeView) Matchers.anyBoolean(org.mockito.Matchers.anyBoolean) UtkastRepository(se.inera.intyg.webcert.persistence.utkast.repository.UtkastRepository) ArendeAmne(se.inera.intyg.webcert.persistence.arende.model.ArendeAmne) Matchers.eq(org.mockito.Matchers.eq) Status(se.inera.intyg.webcert.persistence.model.Status) MedicinsktArende(se.inera.intyg.webcert.persistence.arende.model.MedicinsktArende) org.mockito(org.mockito) SekretessStatus(se.inera.intyg.webcert.common.model.SekretessStatus) ImmutableMap(com.google.common.collect.ImmutableMap) MoreCollectors(com.google.common.collect.MoreCollectors) Personnummer(se.inera.intyg.schemas.contract.Personnummer) Signatur(se.inera.intyg.webcert.persistence.utkast.model.Signatur) Instant(java.time.Instant) Collectors(java.util.stream.Collectors) Arende(se.inera.intyg.webcert.persistence.arende.model.Arende) Utkast(se.inera.intyg.webcert.persistence.utkast.model.Utkast) ZoneId(java.time.ZoneId) QueryFragaSvarParameter(se.inera.intyg.webcert.web.service.fragasvar.dto.QueryFragaSvarParameter) Matchers.any(org.mockito.Matchers.any) NotificationEvent(se.inera.intyg.webcert.web.service.notification.NotificationEvent) Stream(java.util.stream.Stream) ArendeConversationView(se.inera.intyg.webcert.web.web.controller.api.dto.ArendeConversationView) FrageStallare(se.inera.intyg.webcert.web.service.fragasvar.dto.FrageStallare) MockitoJUnitRunner(org.mockito.junit.MockitoJUnitRunner) se.inera.intyg.infra.security.common.model(se.inera.intyg.infra.security.common.model) WebCertServiceException(se.inera.intyg.webcert.common.service.exception.WebCertServiceException) Filter(se.inera.intyg.webcert.persistence.model.Filter) FragaSvarService(se.inera.intyg.webcert.web.service.fragasvar.FragaSvarService) java.util(java.util) CertificateSenderException(se.inera.intyg.webcert.web.service.certificatesender.CertificateSenderException) ArendeListItem(se.inera.intyg.webcert.web.web.controller.api.dto.ArendeListItem) RunWith(org.junit.runner.RunWith) LocalDateTime(java.time.LocalDateTime) Matchers.anyString(org.mockito.Matchers.anyString) GroupableItem(se.inera.intyg.webcert.common.model.GroupableItem) VardpersonReferens(se.inera.intyg.webcert.persistence.utkast.model.VardpersonReferens) ImmutableList(com.google.common.collect.ImmutableList) Matchers.anyLong(org.mockito.Matchers.anyLong) AuthoritiesHelper(se.inera.intyg.infra.security.authorities.AuthoritiesHelper) Before(org.junit.Before) StatisticsGroupByUtil(se.inera.intyg.webcert.web.service.util.StatisticsGroupByUtil) ArgumentMatchers.isNull(org.mockito.ArgumentMatchers.isNull) ArendeViewConverter(se.inera.intyg.webcert.web.converter.ArendeViewConverter) NotificationService(se.inera.intyg.webcert.web.service.notification.NotificationService) Test(org.junit.Test) ArendeRepository(se.inera.intyg.webcert.persistence.arende.repository.ArendeRepository) AuthoritiesConfigurationTestSetup(se.inera.intyg.webcert.web.auth.bootstrap.AuthoritiesConfigurationTestSetup) Mockito(org.mockito.Mockito) AuthoritiesResolverUtil(se.inera.intyg.infra.security.authorities.AuthoritiesResolverUtil) Vardgivare(se.inera.intyg.infra.integration.hsa.model.Vardgivare) WebCertServiceErrorCodeEnum(se.inera.intyg.webcert.common.service.exception.WebCertServiceErrorCodeEnum) QueryFragaSvarResponse(se.inera.intyg.webcert.web.service.fragasvar.dto.QueryFragaSvarResponse) WebCertUser(se.inera.intyg.webcert.web.service.user.dto.WebCertUser) Clock(java.time.Clock) Matchers.anyList(org.mockito.Matchers.anyList) Assert(org.junit.Assert) Vardenhet(se.inera.intyg.infra.integration.hsa.model.Vardenhet) ArendeConversationView(se.inera.intyg.webcert.web.web.controller.api.dto.ArendeConversationView) MedicinsktArende(se.inera.intyg.webcert.persistence.arende.model.MedicinsktArende) Arende(se.inera.intyg.webcert.persistence.arende.model.Arende) Matchers.anyString(org.mockito.Matchers.anyString) WebCertUser(se.inera.intyg.webcert.web.service.user.dto.WebCertUser) ArendeView(se.inera.intyg.webcert.web.web.controller.api.dto.ArendeView) Test(org.junit.Test)

Example 3 with ArendeConversationView

use of se.inera.intyg.webcert.web.web.controller.api.dto.ArendeConversationView in project webcert by sklintyg.

the class ArendeServiceTest method answerTest.

@Test
public void answerTest() throws CertificateSenderException {
    final String svarPaMeddelandeId = "svarPaMeddelandeId";
    Arende fraga = buildArende(svarPaMeddelandeId, null);
    fraga.setAmne(ArendeAmne.OVRIGT);
    fraga.setSenasteHandelse(LocalDateTime.now());
    fraga.setStatus(Status.PENDING_INTERNAL_ACTION);
    fraga.setPatientPersonId(PERSON_ID);
    when(arendeRepository.findOneByMeddelandeId(svarPaMeddelandeId)).thenReturn(fraga);
    when(webcertUserService.isAuthorizedForUnit(isNull(), anyBoolean())).thenReturn(true);
    when(webcertUserService.getUser()).thenReturn(new WebCertUser());
    ArendeConversationView result = service.answer(svarPaMeddelandeId, "svarstext");
    assertNotNull(result.getFraga());
    assertNotNull(result.getSvar());
    assertEquals(FIXED_TIME_INSTANT, result.getSenasteHandelse().toInstant(ZoneId.systemDefault().getRules().getOffset(FIXED_TIME_INSTANT)));
    verify(webcertUserService).isAuthorizedForUnit(isNull(), anyBoolean());
    verify(arendeRepository, times(2)).save(any(Arende.class));
    verify(monitoringLog).logArendeCreated(anyString(), anyString(), isNull(), any(ArendeAmne.class), anyBoolean());
    verify(certificateSenderService).sendMessageToRecipient(anyString(), anyString());
    verify(notificationService).sendNotificationForQAs(INTYG_ID, NotificationEvent.NEW_ANSWER_FROM_CARE);
    verify(arendeDraftService).delete(INTYG_ID, svarPaMeddelandeId);
}
Also used : ArendeConversationView(se.inera.intyg.webcert.web.web.controller.api.dto.ArendeConversationView) ArendeAmne(se.inera.intyg.webcert.persistence.arende.model.ArendeAmne) MedicinsktArende(se.inera.intyg.webcert.persistence.arende.model.MedicinsktArende) Arende(se.inera.intyg.webcert.persistence.arende.model.Arende) Matchers.anyString(org.mockito.Matchers.anyString) WebCertUser(se.inera.intyg.webcert.web.service.user.dto.WebCertUser) Test(org.junit.Test)

Example 4 with ArendeConversationView

use of se.inera.intyg.webcert.web.web.controller.api.dto.ArendeConversationView in project webcert by sklintyg.

the class ArendeServiceTest method createQuestionTest.

@Test
public void createQuestionTest() throws CertificateSenderException {
    LocalDateTime now = LocalDateTime.now();
    Utkast utkast = buildUtkast();
    doReturn(utkast).when(utkastRepository).findOne(anyString());
    when(webcertUserService.isAuthorizedForUnit(isNull(), anyBoolean())).thenReturn(true);
    when(webcertUserService.getUser()).thenReturn(new WebCertUser());
    Arende arende = new Arende();
    arende.setSenasteHandelse(now);
    ArendeConversationView result = service.createMessage(INTYG_ID, ArendeAmne.KONTKT, "rubrik", "meddelande");
    assertNotNull(result.getFraga());
    assertNull(result.getSvar());
    assertEquals(FIXED_TIME_INSTANT, result.getSenasteHandelse().toInstant(ZoneId.systemDefault().getRules().getOffset(FIXED_TIME_INSTANT)));
    verify(webcertUserService).isAuthorizedForUnit(isNull(), anyBoolean());
    verify(arendeRepository).save(any(Arende.class));
    verify(monitoringLog).logArendeCreated(anyString(), isNull(), isNull(), any(ArendeAmne.class), anyBoolean());
    verify(certificateSenderService).sendMessageToRecipient(anyString(), anyString());
    verify(notificationService).sendNotificationForQAs(INTYG_ID, NotificationEvent.NEW_QUESTION_FROM_CARE);
    verify(arendeDraftService).delete(INTYG_ID, null);
}
Also used : LocalDateTime(java.time.LocalDateTime) Utkast(se.inera.intyg.webcert.persistence.utkast.model.Utkast) ArendeConversationView(se.inera.intyg.webcert.web.web.controller.api.dto.ArendeConversationView) ArendeAmne(se.inera.intyg.webcert.persistence.arende.model.ArendeAmne) MedicinsktArende(se.inera.intyg.webcert.persistence.arende.model.MedicinsktArende) Arende(se.inera.intyg.webcert.persistence.arende.model.Arende) WebCertUser(se.inera.intyg.webcert.web.service.user.dto.WebCertUser) Test(org.junit.Test)

Example 5 with ArendeConversationView

use of se.inera.intyg.webcert.web.web.controller.api.dto.ArendeConversationView in project webcert by sklintyg.

the class ArendeServiceTest method answerUpdatesQuestionTest.

@Test
public void answerUpdatesQuestionTest() throws CertificateSenderException {
    final String svarPaMeddelandeId = "svarPaMeddelandeId";
    Arende fraga = buildArende(svarPaMeddelandeId, null);
    fraga.setAmne(ArendeAmne.OVRIGT);
    fraga.setMeddelandeId(svarPaMeddelandeId);
    fraga.setStatus(Status.PENDING_INTERNAL_ACTION);
    fraga.setPatientPersonId(PERSON_ID);
    when(arendeRepository.findOneByMeddelandeId(svarPaMeddelandeId)).thenReturn(fraga);
    when(webcertUserService.isAuthorizedForUnit(isNull(), anyBoolean())).thenReturn(true);
    when(webcertUserService.getUser()).thenReturn(new WebCertUser());
    ArendeConversationView result = service.answer(svarPaMeddelandeId, "svarstext");
    assertNotNull(result.getFraga());
    assertNotNull(result.getSvar());
    assertEquals(FIXED_TIME_INSTANT, result.getSenasteHandelse().toInstant(ZoneId.systemDefault().getRules().getOffset(FIXED_TIME_INSTANT)));
    verify(webcertUserService).isAuthorizedForUnit(isNull(), anyBoolean());
    verify(monitoringLog).logArendeCreated(anyString(), anyString(), isNull(), any(ArendeAmne.class), anyBoolean());
    verify(certificateSenderService).sendMessageToRecipient(anyString(), anyString());
    verify(notificationService).sendNotificationForQAs(INTYG_ID, NotificationEvent.NEW_ANSWER_FROM_CARE);
    ArgumentCaptor<Arende> arendeCaptor = ArgumentCaptor.forClass(Arende.class);
    verify(arendeRepository, times(2)).save(arendeCaptor.capture());
    verify(arendeDraftService).delete(INTYG_ID, svarPaMeddelandeId);
    Arende updatedQuestion = arendeCaptor.getAllValues().get(1);
    assertEquals(FIXED_TIME_INSTANT, updatedQuestion.getSenasteHandelse().toInstant(ZoneId.systemDefault().getRules().getOffset(FIXED_TIME_INSTANT)));
    assertEquals(Status.CLOSED, updatedQuestion.getStatus());
}
Also used : ArendeConversationView(se.inera.intyg.webcert.web.web.controller.api.dto.ArendeConversationView) ArendeAmne(se.inera.intyg.webcert.persistence.arende.model.ArendeAmne) MedicinsktArende(se.inera.intyg.webcert.persistence.arende.model.MedicinsktArende) Arende(se.inera.intyg.webcert.persistence.arende.model.Arende) Matchers.anyString(org.mockito.Matchers.anyString) WebCertUser(se.inera.intyg.webcert.web.service.user.dto.WebCertUser) Test(org.junit.Test)

Aggregations

ArendeConversationView (se.inera.intyg.webcert.web.web.controller.api.dto.ArendeConversationView)19 Arende (se.inera.intyg.webcert.persistence.arende.model.Arende)14 MedicinsktArende (se.inera.intyg.webcert.persistence.arende.model.MedicinsktArende)14 Test (org.junit.Test)12 LocalDateTime (java.time.LocalDateTime)11 WebCertUser (se.inera.intyg.webcert.web.service.user.dto.WebCertUser)8 ArendeAmne (se.inera.intyg.webcert.persistence.arende.model.ArendeAmne)6 Collectors (java.util.stream.Collectors)5 Clock (java.time.Clock)4 Consumes (javax.ws.rs.Consumes)4 Path (javax.ws.rs.Path)4 Produces (javax.ws.rs.Produces)4 Matchers.anyString (org.mockito.Matchers.anyString)4 AuthoritiesHelper (se.inera.intyg.infra.security.authorities.AuthoritiesHelper)4 Personnummer (se.inera.intyg.schemas.contract.Personnummer)4 ImmutableList (com.google.common.collect.ImmutableList)3 PUT (javax.ws.rs.PUT)3 Utkast (se.inera.intyg.webcert.persistence.utkast.model.Utkast)3 FrageStallare (se.inera.intyg.webcert.web.service.fragasvar.dto.FrageStallare)3 ArendeView (se.inera.intyg.webcert.web.web.controller.api.dto.ArendeView)3