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());
}
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);
}
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());
}
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"));
}
}
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);
}
Aggregations