Search in sources :

Example 6 with ArendeConversationView

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

the class ArendeViewConverterTest method ifMultipleKompltIntygClosestInTimeShouldBeChoosen.

@Test
public void ifMultipleKompltIntygClosestInTimeShouldBeChoosen() {
    // Given
    LocalDateTime fragaDate = LocalDateTime.parse("2016-03-01T11:22:11");
    Arende fraga = createValidArendeForLuse("fraga", fragaDate, "fraga-id", null);
    List<AnsweredWithIntyg> komplt = ImmutableList.of(createMatchingAnsweredWithIntyg(fraga, fragaDate.plusDays(3)), createMatchingAnsweredWithIntyg(fraga, fragaDate.plusDays(1)), createMatchingAnsweredWithIntyg(fraga, fragaDate.plusDays(2)));
    // When
    List<ArendeConversationView> messageThreads = converter.buildArendeConversations(fraga.getIntygsId(), ImmutableList.of(fraga), komplt, Collections.emptyList());
    // Then
    Assertions.assertThat(messageThreads).hasSize(1).extracting(ArendeConversationView::getAnsweredWithIntyg).contains(komplt.get(1));
}
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) AnsweredWithIntyg(se.inera.intyg.webcert.web.web.controller.api.dto.AnsweredWithIntyg) Test(org.junit.Test)

Example 7 with ArendeConversationView

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

the class ArendeViewConverterTest method buildArendeConversationsTest.

@Test
public void buildArendeConversationsTest() {
    final LocalDateTime january = LocalDateTime.parse("2013-01-12T11:22:11");
    final LocalDateTime february = LocalDateTime.parse("2013-02-12T11:22:11");
    final LocalDateTime decemberYear9999 = LocalDateTime.parse("9999-12-11T10:22:00");
    List<Arende> arendeList = new ArrayList<>();
    arendeList.add(buildArende(UUID.randomUUID().toString(), decemberYear9999, february));
    arendeList.add(buildArende(UUID.randomUUID().toString(), january, january));
    // svar
    arendeList.get(1).setSvarPaId(arendeList.get(0).getMeddelandeId());
    arendeList.add(buildArende(UUID.randomUUID().toString(), decemberYear9999, decemberYear9999));
    arendeList.get(2).setAmne(ArendeAmne.PAMINN);
    // paminnelse
    arendeList.get(2).setPaminnelseMeddelandeId(arendeList.get(0).getMeddelandeId());
    arendeList.add(buildArende(UUID.randomUUID().toString(), february, february));
    arendeList.add(buildArende(UUID.randomUUID().toString(), decemberYear9999, decemberYear9999));
    arendeList.add(buildArende(UUID.randomUUID().toString(), january, january));
    List<ArendeConversationView> result = converter.buildArendeConversations(intygsId, arendeList, Collections.emptyList(), Collections.emptyList());
    assertEquals(4, result.size());
    assertEquals(1, result.get(0).getPaminnelser().size());
    assertEquals(arendeList.get(0).getMeddelandeId(), result.get(0).getFraga().getInternReferens());
    assertEquals(arendeList.get(1).getMeddelandeId(), result.get(0).getSvar().getInternReferens());
    assertEquals(arendeList.get(2).getMeddelandeId(), result.get(0).getPaminnelser().get(0).getInternReferens());
    assertEquals(arendeList.get(3).getMeddelandeId(), result.get(2).getFraga().getInternReferens());
    assertEquals(arendeList.get(4).getMeddelandeId(), result.get(1).getFraga().getInternReferens());
    assertEquals(arendeList.get(5).getMeddelandeId(), result.get(3).getFraga().getInternReferens());
    assertEquals(decemberYear9999, result.get(0).getSenasteHandelse());
    assertEquals(decemberYear9999, result.get(1).getSenasteHandelse());
    assertEquals(february, result.get(2).getSenasteHandelse());
    assertEquals(january, result.get(3).getSenasteHandelse());
}
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) Test(org.junit.Test)

Example 8 with ArendeConversationView

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

the class ArendeViewConverter method createConversationViewFromArendeList.

private ArendeConversationView createConversationViewFromArendeList(List<Arende> messagesInThread, List<AnsweredWithIntyg> kompltForIntyg, List<ArendeDraft> arendeDrafts) {
    Optional<Arende> fraga = messagesInThread.stream().filter(a -> getArendeType(a) == ArendeType.FRAGA).reduce((element, otherElement) -> {
        throw new IllegalArgumentException("More than 1 fraga found.");
    });
    Optional<Arende> svar = messagesInThread.stream().filter(a -> getArendeType(a) == ArendeType.SVAR).reduce((element, otherElement) -> {
        throw new IllegalArgumentException("More than 1 svar found.");
    });
    List<Arende> paminnelser = messagesInThread.stream().filter(a -> getArendeType(a) == ArendeType.PAMINNELSE).collect(Collectors.toList());
    if (!fraga.isPresent()) {
        throw new IllegalArgumentException("No fraga found for the given message thread.");
    }
    String draftText = null;
    if (!svar.isPresent() && !FrageStallare.WEBCERT.getKod().equals(fraga.get().getSkickatAv())) {
        draftText = arendeDrafts.stream().filter(d -> d.getQuestionId().equals(fraga.get().getMeddelandeId())).findAny().map(ArendeDraft::getText).orElse(null);
    }
    // Find oldest intyg among kompletterande intyg, that's newer than the fraga
    AnsweredWithIntyg komplt = null;
    if (!svar.isPresent() && fraga.get().getAmne() == ArendeAmne.KOMPLT) {
        komplt = AnsweredWithIntygUtil.returnOldestKompltOlderThan(fraga.get().getTimestamp(), kompltForIntyg);
    }
    return convertToArendeConversationView(fraga.get(), svar.orElse(null), komplt, paminnelser, draftText);
}
Also used : ArendeDraft(se.inera.intyg.webcert.persistence.arende.model.ArendeDraft) ArendeType(se.inera.intyg.webcert.web.web.controller.api.dto.ArendeView.ArendeType) LoggerFactory(org.slf4j.LoggerFactory) Autowired(org.springframework.beans.factory.annotation.Autowired) ArrayList(java.util.ArrayList) ArendeView(se.inera.intyg.webcert.web.web.controller.api.dto.ArendeView) ImmutableList(com.google.common.collect.ImmutableList) CollectionUtils(org.apache.commons.collections.CollectionUtils) ArendeAmne(se.inera.intyg.webcert.persistence.arende.model.ArendeAmne) Map(java.util.Map) Utlatande(se.inera.intyg.common.support.model.common.internal.Utlatande) AnsweredWithIntygUtil(se.inera.intyg.webcert.web.converter.util.AnsweredWithIntygUtil) MedicinsktArende(se.inera.intyg.webcert.persistence.arende.model.MedicinsktArende) Logger(org.slf4j.Logger) MedicinsktArendeView(se.inera.intyg.webcert.web.web.controller.api.dto.MedicinsktArendeView) Throwables(com.google.common.base.Throwables) IntygModuleRegistryImpl(se.inera.intyg.common.support.modules.registry.IntygModuleRegistryImpl) Collectors(java.util.stream.Collectors) Arende(se.inera.intyg.webcert.persistence.arende.model.Arende) IntygServiceImpl(se.inera.intyg.webcert.web.service.intyg.IntygServiceImpl) Objects(java.util.Objects) AnsweredWithIntyg(se.inera.intyg.webcert.web.web.controller.api.dto.AnsweredWithIntyg) List(java.util.List) Component(org.springframework.stereotype.Component) ModuleApi(se.inera.intyg.common.support.modules.support.api.ModuleApi) ArendeConversationView(se.inera.intyg.webcert.web.web.controller.api.dto.ArendeConversationView) Optional(java.util.Optional) FrageStallare(se.inera.intyg.webcert.web.service.fragasvar.dto.FrageStallare) Comparator(java.util.Comparator) Collections(java.util.Collections) ModuleNotFoundException(se.inera.intyg.common.support.modules.registry.ModuleNotFoundException) ArendeDraft(se.inera.intyg.webcert.persistence.arende.model.ArendeDraft) MedicinsktArende(se.inera.intyg.webcert.persistence.arende.model.MedicinsktArende) Arende(se.inera.intyg.webcert.persistence.arende.model.Arende) AnsweredWithIntyg(se.inera.intyg.webcert.web.web.controller.api.dto.AnsweredWithIntyg)

Example 9 with ArendeConversationView

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

the class ArendeServiceImpl method setForwarded.

@Override
@Transactional
public List<ArendeConversationView> setForwarded(String intygsId) {
    WebCertUser user = webcertUserService.getUser();
    List<Arende> arendenToForward = arendeRepository.save(arendeRepository.findByIntygsId(intygsId).stream().filter(isCorrectEnhet(user)).filter(isQuestion()).peek(arende -> authoritiesValidator.given(user, arende.getIntygTyp()).features(AuthoritiesConstants.FEATURE_HANTERA_FRAGOR).privilege(AuthoritiesConstants.PRIVILEGE_VIDAREBEFORDRA_FRAGASVAR).orThrow()).peek(Arende::setArendeToVidareBerordrat).collect(Collectors.toList()));
    if (arendenToForward.isEmpty()) {
        throw new WebCertServiceException(WebCertServiceErrorCodeEnum.DATA_NOT_FOUND, "Could not find any arende related to IntygsId: " + intygsId);
    }
    return getArendeConversationViewList(intygsId, arendenToForward);
}
Also used : Arrays(java.util.Arrays) ArendeDraft(se.inera.intyg.webcert.persistence.arende.model.ArendeDraft) PatientDetailsResolver(se.inera.intyg.webcert.web.service.patient.PatientDetailsResolver) LoggerFactory(org.slf4j.LoggerFactory) Autowired(org.springframework.beans.factory.annotation.Autowired) 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) Fk7263EntryPoint(se.inera.intyg.common.fk7263.support.Fk7263EntryPoint) UtkastRepository(se.inera.intyg.webcert.persistence.utkast.repository.UtkastRepository) SendMessageToRecipientTypeConverter(se.inera.intyg.webcert.common.client.converter.SendMessageToRecipientTypeConverter) ArendeAmne(se.inera.intyg.webcert.persistence.arende.model.ArendeAmne) Map(java.util.Map) HsaEmployeeService(se.inera.intyg.infra.integration.hsa.services.HsaEmployeeService) SendMessageToRecipientType(se.riv.clinicalprocess.healthcond.certificate.sendMessageToRecipient.v2.SendMessageToRecipientType) Status(se.inera.intyg.webcert.persistence.model.Status) MedicinsktArende(se.inera.intyg.webcert.persistence.arende.model.MedicinsktArende) AuthoritiesValidator(se.inera.intyg.infra.security.authorities.validation.AuthoritiesValidator) SekretessStatus(se.inera.intyg.webcert.common.model.SekretessStatus) Predicate(java.util.function.Predicate) Personnummer(se.inera.intyg.schemas.contract.Personnummer) Set(java.util.Set) Collectors(java.util.stream.Collectors) JAXBException(javax.xml.bind.JAXBException) Arende(se.inera.intyg.webcert.persistence.arende.model.Arende) Utkast(se.inera.intyg.webcert.persistence.utkast.model.Utkast) Objects(java.util.Objects) QueryFragaSvarParameter(se.inera.intyg.webcert.web.service.fragasvar.dto.QueryFragaSvarParameter) AnsweredWithIntyg(se.inera.intyg.webcert.web.web.controller.api.dto.AnsweredWithIntyg) List(java.util.List) NotificationEvent(se.inera.intyg.webcert.web.service.notification.NotificationEvent) ArendeConversationView(se.inera.intyg.webcert.web.web.controller.api.dto.ArendeConversationView) FrageStallare(se.inera.intyg.webcert.web.service.fragasvar.dto.FrageStallare) NotNull(org.jetbrains.annotations.NotNull) 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) SendMessageToRecipientTypeBuilder(se.inera.intyg.webcert.web.integration.builders.SendMessageToRecipientTypeBuilder) CertificateSenderException(se.inera.intyg.webcert.web.service.certificatesender.CertificateSenderException) ArendeListItem(se.inera.intyg.webcert.web.web.controller.api.dto.ArendeListItem) LocalDateTime(java.time.LocalDateTime) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) GroupableItem(se.inera.intyg.webcert.common.model.GroupableItem) Value(org.springframework.beans.factory.annotation.Value) ArendeConverter(se.inera.intyg.webcert.web.converter.ArendeConverter) Strings(com.google.common.base.Strings) ArendeListItemConverter(se.inera.intyg.webcert.web.converter.ArendeListItemConverter) TsBasEntryPoint(se.inera.intyg.common.ts_bas.support.TsBasEntryPoint) Service(org.springframework.stereotype.Service) AuthoritiesHelper(se.inera.intyg.infra.security.authorities.AuthoritiesHelper) AnsweredWithIntygUtil(se.inera.intyg.webcert.web.converter.util.AnsweredWithIntygUtil) StatisticsGroupByUtil(se.inera.intyg.webcert.web.service.util.StatisticsGroupByUtil) ArendeViewConverter(se.inera.intyg.webcert.web.converter.ArendeViewConverter) NotificationService(se.inera.intyg.webcert.web.service.notification.NotificationService) Logger(org.slf4j.Logger) ArendeRepository(se.inera.intyg.webcert.persistence.arende.repository.ArendeRepository) TsDiabetesEntryPoint(se.inera.intyg.common.ts_diabetes.support.TsDiabetesEntryPoint) 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) FilterConverter(se.inera.intyg.webcert.web.converter.FilterConverter) Preconditions(com.google.common.base.Preconditions) VisibleForTesting(com.google.common.annotations.VisibleForTesting) AuthoritiesConstants(se.inera.intyg.infra.security.common.model.AuthoritiesConstants) Comparator(java.util.Comparator) Transactional(org.springframework.transaction.annotation.Transactional) MedicinsktArende(se.inera.intyg.webcert.persistence.arende.model.MedicinsktArende) Arende(se.inera.intyg.webcert.persistence.arende.model.Arende) WebCertServiceException(se.inera.intyg.webcert.common.service.exception.WebCertServiceException) WebCertUser(se.inera.intyg.webcert.web.service.user.dto.WebCertUser) Transactional(org.springframework.transaction.annotation.Transactional)

Example 10 with ArendeConversationView

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

the class ArendeServiceImpl method getArenden.

@Override
public List<ArendeConversationView> getArenden(String intygsId) {
    WebCertUser user = webcertUserService.getUser();
    List<Arende> arendeList = getArendeForIntygId(intygsId, user);
    arendeList.stream().findFirst().map(Arende::getPatientPersonId).map(personNummer -> Personnummer.createPersonnummer(personNummer).orElseThrow(() -> new IllegalArgumentException("Could not parse personnummer when querying for arenden."))).ifPresent(pn -> authoritiesValidator.given(user).privilegeIf(AuthoritiesConstants.PRIVILEGE_HANTERA_SEKRETESSMARKERAD_PATIENT, SekretessStatus.TRUE.equals(patientDetailsResolver.getSekretessStatus(pn))).orThrow());
    return getArendeConversationViewList(intygsId, arendeList);
}
Also used : Arrays(java.util.Arrays) ArendeDraft(se.inera.intyg.webcert.persistence.arende.model.ArendeDraft) PatientDetailsResolver(se.inera.intyg.webcert.web.service.patient.PatientDetailsResolver) LoggerFactory(org.slf4j.LoggerFactory) Autowired(org.springframework.beans.factory.annotation.Autowired) 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) Fk7263EntryPoint(se.inera.intyg.common.fk7263.support.Fk7263EntryPoint) UtkastRepository(se.inera.intyg.webcert.persistence.utkast.repository.UtkastRepository) SendMessageToRecipientTypeConverter(se.inera.intyg.webcert.common.client.converter.SendMessageToRecipientTypeConverter) ArendeAmne(se.inera.intyg.webcert.persistence.arende.model.ArendeAmne) Map(java.util.Map) HsaEmployeeService(se.inera.intyg.infra.integration.hsa.services.HsaEmployeeService) SendMessageToRecipientType(se.riv.clinicalprocess.healthcond.certificate.sendMessageToRecipient.v2.SendMessageToRecipientType) Status(se.inera.intyg.webcert.persistence.model.Status) MedicinsktArende(se.inera.intyg.webcert.persistence.arende.model.MedicinsktArende) AuthoritiesValidator(se.inera.intyg.infra.security.authorities.validation.AuthoritiesValidator) SekretessStatus(se.inera.intyg.webcert.common.model.SekretessStatus) Predicate(java.util.function.Predicate) Personnummer(se.inera.intyg.schemas.contract.Personnummer) Set(java.util.Set) Collectors(java.util.stream.Collectors) JAXBException(javax.xml.bind.JAXBException) Arende(se.inera.intyg.webcert.persistence.arende.model.Arende) Utkast(se.inera.intyg.webcert.persistence.utkast.model.Utkast) Objects(java.util.Objects) QueryFragaSvarParameter(se.inera.intyg.webcert.web.service.fragasvar.dto.QueryFragaSvarParameter) AnsweredWithIntyg(se.inera.intyg.webcert.web.web.controller.api.dto.AnsweredWithIntyg) List(java.util.List) NotificationEvent(se.inera.intyg.webcert.web.service.notification.NotificationEvent) ArendeConversationView(se.inera.intyg.webcert.web.web.controller.api.dto.ArendeConversationView) FrageStallare(se.inera.intyg.webcert.web.service.fragasvar.dto.FrageStallare) NotNull(org.jetbrains.annotations.NotNull) 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) SendMessageToRecipientTypeBuilder(se.inera.intyg.webcert.web.integration.builders.SendMessageToRecipientTypeBuilder) CertificateSenderException(se.inera.intyg.webcert.web.service.certificatesender.CertificateSenderException) ArendeListItem(se.inera.intyg.webcert.web.web.controller.api.dto.ArendeListItem) LocalDateTime(java.time.LocalDateTime) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) GroupableItem(se.inera.intyg.webcert.common.model.GroupableItem) Value(org.springframework.beans.factory.annotation.Value) ArendeConverter(se.inera.intyg.webcert.web.converter.ArendeConverter) Strings(com.google.common.base.Strings) ArendeListItemConverter(se.inera.intyg.webcert.web.converter.ArendeListItemConverter) TsBasEntryPoint(se.inera.intyg.common.ts_bas.support.TsBasEntryPoint) Service(org.springframework.stereotype.Service) AuthoritiesHelper(se.inera.intyg.infra.security.authorities.AuthoritiesHelper) AnsweredWithIntygUtil(se.inera.intyg.webcert.web.converter.util.AnsweredWithIntygUtil) StatisticsGroupByUtil(se.inera.intyg.webcert.web.service.util.StatisticsGroupByUtil) ArendeViewConverter(se.inera.intyg.webcert.web.converter.ArendeViewConverter) NotificationService(se.inera.intyg.webcert.web.service.notification.NotificationService) Logger(org.slf4j.Logger) ArendeRepository(se.inera.intyg.webcert.persistence.arende.repository.ArendeRepository) TsDiabetesEntryPoint(se.inera.intyg.common.ts_diabetes.support.TsDiabetesEntryPoint) 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) FilterConverter(se.inera.intyg.webcert.web.converter.FilterConverter) Preconditions(com.google.common.base.Preconditions) VisibleForTesting(com.google.common.annotations.VisibleForTesting) AuthoritiesConstants(se.inera.intyg.infra.security.common.model.AuthoritiesConstants) Comparator(java.util.Comparator) Transactional(org.springframework.transaction.annotation.Transactional) 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)

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