Search in sources :

Example 1 with UtkastRepository

use of se.inera.intyg.webcert.persistence.utkast.repository.UtkastRepository 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

Preconditions (com.google.common.base.Preconditions)1 Strings (com.google.common.base.Strings)1 LocalDateTime (java.time.LocalDateTime)1 ArrayList (java.util.ArrayList)1 Arrays (java.util.Arrays)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 Predicate (java.util.function.Predicate)1 Collectors (java.util.stream.Collectors)1 SOAPFaultException (javax.xml.ws.soap.SOAPFaultException)1 Logger (org.slf4j.Logger)1 LoggerFactory (org.slf4j.LoggerFactory)1 Autowired (org.springframework.beans.factory.annotation.Autowired)1 Value (org.springframework.beans.factory.annotation.Value)1 Service (org.springframework.stereotype.Service)1 Transactional (org.springframework.transaction.annotation.Transactional)1 AttributedURIType (org.w3.wsaddressing10.AttributedURIType)1