@Test public void testLightEncoding() { String jsonbOrigin = "[\n" + " {\n" + " \"/items[at0002]\": [\n" + " {\n" + " \"/items[at0001]\": [\n" + " {\n" + " \"/name\": \"Urea\",\n" + " \"/value\": {\n" + " \"units\": \"mmol/l\",\n" + " \"accuracy\": 0.0,\n" + " \"magnitude\": 6.7,\n" + " \"precision\": 0,\n" + " \"normalRange\": {\n" + " \"interval\": {\n" + " \"lower\": {\n" + " \"units\": \"mmol/l\",\n" + " \"accuracy\": 0.0,\n" + " \"magnitude\": 2.5,\n" + " \"precision\": 0,\n" + " \"accuracyPercent\": false\n" + " },\n" + " \"upper\": {\n" + " \"units\": \"mmol/l\",\n" + " \"accuracy\": 0.0,\n" + " \"magnitude\": 6.6,\n" + " \"precision\": 0,\n" + " \"accuracyPercent\": false\n" + " },\n" + " \"lowerIncluded\": true,\n" + " \"upperIncluded\": true\n" + " }\n" + " },\n" + " \"accuracyPercent\": false\n" + " },\n" + " \"/$PATH$\": \"/content[openEHR-EHR-OBSERVATION.laboratory_test.v0 and name/value='Laboratory test']/data[at0001]/events[at0002 and name/value='Any event']/data[at0003]/items[openEHR-EHR-CLUSTER.laboratory_test_panel.v0 and name/value='Laboratory test panel']/items[at0002 and name/value='Laboratory result']/items[at0001 and name/value='Urea']\",\n" + " \"/$CLASS$\": \"DvQuantity\"\n" + " }\n" + " ],\n" + " \"/items[at0003]\": [\n" + " {\n" + " \"/name\": \"Comment\",\n" + " \"/value\": {\n" + " \"value\": \"may be technical artefact\"\n" + " },\n" + " \"/$PATH$\": \"/content[openEHR-EHR-OBSERVATION.laboratory_test.v0 and name/value='Laboratory test']/data[at0001]/events[at0002 and name/value='Any event']/data[at0003]/items[openEHR-EHR-CLUSTER.laboratory_test_panel.v0 and name/value='Laboratory test panel']/items[at0002 and name/value='Laboratory result']/items[at0003 and name/value='Comment']\",\n" + " \"/$CLASS$\": \"DvText\"\n" + " }\n" + " ]\n" + " },\n" + " {\n" + " \"/items[at0001]\": [\n" + " {\n" + " \"/name\": \"365760004\",\n" + " \"/value\": {\n" + " \"units\": \"mmol/l\",\n" + " \"accuracy\": 0.0,\n" + " \"magnitude\": 5.8,\n" + " \"precision\": 0,\n" + " \"normalRange\": {\n" + " \"interval\": {\n" + " \"lower\": {\n" + " \"units\": \"mmol/l\",\n" + " \"accuracy\": 0.0,\n" + " \"magnitude\": 3.5,\n" + " \"precision\": 0,\n" + " \"accuracyPercent\": false\n" + " },\n" + " \"upper\": {\n" + " \"units\": \"mmol/l\",\n" + " \"accuracy\": 0.0,\n" + " \"magnitude\": 5.3,\n" + " \"precision\": 0,\n" + " \"accuracyPercent\": false\n" + " },\n" + " \"lowerIncluded\": true,\n" + " \"upperIncluded\": true\n" + " }\n" + " },\n" + " \"accuracyPercent\": false\n" + " },\n" + " \"/$PATH$\": \"/content[openEHR-EHR-OBSERVATION.laboratory_test.v0 and name/value='Laboratory test']/data[at0001]/events[at0002 and name/value='Any event']/data[at0003]/items[openEHR-EHR-CLUSTER.laboratory_test_panel.v0 and name/value='Laboratory test panel']/items[at0002 and name/value='Laboratory result #4']/items[at0001 and name/value='365760004']\",\n" + " \"/$CLASS$\": \"DvQuantity\"\n" + " }\n" + " ]\n" + " },\n" + " {\n" + " \"/items[at0001]\": [\n" + " {\n" + " \"/name\": \"Sodium\",\n" + " \"/value\": {\n" + " \"units\": \"mmol/l\",\n" + " \"accuracy\": 0.0,\n" + " \"magnitude\": 177.0,\n" + " \"precision\": 0,\n" + " \"normalRange\": {\n" + " \"interval\": {\n" + " \"lower\": {\n" + " \"units\": \"mmol/l\",\n" + " \"accuracy\": 0.0,\n" + " \"magnitude\": 133.0,\n" + " \"precision\": 0,\n" + " \"accuracyPercent\": false\n" + " },\n" + " \"upper\": {\n" + " \"units\": \"mmol/l\",\n" + " \"accuracy\": 0.0,\n" + " \"magnitude\": 146.0,\n" + " \"precision\": 0,\n" + " \"accuracyPercent\": false\n" + " },\n" + " \"lowerIncluded\": true,\n" + " \"upperIncluded\": true\n" + " }\n" + " },\n" + " \"accuracyPercent\": false\n" + " },\n" + " \"/$PATH$\": \"/content[openEHR-EHR-OBSERVATION.laboratory_test.v0 and name/value='Laboratory test']/data[at0001]/events[at0002 and name/value='Any event']/data[at0003]/items[openEHR-EHR-CLUSTER.laboratory_test_panel.v0 and name/value='Laboratory test panel']/items[at0002 and name/value='Laboratory result #3']/items[at0001 and name/value='Sodium']\",\n" + " \"/$CLASS$\": \"DvQuantity\"\n" + " }\n" + " ]\n" + " },\n" + " {\n" + " \"/items[at0001]\": [\n" + " {\n" + " \"/name\": \"Creatinine\",\n" + " \"/value\": {\n" + " \"units\": \"mmol/l\",\n" + " \"accuracy\": 0.0,\n" + " \"magnitude\": 115.0,\n" + " \"precision\": 0,\n" + " \"normalRange\": {\n" + " \"interval\": {\n" + " \"lower\": {\n" + " \"units\": \"mmol/l\",\n" + " \"accuracy\": 0.0,\n" + " \"magnitude\": 80.0,\n" + " \"precision\": 0,\n" + " \"accuracyPercent\": false\n" + " },\n" + " \"upper\": {\n" + " \"units\": \"mmol/l\",\n" + " \"accuracy\": 0.0,\n" + " \"magnitude\": 110.0,\n" + " \"precision\": 0,\n" + " \"accuracyPercent\": false\n" + " },\n" + " \"lowerIncluded\": true,\n" + " \"upperIncluded\": true\n" + " }\n" + " },\n" + " \"accuracyPercent\": false\n" + " },\n" + " \"/$PATH$\": \"/content[openEHR-EHR-OBSERVATION.laboratory_test.v0 and name/value='Laboratory test']/data[at0001]/events[at0002 and name/value='Any event']/data[at0003]/items[openEHR-EHR-CLUSTER.laboratory_test_panel.v0 and name/value='Laboratory test panel']/items[at0002 and name/value='Laboratory result #2']/items[at0001 and name/value='Creatinine']\",\n" + " \"/$CLASS$\": \"DvQuantity\"\n" + " }\n" + " ]\n" + " }\n" + " ]\n" + " }\n" + "]"; String translated = new LightRawJsonEncoder(jsonbOrigin).encodeContentAsString("test"); assertNotNull(translated); System.out.println(translated); }
public String encodeContentAsString(String root){ GsonBuilder gsondb = EncodeUtil.getGsonBuilderInstance(); if (jsonbOrigin.startsWith("[")){ jsonbOrigin = jsonbOrigin.trim().substring(1, jsonbOrigin.length()-1); } Map<String, Object> fromDB = gsondb.create().fromJson(jsonbOrigin, Map.class); GsonBuilder gsonRaw = EncodeUtil.getGsonBuilderInstance(I_DvTypeAdapter.AdapterType._DBJSON2RAWJSON); String raw = gsonRaw.create().toJson(fromDB); return raw; }
LightRawJsonEncoder { public String encodeContentAsString(String root){ GsonBuilder gsondb = EncodeUtil.getGsonBuilderInstance(); if (jsonbOrigin.startsWith("[")){ jsonbOrigin = jsonbOrigin.trim().substring(1, jsonbOrigin.length()-1); } Map<String, Object> fromDB = gsondb.create().fromJson(jsonbOrigin, Map.class); GsonBuilder gsonRaw = EncodeUtil.getGsonBuilderInstance(I_DvTypeAdapter.AdapterType._DBJSON2RAWJSON); String raw = gsonRaw.create().toJson(fromDB); return raw; } }
LightRawJsonEncoder { public String encodeContentAsString(String root){ GsonBuilder gsondb = EncodeUtil.getGsonBuilderInstance(); if (jsonbOrigin.startsWith("[")){ jsonbOrigin = jsonbOrigin.trim().substring(1, jsonbOrigin.length()-1); } Map<String, Object> fromDB = gsondb.create().fromJson(jsonbOrigin, Map.class); GsonBuilder gsonRaw = EncodeUtil.getGsonBuilderInstance(I_DvTypeAdapter.AdapterType._DBJSON2RAWJSON); String raw = gsonRaw.create().toJson(fromDB); return raw; } LightRawJsonEncoder(String jsonbOrigin); }
LightRawJsonEncoder { public String encodeContentAsString(String root){ GsonBuilder gsondb = EncodeUtil.getGsonBuilderInstance(); if (jsonbOrigin.startsWith("[")){ jsonbOrigin = jsonbOrigin.trim().substring(1, jsonbOrigin.length()-1); } Map<String, Object> fromDB = gsondb.create().fromJson(jsonbOrigin, Map.class); GsonBuilder gsonRaw = EncodeUtil.getGsonBuilderInstance(I_DvTypeAdapter.AdapterType._DBJSON2RAWJSON); String raw = gsonRaw.create().toJson(fromDB); return raw; } LightRawJsonEncoder(String jsonbOrigin); String encodeContentAsString(String root); Map encodeContentAsMap(String root); }
LightRawJsonEncoder { public String encodeContentAsString(String root){ GsonBuilder gsondb = EncodeUtil.getGsonBuilderInstance(); if (jsonbOrigin.startsWith("[")){ jsonbOrigin = jsonbOrigin.trim().substring(1, jsonbOrigin.length()-1); } Map<String, Object> fromDB = gsondb.create().fromJson(jsonbOrigin, Map.class); GsonBuilder gsonRaw = EncodeUtil.getGsonBuilderInstance(I_DvTypeAdapter.AdapterType._DBJSON2RAWJSON); String raw = gsonRaw.create().toJson(fromDB); return raw; } LightRawJsonEncoder(String jsonbOrigin); String encodeContentAsString(String root); Map encodeContentAsMap(String root);  }