Search in sources :

Example 96 with WebCertUser

use of se.inera.intyg.webcert.web.service.user.dto.WebCertUser in project webcert by sklintyg.

the class StatModuleApiControllerTest method setupDataAndExpectations.

@Before
public void setupDataAndExpectations() {
    fragaSvarStatsMap = new HashMap<>();
    fragaSvarStatsMap.put("VE1", 2L);
    fragaSvarStatsMap.put("VE1M1", 3L);
    fragaSvarStatsMap.put("VE1M2", 3L);
    fragaSvarStatsMap.put("VE2", 2L);
    fragaSvarStatsMap.put("VE3", 1L);
    arendeStatsMap = new HashMap<>();
    arendeStatsMap.put("VE1", 2L);
    arendeStatsMap.put("VE1M1", 3L);
    arendeStatsMap.put("VE1M2", 3L);
    arendeStatsMap.put("VE2", 2L);
    arendeStatsMap.put("VE3", 1L);
    intygStatsMap = new HashMap<>();
    intygStatsMap.put("VE1M1", 1L);
    intygStatsMap.put("VE1M2", 2L);
    intygStatsMap.put("VE2", 2L);
    mockUser = new WebCertUser();
    Role role = AUTHORITIES_RESOLVER.getRole(AuthoritiesConstants.ROLE_LAKARE);
    mockUser.setRoles(AuthoritiesResolverUtil.toMap(role));
    mockUser.setAuthorities(AuthoritiesResolverUtil.toMap(role.getPrivileges(), Privilege::getName));
    ve1 = new Vardenhet("VE1", "Vardenhet1");
    ve1.getMottagningar().add(new Mottagning("VE1M1", "Mottagning1"));
    ve1.getMottagningar().add(new Mottagning("VE1M2", "Mottagning2"));
    ve2 = new Vardenhet("VE2", "Vardenhet2");
    ve2.getMottagningar().add(new Mottagning("VE2M1", "Mottagning3"));
    ve3 = new Vardenhet("VE3", "Vardenhet3");
    ve4 = new Vardenhet("VE4", "Vardenhet4");
    Vardgivare vg = new Vardgivare("VG1", "Vardgivaren");
    vg.setVardenheter(Arrays.asList(ve1, ve2, ve3, ve4));
    mockUser.setVardgivare(Collections.singletonList(vg));
    mockUser.setValdVardgivare(vg);
    when(authoritiesHelper.getIntygstyperForPrivilege(any(UserDetails.class), anyString())).thenReturn(Stream.of("fk7263").collect(Collectors.toSet()));
    when(webCertUserService.getUser()).thenReturn(mockUser);
}
Also used : Role(se.inera.intyg.infra.security.common.model.Role) UserDetails(se.inera.intyg.infra.security.common.model.UserDetails) Vardenhet(se.inera.intyg.infra.integration.hsa.model.Vardenhet) Vardgivare(se.inera.intyg.infra.integration.hsa.model.Vardgivare) WebCertUser(se.inera.intyg.webcert.web.service.user.dto.WebCertUser) Mottagning(se.inera.intyg.infra.integration.hsa.model.Mottagning) Before(org.junit.Before)

Example 97 with WebCertUser

use of se.inera.intyg.webcert.web.service.user.dto.WebCertUser in project webcert by sklintyg.

the class FragaSvarServiceImpl method saveSvar.

@Override
public FragaSvar saveSvar(Long fragaSvarsId, String svarsText) {
    // Input sanity check
    if (Strings.isNullOrEmpty(svarsText)) {
        throw new WebCertServiceException(WebCertServiceErrorCodeEnum.INTERNAL_PROBLEM, "SvarsText cannot be empty!");
    }
    // Look up entity in repository
    FragaSvar fragaSvar = lookupFragaSvar(fragaSvarsId);
    // Is user authorized to save an answer to this question?
    verifyEnhetsAuth(fragaSvar.getVardperson().getEnhetsId(), false);
    if (!fragaSvar.getStatus().equals(Status.PENDING_INTERNAL_ACTION)) {
        throw new WebCertServiceException(WebCertServiceErrorCodeEnum.INVALID_STATE, "FragaSvar with id " + fragaSvar.getInternReferens().toString() + " has invalid state for saving answer(" + fragaSvar.getStatus() + ")");
    }
    // Implement Business Rule FS-007
    if (Amne.PAMINNELSE.equals(fragaSvar.getAmne())) {
        throw new WebCertServiceException(WebCertServiceErrorCodeEnum.INTERNAL_PROBLEM, "FragaSvar with id " + fragaSvar.getInternReferens().toString() + " has invalid Amne(" + fragaSvar.getAmne() + ") for saving answer");
    }
    if (Amne.KOMPLETTERING_AV_LAKARINTYG.equals(fragaSvar.getAmne())) {
        throw new WebCertServiceException(WebCertServiceErrorCodeEnum.INTERNAL_PROBLEM, "FragaSvar with id " + fragaSvar.getInternReferens().toString() + " has invalid Amne(" + fragaSvar.getAmne() + ") for saving answer");
    }
    LocalDateTime now = LocalDateTime.now();
    WebCertUser user = webCertUserService.getUser();
    // Ok, lets save the answer
    fragaSvar.setVardAktorHsaId(user.getHsaId());
    fragaSvar.setVardAktorNamn(user.getNamn());
    fragaSvar.setSvarsText(svarsText);
    fragaSvar.setSvarSkickadDatum(now);
    fragaSvar.setStatus(Status.CLOSED);
    fragaSvar.setSvarSigneringsDatum(now);
    FragaSvar saved = fragaSvarRepository.save(fragaSvar);
    sendFragaSvarToExternalParty(saved);
    arendeDraftService.delete(fragaSvar.getIntygsReferens().getIntygsId(), Long.toString(fragaSvar.getInternReferens()));
    return saved;
}
Also used : LocalDateTime(java.time.LocalDateTime) FragaSvar(se.inera.intyg.webcert.persistence.fragasvar.model.FragaSvar) WebCertServiceException(se.inera.intyg.webcert.common.service.exception.WebCertServiceException) WebCertUser(se.inera.intyg.webcert.web.service.user.dto.WebCertUser)

Example 98 with WebCertUser

use of se.inera.intyg.webcert.web.service.user.dto.WebCertUser in project webcert by sklintyg.

the class FragaSvarServiceImpl method getFragaSvarHsaIdByEnhet.

@Override
@Transactional(value = "jpaTransactionManager", readOnly = true)
public List<Lakare> getFragaSvarHsaIdByEnhet(String enhetsId) {
    List<String> enhetsIdParams = new ArrayList<>();
    if (enhetsId != null) {
        verifyEnhetsAuth(enhetsId);
        enhetsIdParams.add(enhetsId);
    } else {
        WebCertUser user = webCertUserService.getUser();
        enhetsIdParams.addAll(user.getIdsOfSelectedVardenhet());
    }
    List<Lakare> mdList = new ArrayList<>();
    List<Object[]> tempList = fragaSvarRepository.findDistinctFragaSvarHsaIdByEnhet(enhetsIdParams);
    for (Object[] obj : tempList) {
        mdList.add(new Lakare((String) obj[0], (String) obj[1]));
    }
    return mdList;
}
Also used : Lakare(se.inera.intyg.webcert.web.service.dto.Lakare) ArrayList(java.util.ArrayList) WebCertUser(se.inera.intyg.webcert.web.service.user.dto.WebCertUser) Transactional(org.springframework.transaction.annotation.Transactional)

Example 99 with WebCertUser

use of se.inera.intyg.webcert.web.service.user.dto.WebCertUser in project webcert by sklintyg.

the class FragaSvarServiceImpl method saveNewQuestion.

@Override
public FragaSvar saveNewQuestion(String intygId, String typ, Amne amne, String frageText) {
    // Argument check
    if (Strings.isNullOrEmpty(frageText)) {
        throw new WebCertServiceException(WebCertServiceErrorCodeEnum.INTERNAL_PROBLEM, "frageText cannot be empty!");
    }
    if (amne == null) {
        throw new WebCertServiceException(WebCertServiceErrorCodeEnum.INTERNAL_PROBLEM, "Amne cannot be null!");
    } else if (!VALID_VARD_AMNEN.contains(amne)) {
        // Businessrule RE-013
        throw new WebCertServiceException(WebCertServiceErrorCodeEnum.INTERNAL_PROBLEM, "Invalid Amne " + amne + " for new question from vard!");
    }
    // Fetch from Intygstjansten. Note that if Intygstjansten is unresponsive, the Intyg will be loaded from WebCert
    // if possible.
    IntygContentHolder intyg = intygService.fetchIntygData(intygId, typ, false);
    WebCertUser user = webCertUserService.getUser();
    // Get vardperson that posed the question
    // Is user authorized to save an answer to this question?
    verifyEnhetsAuth(intyg.getUtlatande().getGrundData().getSkapadAv().getVardenhet().getEnhetsid(), false);
    // Verksamhetsregel FS-001 (Is the certificate sent to FK)
    if (!isCertificateSentToFK(intyg.getStatuses())) {
        throw new WebCertServiceException(WebCertServiceErrorCodeEnum.INTERNAL_PROBLEM, "FS-001: Certificate must be sent to FK first before sending question!");
    }
    // Verify that certificate is not revoked
    if (intyg.isRevoked()) {
        throw new WebCertServiceException(WebCertServiceErrorCodeEnum.INTERNAL_PROBLEM, "FS-XXX: Cannot save Fraga when certificate is revoked!");
    }
    IntygsReferens intygsReferens = FragaSvarConverter.convertToIntygsReferens(intyg.getUtlatande());
    HoSPersonal hoSPersonal = IntygConverterUtil.buildHosPersonalFromWebCertUser(user, null);
    Vardperson vardPerson = FragaSvarConverter.convert(hoSPersonal);
    FragaSvar fraga = new FragaSvar();
    fraga.setFrageStallare(FrageStallare.WEBCERT.getKod());
    fraga.setAmne(amne);
    fraga.setFrageText(frageText);
    LocalDateTime now = LocalDateTime.now();
    fraga.setFrageSkickadDatum(now);
    fraga.setFrageSigneringsDatum(now);
    fraga.setIntygsReferens(intygsReferens);
    fraga.setVardperson(vardPerson);
    fraga.setStatus(Status.PENDING_EXTERNAL_ACTION);
    fraga.setVardAktorHsaId(user.getHsaId());
    fraga.setVardAktorNamn(user.getNamn());
    // Ok, lets save the question
    FragaSvar saved = fragaSvarRepository.save(fraga);
    // Send to external party (FK)
    SendMedicalCertificateQuestionType sendType = new SendMedicalCertificateQuestionType();
    QuestionToFkType question = FKQuestionConverter.convert(saved);
    // Remove ASAP.
    if ("true".equalsIgnoreCase(forceFullstandigtNamn)) {
        question.getLakarutlatande().getPatient().setFullstandigtNamn("---");
    }
    sendType.setQuestion(question);
    AttributedURIType logicalAddress = new AttributedURIType();
    logicalAddress.setValue(sendQuestionToFkLogicalAddress);
    SendMedicalCertificateQuestionResponseType response;
    try {
        response = sendQuestionToFKClient.sendMedicalCertificateQuestion(logicalAddress, sendType);
    } catch (SOAPFaultException e) {
        LOGGER.error("Failed to send question to FK, error was: " + e.getMessage());
        throw new WebCertServiceException(WebCertServiceErrorCodeEnum.EXTERNAL_SYSTEM_PROBLEM, e.getMessage());
    }
    if (!response.getResult().getResultCode().equals(ResultCodeEnum.OK)) {
        LOGGER.error("Failed to send question to FK, result was " + response.getResult().toString());
        throw new WebCertServiceException(WebCertServiceErrorCodeEnum.EXTERNAL_SYSTEM_PROBLEM, response.getResult().getErrorText());
    }
    monitoringService.logQuestionSent(saved.getExternReferens(), saved.getInternReferens(), (saved.getIntygsReferens() == null) ? null : saved.getIntygsReferens().getIntygsId(), saved.getVardAktorHsaId(), saved.getAmne());
    // Notify stakeholders
    sendNotification(saved, NotificationEvent.NEW_QUESTION_FROM_CARE);
    arendeDraftService.delete(intygId, null);
    return saved;
}
Also used : Vardperson(se.inera.intyg.webcert.persistence.fragasvar.model.Vardperson) LocalDateTime(java.time.LocalDateTime) AttributedURIType(org.w3.wsaddressing10.AttributedURIType) SOAPFaultException(javax.xml.ws.soap.SOAPFaultException) QuestionToFkType(se.inera.ifv.insuranceprocess.healthreporting.sendmedicalcertificatequestionresponder.v1.QuestionToFkType) WebCertServiceException(se.inera.intyg.webcert.common.service.exception.WebCertServiceException) HoSPersonal(se.inera.intyg.common.support.model.common.internal.HoSPersonal) IntygContentHolder(se.inera.intyg.webcert.web.service.intyg.dto.IntygContentHolder) IntygsReferens(se.inera.intyg.webcert.persistence.fragasvar.model.IntygsReferens) FragaSvar(se.inera.intyg.webcert.persistence.fragasvar.model.FragaSvar) SendMedicalCertificateQuestionType(se.inera.ifv.insuranceprocess.healthreporting.sendmedicalcertificatequestionresponder.v1.SendMedicalCertificateQuestionType) SendMedicalCertificateQuestionResponseType(se.inera.ifv.insuranceprocess.healthreporting.sendmedicalcertificatequestionresponder.v1.SendMedicalCertificateQuestionResponseType) WebCertUser(se.inera.intyg.webcert.web.service.user.dto.WebCertUser)

Example 100 with WebCertUser

use of se.inera.intyg.webcert.web.service.user.dto.WebCertUser 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

WebCertUser (se.inera.intyg.webcert.web.service.user.dto.WebCertUser)217 Test (org.junit.Test)123 IntegrationParameters (se.inera.intyg.webcert.web.web.controller.integration.dto.IntegrationParameters)32 Utkast (se.inera.intyg.webcert.persistence.utkast.model.Utkast)31 Personnummer (se.inera.intyg.schemas.contract.Personnummer)24 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)23 WebCertServiceException (se.inera.intyg.webcert.common.service.exception.WebCertServiceException)23 Role (se.inera.intyg.infra.security.common.model.Role)18 HoSPersonal (se.inera.intyg.common.support.model.common.internal.HoSPersonal)16 Arende (se.inera.intyg.webcert.persistence.arende.model.Arende)15 CopyIntygRequest (se.inera.intyg.webcert.web.web.controller.api.dto.CopyIntygRequest)15 Utlatande (se.inera.intyg.common.support.model.common.internal.Utlatande)14 Vardenhet (se.inera.intyg.infra.integration.hsa.model.Vardenhet)14 CopyUtkastBuilderResponse (se.inera.intyg.webcert.web.service.utkast.dto.CopyUtkastBuilderResponse)14 Vardgivare (se.inera.intyg.infra.integration.hsa.model.Vardgivare)13 Feature (se.inera.intyg.infra.security.common.model.Feature)13 HashMap (java.util.HashMap)12 MedicinsktArende (se.inera.intyg.webcert.persistence.arende.model.MedicinsktArende)12 Transactional (org.springframework.transaction.annotation.Transactional)11 Path (javax.ws.rs.Path)10