use of se.inera.intyg.webcert.common.service.exception.WebCertServiceException in project webcert by sklintyg.
the class IntygApiController method listDraftsAndIntygForPerson.
/**
* Compiles a list of Intyg from two data sources. Signed Intyg are
* retrieved from IntygstjÀnst, drafts are retrieved from Webcerts db. Both
* types of Intyg are converted and merged into one sorted list.
*
* @param personNummerIn personnummer
* @return a Response carrying a list containing all Intyg for a person.
*/
@GET
@Path("/person/{personNummer}")
@Produces(MediaType.APPLICATION_JSON + UTF_8_CHARSET)
public Response listDraftsAndIntygForPerson(@PathParam("personNummer") String personNummerIn) {
Personnummer personNummer = createPnr(personNummerIn);
LOG.debug("Retrieving intyg for person {}", personNummer.getPersonnummerHash());
// INTYG-4086 (epic) - make sure only users with HANTERA_SEKRETESSMARKERAD_PATIENT can list intyg for patient
// with sekretessmarkering.
SekretessStatus patientSekretess = patientDetailsResolver.getSekretessStatus(personNummer);
if (patientSekretess == SekretessStatus.UNDEFINED) {
throw new WebCertServiceException(WebCertServiceErrorCodeEnum.PU_PROBLEM, "Error checking sekretessmarkering state in PU-service.");
}
authoritiesValidator.given(getWebCertUserService().getUser()).privilegeIf(AuthoritiesConstants.PRIVILEGE_HANTERA_SEKRETESSMARKERAD_PATIENT, patientSekretess == SekretessStatus.TRUE).orThrow();
List<String> enhetsIds = getEnhetIdsForCurrentUser();
if (enhetsIds.isEmpty()) {
LOG.error("Current user has no assignments");
return Response.status(Status.BAD_REQUEST).build();
}
Pair<List<ListIntygEntry>, Boolean> intygItemListResponse = intygService.listIntyg(enhetsIds, personNummer);
LOG.debug("Got #{} intyg", intygItemListResponse.getLeft().size());
List<Utkast> utkastList;
if (authoritiesValidator.given(getWebCertUserService().getUser()).features(AuthoritiesConstants.FEATURE_HANTERA_INTYGSUTKAST).isVerified()) {
Set<String> intygstyper = authoritiesHelper.getIntygstyperForPrivilege(getWebCertUserService().getUser(), AuthoritiesConstants.PRIVILEGE_VISA_INTYG);
utkastList = utkastRepository.findDraftsByPatientAndEnhetAndStatus(DaoUtil.formatPnrForPersistence(personNummer), enhetsIds, ALL_DRAFTS, intygstyper);
LOG.debug("Got #{} utkast", utkastList.size());
} else {
utkastList = Collections.emptyList();
}
List<ListIntygEntry> allIntyg = IntygDraftsConverter.merge(intygItemListResponse.getLeft(), utkastList);
// INTYG-4477
if (patientSekretess == SekretessStatus.TRUE) {
Set<String> allowedTypes = authoritiesHelper.getIntygstyperAllowedForSekretessmarkering();
allIntyg = allIntyg.stream().filter(intyg -> allowedTypes.contains(intyg.getIntygType())).collect(Collectors.toList());
}
Response.ResponseBuilder responseBuilder = Response.ok(allIntyg);
if (intygItemListResponse.getRight()) {
responseBuilder = responseBuilder.header(OFFLINE_MODE, Boolean.TRUE.toString());
}
return responseBuilder.build();
}
use of se.inera.intyg.webcert.common.service.exception.WebCertServiceException in project webcert by sklintyg.
the class IntygApiController method setNotifiedOnIntyg.
/**
* Sets the notified flag on an Intyg.
*
* @param intygsId Id of the Intyg
* @param notifiedState True or False
* @return Response
*/
@PUT
@Path("/{intygsTyp}/{intygsId}/{version}/vidarebefordra")
@Produces(MediaType.APPLICATION_JSON + UTF_8_CHARSET)
@Consumes(MediaType.APPLICATION_JSON)
public Response setNotifiedOnIntyg(@PathParam("intygsTyp") String intygsTyp, @PathParam("intygsId") String intygsId, @PathParam("version") long version, NotifiedState notifiedState) {
authoritiesValidator.given(getWebCertUserService().getUser(), intygsTyp).features(AuthoritiesConstants.FEATURE_HANTERA_INTYGSUTKAST).privilege(AuthoritiesConstants.PRIVILEGE_VIDAREBEFORDRA_UTKAST).orThrow();
Utkast updatedIntyg;
try {
updatedIntyg = utkastService.setNotifiedOnDraft(intygsId, version, notifiedState.isNotified());
} catch (OptimisticLockException | OptimisticLockingFailureException e) {
monitoringLogService.logUtkastConcurrentlyEdited(intygsId, intygsTyp);
throw new WebCertServiceException(WebCertServiceErrorCodeEnum.CONCURRENT_MODIFICATION, e.getMessage());
}
LOG.debug("Set forward to {} on intyg {} with id '{}'", new Object[] { updatedIntyg.getVidarebefordrad(), intygsTyp, updatedIntyg.getIntygsId() });
ListIntygEntry intygEntry = IntygDraftsConverter.convertUtkastToListIntygEntry(updatedIntyg);
return Response.ok(intygEntry).build();
}
use of se.inera.intyg.webcert.common.service.exception.WebCertServiceException 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.webcert.common.service.exception.WebCertServiceException in project webcert by sklintyg.
the class UtkastServiceImpl method getPopulatedModelFromIntygModule.
private String getPopulatedModelFromIntygModule(String intygType, CreateNewDraftHolder draftRequest) {
LOG.debug("Calling module '{}' to get populated model", intygType);
String modelAsJson;
try {
ModuleApi moduleApi = moduleRegistry.getModuleApi(intygType);
modelAsJson = moduleApi.createNewInternal(draftRequest);
} catch (ModuleException | ModuleNotFoundException me) {
throw new WebCertServiceException(WebCertServiceErrorCodeEnum.MODULE_PROBLEM, me);
}
LOG.debug("Got populated model of {} chars from module '{}'", getSafeLength(modelAsJson), intygType);
return modelAsJson;
}
use of se.inera.intyg.webcert.common.service.exception.WebCertServiceException in project webcert by sklintyg.
the class SendMessageToCareResponderImplTest method testSendRequestToServiceFailed.
@Test
public void testSendRequestToServiceFailed() throws WebCertServiceException {
when(arendeService.processIncomingMessage(any())).thenThrow(new WebCertServiceException(WebCertServiceErrorCodeEnum.INTERNAL_PROBLEM, ""));
SendMessageToCareResponseType response = responder.sendMessageToCare(DEFAULT_LOGICAL_ADDRESS, createNewRequest());
assertNotNull(response.getResult());
assertEquals(ResultCodeType.ERROR, response.getResult().getResultCode());
assertEquals(ErrorIdType.APPLICATION_ERROR, response.getResult().getErrorId());
}
Aggregations