use of com.nedap.archie.rm.composition.Composition in project openEHR_SDK by ehrbase.
the class CompositionConverterImp method convertStructuredToRaw.
@Override
public String convertStructuredToRaw(String template, String defaultLanguage, String structuredComposition, Map<String, Object> compositionBuilderContext) throws Exception {
String fixed = structuredComposition.replace("\"end_time\"", "\"_end_time\"").replace("\"дата_открытия_талона\":[\"20.03.2020\"]", "\"дата_открытия_талона\":[\"2020-03-20\"]").replace("\"дата_закрытия_талона\":[\"20.03.2020\"]", "\"дата_закрытия_талона\":[\"2020-03-20\"]").replace("\"дата_посещения\":[\"20.03.2020\"]", "\"дата_посещения\":[\"2020-03-20T00:00\"]");
Composition composition = Helper.getFlatJson(template, FlatFormat.STRUCTURED).unmarshal(fixed);
return new CanonicalJson().marshal(composition).replace("\"_type\"", "\"@class\"");
}
use of com.nedap.archie.rm.composition.Composition 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 com.nedap.archie.rm.composition.Composition 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 com.nedap.archie.rm.composition.Composition in project openEHR_SDK by ehrbase.
the class FlatJsonMarshallerTest method toFlatJsonMultiOccurrence.
@Test
public void toFlatJsonMultiOccurrence() throws IOException, XmlException {
OPERATIONALTEMPLATE template = TemplateDocument.Factory.parse(OperationalTemplateTestData.MULTI_OCCURRENCE.getStream()).getTemplate();
Composition composition = new CanonicalJson().unmarshal(IOUtils.toString(CompositionTestDataCanonicalJson.MULTI_OCCURRENCE.getStream(), StandardCharsets.UTF_8), Composition.class);
FlatJsonMarshaller cut = new FlatJsonMarshaller();
String actual = cut.toFlatJson(composition, new OPTParser(template).parse());
assertThat(actual).isNotNull();
String expected = IOUtils.toString(CompositionTestDataSimSDTJson.MULTI_OCCURRENCE.getStream(), StandardCharsets.UTF_8);
List<String> errors = compere(actual, expected);
checkErrors(errors, new String[] { "Missing path: encounter/body_temperature:1/any_event:0/temperature|magnitude, value: 22.0", "Missing path: encounter/body_temperature:1/any_event:1/temperature|magnitude, value: 11.0", "Missing path: encounter/body_temperature:0/any_event:0/temperature|magnitude, value: 22.0", "Missing path: encounter/body_temperature:0/any_event:1/temperature|magnitude, value: 11.0" }, new String[] { "Extra path: encounter/body_temperature:0/any_event:0/temperature|magnitude, value: 22", "Extra path: encounter/body_temperature:0/any_event:1/temperature|magnitude, value: 11", "Extra path: encounter/body_temperature:1/any_event:0/temperature|magnitude, value: 22", "Extra path: encounter/body_temperature:1/any_event:1/temperature|magnitude, value: 11" });
}
use of com.nedap.archie.rm.composition.Composition in project openEHR_SDK by ehrbase.
the class FlatJsonMarshallerTest method toFlatJsonIps.
@Test
public void toFlatJsonIps() throws Exception {
OPERATIONALTEMPLATE template = TemplateDocument.Factory.parse(OperationalTemplateTestData.IPS.getStream()).getTemplate();
Composition composition = new CanonicalJson().unmarshal(IOUtils.toString(CompositionTestDataCanonicalJson.IPS.getStream(), StandardCharsets.UTF_8), Composition.class);
FlatJsonMarshaller marshaller = new FlatJsonMarshaller();
String actual = marshaller.toFlatJson(composition, new OPTParser(template).parse());
assertThat(actual).isNotNull();
String expected = IOUtils.toString(CompositionTestDataSimSDTJson.IPS.getStream(), StandardCharsets.UTF_8);
List<String> errors = compere(actual, expected);
checkErrors(errors, new String[] { "Missing path: international_patient_summary/medication_summary/medication_statement/order_id:0|id, value: 9a0e5173-07c8-443d-b414-24432b9d95ca", "Missing path: international_patient_summary/medical_devices/device_use_statement/device_details:0/medical_device/unique_device_identifier_udi|id, value: 73b166ae-1c28-4ce0-8c08-a9587d8fd95a", "Missing path: international_patient_summary/medical_devices/device_use_statement/device_details:0/medical_device/other_identifier:0|id, value: 60287ff3-ec0f-4cd5-9000-2c05af2e6a84", "Missing path: international_patient_summary/diagnostic_results/imaging_examination_result/examination_request_details:0/requester_order_identifier|id, value: 38a6687c-5136-4e75-9f1c-126e8f0e112b", "Missing path: international_patient_summary/diagnostic_results/imaging_examination_result/examination_request_details:0/receiver_order_identifier|id, value: 9fc6db02-81de-4ec9-afe4-f365c42019e1", "Missing path: international_patient_summary/diagnostic_results/imaging_examination_result/examination_request_details:0/report_identifier|id, value: a147525c-4763-4070-ba22-26e6b33348f4", "Missing path: international_patient_summary/diagnostic_results/imaging_examination_result/examination_request_details:0/reported_image:0/image_identifier|id, value: 5462ef5c-2275-47c2-8fb5-f9f1d7a19613", "Missing path: international_patient_summary/diagnostic_results/imaging_examination_result/examination_request_details:0/reported_image:0/dicom_series_identifier|id, value: 55dd86d7-52ff-4064-8dc7-f8d9b2bc22e7", "Missing path: international_patient_summary/diagnostic_results/imaging_examination_result/examination_request_details:0/comparison_image:0/image_identifier|id, value: a6c20273-7b53-4c04-9b2c-2d4c218893b2", "Missing path: international_patient_summary/diagnostic_results/imaging_examination_result/examination_request_details:0/comparison_image:0/dicom_series_identifier|id, value: 1ba8eff7-8f3f-4625-9432-05aa01726073", "Missing path: international_patient_summary/vital_signs/pulse_oximetry/any_event:0/spo, value: 0.8920999999999999", "Missing path: international_patient_summary/plan_of_care/care_plan/care_plan_id|id, value: 0942fb74-27f8-48c6-869e-10192740c371", "Missing path: international_patient_summary/plan_of_care/service_request/current_activity:0/action_archetype_id, value: /.*/", "Missing path: international_patient_summary/medication_summary/medication_statement/dosage/timing_-_daily/frequency/quantity_value|precision, value: 0", "Missing path: international_patient_summary/medication_summary/medication_statement/timing_-_non-daily/frequency/quantity_value|precision, value: 0", "Missing path: international_patient_summary/vital_signs/respiration/any_event:0/rate|precision, value: 0", "Missing path: international_patient_summary/vital_signs/pulse_heart_beat/any_event:0/rate|precision, value: 0", "Missing path: international_patient_summary/vital_signs/body_temperature/any_event:0/temperature|precision, value: 1", "Missing path: international_patient_summary/vital_signs/body_mass_index/any_event:0/body_mass_index|precision, value: 1", "Missing path: international_patient_summary/vital_signs/blood_pressure/any_event:0/systolic|precision, value: 0", "Missing path: international_patient_summary/vital_signs/blood_pressure/any_event:0/diastolic|precision, value: 0", "Missing path: international_patient_summary/social_history/alcohol_consumption_summary/per_episode:0/typical_consumption_alcohol_units|precision, value: 1" }, new String[] { "Extra path: international_patient_summary/medication_summary/medication_statement/order_id:0, value: 9a0e5173-07c8-443d-b414-24432b9d95ca", "Extra path: international_patient_summary/medical_devices/device_use_statement/device_details:0/medical_device/unique_device_identifier_udi, value: 73b166ae-1c28-4ce0-8c08-a9587d8fd95a", "Extra path: international_patient_summary/medical_devices/device_use_statement/device_details:0/medical_device/other_identifier:0, value: 60287ff3-ec0f-4cd5-9000-2c05af2e6a84", "Extra path: international_patient_summary/diagnostic_results/imaging_examination_result/examination_request_details:0/requester_order_identifier, value: 38a6687c-5136-4e75-9f1c-126e8f0e112b", "Extra path: international_patient_summary/diagnostic_results/imaging_examination_result/examination_request_details:0/receiver_order_identifier, value: 9fc6db02-81de-4ec9-afe4-f365c42019e1", "Extra path: international_patient_summary/diagnostic_results/imaging_examination_result/examination_request_details:0/report_identifier, value: a147525c-4763-4070-ba22-26e6b33348f4", "Extra path: international_patient_summary/diagnostic_results/imaging_examination_result/examination_request_details:0/reported_image:0/image_identifier, value: 5462ef5c-2275-47c2-8fb5-f9f1d7a19613", "Extra path: international_patient_summary/diagnostic_results/imaging_examination_result/examination_request_details:0/reported_image:0/dicom_series_identifier, value: 55dd86d7-52ff-4064-8dc7-f8d9b2bc22e7", "Extra path: international_patient_summary/diagnostic_results/imaging_examination_result/examination_request_details:0/comparison_image:0/image_identifier, value: a6c20273-7b53-4c04-9b2c-2d4c218893b2", "Extra path: international_patient_summary/diagnostic_results/imaging_examination_result/examination_request_details:0/comparison_image:0/dicom_series_identifier, value: 1ba8eff7-8f3f-4625-9432-05aa01726073", "Extra path: international_patient_summary/vital_signs/pulse_oximetry/any_event:0/spo, value: 0.8921", "Extra path: international_patient_summary/plan_of_care/care_plan/care_plan_id, value: 0942fb74-27f8-48c6-869e-10192740c371" });
}
Aggregations