Search in sources :

Example 1 with ArendeView

use of se.inera.intyg.webcert.web.web.controller.api.dto.ArendeView 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 2 with ArendeView

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

the class ArendeViewConverterTest method testConvertKompletteringWithoutInstans.

@SuppressWarnings("unchecked")
@Test
public void testConvertKompletteringWithoutInstans() throws ModuleNotFoundException {
    Arende arende = buildArende("lisjp");
    arende.setKomplettering(Arrays.asList(buildMedicinsktArende("1", null, "arende1")));
    ArendeView result = converter.convertToDto(arende);
    assertEquals(1, result.getKompletteringar().size());
    assertEquals(RespConstants.GRUNDFORMEDICINSKTUNDERLAG_SVAR_JSON_ID_1, result.getKompletteringar().get(0).getJsonPropertyHandle());
    assertEquals(new Integer(0), result.getKompletteringar().get(0).getPosition());
    assertEquals(VARDAKTOR_NAMN, result.getVardaktorNamn());
    assertEquals(ENHETS_NAMN, result.getEnhetsnamn());
    assertEquals(VARDGIVARE_NAMN, result.getVardgivarnamn());
    verify(moduleApi).getModuleSpecificArendeParameters(any(Utlatande.class), any(List.class));
}
Also used : LuseUtlatande(se.inera.intyg.common.luse.model.internal.LuseUtlatande) LisjpUtlatande(se.inera.intyg.common.lisjp.model.internal.LisjpUtlatande) MedicinsktArende(se.inera.intyg.webcert.persistence.arende.model.MedicinsktArende) Arende(se.inera.intyg.webcert.persistence.arende.model.Arende) ImmutableList(com.google.common.collect.ImmutableList) ArendeView(se.inera.intyg.webcert.web.web.controller.api.dto.ArendeView) Test(org.junit.Test)

Example 3 with ArendeView

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

the class ArendeViewConverterTest method testConvertToArendeWithoutKomplettering.

@SuppressWarnings("unchecked")
@Test
public void testConvertToArendeWithoutKomplettering() throws ModuleNotFoundException {
    ArendeView result = converter.convertToDto(buildArende("meddelandeId", LocalDateTime.now(), LocalDateTime.now()));
    assertTrue(result.getKompletteringar().isEmpty());
    assertEquals(VARDAKTOR_NAMN, result.getVardaktorNamn());
    assertEquals(ENHETS_NAMN, result.getEnhetsnamn());
    assertEquals(VARDGIVARE_NAMN, result.getVardgivarnamn());
    verify(moduleApi, never()).getModuleSpecificArendeParameters(any(Utlatande.class), any(List.class));
}
Also used : LuseUtlatande(se.inera.intyg.common.luse.model.internal.LuseUtlatande) LisjpUtlatande(se.inera.intyg.common.lisjp.model.internal.LisjpUtlatande) ImmutableList(com.google.common.collect.ImmutableList) ArendeView(se.inera.intyg.webcert.web.web.controller.api.dto.ArendeView) Test(org.junit.Test)

Example 4 with ArendeView

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

the class ArendeViewConverterTest method testConvertToArendeForLuse.

@SuppressWarnings("unchecked")
@Test
public void testConvertToArendeForLuse() throws ModuleNotFoundException {
    ArendeView result = converter.convertToDto(buildArende("luse"));
    assertNotNull(result.getKompletteringar().get(0).getJsonPropertyHandle());
    assertEquals(RespConstants.KANNEDOM_SVAR_JSON_ID_2, result.getKompletteringar().get(1).getJsonPropertyHandle());
    assertEquals(RespConstants.UNDERLAG_SVAR_JSON_ID_4, result.getKompletteringar().get(2).getJsonPropertyHandle());
    assertEquals(new Integer(0), result.getKompletteringar().get(0).getPosition());
    assertEquals(new Integer(0), result.getKompletteringar().get(1).getPosition());
    assertEquals(new Integer(1), result.getKompletteringar().get(2).getPosition());
    assertEquals(VARDAKTOR_NAMN, result.getVardaktorNamn());
    assertEquals(ENHETS_NAMN, result.getEnhetsnamn());
    assertEquals(VARDGIVARE_NAMN, result.getVardgivarnamn());
    verify(moduleApi).getModuleSpecificArendeParameters(any(Utlatande.class), any(List.class));
}
Also used : LuseUtlatande(se.inera.intyg.common.luse.model.internal.LuseUtlatande) LisjpUtlatande(se.inera.intyg.common.lisjp.model.internal.LisjpUtlatande) ImmutableList(com.google.common.collect.ImmutableList) ArendeView(se.inera.intyg.webcert.web.web.controller.api.dto.ArendeView) Test(org.junit.Test)

Example 5 with ArendeView

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

the class ArendeViewConverterTest method differentMessageThreadsShouldBeSeparatedAndSortedOnSenasteHandelse.

@Test
public void differentMessageThreadsShouldBeSeparatedAndSortedOnSenasteHandelse() {
    // Given
    LocalDateTime startOfFirstThread = LocalDateTime.parse("2016-03-01T11:22:11");
    Arende fraga1 = createValidArendeForLuse("fraga", startOfFirstThread, "fraga1-id", null);
    Arende p11 = createValidArendeForLuse("paminnelse", startOfFirstThread.plusHours(2), "paminnelse-1.1-id", fraga1);
    Arende p12 = createValidArendeForLuse("paminnelse", startOfFirstThread.plusDays(1), "paminnelse-1.2-id", fraga1);
    Arende p13 = createValidArendeForLuse("paminnelse", startOfFirstThread.plusDays(3), "paminnelse-1.3-id", fraga1);
    Arende svar1 = createValidArendeForLuse("svar", startOfFirstThread.plusDays(4), "svar-1-id", fraga1);
    LocalDateTime startOfSecondThread = LocalDateTime.parse("2016-03-02T11:22:11");
    Arende fraga2 = createValidArendeForLuse("fraga", startOfSecondThread, "fraga2-id", null);
    Arende p21 = createValidArendeForLuse("paminnelse", startOfFirstThread.plusHours(2), "paminnelse-2.1-id", fraga2);
    Arende p22 = createValidArendeForLuse("paminnelse", startOfFirstThread.plusDays(1), "paminnelse-2.2-id", fraga2);
    Arende svar2 = createValidArendeForLuse("svar", startOfFirstThread.plusDays(4), "svar-2-id", fraga2);
    List<Arende> mixedThreads = ImmutableList.of(fraga1, fraga2, p11, p21, p12, p22, p13, svar2, svar1);
    // When
    List<ArendeConversationView> createdList = converter.buildArendeConversations(intygsId, mixedThreads, Collections.emptyList(), Collections.emptyList());
    // Then
    List<ArendeView> expectedPaminnelser1Dtos = Stream.of(p13, p12, p11).map(converter::convertToDto).collect(Collectors.toList());
    List<ArendeView> expectedPaminnelser2Dtos = Stream.of(p22, p21).map(converter::convertToDto).collect(Collectors.toList());
    Assertions.assertThat(createdList).hasSize(2).extracting("fraga", "svar", "paminnelser").contains(tuple(converter.convertToDto(fraga1), converter.convertToDto(svar1), expectedPaminnelser1Dtos), tuple(converter.convertToDto(fraga2), converter.convertToDto(svar2), expectedPaminnelser2Dtos));
}
Also used : LocalDateTime(java.time.LocalDateTime) 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) ArendeView(se.inera.intyg.webcert.web.web.controller.api.dto.ArendeView) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)9 ArendeView (se.inera.intyg.webcert.web.web.controller.api.dto.ArendeView)9 ImmutableList (com.google.common.collect.ImmutableList)7 LisjpUtlatande (se.inera.intyg.common.lisjp.model.internal.LisjpUtlatande)6 LuseUtlatande (se.inera.intyg.common.luse.model.internal.LuseUtlatande)6 Arende (se.inera.intyg.webcert.persistence.arende.model.Arende)6 MedicinsktArende (se.inera.intyg.webcert.persistence.arende.model.MedicinsktArende)6 LocalDateTime (java.time.LocalDateTime)3 ArendeConversationView (se.inera.intyg.webcert.web.web.controller.api.dto.ArendeConversationView)2 ImmutableMap (com.google.common.collect.ImmutableMap)1 MoreCollectors (com.google.common.collect.MoreCollectors)1 Clock (java.time.Clock)1 Instant (java.time.Instant)1 ZoneId (java.time.ZoneId)1 java.util (java.util)1 Collectors (java.util.stream.Collectors)1 Stream (java.util.stream.Stream)1 Assert (org.junit.Assert)1 Before (org.junit.Before)1 RunWith (org.junit.runner.RunWith)1