use of org.ehrbase.serialisation.dbencoding.rmobject.FeederAuditEncoding in project ehrbase by ehrbase.
the class EntryAccess method retrieveInstanceInCompositionVersion.
public static List<I_EntryAccess> retrieveInstanceInCompositionVersion(I_DomainAccess domainAccess, I_CompositionAccess compositionHistoryAccess, int version) {
Result<EntryHistoryRecord> entryHistoryRecords = domainAccess.getContext().selectFrom(ENTRY_HISTORY).where(ENTRY_HISTORY.COMPOSITION_ID.eq(compositionHistoryAccess.getId())).and(ENTRY_HISTORY.SYS_TRANSACTION.eq(compositionHistoryAccess.getSysTransaction())).fetch();
// build the list of parameters to recreate the composition
Map<SystemValue, Object> values = new HashMap<>();
values.put(SystemValue.COMPOSER, new PersistedPartyProxy(domainAccess).retrieve(compositionHistoryAccess.getComposerId()));
EventContext context = I_ContextAccess.retrieveHistoricalEventContext(domainAccess, compositionHistoryAccess.getId(), compositionHistoryAccess.getSysTransaction());
if (context == null) {
// unchanged context use the current one!
// also optional handling of context, because persistent compositions don't have a context
compositionHistoryAccess.getContextId().ifPresent(uuid -> I_ContextAccess.retrieveInstance(domainAccess, uuid).mapRmEventContext());
}
values.put(SystemValue.CONTEXT, context);
values.put(SystemValue.LANGUAGE, new CodePhrase(new TerminologyId("ISO_639-1"), compositionHistoryAccess.getLanguageCode()));
String territory2letters = domainAccess.getContext().fetchOne(TERRITORY, TERRITORY.CODE.eq(compositionHistoryAccess.getTerritoryCode())).getTwoletter();
values.put(SystemValue.TERRITORY, new CodePhrase(new TerminologyId("ISO_3166-1"), territory2letters));
values.put(SystemValue.FEEDER_AUDIT, new FeederAuditEncoding().fromDB(compositionHistoryAccess.getFeederAudit()));
List<I_EntryAccess> content = new ArrayList<>();
try {
EntryAccess entryAccess = new EntryAccess(domainAccess);
for (EntryHistoryRecord record : entryHistoryRecords) {
// set the record UID in the composition
UUID compositionId = compositionHistoryAccess.getId();
values.put(SystemValue.UID, new ObjectVersionId(compositionId.toString() + "::" + domainAccess.getServerConfig().getNodename() + "::" + version));
entryAccess.entryRecord = domainAccess.getContext().newRecord(ENTRY);
entryAccess.entryRecord.from(record);
entryAccess.composition = new RawJson().unmarshal(record.getEntry().data(), Composition.class);
setCompositionAttributes(entryAccess.composition, values);
buildArchetypeDetails(entryAccess);
content.add(entryAccess);
}
} catch (Exception e) {
throw new IllegalArgumentException(DB_INCONSISTENCY + e);
}
return content;
}
use of org.ehrbase.serialisation.dbencoding.rmobject.FeederAuditEncoding in project openEHR_SDK by ehrbase.
the class DBEncodeTest method testEncodeDecodeFeederAudit.
@Test
public void testEncodeDecodeFeederAudit() {
String jsonFeederAudit = "{\n" + " \"originating_system_item_ids\": [\n" + " {\n" + " \"issuer\": \"EMIS\",\n" + " \"assigner\": \"EMIS\",\n" + " \"id\": \"123456\",\n" + " \"type\": \"FHIR\"\n" + " }\n" + " ],\n" + " \"feeder_system_item_ids\": [],\n" + " \"originating_system_audit\": {\n" + " \"system_id\": \"EMIS\",\n" + " \"time\": {\n" + " \"value\": \"2016-12-20T00:11:02.518+02:00\",\n" + " \"epoch_offset\": 1.482185462E9\n" + " }\n" + " }\n" + " }";
CanonicalJson cut = new CanonicalJson();
FeederAudit feederAudit = cut.unmarshal(jsonFeederAudit, FeederAudit.class);
String encodedToDB = new FeederAuditEncoding().toDB(feederAudit);
FeederAudit decodedFromDB = new FeederAuditEncoding().fromDB(encodedToDB);
assertEquals(feederAudit.getOriginatingSystemAudit().getSystemId(), decodedFromDB.getOriginatingSystemAudit().getSystemId());
}
use of org.ehrbase.serialisation.dbencoding.rmobject.FeederAuditEncoding in project openEHR_SDK by ehrbase.
the class DBEncodeTest method testEncodeDecodeFeederAuditWithOriginalContent.
@Test
public void testEncodeDecodeFeederAuditWithOriginalContent() {
String jsonFeederAudit = " {\n" + " \"_type\" : \"FEEDER_AUDIT\",\n" + " \"original_content\" : {\n" + " \"_type\" : \"DV_PARSABLE\",\n" + " \"value\" : \"{\\\"resourceType\\\":\\\"Observation\\\",\\\"meta\\\":{\\\"profile\\\":[\\\"https://www.medizininformatik-initiative.de/fhir/core/StructureDefinition/ObservationLab\\\"]},\\\"identifier\\\":[{\\\"type\\\":{\\\"coding\\\":[{\\\"system\\\":\\\"http://terminology.hl7.org/CodeSystem/v2-0203\\\",\\\"code\\\":\\\"OBI\\\"}]},\\\"system\\\":\\\"https://diz.mii.de/fhir/core/NamingSystem/test-lab-results\\\",\\\"value\\\":\\\"59826-8_1234567890\\\",\\\"assigner\\\":{\\\"identifier\\\":{\\\"system\\\":\\\"https://www.medizininformatik-initiative.de/fhir/core/NamingSystem/org-identifier\\\",\\\"value\\\":\\\"DIZ-ID\\\"}}}],\\\"status\\\":\\\"final\\\",\\\"category\\\":[{\\\"coding\\\":[{\\\"system\\\":\\\"http://loinc.org\\\",\\\"code\\\":\\\"26436-6\\\"},{\\\"system\\\":\\\"http://terminology.hl7.org/CodeSystem/observation-category\\\",\\\"code\\\":\\\"laboratory\\\"}]}],\\\"code\\\":{\\\"coding\\\":[{\\\"system\\\":\\\"http://loinc.org\\\",\\\"code\\\":\\\"59826-8\\\",\\\"display\\\":\\\"Creatinine [Moles/volume] in Blood\\\"}],\\\"text\\\":\\\"Kreatinin\\\"},\\\"subject\\\":{\\\"reference\\\":\\\"Patient/679e3fc3-cc9a-4e04-bc81-cb4d4a7e8e1c\\\"},\\\"encounter\\\":{\\\"reference\\\":\\\"Encounter/555\\\"},\\\"effectiveDateTime\\\":\\\"2018-11-20T12:05:00+01:00\\\",\\\"issued\\\":\\\"2018-03-11T10:28:00+01:00\\\",\\\"performer\\\":[{\\\"reference\\\":\\\"Organization/7772\\\",\\\"display\\\":\\\"Zentrallabor des IKCL\\\"}],\\\"valueQuantity\\\":{\\\"value\\\":72,\\\"unit\\\":\\\"..mol/l\\\",\\\"system\\\":\\\"http://unitsofmeasure.org\\\",\\\"code\\\":\\\"umol/L\\\"},\\\"interpretation\\\":[{\\\"coding\\\":[{\\\"system\\\":\\\"http://terminology.hl7.org/CodeSystem/v3-ObservationInterpretation\\\",\\\"code\\\":\\\"N\\\"}]}],\\\"referenceRange\\\":[{\\\"low\\\":{\\\"value\\\":72},\\\"high\\\":{\\\"value\\\":127},\\\"type\\\":{\\\"coding\\\":[{\\\"system\\\":\\\"http://terminology.hl7.org/CodeSystem/referencerange-meaning\\\",\\\"code\\\":\\\"normal\\\",\\\"display\\\":\\\"Normal Range\\\"}]}}]}\",\n" + " \"formalism\" : \"application/json\"\n" + " },\n" + " \"originating_system_audit\" : {\n" + " \"_type\" : \"FEEDER_AUDIT_DETAILS\",\n" + " \"system_id\" : \"FHIR-bridge\"\n" + " }\n" + " }";
CanonicalJson cut = new CanonicalJson();
FeederAudit feederAudit = cut.unmarshal(jsonFeederAudit, FeederAudit.class);
String encodedToDB = new FeederAuditEncoding().toDB(feederAudit);
FeederAudit decodedFromDB = new FeederAuditEncoding().fromDB(encodedToDB);
assertEquals(feederAudit.getOriginatingSystemAudit().getSystemId(), decodedFromDB.getOriginatingSystemAudit().getSystemId());
}
use of org.ehrbase.serialisation.dbencoding.rmobject.FeederAuditEncoding 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;
}
Aggregations