Search in sources :

Example 31 with FragaSvar

use of se.inera.intyg.webcert.persistence.fragasvar.model.FragaSvar 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)

Example 32 with FragaSvar

use of se.inera.intyg.webcert.persistence.fragasvar.model.FragaSvar in project webcert by sklintyg.

the class ReceiveQuestionResponderImpl method receiveMedicalCertificateQuestion.

@Override
public ReceiveMedicalCertificateQuestionResponseType receiveMedicalCertificateQuestion(AttributedURIType logicalAddress, ReceiveMedicalCertificateQuestionType request) {
    ReceiveMedicalCertificateQuestionResponseType response = new ReceiveMedicalCertificateQuestionResponseType();
    // Validate incoming request
    List<String> validationMessages = QuestionAnswerValidator.validate(request);
    if (!validationMessages.isEmpty()) {
        response.setResult(ResultOfCallUtil.failResult(Joiner.on(",").join(validationMessages)));
        return response;
    }
    // Transform to a FragaSvar object
    FragaSvar fragaSvar = converter.convert(request.getQuestion());
    // Notify stakeholders
    sendNotification(processQuestion(fragaSvar));
    // Set result and send response back to caller
    response.setResult(ResultOfCallUtil.okResult());
    return response;
}
Also used : FragaSvar(se.inera.intyg.webcert.persistence.fragasvar.model.FragaSvar) ReceiveMedicalCertificateQuestionResponseType(se.inera.ifv.insuranceprocess.healthreporting.receivemedicalcertificatequestionsponder.v1.ReceiveMedicalCertificateQuestionResponseType)

Example 33 with FragaSvar

use of se.inera.intyg.webcert.persistence.fragasvar.model.FragaSvar in project webcert by sklintyg.

the class UtkastBootstrapBean method createFragaSvar.

private FragaSvar createFragaSvar(Utlatande utlatande, FrageStallare fragestallare, boolean komplettering, boolean paminnelse) {
    FragaSvar fs = new FragaSvar();
    fs.setFrageSigneringsDatum(LocalDateTime.now());
    fs.setFrageSkickadDatum(LocalDateTime.now());
    if (fragestallare.equals(FrageStallare.FORSAKRINGSKASSAN)) {
        fs.setStatus(Status.PENDING_INTERNAL_ACTION);
        fs.setExternaKontakter(new HashSet<>(Arrays.asList("Testperson1 FK", "Testperson2 FK")));
        fs.setExternReferens("Extern referens");
        fs.setSistaDatumForSvar(LocalDate.now().plusWeeks(2));
    } else {
        fs.setStatus(Status.PENDING_EXTERNAL_ACTION);
    }
    fs.setFrageStallare(fragestallare.getKod());
    fs.setFrageText("Detta är frågan");
    fs.setIntygsReferens(new IntygsReferens(utlatande.getId(), utlatande.getTyp(), utlatande.getGrundData().getPatient().getPersonId(), null, utlatande.getGrundData().getSigneringsdatum()));
    if (komplettering) {
        fs.setAmne(Amne.KOMPLETTERING_AV_LAKARINTYG);
        Komplettering kompl1 = new Komplettering();
        kompl1.setFalt("fält");
        kompl1.setText("kompletteringstext");
        fs.setKompletteringar(new HashSet<>(Arrays.asList(kompl1)));
    } else if (paminnelse) {
        fs.setAmne(Amne.PAMINNELSE);
    } else {
        fs.setAmne(fsAmnen.get(rand.nextInt(fsAmnen.size())));
    }
    fs.setMeddelandeRubrik("Rubrik");
    fs.setVardAktorHsaId(utlatande.getGrundData().getSkapadAv().getPersonId());
    fs.setVardAktorNamn(utlatande.getGrundData().getSkapadAv().getFullstandigtNamn());
    fs.setVardperson(FragaSvarConverter.convert(utlatande.getGrundData().getSkapadAv()));
    fs.setVidarebefordrad(false);
    return fs;
}
Also used : IntygsReferens(se.inera.intyg.webcert.persistence.fragasvar.model.IntygsReferens) FragaSvar(se.inera.intyg.webcert.persistence.fragasvar.model.FragaSvar) Komplettering(se.inera.intyg.webcert.persistence.fragasvar.model.Komplettering)

Example 34 with FragaSvar

use of se.inera.intyg.webcert.persistence.fragasvar.model.FragaSvar in project webcert by sklintyg.

the class FragaSvarModuleApiControllerTest method buildFragaSvarViewList.

private List<FragaSvarView> buildFragaSvarViewList() {
    List<FragaSvarView> fragaSvarViewList = new ArrayList<>();
    IntygsReferens intygsReferens = mock(IntygsReferens.class);
    FragaSvar fs = mock(FragaSvar.class);
    FragaSvarView fsw = mock(FragaSvarView.class);
    fragaSvarViewList.add(fsw);
    return fragaSvarViewList;
}
Also used : IntygsReferens(se.inera.intyg.webcert.persistence.fragasvar.model.IntygsReferens) ArrayList(java.util.ArrayList) FragaSvar(se.inera.intyg.webcert.persistence.fragasvar.model.FragaSvar) FragaSvarView(se.inera.intyg.webcert.web.web.controller.api.dto.FragaSvarView)

Example 35 with FragaSvar

use of se.inera.intyg.webcert.persistence.fragasvar.model.FragaSvar in project webcert by sklintyg.

the class FragaSvarRepositoryTest method buildFragaSvarFraga.

private FragaSvar buildFragaSvarFraga(String enhetsId, Status status, String hsaid, String hsaNamn) {
    FragaSvar f = new FragaSvar();
    f.setExternaKontakter(new HashSet<>(Arrays.asList("KONTAKT1", "KONTAKT2", "KONTAKT3")));
    f.setAmne(Amne.AVSTAMNINGSMOTE);
    f.setExternReferens("externReferens");
    f.setFrageSigneringsDatum(FRAGA_SIGN_DATE);
    f.setFrageSkickadDatum(FRAGA_SENT_DATE);
    f.setFrageStallare("Olle");
    Vardperson vardperson = new Vardperson();
    vardperson.setEnhetsId(enhetsId);
    vardperson.setEnhetsnamn(enhetsId + "-namnet");
    vardperson.setHsaId(hsaid);
    vardperson.setNamn(hsaNamn);
    f.setVardperson(vardperson);
    f.setFrageText("Detta var ju otydligt formulerat!");
    f.setIntygsReferens(INTYGS_REFERENS);
    f.setStatus(status);
    return f;
}
Also used : Vardperson(se.inera.intyg.webcert.persistence.fragasvar.model.Vardperson) FragaSvar(se.inera.intyg.webcert.persistence.fragasvar.model.FragaSvar)

Aggregations

FragaSvar (se.inera.intyg.webcert.persistence.fragasvar.model.FragaSvar)71 Test (org.junit.Test)42 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)14 IntygsReferens (se.inera.intyg.webcert.persistence.fragasvar.model.IntygsReferens)11 Vardperson (se.inera.intyg.webcert.persistence.fragasvar.model.Vardperson)11 Produces (javax.ws.rs.Produces)7 AttributedURIType (org.w3.wsaddressing10.AttributedURIType)7 Path (javax.ws.rs.Path)6 Filter (se.inera.intyg.webcert.persistence.model.Filter)6 LocalDateTime (java.time.LocalDateTime)5 Consumes (javax.ws.rs.Consumes)5 WebCertUser (se.inera.intyg.webcert.web.service.user.dto.WebCertUser)5 ArendeListItem (se.inera.intyg.webcert.web.web.controller.api.dto.ArendeListItem)5 ArrayList (java.util.ArrayList)4 SOAPFaultException (javax.xml.ws.soap.SOAPFaultException)4 SendMedicalCertificateAnswerResponseType (se.inera.ifv.insuranceprocess.healthreporting.sendmedicalcertificateanswerresponder.v1.SendMedicalCertificateAnswerResponseType)4 SendMedicalCertificateAnswerType (se.inera.ifv.insuranceprocess.healthreporting.sendmedicalcertificateanswerresponder.v1.SendMedicalCertificateAnswerType)4 SendMedicalCertificateQuestionType (se.inera.ifv.insuranceprocess.healthreporting.sendmedicalcertificatequestionresponder.v1.SendMedicalCertificateQuestionType)4 WebCertServiceException (se.inera.intyg.webcert.common.service.exception.WebCertServiceException)4 Amne (se.inera.intyg.webcert.persistence.fragasvar.model.Amne)4