Search in sources :

Example 1 with AnsweredWithIntyg

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

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

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

the class FragaSvarServiceImpl method getFragaSvar.

@Override
@Transactional(value = "jpaTransactionManager", readOnly = true)
public List<FragaSvarView> getFragaSvar(String intygId) {
    List<FragaSvar> fragaSvarList = fragaSvarRepository.findByIntygsReferensIntygsId(intygId);
    WebCertUser user = webCertUserService.getUser();
    validateSekretessmarkering(intygId, fragaSvarList, user);
    List<String> hsaEnhetIds = user.getIdsOfSelectedVardenhet();
    // Filter questions to that current user only sees questions issued to
    // units with active employment role
    fragaSvarList.removeIf(fragaSvar -> fragaSvar.getVardperson() != null && !hsaEnhetIds.contains(fragaSvar.getVardperson().getEnhetsId()));
    // Finally sort by senasteHandelseDatum
    // We do the sorting in code, since we need to sort on a derived
    // property and not a direct entity persisted
    // property in which case we could have used an order by in the query.
    fragaSvarList.sort(SENASTE_HANDELSE_DATUM_COMPARATOR);
    List<ArendeDraft> drafts = arendeDraftService.listAnswerDrafts(intygId);
    List<AnsweredWithIntyg> bmi = AnsweredWithIntygUtil.findAllKomplementForGivenIntyg(intygId, utkastRepository);
    List<FragaSvarView> fragaSvarWithBesvaratMedIntygInfo = fragaSvarList.stream().map(fs -> FragaSvarView.create(fs, fs.getFrageSkickadDatum() == null ? null : AnsweredWithIntygUtil.returnOldestKompltOlderThan(fs.getFrageSkickadDatum(), bmi), drafts.stream().filter(d -> Long.toString(fs.getInternReferens()).equals(d.getQuestionId())).findAny().map(ArendeDraft::getText).orElse(null))).collect(Collectors.toList());
    return fragaSvarWithBesvaratMedIntygInfo;
}
Also used : SendMedicalCertificateAnswerType(se.inera.ifv.insuranceprocess.healthreporting.sendmedicalcertificateanswerresponder.v1.SendMedicalCertificateAnswerType) Amne(se.inera.intyg.webcert.persistence.fragasvar.model.Amne) IntygConverterUtil(se.inera.intyg.webcert.web.converter.util.IntygConverterUtil) Arrays(java.util.Arrays) IntygContentHolder(se.inera.intyg.webcert.web.service.intyg.dto.IntygContentHolder) 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) FragaSvarView(se.inera.intyg.webcert.web.web.controller.api.dto.FragaSvarView) FKQuestionConverter(se.inera.intyg.webcert.web.converter.FKQuestionConverter) UtkastRepository(se.inera.intyg.webcert.persistence.utkast.repository.UtkastRepository) Map(java.util.Map) Status(se.inera.intyg.webcert.persistence.model.Status) AuthoritiesValidator(se.inera.intyg.infra.security.authorities.validation.AuthoritiesValidator) SekretessStatus(se.inera.intyg.webcert.common.model.SekretessStatus) Komplettering(se.inera.intyg.webcert.persistence.fragasvar.model.Komplettering) Predicate(java.util.function.Predicate) Personnummer(se.inera.intyg.schemas.contract.Personnummer) CertificateState(se.inera.intyg.common.support.model.CertificateState) Set(java.util.Set) Collectors(java.util.stream.Collectors) IntygsReferens(se.inera.intyg.webcert.persistence.fragasvar.model.IntygsReferens) Vardperson(se.inera.intyg.webcert.persistence.fragasvar.model.Vardperson) Objects(java.util.Objects) AnsweredWithIntyg(se.inera.intyg.webcert.web.web.controller.api.dto.AnsweredWithIntyg) List(java.util.List) NotificationEvent(se.inera.intyg.webcert.web.service.notification.NotificationEvent) ResultCodeEnum(se.inera.ifv.insuranceprocess.healthreporting.v2.ResultCodeEnum) SOAPFaultException(javax.xml.ws.soap.SOAPFaultException) SendMedicalCertificateQuestionResponderInterface(se.inera.ifv.insuranceprocess.healthreporting.sendmedicalcertificatequestion.rivtabp20.v1.SendMedicalCertificateQuestionResponderInterface) FrageStallare(se.inera.intyg.webcert.web.service.fragasvar.dto.FrageStallare) SendMedicalCertificateQuestionResponseType(se.inera.ifv.insuranceprocess.healthreporting.sendmedicalcertificatequestionresponder.v1.SendMedicalCertificateQuestionResponseType) WebCertServiceException(se.inera.intyg.webcert.common.service.exception.WebCertServiceException) Filter(se.inera.intyg.webcert.persistence.model.Filter) ArendeDraftService(se.inera.intyg.webcert.web.service.arende.ArendeDraftService) ArendeListItem(se.inera.intyg.webcert.web.web.controller.api.dto.ArendeListItem) FragaSvarSenasteHandelseDatumComparator(se.inera.intyg.webcert.web.service.util.FragaSvarSenasteHandelseDatumComparator) LocalDateTime(java.time.LocalDateTime) IntygService(se.inera.intyg.webcert.web.service.intyg.IntygService) HashMap(java.util.HashMap) HoSPersonal(se.inera.intyg.common.support.model.common.internal.HoSPersonal) GroupableItem(se.inera.intyg.webcert.common.model.GroupableItem) ArrayList(java.util.ArrayList) Value(org.springframework.beans.factory.annotation.Value) QuestionToFkType(se.inera.ifv.insuranceprocess.healthreporting.sendmedicalcertificatequestionresponder.v1.QuestionToFkType) Strings(com.google.common.base.Strings) ArendeListItemConverter(se.inera.intyg.webcert.web.converter.ArendeListItemConverter) FKAnswerConverter(se.inera.intyg.webcert.web.converter.FKAnswerConverter) FragaSvar(se.inera.intyg.webcert.persistence.fragasvar.model.FragaSvar) Service(org.springframework.stereotype.Service) FragaSvarRepository(se.inera.intyg.webcert.persistence.fragasvar.repository.FragaSvarRepository) 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) SendMedicalCertificateAnswerResponseType(se.inera.ifv.insuranceprocess.healthreporting.sendmedicalcertificateanswerresponder.v1.SendMedicalCertificateAnswerResponseType) NotificationService(se.inera.intyg.webcert.web.service.notification.NotificationService) Logger(org.slf4j.Logger) AttributedURIType(org.w3.wsaddressing10.AttributedURIType) SendMedicalCertificateAnswerResponderInterface(se.inera.ifv.insuranceprocess.healthreporting.sendmedicalcertificateanswer.rivtabp20.v1.SendMedicalCertificateAnswerResponderInterface) AnswerToFkType(se.inera.ifv.insuranceprocess.healthreporting.sendmedicalcertificateanswerresponder.v1.AnswerToFkType) SendMedicalCertificateQuestionType(se.inera.ifv.insuranceprocess.healthreporting.sendmedicalcertificatequestionresponder.v1.SendMedicalCertificateQuestionType) WebCertServiceErrorCodeEnum(se.inera.intyg.webcert.common.service.exception.WebCertServiceErrorCodeEnum) QueryFragaSvarResponse(se.inera.intyg.webcert.web.service.fragasvar.dto.QueryFragaSvarResponse) FragaSvarConverter(se.inera.intyg.webcert.web.converter.FragaSvarConverter) WebCertUser(se.inera.intyg.webcert.web.service.user.dto.WebCertUser) Preconditions(com.google.common.base.Preconditions) AuthoritiesConstants(se.inera.intyg.infra.security.common.model.AuthoritiesConstants) Transactional(org.springframework.transaction.annotation.Transactional) ArendeDraft(se.inera.intyg.webcert.persistence.arende.model.ArendeDraft) FragaSvar(se.inera.intyg.webcert.persistence.fragasvar.model.FragaSvar) AnsweredWithIntyg(se.inera.intyg.webcert.web.web.controller.api.dto.AnsweredWithIntyg) WebCertUser(se.inera.intyg.webcert.web.service.user.dto.WebCertUser) FragaSvarView(se.inera.intyg.webcert.web.web.controller.api.dto.FragaSvarView) Transactional(org.springframework.transaction.annotation.Transactional)

Aggregations

AnsweredWithIntyg (se.inera.intyg.webcert.web.web.controller.api.dto.AnsweredWithIntyg)3 LocalDateTime (java.time.LocalDateTime)2 ArrayList (java.util.ArrayList)2 List (java.util.List)2 Map (java.util.Map)2 Objects (java.util.Objects)2 Collectors (java.util.stream.Collectors)2 Logger (org.slf4j.Logger)2 LoggerFactory (org.slf4j.LoggerFactory)2 Autowired (org.springframework.beans.factory.annotation.Autowired)2 Arende (se.inera.intyg.webcert.persistence.arende.model.Arende)2 ArendeDraft (se.inera.intyg.webcert.persistence.arende.model.ArendeDraft)2 MedicinsktArende (se.inera.intyg.webcert.persistence.arende.model.MedicinsktArende)2 AnsweredWithIntygUtil (se.inera.intyg.webcert.web.converter.util.AnsweredWithIntygUtil)2 FrageStallare (se.inera.intyg.webcert.web.service.fragasvar.dto.FrageStallare)2 ArendeConversationView (se.inera.intyg.webcert.web.web.controller.api.dto.ArendeConversationView)2 Preconditions (com.google.common.base.Preconditions)1 Strings (com.google.common.base.Strings)1 Throwables (com.google.common.base.Throwables)1 ImmutableList (com.google.common.collect.ImmutableList)1