use of se.inera.intyg.schemas.contract.Personnummer in project webcert by sklintyg.
the class SrsApiController method setConsent.
@PUT
@Path("/consent/{personnummer}/{hsaId}")
@Produces(MediaType.APPLICATION_JSON + UTF_8_CHARSET)
@Consumes(MediaType.APPLICATION_JSON)
@ApiOperation(value = "Set consent for patient and careunit", httpMethod = "PUT", produces = MediaType.APPLICATION_JSON)
public Response setConsent(@ApiParam(value = "Personnummer") @PathParam("personnummer") String personnummer, @ApiParam(value = "HsaId för vårdenhet") @PathParam("hsaId") String hsaId, boolean consent) {
authoritiesValidator.given(getWebCertUserService().getUser()).features(AuthoritiesConstants.FEATURE_SRS).orThrow();
try {
Personnummer p = createPnr(personnummer);
ResultCodeEnum result = srsService.setConsent(hsaId, p, consent);
monitoringLog.logSetSrsConsent(p, consent);
return Response.ok(result).build();
} catch (InvalidPersonNummerException e) {
return Response.status(Response.Status.BAD_REQUEST).build();
}
}
use of se.inera.intyg.schemas.contract.Personnummer in project webcert by sklintyg.
the class UtkastApiController method performUtkastFilterQuery.
private QueryIntygResponse performUtkastFilterQuery(UtkastFilter filter) {
// INTYG-4486: We can not get a totalCount with pageSize set if since we need to lookup/verify
// sekretess!=UNDEFINED each entry from puService - even if user has authority to view sekretessmarkerade
// resources.
Integer pageSize = filter.getPageSize();
filter.setPageSize(null);
List<ListIntygEntry> listIntygEntries = IntygDraftsConverter.convertUtkastsToListIntygEntries(utkastService.filterIntyg(filter));
// INTYG-4486, INTYG-4086: Always filter out any items with UNDEFINED sekretessmarkering status and not
// authorized
Map<Personnummer, SekretessStatus> sekretessStatusMap = patientDetailsResolver.getSekretessStatusForList(listIntygEntries.stream().map(lie -> lie.getPatientId()).collect(Collectors.toList()));
final WebCertUser user = getWebCertUserService().getUser();
listIntygEntries = listIntygEntries.stream().filter(lie -> this.passesSekretessCheck(lie.getPatientId(), lie.getIntygType(), user, sekretessStatusMap)).collect(Collectors.toList());
// INTYG-4086: Mark all remaining ListIntygEntry having a patient with sekretessmarkering
listIntygEntries.stream().forEach(lie -> markSekretessMarkering(lie, sekretessStatusMap));
int totalCountOfFilteredIntyg = listIntygEntries.size();
// logic
if (filter.getStartFrom() < listIntygEntries.size()) {
int toIndex = filter.getStartFrom() + pageSize;
if (toIndex > listIntygEntries.size()) {
toIndex = listIntygEntries.size();
}
listIntygEntries = listIntygEntries.subList(filter.getStartFrom(), toIndex);
} else {
// Index out of range
listIntygEntries.clear();
}
QueryIntygResponse response = new QueryIntygResponse(listIntygEntries);
response.setTotalCount(totalCountOfFilteredIntyg);
return response;
}
use of se.inera.intyg.schemas.contract.Personnummer in project webcert by sklintyg.
the class CopyUtkastServiceImpl method createUtkastFromTemplate.
@Override
public CreateUtkastFromTemplateResponse createUtkastFromTemplate(CreateUtkastFromTemplateRequest copyRequest) {
String originalIntygId = copyRequest.getOriginalIntygId();
LOG.debug("Creating utkast from template certificate '{}'", originalIntygId);
WebCertUser user = userService.getUser();
boolean coherentJournaling = user != null && user.getParameters() != null && user.getParameters().isSjf();
try {
if (intygService.isRevoked(copyRequest.getOriginalIntygId(), copyRequest.getOriginalIntygTyp(), coherentJournaling)) {
LOG.debug("Cannot create utkast from template certificate with id '{}', the certificate is revoked", originalIntygId);
throw new WebCertServiceException(WebCertServiceErrorCodeEnum.INVALID_STATE, "Original certificate is revoked");
}
String intygsTyp = copyRequest.getTyp();
if (authoritiesValidator.given(user, intygsTyp).features(AuthoritiesConstants.FEATURE_UNIKT_INTYG, AuthoritiesConstants.FEATURE_UNIKT_INTYG_INOM_VG, AuthoritiesConstants.FEATURE_UNIKT_UTKAST_INOM_VG).isVerified()) {
Personnummer personnummer = copyRequest.containsNyttPatientPersonnummer() ? copyRequest.getNyttPatientPersonnummer() : copyRequest.getPatient().getPersonId();
Map<String, Map<String, Boolean>> intygstypToStringToBoolean = utkastService.checkIfPersonHasExistingIntyg(personnummer, user);
Boolean utkastExists = intygstypToStringToBoolean.get("utkast").get(intygsTyp);
Boolean intygExists = intygstypToStringToBoolean.get("intyg").get(intygsTyp);
if (utkastExists != null && utkastExists) {
if (authoritiesValidator.given(user, intygsTyp).features(AuthoritiesConstants.FEATURE_UNIKT_UTKAST_INOM_VG).isVerified()) {
throw new WebCertServiceException(WebCertServiceErrorCodeEnum.INVALID_STATE, "Drafts of this type must be unique within this caregiver.");
}
}
if (intygExists != null) {
if (authoritiesValidator.given(user, intygsTyp).features(AuthoritiesConstants.FEATURE_UNIKT_INTYG).isVerified()) {
throw new WebCertServiceException(WebCertServiceErrorCodeEnum.INVALID_STATE, "Certificates of this type must be globally unique.");
} else if (intygExists && authoritiesValidator.given(user, intygsTyp).features(AuthoritiesConstants.FEATURE_UNIKT_INTYG_INOM_VG).isVerified()) {
throw new WebCertServiceException(WebCertServiceErrorCodeEnum.INVALID_STATE, "Certificates of this type must be unique within this caregiver.");
}
}
}
verifyNotReplacedWithSigned(copyRequest.getOriginalIntygId(), "create utkast from template");
CopyUtkastBuilderResponse builderResponse = buildUtkastFromTemplateBuilderResponse(copyRequest, originalIntygId, true, coherentJournaling);
Utkast savedUtkast = saveAndNotify(builderResponse, user);
if (copyRequest.isDjupintegrerad()) {
checkIntegreradEnhet(builderResponse);
}
return new CreateUtkastFromTemplateResponse(savedUtkast.getIntygsTyp(), savedUtkast.getIntygsId(), originalIntygId);
} catch (ModuleException | ModuleNotFoundException me) {
LOG.error("Module exception occured when trying to make a copy of " + originalIntygId);
throw new WebCertServiceException(WebCertServiceErrorCodeEnum.MODULE_PROBLEM, me);
}
}
use of se.inera.intyg.schemas.contract.Personnummer in project webcert by sklintyg.
the class NotificationPatientEnricher method enrichWithPatient.
public void enrichWithPatient(Intyg intyg) throws TemporaryException {
// INTYG-4190, hämta patientens uppgifter från PU-tjänsten och klistra in i utlåtandet.
String intygsTyp = intyg.getTyp().getCode();
switch(intygsTyp.toLowerCase()) {
case "luse":
case "luae_na":
case "luae_fs":
case "lisjp":
String personId = intyg.getPatient().getPersonId().getExtension();
Personnummer personnummer = Personnummer.createPersonnummer(personId).orElseThrow(() -> new IllegalArgumentException("Cannot create Personummer object from personId: " + personId));
PersonSvar personSvar = puService.getPerson(personnummer);
if (personSvar.getStatus() == PersonSvar.Status.FOUND) {
if (!personSvar.getPerson().isSekretessmarkering()) {
intyg.setPatient(buildPatientFromPersonSvar(personSvar.getPerson()));
} else {
intyg.getPatient().setEfternamn(SEKRETESSMARKERING);
intyg.getPatient().setFornamn(EMPTY_STRING);
intyg.getPatient().setMellannamn(EMPTY_STRING);
intyg.getPatient().setPostadress(EMPTY_STRING);
intyg.getPatient().setPostnummer(EMPTY_STRING);
intyg.getPatient().setPostort(EMPTY_STRING);
}
} else if (personSvar.getStatus() == PersonSvar.Status.ERROR) {
throw new TemporaryException(new IllegalStateException("Could not query PU-service for enriching notification with patient data."));
} else {
LOG.warn("PU-service returned NOT_FOUND for personnummer: {}, not enriching notification.", personnummer.getPersonnummerHash());
}
break;
default:
// Do nothing
break;
}
}
use of se.inera.intyg.schemas.contract.Personnummer in project webcert by sklintyg.
the class GetPrivatePractitionerResponderStub method getGetPrivatePractitionerResponseTypeForPnr.
private GetPrivatePractitionerResponseType getGetPrivatePractitionerResponseTypeForPnr(GetPrivatePractitionerType parameters) {
String id = parameters.getPersonalIdentityNumber();
Personnummer personnummer = Personnummer.createPersonnummer(id).orElse(null);
GetPrivatePractitionerResponseType response = new GetPrivatePractitionerResponseType();
// if matching -- create error response
if (PERSONNUMMER_ERROR_RESPONSE.equals(id)) {
response.setHoSPerson(null);
response.setResultCode(ResultCodeEnum.ERROR);
response.setResultText("FAILURE: an error occured while trying to get private practitioner with personal identity number: " + Personnummer.getPersonnummerHashSafe(personnummer) + " exists.");
return response;
}
// if matching -- throw exception
if (PERSONNUMMER_THROW_EXCEPTION.equals(id)) {
throw new SOAPFaultException(createSOAPFault());
}
HoSPersonType person = personStub.get(id);
if (person == null) {
response.setResultCode(ResultCodeEnum.INFO);
response.setResultText("No private practitioner with personal identity number: " + Personnummer.getPersonnummerHashSafe(personnummer) + " exists.");
} else {
response.setHoSPerson(person);
response.setResultCode(ResultCodeEnum.OK);
}
return response;
}
Aggregations