@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); }
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 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 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); }
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); }
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);  }