use of se.inera.intyg.common.support.modules.support.api.exception.ModuleException in project webcert by sklintyg.
the class UtkastModuleApiController method getDraft.
/**
* Returns the draft certificate as JSON identified by the intygId.
*
* @param intygsId The id of the certificate
* @return a JSON object
*/
@GET
@Path("/{intygsTyp}/{intygsId}")
@Produces(MediaType.APPLICATION_JSON + UTF_8_CHARSET)
public Response getDraft(@PathParam("intygsTyp") String intygsTyp, @PathParam("intygsId") String intygsId, @Context HttpServletRequest request) {
LOG.debug("Retrieving Intyg with id {} and type {}", intygsId, intygsTyp);
Utkast utkast = utkastService.getDraft(intygsId, intygsTyp);
Patient resolvedPatient = patientDetailsResolver.resolvePatient(utkast.getPatientPersonnummer(), intygsTyp);
if (resolvedPatient == null) {
throw new WebCertServiceException(WebCertServiceErrorCodeEnum.PU_PROBLEM, "Could not resolve Patient in PU-service when opening draft.");
}
authoritiesValidator.given(getWebCertUserService().getUser(), intygsTyp).features(AuthoritiesConstants.FEATURE_HANTERA_INTYGSUTKAST).privilege(AuthoritiesConstants.PRIVILEGE_SKRIVA_INTYG).orThrow();
verifySekretessmarkering(intygsTyp, utkast.getEnhetsId(), resolvedPatient);
request.getSession(true).removeAttribute(LAST_SAVED_DRAFT);
DraftHolder draftHolder = new DraftHolder();
draftHolder.setVersion(utkast.getVersion());
draftHolder.setVidarebefordrad(utkast.getVidarebefordrad());
draftHolder.setStatus(utkast.getStatus());
draftHolder.setEnhetsNamn(utkast.getEnhetsNamn());
draftHolder.setVardgivareNamn(utkast.getVardgivarNamn());
draftHolder.setLatestTextVersion(intygTextsService.getLatestVersion(utkast.getIntygsTyp()));
Relations relations1 = certificateRelationService.getRelations(utkast.getIntygsId());
draftHolder.setRelations(relations1);
draftHolder.setKlartForSigneringDatum(utkast.getKlartForSigneringDatum());
draftHolder.setCreated(utkast.getSkapad());
// The patientResolved is unnecessary?
draftHolder.setPatientResolved(true);
draftHolder.setSekretessmarkering(resolvedPatient.isSekretessmarkering());
draftHolder.setAvliden(resolvedPatient.isAvliden());
// Businesss logic below should not be here inside a controller.. Should preferably be moved in the future.
try {
try {
Utlatande utlatande = moduleRegistry.getModuleApi(intygsTyp).getUtlatandeFromJson(utkast.getModel());
draftHolder.setPatientNameChangedInPU(patientDetailsResolver.isPatientNamedChanged(utlatande.getGrundData().getPatient(), resolvedPatient));
draftHolder.setPatientAddressChangedInPU(patientDetailsResolver.isPatientAddressChanged(utlatande.getGrundData().getPatient(), resolvedPatient));
} catch (IOException e) {
LOG.error("Failed to getUtlatandeFromJson intygsId {} while checking for updated patient information", intygsId);
}
if (!completeAddressProvided(resolvedPatient)) {
// Overwrite retrieved address data with saved one.
Patient oldPatientData = null;
try {
oldPatientData = moduleRegistry.getModuleApi(intygsTyp).getUtlatandeFromJson(utkast.getModel()).getGrundData().getPatient();
} catch (IOException e) {
LOG.error("Error while using the module api to convert json to Utlatande for intygsId {}", intygsId);
}
copyOldAddressToNewPatientData(oldPatientData, resolvedPatient);
}
// Update the internal model with the resolved patient. This means the draft may be updated
// with new patient info on the next auto-save!
String updatedModel = moduleRegistry.getModuleApi(intygsTyp).updateBeforeSave(utkast.getModel(), resolvedPatient);
utkast.setModel(updatedModel);
draftHolder.setContent(utkast.getModel());
return Response.ok(draftHolder).build();
} catch (ModuleException | ModuleNotFoundException e) {
throw new WebCertServiceException(WebCertServiceErrorCodeEnum.MODULE_PROBLEM, e.getMessage());
}
}
use of se.inera.intyg.common.support.modules.support.api.exception.ModuleException 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.common.support.modules.support.api.exception.ModuleException 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.common.support.modules.support.api.exception.ModuleException in project webcert by sklintyg.
the class CertificateRevokeProcessor method process.
public void process(@Body String xmlBody, @Header(Constants.INTYGS_ID) String intygsId, @Header(Constants.LOGICAL_ADDRESS) String logicalAddress, @Header(Constants.INTYGS_TYP) String intygsTyp) throws TemporaryException, PermanentException {
checkArgument(!Strings.isNullOrEmpty(intygsId), "Message of type %s does not have a %s header.", Constants.REVOKE_MESSAGE, Constants.INTYGS_ID);
checkArgument(!Strings.isNullOrEmpty(logicalAddress), "Message of type %s does not have a %s header.", Constants.REVOKE_MESSAGE, Constants.LOGICAL_ADDRESS);
checkArgument(!Strings.isNullOrEmpty(intygsTyp), "Message of type %s does not have a %s header.", Constants.REVOKE_MESSAGE, Constants.INTYGS_TYP);
try {
ModuleApi moduleApi = registry.getModuleApi(intygsTyp);
moduleApi.revokeCertificate(xmlBody, logicalAddress);
} catch (ExternalServiceCallException e) {
switch(e.getErroIdEnum()) {
case TECHNICAL_ERROR:
case APPLICATION_ERROR:
throw new TemporaryException(e.getMessage());
default:
throw new PermanentException(e.getMessage());
}
} catch (ModuleException e) {
throw new PermanentException(e.getMessage());
} catch (WebServiceException e) {
throw new TemporaryException(e.getMessage());
} catch (Exception e) {
throw new PermanentException(e.getMessage());
}
}
use of se.inera.intyg.common.support.modules.support.api.exception.ModuleException in project webcert by sklintyg.
the class IntygServiceImpl method buildIntygContentHolderForUtkast.
// NOTE! INTYG-4086. This method is used when fetching Intyg/Utkast from WC locally. The question is, should we
// replace the patient on the existing model with a freshly fetched one here or not? In case we're storing patient
// info entered manually for non FK-types here, we may end up overwriting a manually stored name etc...
private IntygContentHolder buildIntygContentHolderForUtkast(Utkast utkast, boolean relations) {
try {
// INTYG-4086: Patient object populated according to ruleset for the intygstyp at hand.
Patient newPatientData = patientDetailsResolver.resolvePatient(utkast.getPatientPersonnummer(), utkast.getIntygsTyp());
// create an "empty" Patient with personnummer only.
if (newPatientData == null) {
newPatientData = new Patient();
newPatientData.setPersonId(utkast.getPatientPersonnummer());
}
// INTYG-5354, INTYG-5380: Don't use incomplete address from external data sources (PU/js).
Utlatande utlatande = modelFacade.getUtlatandeFromInternalModel(utkast.getIntygsTyp(), utkast.getModel());
if (!completeAddressProvided(newPatientData)) {
// Use the old address data.
Patient oldPatientData = utlatande.getGrundData().getPatient();
copyOldAddressToNewPatientData(oldPatientData, newPatientData);
}
String updatedModel = moduleRegistry.getModuleApi(utkast.getIntygsTyp()).updateBeforeSave(utkast.getModel(), newPatientData);
utlatande = modelFacade.getUtlatandeFromInternalModel(utkast.getIntygsTyp(), updatedModel);
List<Status> statuses = IntygConverterUtil.buildStatusesFromUtkast(utkast);
Relations certificateRelations = certificateRelationService.getRelations(utkast.getIntygsId());
final SekretessStatus sekretessStatus = patientDetailsResolver.getSekretessStatus(newPatientData.getPersonId());
if (SekretessStatus.UNDEFINED.equals(sekretessStatus)) {
throw new WebCertServiceException(WebCertServiceErrorCodeEnum.PU_PROBLEM, "Sekretesstatus could not be fetched from the PU service");
}
final boolean sekretessmarkerad = SekretessStatus.TRUE.equals(sekretessStatus);
boolean patientNameChanged = patientDetailsResolver.isPatientNamedChanged(utlatande.getGrundData().getPatient(), newPatientData);
boolean patientAddressChanged = patientDetailsResolver.isPatientAddressChanged(utlatande.getGrundData().getPatient(), newPatientData);
return IntygContentHolder.builder().setContents(updatedModel).setUtlatande(utlatande).setStatuses(statuses).setRevoked(utkast.getAterkalladDatum() != null).setRelations(certificateRelations).setCreated(utkast.getSkapad()).setDeceased(isDeceased(utkast.getPatientPersonnummer())).setSekretessmarkering(sekretessmarkerad).setPatientNameChangedInPU(patientNameChanged).setPatientAddressChangedInPU(patientAddressChanged).build();
} catch (ModuleException | ModuleNotFoundException e) {
throw new WebCertServiceException(WebCertServiceErrorCodeEnum.MODULE_PROBLEM, e);
}
}
Aggregations