Search in sources :

Example 6 with ArendeListItem

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

the class ArendeServiceImpl method filterArende.

@Override
@Transactional(value = "jpaTransactionManager", readOnly = true)
public QueryFragaSvarResponse filterArende(QueryFragaSvarParameter filterParameters) {
    WebCertUser user = webcertUserService.getUser();
    Set<String> intygstyperForPrivilege = authoritiesHelper.getIntygstyperForPrivilege(user, AuthoritiesConstants.PRIVILEGE_VISA_INTYG);
    Filter filter;
    if (!Strings.isNullOrEmpty(filterParameters.getEnhetId())) {
        verifyEnhetsAuth(filterParameters.getEnhetId(), true);
        filter = FilterConverter.convert(filterParameters, Arrays.asList(filterParameters.getEnhetId()), intygstyperForPrivilege);
    } else {
        filter = FilterConverter.convert(filterParameters, user.getIdsOfSelectedVardenhet(), intygstyperForPrivilege);
    }
    int originalStartFrom = filter.getStartFrom();
    int originalPageSize = filter.getPageSize();
    // INTYG-4086: Do NOT perform any paging. We must first load all applicable QA / ärenden, then apply
    // sekretessmarkering filtering. THEN - we can do paging stuff in-memory. Very inefficient...
    filter.setStartFrom(null);
    filter.setPageSize(null);
    List<ArendeListItem> results = arendeRepository.filterArende(filter).stream().map(ArendeListItemConverter::convert).filter(Objects::nonNull).peek(item -> item.setPaminnelse(!arendeRepository.findByPaminnelseMeddelandeId(item.getMeddelandeId()).isEmpty())).collect(Collectors.toList());
    QueryFragaSvarResponse fsResults = fragaSvarService.filterFragaSvar(filter);
    results.addAll(fsResults.getResults());
    results.sort(Comparator.comparing(ArendeListItem::getReceivedDate).reversed());
    QueryFragaSvarResponse response = new QueryFragaSvarResponse();
    Map<Personnummer, SekretessStatus> sekretessStatusMap = patientDetailsResolver.getSekretessStatusForList(results.stream().map(ali -> Personnummer.createPersonnummer(ali.getPatientId()).get()).collect(Collectors.toList()));
    // INTYG-4086, INTYG-4486: Filter out any items that doesn't pass sekretessmarkering rules
    results = results.stream().filter(ali -> this.passesSekretessCheck(ali.getPatientId(), ali.getIntygTyp(), user, sekretessStatusMap)).collect(Collectors.toList());
    // We must mark all items having patient with sekretessmarkering
    results.stream().filter(ali -> hasSekretessStatus(ali, SekretessStatus.TRUE, sekretessStatusMap)).forEach(ali -> ali.setSekretessmarkering(true));
    response.setTotalCount(results.size());
    if (originalStartFrom >= results.size()) {
        response.setResults(new ArrayList<>());
    } else {
        response.setResults(results.subList(originalStartFrom, Math.min(originalPageSize + originalStartFrom, results.size())));
    }
    return response;
}
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) SekretessStatus(se.inera.intyg.webcert.common.model.SekretessStatus) Fk7263EntryPoint(se.inera.intyg.common.fk7263.support.Fk7263EntryPoint) TsBasEntryPoint(se.inera.intyg.common.ts_bas.support.TsBasEntryPoint) TsDiabetesEntryPoint(se.inera.intyg.common.ts_diabetes.support.TsDiabetesEntryPoint) QueryFragaSvarResponse(se.inera.intyg.webcert.web.service.fragasvar.dto.QueryFragaSvarResponse) Personnummer(se.inera.intyg.schemas.contract.Personnummer) ArendeListItem(se.inera.intyg.webcert.web.web.controller.api.dto.ArendeListItem) Filter(se.inera.intyg.webcert.persistence.model.Filter) Objects(java.util.Objects) WebCertUser(se.inera.intyg.webcert.web.service.user.dto.WebCertUser) Transactional(org.springframework.transaction.annotation.Transactional)

Example 7 with ArendeListItem

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

the class ArendeListItemConverter method convert.

public static ArendeListItem convert(FragaSvar fragaSvar) {
    if (fragaSvar.getIntygsReferens() == null || fragaSvar.getVardperson() == null) {
        return null;
    }
    ArendeListItem res = new ArendeListItem();
    res.setFragestallare(fragaSvar.getFrageStallare());
    res.setIntygId(fragaSvar.getIntygsReferens().getIntygsId());
    res.setIntygTyp(fragaSvar.getIntygsReferens().getIntygsTyp());
    res.setMeddelandeId(Long.toString(fragaSvar.getInternReferens()));
    res.setReceivedDate(fragaSvar.getSenasteHandelseDatum());
    res.setPatientId(fragaSvar.getIntygsReferens().getPatientId().getPersonnummer());
    res.setSigneratAvNamn(fragaSvar.getVardperson().getNamn());
    res.setStatus(fragaSvar.getStatus());
    res.setVidarebefordrad(fragaSvar.getVidarebefordrad());
    res.setAmne(ArendeAmne.fromAmne(fragaSvar.getAmne()).map(ArendeAmne::name).orElse(fragaSvar.getAmne().name()));
    res.setEnhetsnamn(fragaSvar.getVardperson().getEnhetsnamn());
    res.setVardgivarnamn(fragaSvar.getVardperson().getVardgivarnamn());
    return res;
}
Also used : ArendeListItem(se.inera.intyg.webcert.web.web.controller.api.dto.ArendeListItem) ArendeAmne(se.inera.intyg.webcert.persistence.arende.model.ArendeAmne)

Example 8 with ArendeListItem

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

the class ArendeServiceTest method buildArendeListItem.

private ArendeListItem buildArendeListItem(String INTYG_ID, LocalDateTime receivedDate) {
    ArendeListItem arende = new ArendeListItem();
    arende.setIntygId(INTYG_ID);
    arende.setReceivedDate(receivedDate);
    arende.setPatientId(PNR.getPersonnummer());
    return arende;
}
Also used : ArendeListItem(se.inera.intyg.webcert.web.web.controller.api.dto.ArendeListItem)

Example 9 with ArendeListItem

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

the class ArendeListItemConverterTest method testConvertArende.

@Test
public void testConvertArende() {
    final ArendeAmne amne = ArendeAmne.KONTKT;
    final String intygsId = "intygsId";
    final String intygTyp = "luse";
    final String meddelandeId = "meddelandeId";
    final String patientPersonId = "patientPersonId";
    final String signeratAvName = "signeratAvName";
    final String skickatAv = "skickatAv";
    final LocalDateTime skickatTidpunkt = LocalDateTime.now();
    final Status status = Status.ANSWERED;
    final Boolean vidarebefordrad = Boolean.TRUE;
    final String enhetsnamn = "enhetsnamn";
    final String vardgivarnamn = "vardgivarnamn";
    Arende arende = createArende(amne, intygsId, intygTyp, meddelandeId, patientPersonId, signeratAvName, skickatAv, skickatTidpunkt, status, vidarebefordrad, enhetsnamn, vardgivarnamn);
    ArendeListItem result = ArendeListItemConverter.convert(arende);
    assertEquals(amne.name(), result.getAmne());
    assertEquals(intygsId, result.getIntygId());
    assertEquals(intygTyp, result.getIntygTyp());
    assertEquals(meddelandeId, result.getMeddelandeId());
    assertEquals(patientPersonId, result.getPatientId());
    assertEquals(signeratAvName, result.getSigneratAvNamn());
    assertEquals(skickatAv, result.getFragestallare());
    assertEquals(skickatTidpunkt, result.getReceivedDate());
    assertEquals(status, result.getStatus());
    assertEquals(true, result.isVidarebefordrad());
    assertEquals(enhetsnamn, result.getEnhetsnamn());
    assertEquals(vardgivarnamn, result.getVardgivarnamn());
}
Also used : LocalDateTime(java.time.LocalDateTime) Status(se.inera.intyg.webcert.persistence.model.Status) ArendeListItem(se.inera.intyg.webcert.web.web.controller.api.dto.ArendeListItem) ArendeAmne(se.inera.intyg.webcert.persistence.arende.model.ArendeAmne) Arende(se.inera.intyg.webcert.persistence.arende.model.Arende) Test(org.junit.Test)

Example 10 with ArendeListItem

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

the class ArendeListItemConverterTest method testConvert.

@Test
public void testConvert() {
    final String fragestallare = "fragestallare";
    final String intygId = "intygId";
    final String intygTyp = "intygTyp";
    final long internReferens = 13;
    final LocalDateTime senasteHandelse = LocalDateTime.now();
    final String signeratAv = "signeratAv";
    final String enhetsnamn = "enhetsnamn";
    final String vardgivarnamn = "vardgivarnamn";
    final Amne amne = Amne.AVSTAMNINGSMOTE;
    final boolean vidarebefordrad = false;
    final Status status = Status.PENDING_INTERNAL_ACTION;
    FragaSvar fs = createFragaSvar(fragestallare, intygId, intygTyp, patientId, internReferens, senasteHandelse, signeratAv, enhetsnamn, vardgivarnamn, amne, vidarebefordrad, status);
    ArendeListItem arende = ArendeListItemConverter.convert(fs);
    assertNotNull(arende);
    assertEquals(fragestallare, arende.getFragestallare());
    assertEquals(intygId, arende.getIntygId());
    assertEquals(intygTyp, arende.getIntygTyp());
    assertEquals(patientId, arende.getPatientId());
    assertEquals(Long.toString(internReferens), arende.getMeddelandeId());
    assertEquals(senasteHandelse, arende.getReceivedDate());
    assertEquals(signeratAv, arende.getSigneratAvNamn());
    assertEquals(enhetsnamn, arende.getEnhetsnamn());
    assertEquals(vardgivarnamn, arende.getVardgivarnamn());
    assertEquals(ArendeAmne.AVSTMN.name(), arende.getAmne());
    assertEquals(vidarebefordrad, arende.isVidarebefordrad());
    assertEquals(status, arende.getStatus());
}
Also used : LocalDateTime(java.time.LocalDateTime) Status(se.inera.intyg.webcert.persistence.model.Status) ArendeListItem(se.inera.intyg.webcert.web.web.controller.api.dto.ArendeListItem) FragaSvar(se.inera.intyg.webcert.persistence.fragasvar.model.FragaSvar) Amne(se.inera.intyg.webcert.persistence.fragasvar.model.Amne) ArendeAmne(se.inera.intyg.webcert.persistence.arende.model.ArendeAmne) Test(org.junit.Test)

Aggregations

ArendeListItem (se.inera.intyg.webcert.web.web.controller.api.dto.ArendeListItem)11 Test (org.junit.Test)6 ArendeAmne (se.inera.intyg.webcert.persistence.arende.model.ArendeAmne)5 FragaSvar (se.inera.intyg.webcert.persistence.fragasvar.model.FragaSvar)4 LocalDateTime (java.time.LocalDateTime)3 Arende (se.inera.intyg.webcert.persistence.arende.model.Arende)3 Status (se.inera.intyg.webcert.persistence.model.Status)3 Transactional (org.springframework.transaction.annotation.Transactional)2 VisibleForTesting (com.google.common.annotations.VisibleForTesting)1 Preconditions (com.google.common.base.Preconditions)1 Strings (com.google.common.base.Strings)1 Clock (java.time.Clock)1 ArrayList (java.util.ArrayList)1 Arrays (java.util.Arrays)1 Comparator (java.util.Comparator)1 HashMap (java.util.HashMap)1 List (java.util.List)1 Map (java.util.Map)1 Objects (java.util.Objects)1 Set (java.util.Set)1