Search in sources :

Example 6 with QueryFragaSvarParameter

use of se.inera.intyg.webcert.web.service.fragasvar.dto.QueryFragaSvarParameter in project webcert by sklintyg.

the class FilterConverterTest method testNullSafeBoolean.

@Test
public void testNullSafeBoolean() {
    QueryFragaSvarParameter source = createQueryFragaSvarParameter(LocalDateTime.now(), LocalDateTime.now(), "enhetId", "hsaId", 5, null, null, LocalDate.now(), 0, "KOMPLETTERING_FRAN_VARDEN", Boolean.TRUE);
    Filter result = FilterConverter.convert(source, new ArrayList<>(), Stream.of("fk7263").collect(Collectors.toSet()));
    assertFalse(result.isQuestionFromFK());
    assertFalse(result.isQuestionFromWC());
}
Also used : QueryFragaSvarParameter(se.inera.intyg.webcert.web.service.fragasvar.dto.QueryFragaSvarParameter) Filter(se.inera.intyg.webcert.persistence.model.Filter) Test(org.junit.Test)

Example 7 with QueryFragaSvarParameter

use of se.inera.intyg.webcert.web.service.fragasvar.dto.QueryFragaSvarParameter 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 8 with QueryFragaSvarParameter

use of se.inera.intyg.webcert.web.service.fragasvar.dto.QueryFragaSvarParameter in project webcert by sklintyg.

the class FilterConverterTest method testConvert.

@Test
public void testConvert() {
    final LocalDateTime changedFrom = LocalDateTime.now();
    final LocalDateTime changedTo = LocalDateTime.now().plusDays(1);
    final String enhetId = "enhetId";
    final String otherEnhetId = "otherId";
    final String otherEnhetId2 = "otherId2";
    final String hsaId = "hsaId";
    final Integer pageSize = 5;
    final Boolean questionFromFK = Boolean.TRUE;
    final Boolean questionFromWC = Boolean.FALSE;
    final LocalDate replyLatest = LocalDate.now();
    final Integer startFrom = 0;
    final String vantarPa = "SVAR_FRAN_FK";
    final Boolean vidarebefordrad = Boolean.TRUE;
    QueryFragaSvarParameter source = createQueryFragaSvarParameter(changedFrom, changedTo, enhetId, hsaId, pageSize, questionFromFK, questionFromWC, replyLatest, startFrom, vantarPa, vidarebefordrad);
    List<String> unitIds = Arrays.asList(otherEnhetId, otherEnhetId2);
    Filter result = FilterConverter.convert(source, unitIds, Stream.of("fk7263").collect(Collectors.toSet()));
    assertEquals(changedFrom, result.getChangedFrom());
    assertTrue(changedTo.isBefore(result.getChangedTo()));
    assertEquals(2, result.getEnhetsIds().size());
    assertEquals(otherEnhetId, result.getEnhetsIds().get(0));
    assertEquals(otherEnhetId2, result.getEnhetsIds().get(1));
    assertEquals(hsaId, result.getHsaId());
    assertEquals(pageSize, result.getPageSize());
    assertTrue(result.isQuestionFromFK());
    assertFalse(result.isQuestionFromWC());
    assertEquals(replyLatest, result.getReplyLatest());
    assertEquals(startFrom, result.getStartFrom());
    assertEquals(VantarPa.SVAR_FRAN_FK, result.getVantarPa());
    assertTrue(result.getVidarebefordrad());
}
Also used : LocalDateTime(java.time.LocalDateTime) QueryFragaSvarParameter(se.inera.intyg.webcert.web.service.fragasvar.dto.QueryFragaSvarParameter) Filter(se.inera.intyg.webcert.persistence.model.Filter) LocalDate(java.time.LocalDate) Test(org.junit.Test)

Example 9 with QueryFragaSvarParameter

use of se.inera.intyg.webcert.web.service.fragasvar.dto.QueryFragaSvarParameter in project webcert by sklintyg.

the class FilterConverterTest method createQueryFragaSvarParameter.

private QueryFragaSvarParameter createQueryFragaSvarParameter(LocalDateTime changedFrom, LocalDateTime changedTo, String enhetId, String hsaId, Integer pageSize, Boolean questionFromFK, Boolean questionFromWC, LocalDate replyLatest, Integer startFrom, String vantarPa, Boolean vidarebefordrad) {
    QueryFragaSvarParameter res = new QueryFragaSvarParameter();
    res.setChangedFrom(changedFrom);
    res.setChangedTo(changedTo);
    res.setEnhetId(enhetId);
    res.setHsaId(hsaId);
    res.setPageSize(pageSize);
    res.setQuestionFromFK(questionFromFK);
    res.setQuestionFromWC(questionFromWC);
    res.setReplyLatest(replyLatest);
    res.setStartFrom(startFrom);
    res.setVantarPa(vantarPa);
    res.setVidarebefordrad(vidarebefordrad);
    return res;
}
Also used : QueryFragaSvarParameter(se.inera.intyg.webcert.web.service.fragasvar.dto.QueryFragaSvarParameter)

Example 10 with QueryFragaSvarParameter

use of se.inera.intyg.webcert.web.service.fragasvar.dto.QueryFragaSvarParameter in project webcert by sklintyg.

the class FilterConverterTest method testNoPageSizeNorStartFrom.

@Test
public void testNoPageSizeNorStartFrom() {
    QueryFragaSvarParameter source = createQueryFragaSvarParameter(LocalDateTime.now(), LocalDateTime.now(), "enhetId", "hsaId", null, Boolean.FALSE, Boolean.TRUE, LocalDate.now(), null, "KOMPLETTERING_FRAN_VARDEN", Boolean.TRUE);
    Filter result = FilterConverter.convert(source, new ArrayList<>(), Stream.of("fk7263").collect(Collectors.toSet()));
    assertEquals(Integer.valueOf(0), result.getStartFrom());
    assertEquals(FilterConverter.DEFAULT_PAGE_SIZE, result.getPageSize());
}
Also used : QueryFragaSvarParameter(se.inera.intyg.webcert.web.service.fragasvar.dto.QueryFragaSvarParameter) Filter(se.inera.intyg.webcert.persistence.model.Filter) Test(org.junit.Test)

Aggregations

QueryFragaSvarParameter (se.inera.intyg.webcert.web.service.fragasvar.dto.QueryFragaSvarParameter)13 Test (org.junit.Test)11 Filter (se.inera.intyg.webcert.persistence.model.Filter)11 Arende (se.inera.intyg.webcert.persistence.arende.model.Arende)8 MedicinsktArende (se.inera.intyg.webcert.persistence.arende.model.MedicinsktArende)8 QueryFragaSvarResponse (se.inera.intyg.webcert.web.service.fragasvar.dto.QueryFragaSvarResponse)8 WebCertUser (se.inera.intyg.webcert.web.service.user.dto.WebCertUser)4 LocalDateTime (java.time.LocalDateTime)2 Matchers.anyString (org.mockito.Matchers.anyString)2 Personnummer (se.inera.intyg.schemas.contract.Personnummer)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 LocalDate (java.time.LocalDate)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