PathValue implements I_PathValue { public Composition assign(Map<String, Object> keyValues) throws Exception { Map<String, Object> mapContent = new HashMap<>(); Boolean hasContext = false; Boolean hasComposer = false; for (String path : keyValues.keySet()) { String value; try { value = (String) keyValues.get(path); }catch (Exception e){ throw new IllegalArgumentException("Value could not be interpreted, path:"+path+ ", found:"+keyValues.get(path)); } if (path.startsWith(CONTENT_TAG)) { mapContent.put(path, value); } else if (path.startsWith(CONTEXT_TAG) && !hasContext) { hasContext = assignContextAttribute(keyValues); } else if (path.startsWith(LANGUAGE_TAG)) language = parseLanguageAttribute(value); else if (path.startsWith(UID_TAG)) uid = parseUIDAttribute(value); else if (path.startsWith(TERRITORY_TAG)) territory = parseTerritoryAttribute(value); else if (path.matches(COMPOSER_REGEXP) && !hasComposer) { value = keyValues.get(COMPOSER_TAG+IDENTIFIER_PARTY_ID_SUBTAG) + "::" + keyValues.get(COMPOSER_TAG+IDENTIFIER_PARTY_NAME_SUBTAG); composer = parseComposerAttribute(value); hasComposer = true; } else log.debug("Passthrough unhandled directive:"+path); } EventContext eventContext = null; if (hasContext) { TerminologyService terminologyService = TerminologyServiceWrapper.getInstance(); eventContext = new EventContext(healthCareFacility, (startTime != null) ? startTime : new DvDateTime(new DateTime(0L).toString()), (endTime != null) ? endTime : new DvDateTime(DateTime.now().toString()), participationList.isEmpty() ? null : participationList, location, setting == null ? new DvCodedText("null", "openehr", "238") : setting, otherContext, terminologyService); } Map<SystemValue, Object> map = new HashMap<>(); if (hasContext) map.put(SystemValue.CONTEXT, eventContext); if (language != null) map.put(SystemValue.LANGUAGE, language); if (territory != null) map.put(SystemValue.TERRITORY, territory); if (hasComposer) map.put(SystemValue.COMPOSER, composer); if (category != null) map.put(SystemValue.CATEGORY, category); if (uid != null) map.put(SystemValue.UID, uid); contentBuilder = I_ContentBuilder.getInstance(map, knowledge, templateId); Composition composition = contentBuilder.generateNewComposition(); ConstraintUtils constraintUtils = new ConstraintUtils(contentBuilder.isLenient(), composition, contentBuilder.getConstraintMapper()); constraintUtils.validateLocatable(); assignItemStructure(CONTENT_TAG, composition, mapContent); if (composition.getContext().getOtherContext() != null) assignItemStructure(OTHER_CONTEXT_TAG, composition.getContext().getOtherContext(), otherContextMap); new ConstraintUtils(contentBuilder.isLenient(), composition, contentBuilder.getConstraintMapper()).validateLocatable(); return composition; } PathValue(I_KnowledgeCache cache, String templateId, Properties properties);  PathValue(I_ContentBuilder contentBuilder, I_KnowledgeCache cache, String templateId, Properties properties);  PathValue(Properties properties); Composition assign(Map<String, Object> keyValues); Boolean update(Composition composition, Map<String, Object> keyValues); Boolean updateEventContext(EventContext eventContext, Map<String, Object> keyValues); boolean assignItemStructure(String filterTag, Locatable locatable, Map<String, Object> pathValues); static Object decodeValue(String dvClassName, Map<String, String> dvMap, Map<String, Object> args); @Override boolean isModifiedContext(); @Override boolean isModifiedAttributes(); @Override boolean isModifiedContent(); @Override void setLenient(Boolean lenient);  }
@Test public void testSerializeArray() throws Exception { String templateId = "IDCR - Adverse Reaction List.v1"; I_ContentBuilder content = I_ContentBuilder.getInstance(null, I_ContentBuilder.OPT, knowledge, templateId); content.generateNewComposition(); PathValue pathValue = new PathValue(knowledge, templateId, new Properties()); for (String testfile: new String[]{"ecisflat", "ecisflat2"}) { FileReader fileReader = new FileReader(resourcePath+"/samples/adverse_reaction_list."+testfile+".json"); Map<String, Object> valuePairs = FlatJsonUtil.inputStream2Map(fileReader); Composition composition = pathValue.assign(valuePairs); assertNotNull(composition); I_CompositionSerializer compositionSerializer = I_CompositionSerializer.getInstance(); String dbEncoded = compositionSerializer.dbEncode(composition); System.out.print(dbEncoded); I_ContentBuilder contentBuilder = I_ContentBuilder.getInstance(knowledge, templateId); Composition retrieved = contentBuilder.buildCompositionFromJson(dbEncoded); assertNotNull(retrieved); Map<String, String> testRetMap = new EcisFlattener().render(retrieved); GsonBuilder builder = new GsonBuilder(); Gson gson = builder.setPrettyPrinting().disableHtmlEscaping().create(); String jsonString = gson.toJson(testRetMap); System.out.println(jsonString); } }
@Test public void testSerialize() throws Exception { String templateId = "RIPPLE - Minimal referral.v0"; PathValue pathValue = new PathValue(knowledge, templateId, new Properties()); FileReader fileReader = new FileReader("src/test/resources/ecisflat/RIPPLE_minimal_referral.v0.kv.json"); Map<String, Object> valuePairs = FlatJsonUtil.inputStream2Map(fileReader); Composition composition = pathValue.assign(valuePairs); assertNotNull(composition); ContentHelper compositionHelper = new ContentHelper(); I_CompositionSerializer compositionSerializer = I_CompositionSerializer.getInstance(CompositionSerializer.WalkerOutputMode.PATH); String dbEncoded = compositionSerializer.dbEncode(composition); System.out.print(dbEncoded); Gson gson = EncodeUtil.getGsonBuilderInstance().setPrettyPrinting().create(); Map rawEncoded = gson.fromJson(compositionSerializer.dbEncode(composition), Map.class); assertNotNull(rawEncoded); I_ContentBuilder contentBuilder = I_ContentBuilder.getInstance(knowledge, templateId); Composition retrieved = contentBuilder.buildCompositionFromJson(dbEncoded); assertNotNull(retrieved); Map<String, String> testRetMap = new EcisFlattener().render(retrieved); GsonBuilder builder = new GsonBuilder(); gson = builder.setPrettyPrinting().disableHtmlEscaping().create(); String jsonString = gson.toJson(testRetMap); System.out.println(jsonString); I_FlatJsonCompositionConverter jsonCompositionConverter = FlatJsonCompositionConverter.getInstance(knowledge); Map<String, Object> flatMap = jsonCompositionConverter.fromComposition(templateId, retrieved); flatMap.put("ctx/language", "en"); flatMap.put("ctx/territory", "GB"); String outMap = JsonUtil.toJsonString(flatMap); System.out.println(outMap); }
@Test public void testAssignment_OPT_RALPH_20() throws Exception { PathValue pathValue = new PathValue(knowledge, "careplan.v1", new Properties()); kvPairs.clear(); kvPairs.put("/category", "openehr::433|event|"); kvPairs.put("/territory", "GB"); kvPairs.put("/language", "en"); kvPairs.put( "/content[openEHR-EHR-EVALUATION.careplan.v1]/data[at0001]/items[at0002]", "My Care Plan" ); kvPairs.put( "/content[openEHR-EHR-EVALUATION.careplan.v1]/guideline", "local::test" ); kvPairs.put( "/content[openEHR-EHR-EVALUATION.careplan.v1]/data[at0001]/items[at0011]", "A test care plan" ); kvPairs.put( "/content[openEHR-EHR-EVALUATION.careplan.v1]/data[at0001]/items[at0021]", "local::at0024|Active|" ); kvPairs.put( "/content[openEHR-EHR-INSTRUCTION.procedure.v1]/activities[at0001]/description[at0002]/items[at0003]", "foo" ); kvPairs.put( "/content[openEHR-EHR-INSTRUCTION.procedure.v1]/activities[at0001]/description[at0002]/items[at0012]", "Test name" ); Composition composition = pathValue.assign(kvPairs); Map<String, String> testRetMap = new EcisFlattener().render(composition); GsonBuilder builder = new GsonBuilder(); Gson gson = builder.setPrettyPrinting().disableHtmlEscaping().create(); String jsonString = gson.toJson(testRetMap); System.out.println(jsonString); }
@Test public void testAssignment_OPT_RALPH_BMI() throws Exception { PathValue pathValue = new PathValue(knowledge, "BMI", new Properties()); kvPairs.clear(); kvPairs.put("/category", "openehr::433|event|"); kvPairs.put("/territory", "GB"); kvPairs.put("/language", "en"); kvPairs.put( "/content[openEHR-EHR-OBSERVATION.body_mass_index.v1]/data[at0001]/events[at0002]/data[at0003]/items[at0004]|value", "18.5,kg/m2"); kvPairs.put( "/content[openEHR-EHR-OBSERVATION.body_weight.v1]/data[at0002]/events[at0003]/data[at0001]/items[at0004]|value", "65.2,kg"); kvPairs.put( "/content[openEHR-EHR-OBSERVATION.height.v1]/data[at0001]/events[at0002]/data[at0003]/items[at0004]|value", "167,cm"); Composition composition = pathValue.assign(kvPairs); Map<String, String> testRetMap = new EcisFlattener().render(composition); GsonBuilder builder = new GsonBuilder(); Gson gson = builder.setPrettyPrinting().disableHtmlEscaping().create(); String jsonString = gson.toJson(testRetMap); System.out.println(jsonString); }
@Test public void testAssignment_OPT() throws Exception { PathValue pathValue = new PathValue(knowledge, "UK AoMRC Outpatient Letter", new Properties()); kvPairs.clear(); kvPairs.put("/context/other_context[at0001]/items[at0005]", "complete"); kvPairs.put("/context/other_context[at0001]/items[openEHR-EHR-CLUSTER.distribution.v1]/items[at0006]", "2015-10-21T10:00:00"); kvPairs.put("/context/other_context[at0001]/items[openEHR-EHR-CLUSTER.individual_personal_uk.v1]/items[openEHR-EHR-CLUSTER.person_name.v1]/items[at0022]", "true"); kvPairs.put("/context/other_context[at0001]/items[openEHR-EHR-CLUSTER.individual_personal_uk.v1]/items[openEHR-EHR-CLUSTER.person_name.v1]/items[at0014]", "2014-10-15::2022-12-31"); kvPairs.put("/content[openEHR-EHR-SECTION.demographics_rcp.v1]/items[openEHR-EHR-ADMIN_ENTRY.key_contacts.v1]/data[at0001]/items[at0018]/items[openEHR-EHR-CLUSTER.individual_personal_uk.v1]/items[openEHR-EHR-CLUSTER.person_name.v1]/items[at0001]", "Joe Doe"); kvPairs.put("/content[openEHR-EHR-SECTION.history_rcp.v1]/items[openEHR-EHR-OBSERVATION.story.v1 and name/value='Story/History']/data[at0001]/events[at0002]/data[at0003]/items[at0004]", "big complain"); kvPairs.put("/content[openEHR-EHR-SECTION.history_rcp.v1]/items[openEHR-EHR-OBSERVATION.story.v1 and name/value='History since last contact']/data[at0001]/events[at0002]/data[at0003]/items[at0004]", "a long history"); kvPairs.put("/content[openEHR-EHR-SECTION.history_rcp.v1]/items[openEHR-EHR-EVALUATION.reason_for_encounter.v1]/data[at0001]/items[at0002]", "does not sleep"); kvPairs.put("/content[openEHR-EHR-SECTION.history_rcp.v1]/items[openEHR-EHR-EVALUATION.reason_for_encounter.v1]/data[at0001]/items[at0004]", "think too much"); kvPairs.put("/content[openEHR-EHR-SECTION.history_rcp.v1]/items[openEHR-EHR-EVALUATION.reason_for_encounter.v1]/data[at0001]/items[at0005]", "think way too much"); kvPairs.put("/content[openEHR-EHR-SECTION.history_rcp.v1]/items[openEHR-EHR-SECTION.adhoc.v1]/items[openEHR-EHR-SECTION.adhoc.v1 and name/value='Past medical history']/items[openEHR-EHR-EVALUATION.problem_diagnosis.v1]/protocol[at0032]/items[at0035]", "http: kvPairs.put("/content[openEHR-EHR-SECTION.history_rcp.v1]/items[openEHR-EHR-SECTION.adhoc.v1]/items[openEHR-EHR-SECTION.adhoc.v1 and name/value='Past medical history']/items[openEHR-EHR-EVALUATION.problem_diagnosis.v1]/protocol[at0032]/items[openEHR-EHR-CLUSTER.problem_status.v1]/items[at0060]", "local::1|Past|"); kvPairs.put("/content[openEHR-EHR-SECTION.history_rcp.v1]/items[openEHR-EHR-SECTION.adhoc.v1]/items[openEHR-EHR-SECTION.adhoc.v1]/items[openEHR-EHR-EVALUATION.problem_diagnosis.v1]/data[at0001]/items[at0002]", "test"); kvPairs.put("/content[openEHR-EHR-SECTION.medication_medical_devices_rcp.v1]/items[openEHR-EHR-SECTION.current_medication_rcp.v1]/items[openEHR-EHR-INSTRUCTION.medication_order_uk.v1]/activities[at0001]/description[at0002]/items[openEHR-EHR-CLUSTER.medication_item.v1]/items[at0001]", "@1|Choice #1"); kvPairs.put("/content[openEHR-EHR-SECTION.medication_medical_devices_rcp.v1]/items[openEHR-EHR-SECTION.current_medication_rcp.v1]/items[openEHR-EHR-INSTRUCTION.medication_order_uk.v1]/activities[at0001]/description[at0002]/items[at0039]/items[at0041]", "@2|local::111|Continue Indefinitely|"); kvPairs.put("/content[openEHR-EHR-SECTION.examination_findings_rcp.v1]/items[openEHR-EHR-SECTION.vital_signs.v1]/items[openEHR-EHR-OBSERVATION.news_rcp_uk.v1]/data[at0001]/events[at0002]/data[at0003]/items[at0006]", "1|SNOMED-CT::313267000|Stroke|"); kvPairs.put("/context/other_context[at0001]/items[openEHR-EHR-CLUSTER.individual_personal_uk.v1]/items[openEHR-EHR-CLUSTER.person_name.v1]/items[at0014]", "2010-10-10T10:00:00Z::2011-11-11T11:00:00Z"); kvPairs.put("/content[openEHR-EHR-SECTION.investigations_results_rcp.v1]/items[openEHR-EHR-OBSERVATION.lab_test.v1]/data[at0001]/events[at0002]/data[at0003]/items[at0078]", "@DVQUANTITY|12345,kg"); kvPairs.put("/content[openEHR-EHR-SECTION.medication_medical_devices_rcp.v1]/items[openEHR-EHR-SECTION.current_medication_rcp.v1]/items[openEHR-EHR-EVALUATION.exclusion-medication.v1]/data[at0001]/items[at0003.1]", "@1|local::111|Continue Indefinitely|"); Composition composition = pathValue.assign(kvPairs); Map<String, String> testRetMap = new EcisFlattener().render(composition); GsonBuilder builder = new GsonBuilder(); Gson gson = builder.setPrettyPrinting().disableHtmlEscaping().create(); String jsonString = gson.toJson(testRetMap); System.out.println(jsonString); }