Search in sources :

Example 26 with DvDateTime

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

the class HistoryPostprocessor method process.

/**
 * {@inheritDoc}
 */
@Override
public void process(String term, History rmObject, Map<FlatPathDto, String> values, Set<String> consumedPaths, Context<Map<FlatPathDto, String>> context) {
    setValue(term + PATH_DIVIDER + "history_origin", null, values, s -> {
        if (s != null) {
            rmObject.setOrigin(new DvDateTime(s));
        }
    }, String.class, consumedPaths);
    if (rmObject.getOrigin() == null || rmObject.getOrigin().getValue() == null) {
        Optional<TemporalAccessor> first = ((History<ItemStructure>) rmObject).getEvents().stream().map(Event::getTime).filter(Objects::nonNull).map(DvDateTime::getValue).filter(Objects::nonNull).sorted().findFirst();
        first.ifPresent(temporalAccessor -> ((History<ItemStructure>) rmObject).setOrigin(new DvDateTime(temporalAccessor)));
    }
}
Also used : TemporalAccessor(java.time.temporal.TemporalAccessor) Objects(java.util.Objects) ItemStructure(com.nedap.archie.rm.datastructures.ItemStructure) DvDateTime(com.nedap.archie.rm.datavalues.quantity.datetime.DvDateTime)

Example 27 with DvDateTime

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

the class DvDateTimeAttributes method instanceFromValue.

public static DvDateTimeAttributes instanceFromValue(DvDateTime dvDateTime) {
    TemporalAccessor localDate;
    TemporalAccessor actual = dvDateTime.getValue();
    if (actual.isSupported(ChronoField.YEAR) && actual.isSupported(ChronoField.MONTH_OF_YEAR) && actual.isSupported(ChronoField.DAY_OF_MONTH))
        localDate = LocalDate.of(actual.get(ChronoField.YEAR), actual.get(ChronoField.MONTH_OF_YEAR), actual.get(ChronoField.DAY_OF_MONTH));
    else if (actual.isSupported(ChronoField.YEAR) && actual.isSupported(ChronoField.MONTH_OF_YEAR))
        localDate = YearMonth.of(actual.get(ChronoField.YEAR), actual.get(ChronoField.MONTH_OF_YEAR));
    else if (actual.isSupported(ChronoField.YEAR))
        localDate = Year.of(actual.get(ChronoField.YEAR));
    else
        throw new IllegalArgumentException("DvDateTime supplied is not valid:" + actual);
    DvTimeAttributes dvTimeAttributes = DvTimeAttributes.instanceFromValue(dvDateTime.getValue());
    DvDateAttributes dvDateAttributes = DvDateAttributes.instanceFromValue(new DvDate((Temporal) localDate));
    if (dvTimeAttributes == null) {
        dvDateTime = new DvDateTime(dvDateAttributes.getValueAsProvided());
    }
    return new DvDateTimeAttributes(dvDateTime, dvDateAttributes, dvTimeAttributes);
}
Also used : TemporalAccessor(java.time.temporal.TemporalAccessor) Temporal(java.time.temporal.Temporal) DvTimeAttributes(org.ehrbase.serialisation.attributes.datavalues.datetime.time.DvTimeAttributes) DvDate(com.nedap.archie.rm.datavalues.quantity.datetime.DvDate) DvDateAttributes(org.ehrbase.serialisation.attributes.datavalues.datetime.date.DvDateAttributes) DvDateTime(com.nedap.archie.rm.datavalues.quantity.datetime.DvDateTime)

Example 28 with DvDateTime

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

the class FeederAudiDetailsStdConfig method buildChildValues.

@Override
public /**
 * {@inheritDoc}
 */
Map<String, Object> buildChildValues(String currentTerm, FeederAuditDetails rmObject, Context<Map<String, Object>> context) {
    Map<String, Object> result = new HashMap<>();
    addValue(result, currentTerm, "time", Optional.ofNullable(rmObject.getTime()).map(DvDateTime::getValue).orElse(null));
    addValue(result, currentTerm, "system_id", rmObject.getSystemId());
    addValue(result, currentTerm, "version_id", rmObject.getVersionId());
    if (rmObject.getLocation() != null) {
        StdConfig stdConfig = findStdConfig(rmObject.getLocation().getClass());
        result.putAll(stdConfig.buildChildValues(currentTerm + "/location", rmObject.getLocation(), context));
    }
    if (rmObject.getProvider() != null) {
        StdConfig stdConfig = findStdConfig(rmObject.getProvider().getClass());
        result.putAll(stdConfig.buildChildValues(currentTerm + "/provider", rmObject.getProvider(), context));
    }
    if (rmObject.getSubject() != null) {
        StdConfig stdConfig = findStdConfig(rmObject.getSubject().getClass());
        result.putAll(stdConfig.buildChildValues(currentTerm + "/subject", rmObject.getSubject(), context));
    }
    return result;
}
Also used : HashMap(java.util.HashMap) StdFromCompositionWalker.findStdConfig(org.ehrbase.serialisation.flatencoding.std.marshal.StdFromCompositionWalker.findStdConfig) DvDateTime(com.nedap.archie.rm.datavalues.quantity.datetime.DvDateTime)

Example 29 with DvDateTime

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

the class CanonicalJsonMarshallingTest method MarshalDvDateTime.

// check that dot is not converted into a comma!
@Test
public void MarshalDvDateTime() {
    DvDateTime dvDateTime = new DvDateTime("2021-10-01T10:32:51.543+07:00");
    CanonicalJson cut = new CanonicalJson();
    String actual = cut.marshal(dvDateTime);
    assertThat(actual).isEqualToIgnoringWhitespace("{" + "  \"_type\" : \"DV_DATE_TIME\"," + "  \"value\" : \"2021-10-01T10:32:51.543+07:00\"" + "}");
}
Also used : DvDateTime(com.nedap.archie.rm.datavalues.quantity.datetime.DvDateTime) Test(org.junit.Test)

Example 30 with DvDateTime

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

the class DBEncodeTest method testDBDecodeDvIntervalCompositeClass.

@Test
public void testDBDecodeDvIntervalCompositeClass() throws Exception {
    String db_encoded = IOUtils.resourceToString("/composition/canonical_json/composition_with_dvinterval_composite.json", UTF_8);
    assertNotNull(db_encoded);
    JsonElement converted = new LightRawJsonEncoder(db_encoded).encodeContentAsJson(null);
    // see if this can be interpreted by Archie
    Composition composition = new CanonicalJson().unmarshal(converted.toString(), Composition.class);
    // hack the composition to figure out what is the format of DvInterval...
    ((DvInterval) ((Element) ((AdminEntry) composition.getContent().get(0)).getData().getItems().get(0)).getValue()).setLower(new DvDateTime("2019-11-22T00:00+01:00"));
    ((DvInterval) ((Element) ((AdminEntry) composition.getContent().get(0)).getData().getItems().get(0)).getValue()).setUpper(new DvDateTime("2019-12-22T00:00+01:00"));
    assertNotNull(composition);
    String toJson = new CanonicalJson().marshal(composition);
    String interpreted = new CanonicalXML().marshal(composition);
    assertNotNull(interpreted);
}
Also used : DvInterval(com.nedap.archie.rm.datavalues.quantity.DvInterval) Composition(com.nedap.archie.rm.composition.Composition) CanonicalJson(org.ehrbase.serialisation.jsonencoding.CanonicalJson) CompositionTestDataCanonicalJson(org.ehrbase.test_data.composition.CompositionTestDataCanonicalJson) LightRawJsonEncoder(org.ehrbase.serialisation.dbencoding.rawjson.LightRawJsonEncoder) JsonElement(com.google.gson.JsonElement) AdminEntry(com.nedap.archie.rm.composition.AdminEntry) CanonicalXML(org.ehrbase.serialisation.xmlencoding.CanonicalXML) CompositionTestDataCanonicalXML(org.ehrbase.test_data.composition.CompositionTestDataCanonicalXML) DvDateTime(com.nedap.archie.rm.datavalues.quantity.datetime.DvDateTime) Test(org.junit.Test)

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