Search in sources :

Example 1 with RecordedDvCodedText

use of org.ehrbase.service.RecordedDvCodedText 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 RecordedDvCodedText

use of org.ehrbase.service.RecordedDvCodedText in project ehrbase by ehrbase.

the class EhrAccess method getStatus.

// get latest status
@Override
public EhrStatus getStatus() {
    EhrStatus status = new EhrStatus();
    status.setModifiable(isModifiable());
    status.setQueryable(isQueryable());
    // set otherDetails if available
    if (getStatusAccess().getStatusRecord().getOtherDetails() != null) {
        status.setOtherDetails(getStatusAccess().getStatusRecord().getOtherDetails());
    }
    // Locatable attribute
    status.setArchetypeNodeId(getArchetypeNodeId());
    Object name = new RecordedDvCodedText().fromDB(getStatusAccess().getStatusRecord(), STATUS.NAME);
    status.setName(name instanceof DvText ? (DvText) name : (DvCodedText) name);
    UUID statusId = getStatusAccess().getStatusRecord().getId();
    status.setUid(new HierObjectId(statusId.toString() + "::" + getServerConfig().getNodename() + "::" + I_StatusAccess.getLatestVersionNumber(this, statusId)));
    PartySelf partySelf = (PartySelf) new PersistedPartyProxy(this).retrieve(getParty());
    status.setSubject(partySelf);
    return status;
}
Also used : EhrStatus(com.nedap.archie.rm.ehr.EhrStatus) RecordedDvCodedText(org.ehrbase.service.RecordedDvCodedText) RecordedDvCodedText(org.ehrbase.service.RecordedDvCodedText) DvCodedText(com.nedap.archie.rm.datavalues.DvCodedText) UUID(java.util.UUID) HierObjectId(com.nedap.archie.rm.support.identification.HierObjectId) DvText(com.nedap.archie.rm.datavalues.DvText) RecordedDvText(org.ehrbase.service.RecordedDvText) PartySelf(com.nedap.archie.rm.generic.PartySelf) PersistedPartyProxy(org.ehrbase.dao.access.jooq.party.PersistedPartyProxy)

Example 3 with RecordedDvCodedText

use of org.ehrbase.service.RecordedDvCodedText in project ehrbase by ehrbase.

the class EntryAccess method setFields.

/**
 * Sets the field of a new Entry record (as part of the calling {@link EntryAccess} instance) with
 * given parameters. The Composition of the calling {@link EntryAccess} will be updated with the
 * given {@link Composition} as a result.
 *
 * @param templateId    ID of template
 * @param sequence      Sequence number
 * @param compositionId ID of composition
 * @param composition   {@link Composition} object with more information for the entry
 */
private void setFields(String templateId, Integer sequence, UUID compositionId, Composition composition) {
    entryRecord = getContext().newRecord(ENTRY);
    entryRecord.setTemplateId(templateId);
    entryRecord.setSequence(sequence);
    entryRecord.setCompositionId(compositionId);
    entryRecord.setRmVersion(composition.getArchetypeDetails().getRmVersion());
    new RecordedDvCodedText().toDB(entryRecord, ENTRY.CATEGORY, composition.getCategory());
    setCompositionFields(entryRecord, composition);
    setCompositionName(composition.getName());
    this.composition = composition;
}
Also used : RecordedDvCodedText(org.ehrbase.service.RecordedDvCodedText)

Example 4 with RecordedDvCodedText

use of org.ehrbase.service.RecordedDvCodedText 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 RecordedDvCodedText

use of org.ehrbase.service.RecordedDvCodedText in project ehrbase by ehrbase.

the class StatusAccess method getStatus.

@Override
public EhrStatus getStatus() {
    EhrStatus status = new EhrStatus();
    status.setModifiable(getStatusRecord().getIsModifiable());
    status.setQueryable(getStatusRecord().getIsQueryable());
    // set otherDetails if available
    if (getStatusRecord().getOtherDetails() != null) {
        status.setOtherDetails(getStatusRecord().getOtherDetails());
    }
    // Locatable attribute
    status.setArchetypeNodeId(getStatusRecord().getArchetypeNodeId());
    Object name = new RecordedDvCodedText().fromDB(getStatusRecord(), STATUS.NAME);
    status.setName(name instanceof DvText ? (DvText) name : (DvCodedText) name);
    UUID statusId = getStatusRecord().getId();
    status.setUid(new HierObjectId(statusId.toString() + "::" + getServerConfig().getNodename() + "::" + I_StatusAccess.getLatestVersionNumber(this, statusId)));
    PartySelf partySelf = (PartySelf) new PersistedPartyProxy(this).retrieve(getStatusRecord().getParty());
    status.setSubject(partySelf);
    return status;
}
Also used : EhrStatus(com.nedap.archie.rm.ehr.EhrStatus) RecordedDvCodedText(org.ehrbase.service.RecordedDvCodedText) RecordedDvCodedText(org.ehrbase.service.RecordedDvCodedText) DvCodedText(com.nedap.archie.rm.datavalues.DvCodedText) UUID(java.util.UUID) HierObjectId(com.nedap.archie.rm.support.identification.HierObjectId) DvText(com.nedap.archie.rm.datavalues.DvText) PartySelf(com.nedap.archie.rm.generic.PartySelf) PersistedPartyProxy(org.ehrbase.dao.access.jooq.party.PersistedPartyProxy)

Aggregations

RecordedDvCodedText (org.ehrbase.service.RecordedDvCodedText)7 PersistedPartyProxy (org.ehrbase.dao.access.jooq.party.PersistedPartyProxy)6 DvCodedText (com.nedap.archie.rm.datavalues.DvCodedText)4 DvDateTime (com.nedap.archie.rm.datavalues.quantity.datetime.DvDateTime)3 Participation (com.nedap.archie.rm.generic.Participation)3 PartyIdentified (com.nedap.archie.rm.generic.PartyIdentified)3 PartyProxy (com.nedap.archie.rm.generic.PartyProxy)3 ArrayList (java.util.ArrayList)3 UUID (java.util.UUID)3 RawJson (org.ehrbase.serialisation.dbencoding.RawJson)3 RecordedDvDateTime (org.ehrbase.service.RecordedDvDateTime)3 EventContext (com.nedap.archie.rm.composition.EventContext)2 DvIdentifier (com.nedap.archie.rm.datavalues.DvIdentifier)2 DvText (com.nedap.archie.rm.datavalues.DvText)2 EhrStatus (com.nedap.archie.rm.ehr.EhrStatus)2 PartySelf (com.nedap.archie.rm.generic.PartySelf)2 HierObjectId (com.nedap.archie.rm.support.identification.HierObjectId)2 PartyIdentifiedRecord (org.ehrbase.jooq.pg.tables.records.PartyIdentifiedRecord)2 RecordedDvText (org.ehrbase.service.RecordedDvText)2 Composition (com.nedap.archie.rm.composition.Composition)1