Search in sources :

Example 1 with I_ContextAccess

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();
}
Also used : EventContext(com.nedap.archie.rm.composition.EventContext) I_EntryAccess(org.ehrbase.dao.access.interfaces.I_EntryAccess) I_ContextAccess(org.ehrbase.dao.access.interfaces.I_ContextAccess) UUID(java.util.UUID) ObjectNotFoundException(org.ehrbase.api.exception.ObjectNotFoundException) InternalServerException(org.ehrbase.api.exception.InternalServerException) SQLException(java.sql.SQLException)

Example 2 with I_ContextAccess

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());
}
Also used : I_ContextAccess(org.ehrbase.dao.access.interfaces.I_ContextAccess)

Example 3 with I_ContextAccess

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;
}
Also used : I_ContextAccess(org.ehrbase.dao.access.interfaces.I_ContextAccess)

Example 4 with I_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;
}
Also used : I_EntryAccess(org.ehrbase.dao.access.interfaces.I_EntryAccess) CodePhrase(com.nedap.archie.rm.datatypes.CodePhrase) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) ObjectVersionId(com.nedap.archie.rm.support.identification.ObjectVersionId) I_EntryAccess(org.ehrbase.dao.access.interfaces.I_EntryAccess) RecordedDvCodedText(org.ehrbase.service.RecordedDvCodedText) FeederAuditEncoding(org.ehrbase.serialisation.dbencoding.rmobject.FeederAuditEncoding) LinksEncoding(org.ehrbase.serialisation.dbencoding.rmobject.LinksEncoding) TerminologyId(com.nedap.archie.rm.support.identification.TerminologyId) Composition(com.nedap.archie.rm.composition.Composition) RawJson(org.ehrbase.serialisation.dbencoding.RawJson) InternalServerException(org.ehrbase.api.exception.InternalServerException) PersistedPartyProxy(org.ehrbase.dao.access.jooq.party.PersistedPartyProxy) I_ContextAccess(org.ehrbase.dao.access.interfaces.I_ContextAccess) EntryRecord(org.ehrbase.jooq.pg.tables.records.EntryRecord)

Example 5 with I_ContextAccess

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;
}
Also used : EventContext(com.nedap.archie.rm.composition.EventContext) I_EntryAccess(org.ehrbase.dao.access.interfaces.I_EntryAccess) I_ContextAccess(org.ehrbase.dao.access.interfaces.I_ContextAccess) UUID(java.util.UUID)

Aggregations

I_ContextAccess (org.ehrbase.dao.access.interfaces.I_ContextAccess)6 I_EntryAccess (org.ehrbase.dao.access.interfaces.I_EntryAccess)3 EventContext (com.nedap.archie.rm.composition.EventContext)2 UUID (java.util.UUID)2 InternalServerException (org.ehrbase.api.exception.InternalServerException)2 Composition (com.nedap.archie.rm.composition.Composition)1 CodePhrase (com.nedap.archie.rm.datatypes.CodePhrase)1 ObjectVersionId (com.nedap.archie.rm.support.identification.ObjectVersionId)1 TerminologyId (com.nedap.archie.rm.support.identification.TerminologyId)1 SQLException (java.sql.SQLException)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 ObjectNotFoundException (org.ehrbase.api.exception.ObjectNotFoundException)1 PersistedPartyProxy (org.ehrbase.dao.access.jooq.party.PersistedPartyProxy)1 EntryRecord (org.ehrbase.jooq.pg.tables.records.EntryRecord)1 EventContextRecord (org.ehrbase.jooq.pg.tables.records.EventContextRecord)1 RawJson (org.ehrbase.serialisation.dbencoding.RawJson)1 FeederAuditEncoding (org.ehrbase.serialisation.dbencoding.rmobject.FeederAuditEncoding)1 LinksEncoding (org.ehrbase.serialisation.dbencoding.rmobject.LinksEncoding)1 RecordedDvCodedText (org.ehrbase.service.RecordedDvCodedText)1