Search in sources :

Example 41 with DvDateTime

use of com.nedap.archie.rm.datavalues.quantity.datetime.DvDateTime in project ehrbase by ehrbase.

the class ContributionServiceImp method retrieveAuditDetails.

/**
 * retrieval and building of AuditDetails object attached to the given contribution context
 * @param contributionId ID of contribution
 * @return {@link AuditDetails} object from contribution
 */
private AuditDetails retrieveAuditDetails(UUID contributionId) {
    UUID auditId = I_ContributionAccess.retrieveInstance(this.getDataAccess(), contributionId).getHasAuditDetails();
    I_AuditDetailsAccess auditDetailsAccess = new AuditDetailsAccess(this.getDataAccess()).retrieveInstance(this.getDataAccess(), auditId);
    String systemId = auditDetailsAccess.getSystemId().toString();
    PartyProxy committer = new PersistedPartyProxy(this.getDataAccess()).retrieve(auditDetailsAccess.getCommitter());
    DvDateTime timeCommitted = new DvDateTime(LocalDateTime.ofInstant(auditDetailsAccess.getTimeCommitted().toInstant(), ZoneId.of(auditDetailsAccess.getTimeCommittedTzId())));
    int changeTypeCode = I_ConceptAccess.ContributionChangeType.valueOf(auditDetailsAccess.getChangeType().getLiteral().toUpperCase()).getCode();
    // FIXME: what's the terminology ID of the official change type terminology?
    DvCodedText changeType = new DvCodedText(auditDetailsAccess.getChangeType().getLiteral(), new CodePhrase(new TerminologyId("audit change type"), String.valueOf(changeTypeCode)));
    DvText description = new DvText(auditDetailsAccess.getDescription());
    return new AuditDetails(systemId, committer, timeCommitted, changeType, description);
}
Also used : TerminologyId(com.nedap.archie.rm.support.identification.TerminologyId) AuditDetailsAccess(org.ehrbase.dao.access.jooq.AuditDetailsAccess) DvCodedText(com.nedap.archie.rm.datavalues.DvCodedText) CodePhrase(com.nedap.archie.rm.datatypes.CodePhrase) PersistedPartyProxy(org.ehrbase.dao.access.jooq.party.PersistedPartyProxy) DvDateTime(com.nedap.archie.rm.datavalues.quantity.datetime.DvDateTime) DvText(com.nedap.archie.rm.datavalues.DvText) PersistedPartyProxy(org.ehrbase.dao.access.jooq.party.PersistedPartyProxy) PartyProxy(com.nedap.archie.rm.generic.PartyProxy) AuditDetails(com.nedap.archie.rm.generic.AuditDetails)

Example 42 with DvDateTime

use of com.nedap.archie.rm.datavalues.quantity.datetime.DvDateTime in project ehrbase by ehrbase.

the class EhrServiceImp method getVersionedEhrStatus.

@Override
public VersionedEhrStatus getVersionedEhrStatus(UUID ehrUid) {
    // FIXME VERSIONED_OBJECT_POC: Pre_has_ehr: has_ehr (an_ehr_id)
    // FIXME VERSIONED_OBJECT_POC: Pre_has_ehr_status_version: has_ehr_status_version (an_ehr_id, a_version_uid)
    Optional<EhrStatus> ehrStatus = getEhrStatus(ehrUid);
    VersionedEhrStatus versionedEhrStatus = new VersionedEhrStatus();
    if (ehrStatus.isPresent()) {
        versionedEhrStatus.setUid(new HierObjectId(ehrStatus.get().getUid().getRoot().getValue()));
        versionedEhrStatus.setOwnerId(new ObjectRef<>(new HierObjectId(ehrUid.toString()), "local", "EHR"));
        I_EhrAccess ehrAccess = I_EhrAccess.retrieveInstance(getDataAccess(), ehrUid);
        versionedEhrStatus.setTimeCreated(new DvDateTime(OffsetDateTime.of(ehrAccess.getStatusAccess().getInitialTimeOfVersionedEhrStatus().toLocalDateTime(), OffsetDateTime.now().getOffset())));
    }
    return versionedEhrStatus;
}
Also used : VersionedEhrStatus(com.nedap.archie.rm.ehr.VersionedEhrStatus) VersionedEhrStatus(com.nedap.archie.rm.ehr.VersionedEhrStatus) EhrStatus(com.nedap.archie.rm.ehr.EhrStatus) HierObjectId(com.nedap.archie.rm.support.identification.HierObjectId) DvDateTime(com.nedap.archie.rm.datavalues.quantity.datetime.DvDateTime)

Example 43 with DvDateTime

use of com.nedap.archie.rm.datavalues.quantity.datetime.DvDateTime 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)

Example 44 with DvDateTime

use of com.nedap.archie.rm.datavalues.quantity.datetime.DvDateTime in project ehrbase by ehrbase.

the class ContextAccess method setRecordFields.

/**
 * setup an EventContextRecord instance based on values from an EventContext instance
 *
 * @param id
 * @param eventContext
 */
@Override
public void setRecordFields(UUID id, EventContext eventContext) {
    RecordedDvDateTime recordedDvDateTime = new RecordedDvDateTime(eventContext.getStartTime());
    eventContextRecord.setStartTime(recordedDvDateTime.toTimestamp());
    recordedDvDateTime.zoneId().ifPresent(eventContextRecord::setStartTimeTzid);
    if (eventContext.getEndTime() != null) {
        recordedDvDateTime = new RecordedDvDateTime(eventContext.getEndTime());
        eventContextRecord.setEndTime(recordedDvDateTime.toTimestamp());
        recordedDvDateTime.zoneId().ifPresent(eventContextRecord::setEndTimeTzid);
    }
    eventContextRecord.setId(id != null ? id : UUID.randomUUID());
    // Health care facility
    if (eventContext.getHealthCareFacility() != null) {
        UUID healthcareFacilityId = new PersistedPartyProxy(this).getOrCreate(eventContext.getHealthCareFacility());
        eventContextRecord.setFacility(healthcareFacilityId);
    }
    // location
    if (eventContext.getLocation() != null)
        eventContextRecord.setLocation(eventContext.getLocation());
    new RecordedDvCodedText().toDB(eventContextRecord, EVENT_CONTEXT.SETTING, eventContext.getSetting());
    if (eventContext.getParticipations() != null) {
        for (Participation participation : eventContext.getParticipations()) {
            ParticipationRecord participationRecord = getContext().newRecord(PARTICIPATION);
            participationRecord.setEventContext(eventContextRecord.getId());
            new RecordedDvText().toDB(participationRecord, PARTICIPATION.FUNCTION, participation.getFunction());
            if (participation.getMode() != null)
                new RecordedDvCodedText().toDB(participationRecord, PARTICIPATION.MODE, participation.getMode());
            if (participation.getTime() != null) {
                DvDateTime lower = participation.getTime().getLower();
                if (lower != null) {
                    recordedDvDateTime = new RecordedDvDateTime(lower);
                    participationRecord.setTimeLower(recordedDvDateTime.toTimestamp());
                    recordedDvDateTime.zoneId().ifPresent(participationRecord::setTimeLowerTz);
                }
                DvDateTime upper = participation.getTime().getUpper();
                if (upper != null) {
                    recordedDvDateTime = new RecordedDvDateTime(upper);
                    participationRecord.setTimeUpper(recordedDvDateTime.toTimestamp());
                    recordedDvDateTime.zoneId().ifPresent(participationRecord::setTimeUpperTz);
                }
            }
            // only PartyIdentified performer is supported now
            PartyIdentified performer;
            PartyProxy setPerformer = participation.getPerformer();
            if (!(setPerformer instanceof PartyIdentified)) {
                log.warn("Set performer is using unsupported type: {}", setPerformer);
                break;
            }
            performer = (PartyIdentified) setPerformer;
            UUID performerUuid = new PersistedPartyProxy(this).getOrCreate(performer);
            // set the performer
            participationRecord.setPerformer(performerUuid);
            participations.add(participationRecord);
        }
    }
    // other context
    if (eventContext.getOtherContext() != null && CollectionUtils.isNotEmpty(eventContext.getOtherContext().getItems())) {
        // set up the JSONB field other_context
        eventContextRecord.setOtherContext(JSONB.valueOf(new RawJson().marshal(eventContext.getOtherContext())));
    }
}
Also used : Participation(com.nedap.archie.rm.generic.Participation) PartyIdentified(com.nedap.archie.rm.generic.PartyIdentified) ParticipationRecord(org.ehrbase.jooq.pg.tables.records.ParticipationRecord) RawJson(org.ehrbase.serialisation.dbencoding.RawJson) PersistedPartyProxy(org.ehrbase.dao.access.jooq.party.PersistedPartyProxy) DvDateTime(com.nedap.archie.rm.datavalues.quantity.datetime.DvDateTime) RecordedDvDateTime(org.ehrbase.service.RecordedDvDateTime) RecordedDvDateTime(org.ehrbase.service.RecordedDvDateTime) RecordedDvText(org.ehrbase.service.RecordedDvText) RecordedDvCodedText(org.ehrbase.service.RecordedDvCodedText) PersistedPartyProxy(org.ehrbase.dao.access.jooq.party.PersistedPartyProxy) PartyProxy(com.nedap.archie.rm.generic.PartyProxy) UUID(java.util.UUID)

Aggregations

DvDateTime (com.nedap.archie.rm.datavalues.quantity.datetime.DvDateTime)44 PartyIdentified (com.nedap.archie.rm.generic.PartyIdentified)11 Test (org.junit.Test)10 DvCodedText (com.nedap.archie.rm.datavalues.DvCodedText)8 PartyProxy (com.nedap.archie.rm.generic.PartyProxy)7 EventContext (com.nedap.archie.rm.composition.EventContext)6 HierObjectId (com.nedap.archie.rm.support.identification.HierObjectId)5 TerminologyId (com.nedap.archie.rm.support.identification.TerminologyId)5 PersistedPartyProxy (org.ehrbase.dao.access.jooq.party.PersistedPartyProxy)5 Composition (com.nedap.archie.rm.composition.Composition)4 CodePhrase (com.nedap.archie.rm.datatypes.CodePhrase)4 Participation (com.nedap.archie.rm.generic.Participation)4 TemporalAccessor (java.time.temporal.TemporalAccessor)4 Objects (java.util.Objects)4 DvIdentifier (com.nedap.archie.rm.datavalues.DvIdentifier)3 DvText (com.nedap.archie.rm.datavalues.DvText)3 EhrStatus (com.nedap.archie.rm.ehr.EhrStatus)3 AuditDetails (com.nedap.archie.rm.generic.AuditDetails)3 UUID (java.util.UUID)3 Test (org.junit.jupiter.api.Test)3