use of se.inera.intyg.schemas.contract.Personnummer 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.schemas.contract.Personnummer in project webcert by sklintyg.
the class IntygServiceImpl method getIntygData.
/**
* Builds a IntygContentHolder by first trying to get the Intyg from intygstjansten. If
* not found or the Intygstjanst couldn't be reached, the local Utkast - if available -
* will be used instead.
* <p>
* Note that even when found, we check if we need to decorate the response with data from the utkast in order
* to mitigate async send states. (E.g. a send may be in resend due to 3rd party issues, in that case decorate with
* data about sent state from the Utkast)
*
* @param relations
*/
private IntygContentHolder getIntygData(String intygId, String typ, boolean relations) {
try {
CertificateResponse certificate = modelFacade.getCertificate(intygId, typ);
String internalIntygJsonModel = certificate.getInternalModel();
final Personnummer personId = certificate.getUtlatande().getGrundData().getPatient().getPersonId();
// INTYG-4086: Patient object populated according to ruleset for the intygstyp at hand.
// Since an FK-intyg never will have anything other than personId, try to fetch all using ruleset
Patient newPatientData = patientDetailsResolver.resolvePatient(personId, typ);
Utlatande utlatande = null;
boolean patientNameChanged = false;
boolean patientAddressChanged = false;
try {
utlatande = moduleRegistry.getModuleApi(typ).getUtlatandeFromJson(internalIntygJsonModel);
patientNameChanged = patientDetailsResolver.isPatientNamedChanged(utlatande.getGrundData().getPatient(), newPatientData);
patientAddressChanged = patientDetailsResolver.isPatientAddressChanged(utlatande.getGrundData().getPatient(), newPatientData);
} catch (IOException e) {
LOG.error("Failed to getUtlatandeFromJson intygsId {} while checking for updated patient information", intygId);
}
// parameters were available.
if (newPatientData != null) {
// Get the module api and use the "updateBeforeSave" to update the outbound "model" with the
// Patient object.
ModuleApi moduleApi = moduleRegistry.getModuleApi(typ);
// INTYG-5354, INTYG-5380: Don't use incomplete address from external data sources (PU/js).
if (!completeAddressProvided(newPatientData)) {
// Use the old address data.
Patient oldPatientData = utlatande.getGrundData().getPatient();
copyOldAddressToNewPatientData(oldPatientData, newPatientData);
}
internalIntygJsonModel = moduleApi.updateBeforeSave(internalIntygJsonModel, newPatientData);
}
utkastIntygDecorator.decorateWithUtkastStatus(certificate);
Relations certificateRelations = intygRelationHelper.getRelationsForIntyg(intygId);
final SekretessStatus sekretessStatus = patientDetailsResolver.getSekretessStatus(personId);
if (SekretessStatus.UNDEFINED.equals(sekretessStatus)) {
throw new WebCertServiceException(WebCertServiceErrorCodeEnum.PU_PROBLEM, "Sekretesstatus could not be fetched from the PU service");
}
final boolean sekretessmarkering = SekretessStatus.TRUE.equals(sekretessStatus);
Utkast utkast = utkastRepository.findOneByIntygsIdAndIntygsTyp(intygId, typ);
final LocalDateTime created = utkast != null ? utkast.getSkapad() : null;
return IntygContentHolder.builder().setContents(internalIntygJsonModel).setUtlatande(certificate.getUtlatande()).setStatuses(certificate.getMetaData().getStatus()).setRevoked(certificate.isRevoked()).setRelations(certificateRelations).setCreated(created).setDeceased(isDeceased(personId)).setSekretessmarkering(sekretessmarkering).setPatientNameChangedInPU(patientNameChanged).setPatientAddressChangedInPU(patientAddressChanged).build();
} catch (IntygModuleFacadeException me) {
// It's possible the Intygstjanst hasn't received the Intyg yet, look for it locally before rethrowing
// exception
Utkast utkast = utkastRepository.findOneByIntygsIdAndIntygsTyp(intygId, typ);
if (utkast == null) {
throw new WebCertServiceException(WebCertServiceErrorCodeEnum.MODULE_PROBLEM, me);
}
return buildIntygContentHolderForUtkast(utkast, relations);
} catch (WebServiceException wse) {
// Something went wrong communication-wise, try to find a matching Utkast instead.
Utkast utkast = utkastRepository.findOneByIntygsIdAndIntygsTyp(intygId, typ);
if (utkast == null) {
throw new WebCertServiceException(WebCertServiceErrorCodeEnum.DATA_NOT_FOUND, "Cannot get intyg. Intygstjansten was not reachable and the Utkast could " + "not be found, perhaps it was issued by a non-webcert system?");
}
return buildIntygContentHolderForUtkast(utkast, relations);
} catch (ModuleNotFoundException | ModuleException e) {
throw new WebCertServiceException(WebCertServiceErrorCodeEnum.MODULE_PROBLEM, e);
}
}
use of se.inera.intyg.schemas.contract.Personnummer in project webcert by sklintyg.
the class ArendeServiceImpl method filterArende.
@Override
@Transactional(value = "jpaTransactionManager", readOnly = true)
public QueryFragaSvarResponse filterArende(QueryFragaSvarParameter filterParameters) {
WebCertUser user = webcertUserService.getUser();
Set<String> intygstyperForPrivilege = authoritiesHelper.getIntygstyperForPrivilege(user, AuthoritiesConstants.PRIVILEGE_VISA_INTYG);
Filter filter;
if (!Strings.isNullOrEmpty(filterParameters.getEnhetId())) {
verifyEnhetsAuth(filterParameters.getEnhetId(), true);
filter = FilterConverter.convert(filterParameters, Arrays.asList(filterParameters.getEnhetId()), intygstyperForPrivilege);
} else {
filter = FilterConverter.convert(filterParameters, user.getIdsOfSelectedVardenhet(), intygstyperForPrivilege);
}
int originalStartFrom = filter.getStartFrom();
int originalPageSize = filter.getPageSize();
// INTYG-4086: Do NOT perform any paging. We must first load all applicable QA / ärenden, then apply
// sekretessmarkering filtering. THEN - we can do paging stuff in-memory. Very inefficient...
filter.setStartFrom(null);
filter.setPageSize(null);
List<ArendeListItem> results = arendeRepository.filterArende(filter).stream().map(ArendeListItemConverter::convert).filter(Objects::nonNull).peek(item -> item.setPaminnelse(!arendeRepository.findByPaminnelseMeddelandeId(item.getMeddelandeId()).isEmpty())).collect(Collectors.toList());
QueryFragaSvarResponse fsResults = fragaSvarService.filterFragaSvar(filter);
results.addAll(fsResults.getResults());
results.sort(Comparator.comparing(ArendeListItem::getReceivedDate).reversed());
QueryFragaSvarResponse response = new QueryFragaSvarResponse();
Map<Personnummer, SekretessStatus> sekretessStatusMap = patientDetailsResolver.getSekretessStatusForList(results.stream().map(ali -> Personnummer.createPersonnummer(ali.getPatientId()).get()).collect(Collectors.toList()));
// INTYG-4086, INTYG-4486: Filter out any items that doesn't pass sekretessmarkering rules
results = results.stream().filter(ali -> this.passesSekretessCheck(ali.getPatientId(), ali.getIntygTyp(), user, sekretessStatusMap)).collect(Collectors.toList());
// We must mark all items having patient with sekretessmarkering
results.stream().filter(ali -> hasSekretessStatus(ali, SekretessStatus.TRUE, sekretessStatusMap)).forEach(ali -> ali.setSekretessmarkering(true));
response.setTotalCount(results.size());
if (originalStartFrom >= results.size()) {
response.setResults(new ArrayList<>());
} else {
response.setResults(results.subList(originalStartFrom, Math.min(originalPageSize + originalStartFrom, results.size())));
}
return response;
}
use of se.inera.intyg.schemas.contract.Personnummer in project webcert by sklintyg.
the class ArendeServiceImpl method getArenden.
@Override
public List<ArendeConversationView> getArenden(String intygsId) {
WebCertUser user = webcertUserService.getUser();
List<Arende> arendeList = getArendeForIntygId(intygsId, user);
arendeList.stream().findFirst().map(Arende::getPatientPersonId).map(personNummer -> Personnummer.createPersonnummer(personNummer).orElseThrow(() -> new IllegalArgumentException("Could not parse personnummer when querying for arenden."))).ifPresent(pn -> authoritiesValidator.given(user).privilegeIf(AuthoritiesConstants.PRIVILEGE_HANTERA_SEKRETESSMARKERAD_PATIENT, SekretessStatus.TRUE.equals(patientDetailsResolver.getSekretessStatus(pn))).orThrow());
return getArendeConversationViewList(intygsId, arendeList);
}
use of se.inera.intyg.schemas.contract.Personnummer in project webcert by sklintyg.
the class BaseCreateDraftCertificateValidator method validatePersonnummer.
private void validatePersonnummer(ResultValidator errors, String personId) {
Personnummer pnr = createPersonnummer(errors, personId).orElse(null);
PersonnummerChecksumValidator.validate(pnr, errors);
}
Aggregations