use of org.ehrbase.serialisation.RMDataFormat in project openEHR_SDK by ehrbase.
the class RoundTripTest method checkTestCase.
public void checkTestCase(TestCase testCase, SoftAssertions softly) throws IOException {
String value = IOUtils.toString(testCase.simSDTJson.getStream(), UTF_8);
RMDataFormat flatJson = new FlatJasonProvider(new TestDataTemplateProvider()).buildFlatJson(FlatFormat.SIM_SDT, testCase.templateId);
Composition composition = flatJson.unmarshal(value);
Flattener flattener = new Flattener(new TestDataTemplateProvider());
Object flatten = flattener.flatten(composition, testCase.dtoClass);
Unflattener unflattener = new Unflattener(new TestDataTemplateProvider());
RMObject actual = unflattener.unflatten(flatten);
String actualFlat = flatJson.marshal(actual);
List<String> errors = compere(actualFlat, value);
softly.assertThat(errors).filteredOn(s -> s.startsWith("Missing")).as("Test Case %s", testCase.id).containsExactlyInAnyOrder(testCase.missing);
softly.assertThat(errors).filteredOn(s -> s.startsWith("Extra")).as("Test Case %s", testCase.id).containsExactlyInAnyOrder(testCase.extra);
}
use of org.ehrbase.serialisation.RMDataFormat in project openEHR_SDK by ehrbase.
the class CompositionConverterImp method convertFlatToRaw.
@Override
public String convertFlatToRaw(String template, String defaultTemplateLanguage, String flatComposition, Map<String, Object> compositionBuilderContext) throws Exception {
RMDataFormat flatJson = Helper.getFlatJson(template, FlatFormat.SIM_SDT);
Map<String, Object> currentValues = new HashMap<>();
String fixed = flatComposition.replace("прием_пациента/метаданные/дата_и_время_создания_документа:2013-02-27T00:00\":\"00", "прием_пациента/метаданные/дата_и_время_создания_документа\":\"2013-02-27T00:00:00").replace("прием_пациента/административная_информация/дата_приема:2013-03-22T00:00\":\"00", "прием_пациента/административная_информация/дата_приема\":\"2013-03-22");
for (Iterator<Map.Entry<String, JsonNode>> it = OBJECT_MAPPER.readTree(fixed).fields(); it.hasNext(); ) {
Map.Entry<String, JsonNode> e = it.next();
currentValues.put(e.getKey(), e.getValue().asText());
}
compositionBuilderContext.forEach((k, v) -> currentValues.put(replace(k), v));
replaceKey(currentValues, "ficha_individual_da_aten_cao_basica/resumo_do_atendimento/problemas/problem_diagnosis:0/related_item:0/item/value", "ficha_individual_da_aten_cao_basica/resumo_do_atendimento/problemas/problem_diagnosis:0/related_item:0/item/text_value");
// topography is single valued in the template
replaceKey(currentValues, "gel_cancer_diagnosis/problem_diagnosis:3/cancer_diagnosis/topography:78", "gel_cancer_diagnosis/problem_diagnosis:3/cancer_diagnosis/topography");
replaceKey(currentValues, "gel_cancer_diagnosis/problem_diagnosis:1/cancer_diagnosis/topography:19", "gel_cancer_diagnosis/problem_diagnosis:1/cancer_diagnosis/topography");
replaceKey(currentValues, "gel_cancer_diagnosis/problem_diagnosis:5/cancer_diagnosis/topography:137", "gel_cancer_diagnosis/problem_diagnosis:5/cancer_diagnosis/topography");
currentValues.entrySet().stream().filter(e -> "video/mp4".equals(e.getValue())).forEach(e -> currentValues.replace(e.getKey(), "video/H263-2000"));
// add missing terminology for some flat examples
addTerminology(currentValues, "drug_related_problem_report/medication_error/medra_classification");
addTerminology(currentValues, "medication_error_report/medication_error/adverse_effect:1/intervention_details:1/intervention_result");
addTerminology(currentValues, "medication_error_report/medication_error/adverse_effect:1/intervention_details:2/intervention_result");
addTerminology(currentValues, "medication_error_report/medication_error/adverse_effect:1/intervention_details/intervention_result");
addTerminology(currentValues, "medication_error_report/medication_error/adverse_effect:1/reaction");
addTerminology(currentValues, "medication_error_report/medication_error/adverse_effect/intervention_details:1/intervention_result");
addTerminology(currentValues, "medication_error_report/medication_error/adverse_effect/intervention_details:2/intervention_result");
addTerminology(currentValues, "medication_error_report/medication_error/adverse_effect/intervention_details:2/intervention_result");
addTerminology(currentValues, "medication_error_report/medication_error/adverse_effect/intervention_details/intervention_result");
addTerminology(currentValues, "medication_error_report/medication_error/adverse_effect/reaction");
addTerminology(currentValues, "medication_error_report/medication_error/medra_classification");
addTerminology(currentValues, "medication_event_case_summary/case_summary/summary_details/admission_diagnosis_classification");
addTerminology(currentValues, "medication_event_case_summary/case_summary/summary_details/discharge_diagnosis_classification");
addTerminology(currentValues, "adverse_drug_reaction_report/adverse_drug_reaction/adverse_effect:1/intervention_details:1/intervention");
addTerminology(currentValues, "adverse_drug_reaction_report/adverse_drug_reaction/adverse_effect:1/intervention_details:1/intervention_result");
addTerminology(currentValues, "adverse_drug_reaction_report/adverse_drug_reaction/adverse_effect:1/intervention_details:2/intervention");
addTerminology(currentValues, "adverse_drug_reaction_report/adverse_drug_reaction/adverse_effect:1/intervention_details:2/intervention_result");
addTerminology(currentValues, "adverse_drug_reaction_report/adverse_drug_reaction/adverse_effect:1/intervention_details/intervention");
addTerminology(currentValues, "adverse_drug_reaction_report/adverse_drug_reaction/adverse_effect:1/intervention_details/intervention_result");
addTerminology(currentValues, "adverse_drug_reaction_report/adverse_drug_reaction/adverse_effect:1/reaction");
addTerminology(currentValues, "adverse_drug_reaction_report/adverse_drug_reaction/adverse_effect/intervention_details:1/intervention");
addTerminology(currentValues, "adverse_drug_reaction_report/adverse_drug_reaction/adverse_effect/intervention_details:1/intervention_result");
addTerminology(currentValues, "adverse_drug_reaction_report/adverse_drug_reaction/adverse_effect/intervention_details:2/intervention");
addTerminology(currentValues, "adverse_drug_reaction_report/adverse_drug_reaction/adverse_effect/intervention_details:2/intervention_result");
addTerminology(currentValues, "adverse_drug_reaction_report/adverse_drug_reaction/adverse_effect/intervention_details/intervention");
addTerminology(currentValues, "adverse_drug_reaction_report/adverse_drug_reaction/adverse_effect/intervention_details/intervention_result");
addTerminology(currentValues, "adverse_drug_reaction_report/adverse_drug_reaction/adverse_effect/reaction");
addTerminology(currentValues, "adverse_drug_reaction_report/adverse_drug_reaction/medra_classification");
addTerminology(currentValues, "medication_order/medication_detail/medication_action/medicine");
addTerminology(currentValues, "прием_пациента/административная_информация/медицинское_учреждение");
addTerminology(currentValues, "прием_пациента/процедуры/request:0/название_процедуры");
addTerminology(currentValues, "cda_document/xds_metadata/type");
addTerminology(currentValues, "cda_document/xds_metadata/format");
addTerminology(currentValues, "cda_document/cda_component:0/code");
addTerminology(currentValues, "cda_document/cda_component:1/code");
addTerminology(currentValues, "cda_document/xds_metadata/event:0");
addTerminology(currentValues, "cda_document/xds_metadata/class");
addTerminology(currentValues, "cda_document/cda_component:0/code");
addTerminology(currentValues, "cda_document/xds_metadata/event:1");
addTerminology(currentValues, "cda_document/xds_metadata/practice_setting");
addTerminology(currentValues, "xds_document/xds_metadata/practice_setting");
addTerminology(currentValues, "xds_document/xds_metadata/format");
addTerminology(currentValues, "xds_document/xds_metadata/event:0");
addTerminology(currentValues, "xds_document/xds_metadata/event:1");
addTerminology(currentValues, "xds_document/xds_metadata/class");
addTerminology(currentValues, "xds_document/xds_metadata/type");
// instruction_details is an optional rm attribute and thus needs to be prefixed with '_'
replaceKey(currentValues, "приостановка_курса_лекарственной_терапии/сведения_о_выполнении:0/instruction_details|composition_uid", "приостановка_курса_лекарственной_терапии/сведения_о_выполнении:0/_instruction_details|composition_uid");
replaceKey(currentValues, "приостановка_курса_лекарственной_терапии/сведения_о_выполнении:0/instruction_details|activity_id", "приостановка_курса_лекарственной_терапии/сведения_о_выполнении:0/_instruction_details|activity_id");
// add Attribute name and raise upper such that lower < upper
replaceKey(currentValues, "test/interval_quantity/fiels_for_test/upper", "test/interval_quantity/fiels_for_test/upper|magnitude");
currentValues.replace("test/interval_quantity/fiels_for_test/upper|magnitude", "90", "130");
replaceKey(currentValues, "test/interval_quantity/fiels_for_test/lower", "test/interval_quantity/fiels_for_test/lower|magnitude");
// only iso date times are supported
currentValues.replace("ctx/time", "1.2.2012 00:00", "2012-02-01T00:00");
currentValues.replace("vitals/vitals/haemoglobin_a1c/datetime_result_issued", "20.1.2012 19:30", "2012-02-20T19:30");
currentValues.replace("vitals/vitals/body_temperature/any_event/time", "1.1.2012 0:0", "2012-01-01T00:00");
currentValues.replace("ctx/time", "2012-02-01T00:00", "2012-02-01T00:00:00+01:00");
currentValues.replace("ctx/time", "1.2.2012 00:01", "2012-02-01T00:01:00+01:00");
currentValues.replace("ctx/history_origin", "1.2.2012 00:01", "2012-02-01T00:01:00+01:00");
currentValues.replace("vitals/vitals/haemoglobin_a1c/datetime_result_issued", "1/2/2012 8:07", "2012-02-01T00:00:00+01:00");
// date instead of datetime
currentValues.replace("прием_пациента_врачом-стоматологом-хирургом/административная_информация/дата_приема", "2013-04-26T00:00:00", "2013-04-26");
currentValues.replace("test/административная_информация/дата_приема", "2013-06-03T00:00:00.000+06:00", "2013-06-03");
currentValues.replace("test/административная_информация/дата_приема", "2014-01-13T09:13:00.000Z", "2014-01-13");
// fix doubles
currentValues.replace("vitals/vitals/haemoglobin_a1c/any_event/hba1c", "5,1", "5.1");
currentValues.replace("vitals/vitals/body_temperature/any_event/temperature|magnitude", "38,1", "38.1");
currentValues.replace("vitals/vitals/body_temperature:1/any_event/temperature|magnitude", "39,1", "39.1");
// add expected timezone
currentValues.replace("ctx/time", "2012-02-01T00:00", "2012-02-01T00:00:00+01:00");
// It is videoconferencing not videoconference
currentValues.replace("ctx/participation_mode", "videoconference", "videoconferencing");
// IspekBuilderTest.perinatal2 has a dangling ctx/participation_mode:0 and missing subject name
if (currentValues.keySet().stream().filter(k -> k.startsWith("ctx/participation_")).count() == 1 && currentValues.keySet().stream().filter(k -> k.startsWith("perinatal_history/perinatal_history/maternal_pregnancy/")).count() > 0) {
currentValues.remove("ctx/participation_mode:0", "face-to-face communication");
currentValues.put("perinatal_history/perinatal_history/maternal_pregnancy/subject/_name", "Lisa");
}
if (currentValues.containsKey("medical_document/document/content")) {
currentValues.put("medical_document/document/content|formalism", "text");
}
// code is not correctly set in template
if (currentValues.containsKey("visual_acuity_report/visual_acuity:0/any_event:0/test_name|code")) {
currentValues.put("visual_acuity_report/visual_acuity:0/any_event:0/test_name|value", "value");
currentValues.put("visual_acuity_report/visual_acuity:0/any_event:0/test_name|terminology", "terminology");
}
// code is not correctly set in template
if (currentValues.containsKey("visual_acuity_report/visual_acuity:0/any_event:1/test_name|code")) {
currentValues.put("visual_acuity_report/visual_acuity:0/any_event:1/test_name|value", "value");
currentValues.put("visual_acuity_report/visual_acuity:0/any_event:1/test_name|terminology", "terminology");
}
// fix missing "_"
replaceKey(currentValues, "осмотр_терапевта/сведения_о_выполнении_назначения:0/выполнение:0/instruction_details|activity_id", "осмотр_терапевта/сведения_о_выполнении_назначения:0/выполнение:0/_instruction_details|activity_id");
replaceKey(currentValues, "осмотр_терапевта/сведения_о_выполнении_назначения:0/выполнение:0/instruction_details|composition_uid", "осмотр_терапевта/сведения_о_выполнении_назначения:0/выполнение:0/_instruction_details|composition_uid");
replaceKey(currentValues, "xds_document/context/end_time", "xds_document/context/_end_time");
replaceKey(currentValues, "cda_document/cda_component:0/name", "cda_document/cda_component:0/_name");
replaceKey(currentValues, "cda_document/cda_component:1/name", "cda_document/cda_component:1/_name");
Composition composition = flatJson.unmarshal(OBJECT_MAPPER.writeValueAsString(currentValues));
String raw = new CanonicalJson().marshal(composition).replace("\"_type\"", "\"@class\"");
if (composition.getArchetypeDetails().getTemplateId().getValue().equals("ISPEK - MED - Medication Order")) {
// Changing the DVCodedText depending on the asked language is not supported right now
raw = raw.replace("Plan medication", "*Plan medication(en)");
raw = raw.replace("Issue prescription for medication", "*Issue prescription for medication(en)");
}
return raw;
}
use of org.ehrbase.serialisation.RMDataFormat in project openEHR_SDK by ehrbase.
the class StructuredJsonTest method test.
private void test(CompositionTestDataStructuredJson testData, String templateId) throws IOException {
RMDataFormat cut = new FlatJasonProvider(templateProvider).buildFlatJson(FlatFormat.STRUCTURED, templateId);
String flat = IOUtils.toString(testData.getStream(), StandardCharsets.UTF_8);
Composition unmarshal = cut.unmarshal(flat);
SoftAssertions softAssertions = new SoftAssertions();
softAssertions.assertThat(unmarshal).isNotNull();
RMObjectValidator rmObjectValidator = new RMObjectValidator(ArchieRMInfoLookup.getInstance(), s -> null);
softAssertions.assertThat(rmObjectValidator.validate(unmarshal)).filteredOn(m -> !m.getMessage().contains("Inv_null_flavour_indicated")).containsExactlyInAnyOrder();
String actual = cut.marshal(unmarshal);
String expected = IOUtils.toString(testData.getStream(), StandardCharsets.UTF_8);
JSONAssert.assertEquals(expected, actual, JSONCompareMode.NON_EXTENSIBLE);
}
use of org.ehrbase.serialisation.RMDataFormat in project openEHR_SDK by ehrbase.
the class FlatJsonTest method check.
private void check(String templateId, CompositionTestDataSimSDTJson testData, String[] expectedMissing, String[] expectedExtra) throws IOException {
RMDataFormat cut = new FlatJasonProvider(templateProvider).buildFlatJson(FlatFormat.SIM_SDT, templateId);
String flat = IOUtils.toString(testData.getStream(), StandardCharsets.UTF_8);
Composition unmarshal = cut.unmarshal(flat);
SoftAssertions softAssertions = new SoftAssertions();
softAssertions.assertThat(unmarshal).isNotNull();
RMObjectValidator rmObjectValidator = new RMObjectValidator(ArchieRMInfoLookup.getInstance(), s -> null);
softAssertions.assertThat(rmObjectValidator.validate(unmarshal)).filteredOn(m -> !m.getMessage().contains("Inv_null_flavour_indicated")).containsExactlyInAnyOrder();
String actual = cut.marshal(unmarshal);
String expected = IOUtils.toString(testData.getStream(), StandardCharsets.UTF_8);
List<String> errors = compere(actual, expected);
softAssertions.assertThat(errors).filteredOn(s -> s.startsWith("Missing")).containsExactlyInAnyOrder(expectedMissing);
softAssertions.assertThat(errors).filteredOn(s -> s.startsWith("Extra")).containsExactlyInAnyOrder(expectedExtra);
softAssertions.assertAll();
}
use of org.ehrbase.serialisation.RMDataFormat in project openEHR_SDK by ehrbase.
the class FlatJsonTest method roundTripRaw.
@Test
public void roundTripRaw() throws IOException {
CompositionTestDataSimSDTJson testData = CompositionTestDataSimSDTJson.CORONA_WITH_RAW;
String templateId = "Corona_Anamnese";
RMDataFormat cut = new FlatJasonProvider(templateProvider).buildFlatJson(FlatFormat.SIM_SDT, templateId);
String flat = IOUtils.toString(testData.getStream(), StandardCharsets.UTF_8);
Composition unmarshal = cut.unmarshal(flat);
SoftAssertions softAssertions = new SoftAssertions();
softAssertions.assertThat(unmarshal).isNotNull();
RMObjectValidator rmObjectValidator = new RMObjectValidator(ArchieRMInfoLookup.getInstance(), s -> null);
softAssertions.assertThat(rmObjectValidator.validate(unmarshal)).filteredOn(m -> !m.getMessage().contains("Inv_null_flavour_indicated")).containsExactlyInAnyOrder();
String actual = cut.marshal(unmarshal);
String expected = IOUtils.toString(CompositionTestDataSimSDTJson.CORONA.getStream(), StandardCharsets.UTF_8);
List<String> errors = compere(actual, expected);
softAssertions.assertThat(errors).filteredOn(s -> s.startsWith("Missing")).containsExactlyInAnyOrder();
softAssertions.assertThat(errors).filteredOn(s -> s.startsWith("Extra")).containsExactlyInAnyOrder();
softAssertions.assertAll();
}
Aggregations