Search in sources :

Example 1 with PartyIdentifiedRecord

use of org.ehrbase.jooq.pg.tables.records.PartyIdentifiedRecord in project ehrbase by ehrbase.

the class ContextAccess method mapRmEventContext.

/**
 * @throws InternalServerException on failure of decoding DvText or DvDateTime
 */
@Override
public EventContext mapRmEventContext() {
    // get the facility entry
    PartyIdentifiedRecord partyIdentifiedRecord = getContext().fetchOne(PARTY_IDENTIFIED, PARTY_IDENTIFIED.ID.eq(eventContextRecord.getFacility()));
    // facility identifiers
    PartyIdentified healthCareFacility = null;
    if (partyIdentifiedRecord != null) {
        List<DvIdentifier> identifiers = new ArrayList<>();
        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
    getContext().fetch(PARTICIPATION, PARTICIPATION.EVENT_CONTEXT.eq(eventContextRecord.getId())).forEach(record -> {
        // retrieve performer
        PartyProxy performer = new PersistedPartyProxy(this).retrieve(record.getPerformer());
        DvInterval<DvDateTime> dvInterval = convertDvIntervalDvDateTimeFromRecord(record);
        DvCodedText mode = convertModeFromRecord(record);
        Participation participation = new Participation(performer, (DvText) new RecordedDvCodedText().fromDB(record, PARTICIPATION.FUNCTION), mode, dvInterval);
        participationList.add(participation);
    });
    DvCodedText concept = (DvCodedText) new RecordedDvCodedText().fromDB(eventContextRecord, EVENT_CONTEXT.SETTING);
    ItemStructure otherContext = null;
    if (eventContextRecord.getOtherContext() != null) {
        otherContext = new RawJson().unmarshal((eventContextRecord.getOtherContext().data()), ItemStructure.class);
    }
    return new EventContext(healthCareFacility, new RecordedDvDateTime().decodeDvDateTime(eventContextRecord.getStartTime(), eventContextRecord.getStartTimeTzid()), new RecordedDvDateTime().decodeDvDateTime(eventContextRecord.getEndTime(), eventContextRecord.getEndTimeTzid()), participationList.isEmpty() ? null : participationList, eventContextRecord.getLocation(), concept, otherContext);
}
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) RawJson(org.ehrbase.serialisation.dbencoding.RawJson) ArrayList(java.util.ArrayList) ItemStructure(com.nedap.archie.rm.datastructures.ItemStructure) 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) PersistedPartyProxy(org.ehrbase.dao.access.jooq.party.PersistedPartyProxy) PartyProxy(com.nedap.archie.rm.generic.PartyProxy)

Example 2 with PartyIdentifiedRecord

use of org.ehrbase.jooq.pg.tables.records.PartyIdentifiedRecord 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)2 DvCodedText (com.nedap.archie.rm.datavalues.DvCodedText)2 DvIdentifier (com.nedap.archie.rm.datavalues.DvIdentifier)2 DvDateTime (com.nedap.archie.rm.datavalues.quantity.datetime.DvDateTime)2 Participation (com.nedap.archie.rm.generic.Participation)2 PartyIdentified (com.nedap.archie.rm.generic.PartyIdentified)2 PartyProxy (com.nedap.archie.rm.generic.PartyProxy)2 ArrayList (java.util.ArrayList)2 PersistedPartyProxy (org.ehrbase.dao.access.jooq.party.PersistedPartyProxy)2 PartyIdentifiedRecord (org.ehrbase.jooq.pg.tables.records.PartyIdentifiedRecord)2 RecordedDvCodedText (org.ehrbase.service.RecordedDvCodedText)2 RecordedDvDateTime (org.ehrbase.service.RecordedDvDateTime)2 ItemStructure (com.nedap.archie.rm.datastructures.ItemStructure)1 EventContextHistoryRecord (org.ehrbase.jooq.pg.tables.records.EventContextHistoryRecord)1 RawJson (org.ehrbase.serialisation.dbencoding.RawJson)1