Search in sources :

Example 11 with Personnummer

use of se.inera.intyg.schemas.contract.Personnummer in project webcert by sklintyg.

the class SrsApiController method getConsent.

@GET
@Path("/consent/{personnummer}/{hsaId}")
@Produces(MediaType.APPLICATION_JSON + UTF_8_CHARSET)
@ApiOperation(value = "Get consent for patient and careunit", httpMethod = "GET", produces = MediaType.APPLICATION_JSON)
public Response getConsent(@ApiParam(value = "Personnummer") @PathParam("personnummer") String personnummer, @ApiParam(value = "HsaId för vårdenhet") @PathParam("hsaId") String hsaId) {
    authoritiesValidator.given(getWebCertUserService().getUser()).features(AuthoritiesConstants.FEATURE_SRS).orThrow();
    try {
        Personnummer p = createPnr(personnummer);
        Samtyckesstatus response = srsService.getConsent(hsaId, p);
        return Response.ok(response).build();
    } catch (InvalidPersonNummerException e) {
        return Response.status(Response.Status.BAD_REQUEST).build();
    }
}
Also used : Personnummer(se.inera.intyg.schemas.contract.Personnummer) InvalidPersonNummerException(se.inera.intyg.schemas.contract.InvalidPersonNummerException) Samtyckesstatus(se.inera.intyg.clinicalprocess.healthcond.srs.getconsent.v1.Samtyckesstatus) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET) ApiOperation(io.swagger.annotations.ApiOperation)

Example 12 with Personnummer

use of se.inera.intyg.schemas.contract.Personnummer in project webcert by sklintyg.

the class StatisticsGroupByUtil method toSekretessFilteredMap.

/**
 * Takes a list of object[] where each object[] is one of utkast, fraga/svar or arende represented as:
 *
 * [0] id (unique, this is what we want to count per enhetsId)
 * [1] enhetsId
 * [2] personnummer
 *
 * This method will filter out any items belonging to a patient having sekretessmarkering and return the result as a
 * map: EnhetsId -> number of id for that unit.
 *
 * @param groupableItems
 *            Each item is an array of: id, enhetsId, personnummer, intygsTyp.
 * @return
 *         Map with enhetsId -> count, with personummer being sekretessmarkerade has been removed.
 */
public Map<String, Long> toSekretessFilteredMap(List<GroupableItem> groupableItems) {
    if (groupableItems == null || groupableItems.size() == 0) {
        return new HashMap<>();
    }
    List<GroupableItem> filteredGroupableItems = getFilteredGroupableItemList(groupableItems);
    WebCertUser user = webCertUserService.getUser();
    Map<Personnummer, SekretessStatus> sekretessStatusMap = patientDetailsResolver.getSekretessStatusForList(getPersonummerList(filteredGroupableItems));
    // update sekretess status
    filteredGroupableItems.forEach(item -> item.setSekretessStatus(sekretessStatusMap.get(createPnr(item.getPersonnummer()))));
    return filteredGroupableItems.stream().filter(item -> item.getSekretessStatus() != SekretessStatus.UNDEFINED).filter(item -> authoritiesValidator.given(user, item.getIntygsTyp()).privilegeIf(AuthoritiesConstants.PRIVILEGE_HANTERA_SEKRETESSMARKERAD_PATIENT, item.getSekretessStatus() == SekretessStatus.TRUE).isVerified()).collect(Collectors.groupingBy(GroupableItem::getEnhetsId, Collectors.counting()));
}
Also used : Personnummer(se.inera.intyg.schemas.contract.Personnummer) AuthoritiesValidator(se.inera.intyg.infra.security.authorities.validation.AuthoritiesValidator) SekretessStatus(se.inera.intyg.webcert.common.model.SekretessStatus) PatientDetailsResolver(se.inera.intyg.webcert.web.service.patient.PatientDetailsResolver) Personnummer(se.inera.intyg.schemas.contract.Personnummer) Autowired(org.springframework.beans.factory.annotation.Autowired) HashMap(java.util.HashMap) WebCertUserService(se.inera.intyg.webcert.web.service.user.WebCertUserService) Collectors(java.util.stream.Collectors) GroupableItem(se.inera.intyg.webcert.common.model.GroupableItem) Component(org.springframework.stereotype.Component) List(java.util.List) Map(java.util.Map) WebCertUser(se.inera.intyg.webcert.web.service.user.dto.WebCertUser) AuthoritiesConstants(se.inera.intyg.infra.security.common.model.AuthoritiesConstants) GroupableItem(se.inera.intyg.webcert.common.model.GroupableItem) SekretessStatus(se.inera.intyg.webcert.common.model.SekretessStatus) HashMap(java.util.HashMap) WebCertUser(se.inera.intyg.webcert.web.service.user.dto.WebCertUser)

Example 13 with Personnummer

use of se.inera.intyg.schemas.contract.Personnummer in project webcert by sklintyg.

the class IntygIntegrationServiceImpl method ensureDraftPatientInfoUpdated.

/**
 * Updates Patient section of a draft with updated patient details for selected types.
 */
void ensureDraftPatientInfoUpdated(String intygsType, String draftId, long draftVersion, WebCertUser user) {
    // To be allowed to update utkast, we need to have the same authority as when saving a draft..
    authoritiesValidator.given(user, intygsType).features(AuthoritiesConstants.FEATURE_HANTERA_INTYGSUTKAST).privilege(AuthoritiesConstants.PRIVILEGE_SKRIVA_INTYG).orThrow();
    String alternatePatientSSn = user.getParameters().getAlternateSsn();
    Personnummer personnummer = Personnummer.createPersonnummer(alternatePatientSSn).orElse(null);
    UpdatePatientOnDraftRequest request = new UpdatePatientOnDraftRequest(personnummer, draftId, draftVersion);
    utkastService.updatePatientOnDraft(request);
}
Also used : Personnummer(se.inera.intyg.schemas.contract.Personnummer) UpdatePatientOnDraftRequest(se.inera.intyg.webcert.web.service.utkast.dto.UpdatePatientOnDraftRequest)

Example 14 with Personnummer

use of se.inera.intyg.schemas.contract.Personnummer 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 15 with Personnummer

use of se.inera.intyg.schemas.contract.Personnummer 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)

Aggregations

Personnummer (se.inera.intyg.schemas.contract.Personnummer)44 Test (org.junit.Test)15 SekretessStatus (se.inera.intyg.webcert.common.model.SekretessStatus)15 WebCertServiceException (se.inera.intyg.webcert.common.service.exception.WebCertServiceException)11 Utkast (se.inera.intyg.webcert.persistence.utkast.model.Utkast)11 PersonSvar (se.inera.intyg.infra.integration.pu.model.PersonSvar)8 HashMap (java.util.HashMap)6 Map (java.util.Map)6 Response (javax.ws.rs.core.Response)6 WebCertUser (se.inera.intyg.webcert.web.service.user.dto.WebCertUser)6 LocalDateTime (java.time.LocalDateTime)4 ArrayList (java.util.ArrayList)4 List (java.util.List)4 Path (javax.ws.rs.Path)4 Produces (javax.ws.rs.Produces)4 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)4 GroupableItem (se.inera.intyg.webcert.common.model.GroupableItem)4 Collectors (java.util.stream.Collectors)3 Autowired (org.springframework.beans.factory.annotation.Autowired)3 Fk7263EntryPoint (se.inera.intyg.common.fk7263.support.Fk7263EntryPoint)3