use of se.inera.intyg.webcert.web.service.log.dto.LogRequest in project webcert by sklintyg.
the class CopyUtkastServiceImpl method saveAndNotify.
private Utkast saveAndNotify(CopyUtkastBuilderResponse builderResponse, WebCertUser user) {
builderResponse.getUtkastCopy().setSkapad(LocalDateTime.now());
Utkast savedUtkast = utkastRepository.save(builderResponse.getUtkastCopy());
if (user.getParameters() != null && !Strings.isNullOrEmpty(user.getParameters().getReference())) {
referensService.saveReferens(savedUtkast.getIntygsId(), user.getParameters().getReference());
}
notificationService.sendNotificationForDraftCreated(savedUtkast);
LOG.debug("Notification sent: utkast with id '{}' was created as a copy.", savedUtkast.getIntygsId());
LogRequest logRequest = LogRequestFactory.createLogRequestFromUtkast(savedUtkast);
logService.logCreateIntyg(logRequest);
return savedUtkast;
}
use of se.inera.intyg.webcert.web.service.log.dto.LogRequest in project webcert by sklintyg.
the class UtkastServiceImpl method saveDraft.
@Override
@Transactional("jpaTransactionManager")
public SaveDraftResponse saveDraft(String intygId, long version, String draftAsJson, boolean createPdlLogEvent) {
LOG.debug("Saving and validating utkast '{}'", intygId);
Utkast utkast = utkastRepository.findOne(intygId);
if (utkast == null) {
LOG.warn("Utkast '{}' was not found", intygId);
throw new WebCertServiceException(WebCertServiceErrorCodeEnum.DATA_NOT_FOUND, "The utkast could not be found");
}
// check that the draft hasn't been modified concurrently
if (utkast.getVersion() != version) {
LOG.debug("Utkast '{}' was concurrently modified", intygId);
throw new OptimisticLockException(utkast.getSenastSparadAv().getNamn());
}
// check that the draft is still a draft
if (!isTheDraftStillADraft(utkast.getStatus())) {
LOG.error("Utkast '{}' can not be updated since it is no longer in draft mode", intygId);
throw new WebCertServiceException(WebCertServiceErrorCodeEnum.INVALID_STATE, "This utkast can not be updated since it is no longer in draft mode");
}
String intygType = utkast.getIntygsTyp();
// Keep persisted json for comparsion
String persistedJson = utkast.getModel();
// Update draft with user information
updateUtkastModel(utkast, draftAsJson);
// Is draft valid?
DraftValidation draftValidation = validateDraft(intygId, intygType, draftAsJson);
UtkastStatus utkastStatus = draftValidation.isDraftValid() ? UtkastStatus.DRAFT_COMPLETE : UtkastStatus.DRAFT_INCOMPLETE;
utkast.setStatus(utkastStatus);
// Save the updated draft
utkast = saveDraft(utkast);
LOG.debug("Utkast '{}' updated", utkast.getIntygsId());
if (createPdlLogEvent) {
LogRequest logRequest = LogRequestFactory.createLogRequestFromUtkast(utkast);
logService.logUpdateIntyg(logRequest);
monitoringService.logUtkastEdited(utkast.getIntygsId(), utkast.getIntygsTyp());
}
// Notify stakeholders when a draft has been changed/updated
try {
ModuleApi moduleApi = moduleRegistry.getModuleApi(intygType);
if (moduleApi.shouldNotify(persistedJson, draftAsJson)) {
LOG.debug("*** Detected changes in model, sending notification! ***");
sendNotification(utkast, Event.CHANGED);
}
} catch (ModuleException | ModuleNotFoundException e) {
throw new WebCertServiceException(WebCertServiceErrorCodeEnum.MODULE_PROBLEM, e);
}
// Flush JPA changes, to make sure the version attribute is updated
utkastRepository.flush();
return new SaveDraftResponse(utkast.getVersion(), utkastStatus);
}
use of se.inera.intyg.webcert.web.service.log.dto.LogRequest in project webcert by sklintyg.
the class UtkastServiceImpl method deleteUnsignedDraft.
@Override
@Transactional
public void deleteUnsignedDraft(String intygId, long version) {
LOG.debug("Deleting utkast '{}'", intygId);
Utkast utkast = utkastRepository.findOne(intygId);
// check that the draft exists
if (utkast == null) {
throw new WebCertServiceException(WebCertServiceErrorCodeEnum.DATA_NOT_FOUND, "The draft could not be deleted since it could not be found");
}
// check that the draft hasn't been modified concurrently
if (utkast.getVersion() != version) {
LOG.debug("Utkast '{}' was concurrently modified", intygId);
throw new OptimisticLockException(utkast.getSenastSparadAv().getNamn());
}
// check that the draft is still unsigned
if (!isTheDraftStillADraft(utkast.getStatus())) {
LOG.error("Intyg '{}' can not be deleted since it is no longer a draft", intygId);
throw new WebCertServiceException(WebCertServiceErrorCodeEnum.INVALID_STATE, "The draft can not be deleted since it is no longer a draft");
}
// Delete draft from repository
utkastRepository.delete(utkast);
LOG.debug("Deleted draft '{}'", utkast.getIntygsId());
// Audit log
monitoringService.logUtkastDeleted(utkast.getIntygsId(), utkast.getIntygsTyp());
// Notify stakeholders when a draft is deleted
sendNotification(utkast, Event.DELETED);
LogRequest logRequest = LogRequestFactory.createLogRequestFromUtkast(utkast);
logService.logDeleteIntyg(logRequest);
}
use of se.inera.intyg.webcert.web.service.log.dto.LogRequest in project webcert by sklintyg.
the class AbstractUtkastBuilder method populateCopyUtkastFromOrignalUtkast.
/*
* (non-Javadoc)
*
* @see
* se.inera.intyg.webcert.web.service.utkast.CopyUtkastBuilder#populateCopyUtkastFromOrignalUtkast(se.inera.intyg.
* webcert.web.service.utkast.dto.CreateNewDraftCopyRequest, se.inera.intyg.webcert.integration.pu.model.Person)
*/
@Override
@Transactional(value = "jpaTransactionManager", readOnly = true)
public CopyUtkastBuilderResponse populateCopyUtkastFromOrignalUtkast(T copyRequest, Person patientDetails, boolean addRelation, boolean coherentJournaling, boolean enforceEnhet) throws ModuleNotFoundException, ModuleException {
String orignalIntygsId = copyRequest.getOriginalIntygId();
Utkast orgUtkast = utkastRepository.findOne(orignalIntygsId);
ModuleApi orgModuleApi = moduleRegistry.getModuleApi(copyRequest.getOriginalIntygTyp());
Utlatande orgUtlatande;
try {
orgUtlatande = orgModuleApi.getUtlatandeFromJson(orgUtkast.getModel());
} catch (IOException e) {
throw new ModuleException("Could not convert original certificate to Utlatande", e);
}
// Perform enhets auth if coherent journaling is not active.
if (!coherentJournaling || enforceEnhet) {
verifyEnhetsAuth(orgUtkast.getVardgivarId(), orgUtkast.getEnhetsId(), true);
} else {
LogRequest logRequest = LogRequestFactory.createLogRequestFromUtkast(orgUtkast, coherentJournaling);
logService.logReadIntyg(logRequest);
}
CopyUtkastBuilderResponse builderResponse = new CopyUtkastBuilderResponse();
builderResponse.setOrginalEnhetsId(orgUtkast.getEnhetsId());
builderResponse.setOrginalEnhetsNamn(orgUtkast.getEnhetsNamn());
builderResponse.setOrginalVardgivarId(orgUtkast.getVardgivarId());
builderResponse.setOrginalVardgivarNamn(orgUtkast.getVardgivarNamn());
LOG.debug("Populating copy with details from Utkast '{}'", orignalIntygsId);
ModuleApi moduleApi = moduleRegistry.getModuleApi(copyRequest.getTyp());
// Set relation to null if not applicable
Relation relation = createRelation(copyRequest);
String newDraftCopyId = intygsIdStrategy.createId();
String draftCopyJson = getInternalModel(orgUtlatande, moduleApi, copyRequest, patientDetails, relation, newDraftCopyId);
UtkastStatus utkastStatus = validateDraft(moduleApi, draftCopyJson);
Utkast utkast = buildUtkastCopy(copyRequest, newDraftCopyId, copyRequest.getTyp(), addRelation, relation, draftCopyJson, utkastStatus);
if (patientDetails != null) {
populatePatientDetailsFromPerson(utkast, patientDetails);
} else {
populatePatientDetailsFromUtkast(utkast, orgUtkast);
}
replacePatientPersonnummerWithNew(utkast, copyRequest);
builderResponse.setUtkastCopy(utkast);
return builderResponse;
}
use of se.inera.intyg.webcert.web.service.log.dto.LogRequest in project webcert by sklintyg.
the class LogRequestFactoryTest method testCreateLogRequestFromUtkast.
@Test
public void testCreateLogRequestFromUtkast() {
Utkast utkast = buildUtkast(intygsId, "ts-bas", patientPersonnummer, patientFornamn, patientMellannamn, patientEfternamn, enhetsid, enhetsnamn, vardgivarid, vardgivarnamn);
LogRequest res = LogRequestFactory.createLogRequestFromUtkast(utkast);
assertNotNull(res);
assertEquals(intygsId, res.getIntygId());
assertEquals(patientPersonnummer, res.getPatientId());
assertEquals(patientFornamn + " " + patientMellannamn + " " + patientEfternamn, res.getPatientName());
assertEquals(enhetsid, res.getIntygCareUnitId());
assertEquals(enhetsnamn, res.getIntygCareUnitName());
assertEquals(vardgivarid, res.getIntygCareGiverId());
assertEquals(vardgivarnamn, res.getIntygCareGiverName());
assertNull(res.getAdditionalInfo());
}
Aggregations