Search in sources :

Example 1 with DvDateTime

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

the class RecordedDvDateTimeTest method testDecodeDvDateTime.

@Test
public void testDecodeDvDateTime() {
    ZoneOffset zoneId = ZoneOffset.of("-06:00");
    Instant now = Instant.now();
    DvDateTime dateTime;
    dateTime = new RecordedDvDateTime().decodeDvDateTime(Timestamp.valueOf(LocalDateTime.ofInstant(now, zoneId)), zoneId.getId());
    assertEquals(OffsetDateTime.ofInstant(now, zoneId), dateTime.getValue());
    dateTime = new RecordedDvDateTime().decodeDvDateTime(Timestamp.from(now), null);
    assertEquals(LocalDateTime.ofInstant(now, ZoneId.systemDefault()), dateTime.getValue());
    dateTime = new RecordedDvDateTime().decodeDvDateTime(Timestamp.from(now), zoneId.getId());
    assertNotEquals(OffsetDateTime.ofInstant(now, ZoneOffset.UTC), dateTime.getValue());
}
Also used : Instant(java.time.Instant) ZoneOffset(java.time.ZoneOffset) DvDateTime(com.nedap.archie.rm.datavalues.quantity.datetime.DvDateTime) Test(org.junit.Test)

Example 2 with DvDateTime

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

the class EhrServiceImp method getCreationTime.

/**
 * Fetches time of creation of specific EHR record
 *
 * @param ehrId
 * @return LocalDateTime instance of timestamp from DB
 */
public DvDateTime getCreationTime(UUID ehrId) {
    // pre-step: check for valid ehrId
    if (!hasEhr(ehrId)) {
        throw new ObjectNotFoundException("ehr", "No EHR found with given ID: " + ehrId.toString());
    }
    try {
        I_EhrAccess ehrAccess = I_EhrAccess.retrieveInstance(getDataAccess(), ehrId);
        OffsetDateTime offsetDateTime = OffsetDateTime.from(LocalDateTime.from(ehrAccess.getEhrRecord().getDateCreated().toLocalDateTime()).atZone(ZoneId.of(ehrAccess.getEhrRecord().getDateCreatedTzid())));
        return new DvDateTime(offsetDateTime);
    } catch (Exception e) {
        logger.error(e.getMessage());
        throw new InternalServerException(e);
    }
}
Also used : OffsetDateTime(java.time.OffsetDateTime) DvDateTime(com.nedap.archie.rm.datavalues.quantity.datetime.DvDateTime)

Example 3 with DvDateTime

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

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

the class AttestationAccess method getAsAttestation.

@Override
public Attestation getAsAttestation() {
    // take most values from super class entry
    AuditDetails audit = auditDetailsAccess.getAsAuditDetails();
    String systemId = audit.getSystemId();
    PartyProxy committer = audit.getCommitter();
    DvDateTime time = audit.getTimeCommitted();
    DvCodedText changeType = audit.getChangeType();
    DvText description = audit.getDescription();
    // FIXME VERSIONED_OBJECT_POC: implement retrieval from "attested_view" table
    DvMultimedia attestedView = null;
    String proof = attestationRecord.getProof();
    // FIXME VERSIONED_OBJECT_POC: implement?! seems to be completely unsupported right now
    List<DvEHRURI> items = null;
    DvText reason = new DvText(attestationRecord.getReason());
    boolean isPending = attestationRecord.getIsPending();
    return new Attestation(systemId, committer, time, changeType, description, attestedView, proof, items, reason, isPending);
}
Also used : DvCodedText(com.nedap.archie.rm.datavalues.DvCodedText) DvEHRURI(com.nedap.archie.rm.datavalues.DvEHRURI) PartyProxy(com.nedap.archie.rm.generic.PartyProxy) AuditDetails(com.nedap.archie.rm.generic.AuditDetails) DvMultimedia(com.nedap.archie.rm.datavalues.encapsulated.DvMultimedia) Attestation(com.nedap.archie.rm.generic.Attestation) DvDateTime(com.nedap.archie.rm.datavalues.quantity.datetime.DvDateTime) DvText(com.nedap.archie.rm.datavalues.DvText)

Example 5 with DvDateTime

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

the class AuditDetailsAccess method getAsAuditDetails.

@Override
public AuditDetails getAsAuditDetails() {
    String systemId = getSystemId().toString();
    PartyProxy party = new PersistedPartyProxy(this).retrieve(getCommitter());
    DvDateTime time = new DvDateTime(getTimeCommitted().toLocalDateTime());
    DvCodedText changeType = new DvCodedText(getChangeType().getLiteral(), new CodePhrase(new TerminologyId("openehr"), Integer.toString(I_ConceptAccess.ContributionChangeType.valueOf(getChangeType().getLiteral().toUpperCase()).getCode())));
    DvText description = new DvText(getDescription());
    return new AuditDetails(systemId, party, time, changeType, description);
}
Also used : TerminologyId(com.nedap.archie.rm.support.identification.TerminologyId) DvCodedText(com.nedap.archie.rm.datavalues.DvCodedText) CodePhrase(com.nedap.archie.rm.datatypes.CodePhrase) PartyProxy(com.nedap.archie.rm.generic.PartyProxy) PersistedPartyProxy(org.ehrbase.dao.access.jooq.party.PersistedPartyProxy) AuditDetails(com.nedap.archie.rm.generic.AuditDetails) PersistedPartyProxy(org.ehrbase.dao.access.jooq.party.PersistedPartyProxy) DvDateTime(com.nedap.archie.rm.datavalues.quantity.datetime.DvDateTime) DvText(com.nedap.archie.rm.datavalues.DvText)

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