Search in sources :

Example 6 with EventContext

use of com.nedap.archie.rm.composition.EventContext in project openEHR_SDK by ehrbase.

the class EventContextValueInserter method insert.

@Override
public void insert(EventContext rmObject, DefaultValues defaultValues) {
    if (RMHelper.isEmpty(rmObject.getStartTime()) && defaultValues.containsDefaultValue(DefaultValuePath.TIME)) {
        rmObject.setStartTime(new DvDateTime(defaultValues.getDefaultValue(DefaultValuePath.TIME)));
    }
    if (RMHelper.isEmpty(rmObject.getEndTime()) && defaultValues.containsDefaultValue(DefaultValuePath.END_TIME)) {
        rmObject.setEndTime(new DvDateTime(defaultValues.getDefaultValue(DefaultValuePath.END_TIME)));
    }
    if (RMHelper.isEmpty(rmObject.getHealthCareFacility()) && (defaultValues.containsDefaultValue(DefaultValuePath.HEALTHCARE_FACILITY_NAME) || defaultValues.containsDefaultValue(DefaultValuePath.HEALTHCARE_FACILITY_ID))) {
        rmObject.setHealthCareFacility(buildPartyIdentified(defaultValues, DefaultValuePath.HEALTHCARE_FACILITY_NAME, DefaultValuePath.HEALTHCARE_FACILITY_ID, rmObject.getHealthCareFacility()));
    }
    if (RMHelper.isEmpty(rmObject.getLocation()) && defaultValues.containsDefaultValue(DefaultValuePath.LOCATION)) {
        rmObject.setLocation(defaultValues.getDefaultValue(DefaultValuePath.LOCATION));
    }
    if (RMHelper.isEmpty(rmObject.getSetting()) && defaultValues.containsDefaultValue(DefaultValuePath.SETTING)) {
        Setting defaultValue = defaultValues.getDefaultValue(DefaultValuePath.SETTING);
        rmObject.setSetting(new DvCodedText(defaultValue.getValue(), defaultValue.toCodePhrase()));
    }
    if (RMHelper.isEmpty(rmObject.getParticipations()) && defaultValues.containsDefaultValue(DefaultValuePath.PARTICIPATION)) {
        rmObject.setParticipations(defaultValues.getDefaultValue(DefaultValuePath.PARTICIPATION));
    }
    if (rmObject.getParticipations() != null) {
        rmObject.getParticipations().stream().map(Participation::getPerformer).filter(Objects::nonNull).map(PartyProxy::getExternalRef).filter(Objects::nonNull).filter(ref -> ref.getId() != null).forEach(ref -> {
            if (ref.getNamespace() == null && defaultValues.containsDefaultValue(DefaultValuePath.ID_NAMESPACE)) {
                ref.setNamespace(defaultValues.getDefaultValue(DefaultValuePath.ID_NAMESPACE));
            }
            if (ref.getId() instanceof GenericId && ref.getNamespace() == null && defaultValues.containsDefaultValue(DefaultValuePath.ID_SCHEME)) {
                ((GenericId) ref.getId()).setScheme(defaultValues.getDefaultValue(DefaultValuePath.ID_SCHEME));
            }
        });
    }
}
Also used : PartyProxy(com.nedap.archie.rm.generic.PartyProxy) Objects(java.util.Objects) EventContext(com.nedap.archie.rm.composition.EventContext) DvDateTime(com.nedap.archie.rm.datavalues.quantity.datetime.DvDateTime) RMHelper(org.ehrbase.serialisation.walker.RMHelper) DefaultValuePath(org.ehrbase.serialisation.walker.defaultvalues.DefaultValuePath) GenericId(com.nedap.archie.rm.support.identification.GenericId) DvCodedText(com.nedap.archie.rm.datavalues.DvCodedText) Participation(com.nedap.archie.rm.generic.Participation) DefaultValues(org.ehrbase.serialisation.walker.defaultvalues.DefaultValues) Setting(org.ehrbase.client.classgenerator.shareddefinition.Setting) GenericId(com.nedap.archie.rm.support.identification.GenericId) DvCodedText(com.nedap.archie.rm.datavalues.DvCodedText) Setting(org.ehrbase.client.classgenerator.shareddefinition.Setting) Objects(java.util.Objects) DvDateTime(com.nedap.archie.rm.datavalues.quantity.datetime.DvDateTime)

Example 7 with EventContext

use of com.nedap.archie.rm.composition.EventContext in project ehrbase by ehrbase.

the class EventContextFactory method makeNull.

public EventContext makeNull() {
    PartyRef partyRef = new PartyRef(new HierObjectId("ref"), "null", "null");
    PartyIdentified healthcareFacility = new PartyIdentified(partyRef, "null", null);
    DvCodedText concept = new DvCodedText("Other Care", new CodePhrase(new TerminologyId("openehr"), "238"));
    return new EventContext(healthcareFacility, new DvDateTime(new DateTime(0L).toString()), null, null, null, concept, null);
}
Also used : PartyRef(com.nedap.archie.rm.support.identification.PartyRef) EventContext(com.nedap.archie.rm.composition.EventContext) TerminologyId(com.nedap.archie.rm.support.identification.TerminologyId) PartyIdentified(com.nedap.archie.rm.generic.PartyIdentified) DvCodedText(com.nedap.archie.rm.datavalues.DvCodedText) CodePhrase(com.nedap.archie.rm.datatypes.CodePhrase) HierObjectId(com.nedap.archie.rm.support.identification.HierObjectId) DvDateTime(com.nedap.archie.rm.datavalues.quantity.datetime.DvDateTime) DateTime(org.joda.time.DateTime) DvDateTime(com.nedap.archie.rm.datavalues.quantity.datetime.DvDateTime)

Example 8 with EventContext

use of com.nedap.archie.rm.composition.EventContext in project ehrbase by ehrbase.

the class EventContextFactory method makeDummy.

public EventContext makeDummy() {
    PartyRef partyRef = new PartyRef(new GenericId("123456-123", "EHRBASE-SCHEME"), "DEMOGRAPHIC", "PARTY");
    PartyIdentified healthcareFacility = new PartyIdentified(partyRef, "FACILITY", null);
    DateTime timenow = DateTime.now();
    DvCodedText concept = new DvCodedText("Other Care", new CodePhrase(new TerminologyId("openehr"), "238"));
    return new EventContext(healthcareFacility, new DvDateTime(timenow.toString()), null, null, "TEST LAB", concept, null);
}
Also used : PartyRef(com.nedap.archie.rm.support.identification.PartyRef) EventContext(com.nedap.archie.rm.composition.EventContext) TerminologyId(com.nedap.archie.rm.support.identification.TerminologyId) GenericId(com.nedap.archie.rm.support.identification.GenericId) PartyIdentified(com.nedap.archie.rm.generic.PartyIdentified) DvCodedText(com.nedap.archie.rm.datavalues.DvCodedText) CodePhrase(com.nedap.archie.rm.datatypes.CodePhrase) DvDateTime(com.nedap.archie.rm.datavalues.quantity.datetime.DvDateTime) DateTime(org.joda.time.DateTime) DvDateTime(com.nedap.archie.rm.datavalues.quantity.datetime.DvDateTime)

Example 9 with EventContext

use of com.nedap.archie.rm.composition.EventContext 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)

Example 10 with EventContext

use of com.nedap.archie.rm.composition.EventContext in project ehrbase by ehrbase.

the class ContextAccess method retrieveHistoricalEventContext.

/**
 * @throws InternalServerException on failure of decoding DvText or DvDateTime
 */
public static EventContext retrieveHistoricalEventContext(I_DomainAccess domainAccess, UUID compositionId, Timestamp transactionTime) {
    // use fetch any since duplicates are possible during tests...
    EventContextHistoryRecord eventContextHistoryRecord = domainAccess.getContext().fetchAny(EVENT_CONTEXT_HISTORY, EVENT_CONTEXT_HISTORY.COMPOSITION_ID.eq(compositionId).and(EVENT_CONTEXT_HISTORY.SYS_TRANSACTION.eq(transactionTime)));
    // no matching version for this composition
    if (eventContextHistoryRecord == null)
        return null;
    // get the facility entry
    PartyIdentified healthCareFacility = null;
    if (eventContextHistoryRecord.getFacility() != null) {
        PartyIdentifiedRecord partyIdentifiedRecord = domainAccess.getContext().fetchOne(PARTY_IDENTIFIED, PARTY_IDENTIFIED.ID.eq(eventContextHistoryRecord.getFacility()));
        if (partyIdentifiedRecord != null) {
            List<DvIdentifier> identifiers = new ArrayList<>();
            domainAccess.getContext().fetch(IDENTIFIER, IDENTIFIER.PARTY.eq(partyIdentifiedRecord.getId())).forEach(record -> {
                DvIdentifier dvIdentifier = new DvIdentifier();
                dvIdentifier.setIssuer(record.getIssuer());
                dvIdentifier.setAssigner(record.getAssigner());
                dvIdentifier.setId(record.getIdValue());
                dvIdentifier.setType(record.getTypeName());
                identifiers.add(dvIdentifier);
            });
            // get PartyRef values from record
            healthCareFacility = getPartyIdentifiedFromRecord(partyIdentifiedRecord, identifiers);
        }
    }
    List<Participation> participationList = new ArrayList<>();
    // get the participations
    domainAccess.getContext().fetch(PARTICIPATION_HISTORY, PARTICIPATION_HISTORY.EVENT_CONTEXT.eq(eventContextHistoryRecord.getId()).and(PARTICIPATION_HISTORY.SYS_TRANSACTION.eq(transactionTime))).forEach(record -> {
        // retrieve performer
        PartyProxy performer = new PersistedPartyProxy(domainAccess).retrieve(record.getPerformer());
        DvInterval<DvDateTime> startTime = convertDvIntervalDvDateTimeFromRecord(eventContextHistoryRecord);
        DvCodedText mode = convertModeFromRecord(eventContextHistoryRecord);
        Participation participation = new Participation(performer, (DvText) new RecordedDvCodedText().fromDB(record, PARTICIPATION.FUNCTION), mode, startTime);
        participationList.add(participation);
    });
    DvCodedText setting = (DvCodedText) new RecordedDvCodedText().fromDB(eventContextHistoryRecord, EVENT_CONTEXT_HISTORY.SETTING);
    return new EventContext(healthCareFacility, new RecordedDvDateTime().decodeDvDateTime(eventContextHistoryRecord.getStartTime(), eventContextHistoryRecord.getStartTimeTzid()), new RecordedDvDateTime().decodeDvDateTime(eventContextHistoryRecord.getEndTime(), eventContextHistoryRecord.getEndTimeTzid()), participationList.isEmpty() ? null : participationList, eventContextHistoryRecord.getLocation(), setting, null);
}
Also used : Participation(com.nedap.archie.rm.generic.Participation) PartyIdentifiedRecord(org.ehrbase.jooq.pg.tables.records.PartyIdentifiedRecord) PartyIdentified(com.nedap.archie.rm.generic.PartyIdentified) RecordedDvCodedText(org.ehrbase.service.RecordedDvCodedText) DvCodedText(com.nedap.archie.rm.datavalues.DvCodedText) ArrayList(java.util.ArrayList) DvIdentifier(com.nedap.archie.rm.datavalues.DvIdentifier) PersistedPartyProxy(org.ehrbase.dao.access.jooq.party.PersistedPartyProxy) DvDateTime(com.nedap.archie.rm.datavalues.quantity.datetime.DvDateTime) RecordedDvDateTime(org.ehrbase.service.RecordedDvDateTime) EventContext(com.nedap.archie.rm.composition.EventContext) RecordedDvDateTime(org.ehrbase.service.RecordedDvDateTime) RecordedDvCodedText(org.ehrbase.service.RecordedDvCodedText) EventContextHistoryRecord(org.ehrbase.jooq.pg.tables.records.EventContextHistoryRecord) PersistedPartyProxy(org.ehrbase.dao.access.jooq.party.PersistedPartyProxy) PartyProxy(com.nedap.archie.rm.generic.PartyProxy)

Aggregations

EventContext (com.nedap.archie.rm.composition.EventContext)10 DvDateTime (com.nedap.archie.rm.datavalues.quantity.datetime.DvDateTime)6 DvCodedText (com.nedap.archie.rm.datavalues.DvCodedText)5 PartyIdentified (com.nedap.archie.rm.generic.PartyIdentified)5 TerminologyId (com.nedap.archie.rm.support.identification.TerminologyId)4 I_EntryAccess (org.ehrbase.dao.access.interfaces.I_EntryAccess)4 CodePhrase (com.nedap.archie.rm.datatypes.CodePhrase)3 Participation (com.nedap.archie.rm.generic.Participation)3 PartyProxy (com.nedap.archie.rm.generic.PartyProxy)3 ArrayList (java.util.ArrayList)3 UUID (java.util.UUID)3 PersistedPartyProxy (org.ehrbase.dao.access.jooq.party.PersistedPartyProxy)3 DvIdentifier (com.nedap.archie.rm.datavalues.DvIdentifier)2 GenericId (com.nedap.archie.rm.support.identification.GenericId)2 PartyRef (com.nedap.archie.rm.support.identification.PartyRef)2 SQLException (java.sql.SQLException)2 InternalServerException (org.ehrbase.api.exception.InternalServerException)2 ObjectNotFoundException (org.ehrbase.api.exception.ObjectNotFoundException)2 I_ContextAccess (org.ehrbase.dao.access.interfaces.I_ContextAccess)2 PartyIdentifiedRecord (org.ehrbase.jooq.pg.tables.records.PartyIdentifiedRecord)2