@Test public void testFlatJson() throws Exception { String templateId = "COLNEC Medication"; I_FlatJsonCompositionConverter jsonCompositionConverter = FlatJsonCompositionConverter.getInstance(knowledge); FileReader fileReader = new FileReader(resourcePath+"/flat_json_input/COLNEC_Medication_FLAT.json"); Map map = FlatJsonUtil.inputStream2Map(fileReader); Composition lastComposition = jsonCompositionConverter.toComposition(templateId, map); TestCase.assertNotNull(lastComposition); I_CompositionSerializer inspector = I_CompositionSerializer.getInstance(CompositionSerializer.WalkerOutputMode.PATH); Map<String, Object>retmap = inspector.process(lastComposition); String stringified = jsonMapToString(retmap); TestCase.assertNotNull(stringified); I_ContentBuilder content = I_ContentBuilder.getInstance(null, I_ContentBuilder.OPT, knowledge, templateId); Composition newComposition = content.buildCompositionFromJson(stringified); TestCase.assertNotNull(newComposition); GsonBuilder builder = new GsonBuilder(); Gson gson = builder.setPrettyPrinting().disableHtmlEscaping().create(); String jsonString; map = jsonCompositionConverter.fromComposition(templateId, newComposition); jsonString = gson.toJson(map); TestCase.assertNotNull(map); System.out.println(jsonString); Map<String, String> testRetMap = new EcisFlattener().render(newComposition); jsonString = gson.toJson(testRetMap); System.out.println(jsonString); }
@Override public Composition buildCompositionFromJson(String jsonData) throws Exception { long start = System.nanoTime(); Composition newComposition = this.generateNewComposition(); long end = System.nanoTime(); log.debug("generate composition [ms]:"+(end - start)/1000000); if (jsonData == null || jsonData.equals("null")) return newComposition; MapInspector inspector = getMapInspector(jsonData); start = System.nanoTime(); assignValuesFromStack(newComposition, (ArrayDeque) inspector.getStack()); end = System.nanoTime(); log.debug("set values [ms]:"+(end - start)/1000000); this.composition = newComposition; return newComposition; }
ContentBuilder implements I_ContentBuilder { @Override public Composition buildCompositionFromJson(String jsonData) throws Exception { long start = System.nanoTime(); Composition newComposition = this.generateNewComposition(); long end = System.nanoTime(); log.debug("generate composition [ms]:"+(end - start)/1000000); if (jsonData == null || jsonData.equals("null")) return newComposition; MapInspector inspector = getMapInspector(jsonData); start = System.nanoTime(); assignValuesFromStack(newComposition, (ArrayDeque) inspector.getStack()); end = System.nanoTime(); log.debug("set values [ms]:"+(end - start)/1000000); this.composition = newComposition; return newComposition; } }
ContentBuilder implements I_ContentBuilder { @Override public Composition buildCompositionFromJson(String jsonData) throws Exception { long start = System.nanoTime(); Composition newComposition = this.generateNewComposition(); long end = System.nanoTime(); log.debug("generate composition [ms]:"+(end - start)/1000000); if (jsonData == null || jsonData.equals("null")) return newComposition; MapInspector inspector = getMapInspector(jsonData); start = System.nanoTime(); assignValuesFromStack(newComposition, (ArrayDeque) inspector.getStack()); end = System.nanoTime(); log.debug("set values [ms]:"+(end - start)/1000000); this.composition = newComposition; return newComposition; } ContentBuilder(Map<SystemValue, Object> values, I_KnowledgeCache knowledge, String templateId); }
ContentBuilder implements I_ContentBuilder { @Override public Composition buildCompositionFromJson(String jsonData) throws Exception { long start = System.nanoTime(); Composition newComposition = this.generateNewComposition(); long end = System.nanoTime(); log.debug("generate composition [ms]:"+(end - start)/1000000); if (jsonData == null || jsonData.equals("null")) return newComposition; MapInspector inspector = getMapInspector(jsonData); start = System.nanoTime(); assignValuesFromStack(newComposition, (ArrayDeque) inspector.getStack()); end = System.nanoTime(); log.debug("set values [ms]:"+(end - start)/1000000); this.composition = newComposition; return newComposition; } ContentBuilder(Map<SystemValue, Object> values, I_KnowledgeCache knowledge, String templateId); @Override void setEntryData(Composition composition); @Override Object insertCloneInPath(Locatable locatable, Map<String, Object> definition, String path); @Override Composition importCanonicalXML(InputStream inputStream); @Override Composition importAsRM(Composition composition); @Override byte[] exportCanonicalXML(String jsonData, boolean prettyPrint); @Override byte[] exportCanonicalXML(Composition composition, boolean prettyPrint); @Override byte[] exportCanonicalXML(Composition composition, boolean prettyPrint, boolean anyElement); @Override byte[] exportCanonicalXML(Locatable locatable, boolean prettyPrint); @Override byte[] exportCanonicalXML(Locatable locatable, boolean prettyPrint, boolean anyElement); static byte[] canonicalExporter(Composition composition, boolean prettyPrint, boolean anyElement); static Locatable parseOtherDetailsXML(InputStream otherDetailsXmlStream); static byte[] canonicalExporter(Locatable locatable, boolean prettyPrint, boolean anyElement); @Override Composition buildCompositionFromJson(String jsonData); @Override Locatable buildLocatableFromJson(String jsonData); @Override void bindOtherContextFromJson(Composition composition, String jsonData); @Override void bindItemStructureFromJson(ItemStructure itemStructure, String jsonData); @Override String getEntry(); @Override String getTemplateId(); @Override void setTemplateId(String templateId); @Override Composition getComposition(); @Override String getRootArchetypeId(); @Override Map<String, String> getLtreeMap(); void setCompositionParameters(Map<SystemValue, Object> values); void setCompositionAttributes(Composition composition); @Override void setLenient(boolean lenient); @Override Boolean isLenient(); @Override ConstraintMapper getConstraintMapper(); @Override Map<String, Integer> getArrayItemPathMap(); }
ContentBuilder implements I_ContentBuilder { @Override public Composition buildCompositionFromJson(String jsonData) throws Exception { long start = System.nanoTime(); Composition newComposition = this.generateNewComposition(); long end = System.nanoTime(); log.debug("generate composition [ms]:"+(end - start)/1000000); if (jsonData == null || jsonData.equals("null")) return newComposition; MapInspector inspector = getMapInspector(jsonData); start = System.nanoTime(); assignValuesFromStack(newComposition, (ArrayDeque) inspector.getStack()); end = System.nanoTime(); log.debug("set values [ms]:"+(end - start)/1000000); this.composition = newComposition; return newComposition; } ContentBuilder(Map<SystemValue, Object> values, I_KnowledgeCache knowledge, String templateId); @Override void setEntryData(Composition composition); @Override Object insertCloneInPath(Locatable locatable, Map<String, Object> definition, String path); @Override Composition importCanonicalXML(InputStream inputStream); @Override Composition importAsRM(Composition composition); @Override byte[] exportCanonicalXML(String jsonData, boolean prettyPrint); @Override byte[] exportCanonicalXML(Composition composition, boolean prettyPrint); @Override byte[] exportCanonicalXML(Composition composition, boolean prettyPrint, boolean anyElement); @Override byte[] exportCanonicalXML(Locatable locatable, boolean prettyPrint); @Override byte[] exportCanonicalXML(Locatable locatable, boolean prettyPrint, boolean anyElement); static byte[] canonicalExporter(Composition composition, boolean prettyPrint, boolean anyElement); static Locatable parseOtherDetailsXML(InputStream otherDetailsXmlStream); static byte[] canonicalExporter(Locatable locatable, boolean prettyPrint, boolean anyElement); @Override Composition buildCompositionFromJson(String jsonData); @Override Locatable buildLocatableFromJson(String jsonData); @Override void bindOtherContextFromJson(Composition composition, String jsonData); @Override void bindItemStructureFromJson(ItemStructure itemStructure, String jsonData); @Override String getEntry(); @Override String getTemplateId(); @Override void setTemplateId(String templateId); @Override Composition getComposition(); @Override String getRootArchetypeId(); @Override Map<String, String> getLtreeMap(); void setCompositionParameters(Map<SystemValue, Object> values); void setCompositionAttributes(Composition composition); @Override void setLenient(boolean lenient); @Override Boolean isLenient(); @Override ConstraintMapper getConstraintMapper(); @Override Map<String, Integer> getArrayItemPathMap(); static final String SCHEMA_XSI; static final String SCHEMA_OPENEHR_ORG_V1; }