Search in sources :

Example 6 with SekretessStatus

use of se.inera.intyg.webcert.common.model.SekretessStatus in project webcert by sklintyg.

the class CreateDraftCertificateResponderImpl method createDraftCertificate.

@Override
public CreateDraftCertificateResponseType createDraftCertificate(String logicalAddress, CreateDraftCertificateType parameters) {
    Utlatande utkastsParams = parameters.getUtlatande();
    // Redo this: Build a full Vårdgivare -> Vårdenhet -> Mottagning tree and then check.
    String invokingUserHsaId = utkastsParams.getSkapadAv().getPersonalId().getExtension();
    String invokingUnitHsaId = utkastsParams.getSkapadAv().getEnhet().getEnhetsId().getExtension();
    IntygUser user;
    try {
        user = webcertUserDetailsService.loadUserByHsaId(invokingUserHsaId);
    } catch (Exception e) {
        return createMIUErrorResponse(utkastsParams);
    }
    // Validate draft parameters
    ResultValidator resultsValidator = validator.validate(utkastsParams);
    if (resultsValidator.hasErrors()) {
        return createValidationErrorResponse(resultsValidator);
    }
    ResultValidator appErrorsValidator = validator.validateApplicationErrors(utkastsParams, user);
    if (appErrorsValidator.hasErrors()) {
        return createApplicationErrorResponse(appErrorsValidator);
    }
    LOG.debug("Creating draft for invoker '{}' on unit '{}'", invokingUserHsaId, invokingUnitHsaId);
    // Check if the invoking health personal has MIU rights on care unit
    if (!checkMIU(user, invokingUnitHsaId)) {
        return createMIUErrorResponse(utkastsParams);
    }
    user.changeValdVardenhet(invokingUnitHsaId);
    String intygsTyp = utkastsParams.getTypAvUtlatande().getCode().toLowerCase();
    Personnummer personnummer = Personnummer.createPersonnummer(utkastsParams.getPatient().getPersonId().getExtension()).orElseThrow(() -> new WebCertServiceException(WebCertServiceErrorCodeEnum.PU_PROBLEM, "Failed to create valid personnummer for createDraft reques"));
    final SekretessStatus sekretessStatus = patientDetailsResolver.getSekretessStatus(personnummer);
    if (AuthoritiesHelperUtil.mayNotCreateUtkastForSekretessMarkerad(sekretessStatus, user, intygsTyp)) {
        return createErrorResponse("Intygstypen " + intygsTyp + " kan inte utfärdas för patienter med sekretessmarkering", ErrorIdType.APPLICATION_ERROR);
    }
    Map<String, Map<String, Boolean>> intygstypToBoolean = utkastService.checkIfPersonHasExistingIntyg(personnummer, user);
    String uniqueErrorString = AuthoritiesHelperUtil.validateMustBeUnique(user, intygsTyp, intygstypToBoolean);
    if (!uniqueErrorString.isEmpty()) {
        return createErrorResponse(uniqueErrorString, ErrorIdType.APPLICATION_ERROR);
    }
    if (authoritiesValidator.given(user, intygsTyp).features(AuthoritiesConstants.FEATURE_TAK_KONTROLL).isVerified()) {
        // Check if invoking health care unit has required TAK
        SchemaVersion schemaVersion = integreradeEnheterRegistry.getSchemaVersion(invokingUnitHsaId, intygsTyp).orElse(SchemaVersion.VERSION_1);
        TakResult takResult = takService.verifyTakningForCareUnit(invokingUnitHsaId, intygsTyp, schemaVersion, user);
        if (!takResult.isValid()) {
            String error = Joiner.on("; ").join(takResult.getErrorMessages());
            return createErrorResponse(error, ErrorIdType.APPLICATION_ERROR);
        }
    }
    // Create the draft
    Utkast utkast = createNewDraft(utkastsParams, user);
    return createSuccessResponse(utkast.getIntygsId());
}
Also used : SekretessStatus(se.inera.intyg.webcert.common.model.SekretessStatus) SchemaVersion(se.inera.intyg.common.support.modules.support.api.notification.SchemaVersion) TakResult(se.inera.intyg.webcert.integration.tak.model.TakResult) IntygUser(se.inera.intyg.infra.security.common.model.IntygUser) WebCertServiceException(se.inera.intyg.webcert.common.service.exception.WebCertServiceException) WebCertServiceException(se.inera.intyg.webcert.common.service.exception.WebCertServiceException) Personnummer(se.inera.intyg.schemas.contract.Personnummer) Utlatande(se.riv.clinicalprocess.healthcond.certificate.createdraftcertificateresponder.v1.Utlatande) ResultValidator(se.inera.intyg.webcert.web.integration.validators.ResultValidator) Utkast(se.inera.intyg.webcert.persistence.utkast.model.Utkast) Map(java.util.Map)

Example 7 with SekretessStatus

use of se.inera.intyg.webcert.common.model.SekretessStatus in project webcert by sklintyg.

the class CreateDraftCertificateResponderImpl method createDraftCertificate.

@Override
public CreateDraftCertificateResponseType createDraftCertificate(String logicalAddress, CreateDraftCertificateType parameters) {
    Intyg utkastsParams = parameters.getIntyg();
    String invokingUserHsaId = utkastsParams.getSkapadAv().getPersonalId().getExtension();
    String invokingUnitHsaId = utkastsParams.getSkapadAv().getEnhet().getEnhetsId().getExtension();
    IntygUser user;
    try {
        user = webcertUserDetailsService.loadUserByHsaId(invokingUserHsaId);
    } catch (Exception e) {
        return createMIUErrorResponse(utkastsParams);
    }
    // Validate draft parameters
    ResultValidator resultsValidator = validator.validate(utkastsParams);
    if (resultsValidator.hasErrors()) {
        return createValidationErrorResponse(resultsValidator);
    }
    ResultValidator appErrorsValidator = validator.validateApplicationErrors(utkastsParams, user);
    if (appErrorsValidator.hasErrors()) {
        return createApplicationErrorResponse(appErrorsValidator);
    }
    LOG.debug("Creating draft for invoker '{}' on unit '{}'", utkastsParams.getSkapadAv().getPersonalId().getExtension(), invokingUnitHsaId);
    // Check if the invoking health personal has MIU rights on care unit
    if (!HoSPersonHelper.findVardenhetEllerMottagning(user, invokingUnitHsaId).isPresent()) {
        return createMIUErrorResponse(utkastsParams);
    }
    user.changeValdVardenhet(invokingUnitHsaId);
    String intygsTyp = moduleRegistry.getModuleIdFromExternalId(utkastsParams.getTypAvIntyg().getCode());
    Personnummer personnummer = Personnummer.createPersonnummer(utkastsParams.getPatient().getPersonId().getExtension()).orElseThrow(() -> new WebCertServiceException(WebCertServiceErrorCodeEnum.PU_PROBLEM, "Failed to create valid personnummer for createDraft request"));
    SekretessStatus sekretessStatus = patientDetailsResolver.getSekretessStatus(personnummer);
    if (AuthoritiesHelperUtil.mayNotCreateUtkastForSekretessMarkerad(sekretessStatus, user, intygsTyp)) {
        return createErrorResponse("Intygstypen " + intygsTyp.toUpperCase() + " kan inte utfärdas för patienter med sekretessmarkering", ErrorIdType.APPLICATION_ERROR);
    }
    Map<String, Map<String, Boolean>> intygstypToBoolean = utkastService.checkIfPersonHasExistingIntyg(personnummer, user);
    String uniqueErrorString = AuthoritiesHelperUtil.validateMustBeUnique(user, intygsTyp, intygstypToBoolean);
    if (!uniqueErrorString.isEmpty()) {
        return createErrorResponse(uniqueErrorString, ErrorIdType.APPLICATION_ERROR);
    }
    if (authoritiesValidator.given(user, intygsTyp).features(AuthoritiesConstants.FEATURE_TAK_KONTROLL).isVerified()) {
        // Check if invoking health care unit has required TAK
        TakResult takResult = takService.verifyTakningForCareUnit(invokingUnitHsaId, intygsTyp, SchemaVersion.VERSION_3, user);
        if (!takResult.isValid()) {
            String error = Joiner.on("; ").join(takResult.getErrorMessages());
            return createErrorResponse(error, ErrorIdType.APPLICATION_ERROR);
        }
    }
    // Create the draft
    Utkast utkast = createNewDraft(utkastsParams, user);
    return createSuccessResponse(utkast.getIntygsId(), invokingUnitHsaId);
}
Also used : Personnummer(se.inera.intyg.schemas.contract.Personnummer) SekretessStatus(se.inera.intyg.webcert.common.model.SekretessStatus) Intyg(se.riv.clinicalprocess.healthcond.certificate.createdraftcertificateresponder.v3.Intyg) ResultValidator(se.inera.intyg.webcert.web.integration.validators.ResultValidator) Utkast(se.inera.intyg.webcert.persistence.utkast.model.Utkast) TakResult(se.inera.intyg.webcert.integration.tak.model.TakResult) Map(java.util.Map) IntygUser(se.inera.intyg.infra.security.common.model.IntygUser) WebCertServiceException(se.inera.intyg.webcert.common.service.exception.WebCertServiceException) WebCertServiceException(se.inera.intyg.webcert.common.service.exception.WebCertServiceException)

Example 8 with SekretessStatus

use of se.inera.intyg.webcert.common.model.SekretessStatus in project webcert by sklintyg.

the class UtkastApiControllerTest method testFilterDraftsForUnitSkipsSekretessIntygForUserWithoutAuthorithy.

@Test
public void testFilterDraftsForUnitSkipsSekretessIntygForUserWithoutAuthorithy() {
    setupUser("", LuseEntryPoint.MODULE_ID, AuthoritiesConstants.FEATURE_HANTERA_INTYGSUTKAST);
    Map<Personnummer, SekretessStatus> sekretessMap = mock(Map.class);
    when(sekretessMap.get(eq(PATIENT_PERSONNUMMER))).thenReturn(SekretessStatus.FALSE);
    when(sekretessMap.get(eq(PATIENT_PERSONNUMMER_PU_SEKRETESS))).thenReturn(SekretessStatus.TRUE);
    when(patientDetailsResolver.getSekretessStatusForList(anyList())).thenReturn(sekretessMap);
    when(utkastService.filterIntyg(any())).thenReturn(Arrays.asList(buildUtkast(PATIENT_PERSONNUMMER), buildUtkast(PATIENT_PERSONNUMMER_PU_SEKRETESS)));
    final Response response = utkastController.filterDraftsForUnit(buildQueryIntygParameter());
    final QueryIntygResponse queryIntygResponse = response.readEntity(QueryIntygResponse.class);
    assertEquals(1, queryIntygResponse.getTotalCount());
    assertEquals(1, queryIntygResponse.getResults().size());
    assertEquals(PATIENT_PERSONNUMMER, queryIntygResponse.getResults().get(0).getPatientId());
}
Also used : Personnummer(se.inera.intyg.schemas.contract.Personnummer) Response(javax.ws.rs.core.Response) QueryIntygResponse(se.inera.intyg.webcert.web.web.controller.api.dto.QueryIntygResponse) QueryIntygResponse(se.inera.intyg.webcert.web.web.controller.api.dto.QueryIntygResponse) SekretessStatus(se.inera.intyg.webcert.common.model.SekretessStatus) Test(org.junit.Test)

Example 9 with SekretessStatus

use of se.inera.intyg.webcert.common.model.SekretessStatus in project webcert by sklintyg.

the class FragaSvarServiceImpl method validateSekretessmarkering.

/**
 * If there is at least one fragaSvar in the response, we fetch the personId and check for sekretessmarkering.
 */
private void validateSekretessmarkering(String intygsId, List<FragaSvar> fragaSvarList, WebCertUser user) {
    if (fragaSvarList.size() > 0) {
        Personnummer pnr = fragaSvarList.get(0).getIntygsReferens().getPatientId();
        String intygsTyp = fragaSvarList.get(0).getIntygsReferens().getIntygsTyp();
        SekretessStatus sekretessStatus = patientDetailsResolver.getSekretessStatus(pnr);
        if (sekretessStatus == SekretessStatus.UNDEFINED) {
            throw new WebCertServiceException(WebCertServiceErrorCodeEnum.PU_PROBLEM, "Cannot list fraga/svar for '" + intygsId + "'. PU service unavailable or personnummer " + pnr.getPersonnummerHash() + " not valid");
        }
        authoritiesValidator.given(user, intygsTyp).privilegeIf(AuthoritiesConstants.PRIVILEGE_HANTERA_SEKRETESSMARKERAD_PATIENT, sekretessStatus == SekretessStatus.TRUE).orThrow(new WebCertServiceException(WebCertServiceErrorCodeEnum.AUTHORIZATION_PROBLEM_SEKRETESSMARKERING, "User is not allowed to handle sekretessmarkerad patient"));
    }
}
Also used : Personnummer(se.inera.intyg.schemas.contract.Personnummer) SekretessStatus(se.inera.intyg.webcert.common.model.SekretessStatus) WebCertServiceException(se.inera.intyg.webcert.common.service.exception.WebCertServiceException)

Example 10 with SekretessStatus

use of se.inera.intyg.webcert.common.model.SekretessStatus in project webcert by sklintyg.

the class IntygServiceImpl method buildIntygItemListFromDrafts.

private List<ListIntygEntry> buildIntygItemListFromDrafts(List<String> enhetId, Personnummer personnummer) {
    List<UtkastStatus> statuses = new ArrayList<>();
    statuses.add(UtkastStatus.SIGNED);
    SekretessStatus sekretessmarkering = patientDetailsResolver.getSekretessStatus(personnummer);
    Set<String> base = authoritiesHelper.getIntygstyperForPrivilege(webCertUserService.getUser(), AuthoritiesConstants.PRIVILEGE_VISA_INTYG);
    // Remove intygstyper that cannot be issued for a sekretessmarkerad patient
    Set<String> intygsTyper = (sekretessmarkering == SekretessStatus.TRUE || sekretessmarkering == SekretessStatus.UNDEFINED) ? filterAllowedForSekretessMarkering(base) : base;
    List<Utkast> drafts = utkastRepository.findDraftsByPatientAndEnhetAndStatus(DaoUtil.formatPnrForPersistence(personnummer), enhetId, statuses, intygsTyper);
    return IntygDraftsConverter.convertUtkastsToListIntygEntries(drafts);
}
Also used : UtkastStatus(se.inera.intyg.webcert.common.model.UtkastStatus) SekretessStatus(se.inera.intyg.webcert.common.model.SekretessStatus) Utkast(se.inera.intyg.webcert.persistence.utkast.model.Utkast) ArrayList(java.util.ArrayList)

Aggregations

SekretessStatus (se.inera.intyg.webcert.common.model.SekretessStatus)20 Personnummer (se.inera.intyg.schemas.contract.Personnummer)14 WebCertServiceException (se.inera.intyg.webcert.common.service.exception.WebCertServiceException)9 Utkast (se.inera.intyg.webcert.persistence.utkast.model.Utkast)7 Map (java.util.Map)5 HashMap (java.util.HashMap)4 Test (org.junit.Test)4 WebCertUser (se.inera.intyg.webcert.web.service.user.dto.WebCertUser)4 ArrayList (java.util.ArrayList)3 List (java.util.List)3 Response (javax.ws.rs.core.Response)3 ModuleNotFoundException (se.inera.intyg.common.support.modules.registry.ModuleNotFoundException)3 GroupableItem (se.inera.intyg.webcert.common.model.GroupableItem)3 ListIntygEntry (se.inera.intyg.webcert.web.web.controller.api.dto.ListIntygEntry)3 LocalDateTime (java.time.LocalDateTime)2 Collectors (java.util.stream.Collectors)2 Path (javax.ws.rs.Path)2 Produces (javax.ws.rs.Produces)2 WebServiceException (javax.xml.ws.WebServiceException)2 Autowired (org.springframework.beans.factory.annotation.Autowired)2