use of org.ehrbase.dao.access.interfaces.I_ContextAccess in project ehrbase by ehrbase.
the class CompositionAccess method internalCreate.
private UUID internalCreate(LocalDateTime timestamp, UUID committerId, UUID systemId, String description, UUID contribution) {
// check if custom contribution is already set, because changing it would yield updating in DB which is not desired (creates wrong new "version")
if (contribution != null) {
// Retrieve audit metadata from given contribution
var newContributionAccess = I_ContributionAccess.retrieveInstance(this.getDataAccess(), contribution);
systemId = newContributionAccess.getAuditsSystemId();
committerId = newContributionAccess.getAuditsCommitter();
description = newContributionAccess.getAuditsDescription();
} else {
// if not set, create DB entry of contribution so it can get referenced in this composition
// prepare contribution with given values
contributionAccess.setDataType(ContributionDataType.composition);
contributionAccess.setState(ContributionDef.ContributionState.COMPLETE);
contributionAccess.setAuditDetailsValues(committerId, systemId, description, I_ConceptAccess.ContributionChangeType.CREATION);
UUID contributionId = this.contributionAccess.commit();
setContributionId(contributionId);
}
// create DB entry of prepared auditDetails so it can get referenced in this composition
auditDetailsAccess.setChangeType(I_ConceptAccess.fetchContributionChangeType(this, I_ConceptAccess.ContributionChangeType.CREATION));
// prepare composition audit with given values
auditDetailsAccess.setSystemId(systemId);
auditDetailsAccess.setCommitter(committerId);
auditDetailsAccess.setDescription(description);
UUID auditId = this.auditDetailsAccess.commit();
compositionRecord.setHasAudit(auditId);
compositionRecord.setSysTransaction(Timestamp.valueOf(timestamp));
compositionRecord.store();
if (content.isEmpty()) {
logger.warn("Composition has no content:");
}
try {
for (I_EntryAccess entryAccess : content) {
entryAccess.commit(Timestamp.valueOf(timestamp));
}
} catch (Exception exception) {
logger.error("Problem in committing content, rolling back, exception:" + exception);
throw new IllegalArgumentException("Could not commit content:" + exception);
}
if (!composition.getCategory().getDefiningCode().getCodeString().equals("431")) {
EventContext eventContext = composition.getContext();
I_ContextAccess contextAccess = I_ContextAccess.getInstance(this, eventContext);
if (!contextAccess.isVoid()) {
contextAccess.setCompositionId(compositionRecord.getId());
contextAccess.commit(Timestamp.valueOf(timestamp));
}
}
return compositionRecord.getId();
}
use of org.ehrbase.dao.access.interfaces.I_ContextAccess in project ehrbase by ehrbase.
the class CompositionAccess method setContextCompositionId.
/**
* @throws InternalServerException on problem updating context
*/
@Override
public void setContextCompositionId(UUID contextId) {
I_ContextAccess contextAccess = I_ContextAccess.retrieveInstance(this, contextId);
contextAccess.setCompositionId(compositionRecord.getId());
contextAccess.update(TransactionTime.millis());
}
use of org.ehrbase.dao.access.interfaces.I_ContextAccess in project ehrbase by ehrbase.
the class ContextAccess method retrieveInstance.
public static I_ContextAccess retrieveInstance(I_DomainAccess domainAccess, UUID id) {
ContextAccess contextAccess = new ContextAccess(domainAccess);
contextAccess.eventContextRecord = domainAccess.getContext().fetchOne(EVENT_CONTEXT, EVENT_CONTEXT.ID.eq(id));
return contextAccess;
}
use of org.ehrbase.dao.access.interfaces.I_ContextAccess in project ehrbase by ehrbase.
the class EntryAccess method retrieveInstanceInComposition.
/**
* @throws IllegalArgumentException if DB is inconsistent or operation fails
*/
public static List<I_EntryAccess> retrieveInstanceInComposition(I_DomainAccess domainAccess, I_CompositionAccess compositionAccess) {
Result<EntryRecord> entryRecords = domainAccess.getContext().selectFrom(ENTRY).where(ENTRY.COMPOSITION_ID.eq(compositionAccess.getId())).fetch();
// build the list of parameters to recreate the composition
Map<SystemValue, Object> values = new HashMap<>();
values.put(SystemValue.COMPOSER, new PersistedPartyProxy(domainAccess).retrieve(compositionAccess.getComposerId()));
// optional handling for persistent compositions that do not have a context
Optional<I_ContextAccess> opContextAccess = compositionAccess.getContextId().map(id -> I_ContextAccess.retrieveInstance(domainAccess, id));
opContextAccess.ifPresent(context -> values.put(SystemValue.CONTEXT, context.mapRmEventContext()));
values.put(SystemValue.LANGUAGE, new CodePhrase(new TerminologyId("ISO_639-1"), compositionAccess.getLanguageCode()));
String territory2letters = domainAccess.getContext().fetchOne(TERRITORY, TERRITORY.CODE.eq(compositionAccess.getTerritoryCode())).getTwoletter();
values.put(SystemValue.TERRITORY, new CodePhrase(new TerminologyId("ISO_3166-1"), territory2letters));
if (compositionAccess.getFeederAudit() != null) {
values.put(SystemValue.FEEDER_AUDIT, new FeederAuditEncoding().fromDB(compositionAccess.getFeederAudit()));
}
if (compositionAccess.getLinks() != null) {
values.put(SystemValue.LINKS, new LinksEncoding().fromDB(compositionAccess.getLinks()));
}
List<I_EntryAccess> content = new ArrayList<>();
try {
EntryAccess entryAccess = new EntryAccess(domainAccess);
for (EntryRecord record : entryRecords) {
// set the record UID in the composition with matching version number
Integer version = I_CompositionAccess.getLastVersionNumber(domainAccess, compositionAccess.getId());
values.put(SystemValue.UID, new ObjectVersionId(compositionAccess.getId().toString() + "::" + domainAccess.getServerConfig().getNodename() + "::" + version));
entryAccess.entryRecord = record;
String value = record.getEntry().data();
entryAccess.composition = new RawJson().unmarshal(value, Composition.class);
// continuing optional handling for persistent compositions
opContextAccess.map(I_ContextAccess::mapRmEventContext).ifPresent(ec -> values.put(SystemValue.CONTEXT, ec));
values.put(SystemValue.CATEGORY, new RecordedDvCodedText().fromDB(record, ENTRY.CATEGORY));
setCompositionAttributes(entryAccess.composition, values);
buildArchetypeDetails(entryAccess);
content.add(entryAccess);
}
} catch (Exception e) {
throw new IllegalArgumentException(DB_INCONSISTENCY + e);
}
return content;
}
use of org.ehrbase.dao.access.interfaces.I_ContextAccess in project ehrbase by ehrbase.
the class CompositionAccess method internalUpdate.
// root update
boolean internalUpdate(Timestamp transactionTime) {
var result = false;
if (!compositionRecord.changed()) {
compositionRecord.changed(true);
// jOOQ limited support of TSTZRANGE, exclude sys_period from updateComposition!
compositionRecord.changed(COMPOSITION.SYS_PERIOD, false);
}
compositionRecord.setSysTransaction(transactionTime);
// update attributes
updateCompositionData(composition);
result = compositionRecord.update() > 0;
// updateComposition each entry if required
for (I_EntryAccess entryAccess : content) {
entryAccess.setCompositionData(composition);
entryAccess.update(transactionTime, true);
}
// update context
// context
Optional<UUID> contextId = getContextId();
I_ContextAccess contextAccess;
if (contextId.isEmpty()) {
EventContext context = new EventContextFactory().makeNull();
contextAccess = I_ContextAccess.getInstance(this, context);
contextAccess.commit(transactionTime);
} else {
contextAccess = I_ContextAccess.retrieveInstance(this, contextId.get());
}
var newEventContext = composition.getContext();
if (contextId.isPresent()) {
contextAccess.setRecordFields(contextId.get(), newEventContext);
contextAccess.update(transactionTime, true);
}
return result;
}
Aggregations