From 8e2106e887a71f97d484d82bbacc2cbd7b73af6a Mon Sep 17 00:00:00 2001 From: ppazos Date: Wed, 22 Mar 2023 00:17:24 -0300 Subject: [PATCH] fixed parser serializer for demographic dtos --- gradle.properties | 2 +- .../formats/OpenEhrJsonParserQuick.groovy | 7 +- .../formats/OpenEhrJsonSerializer.groovy | 15 ++- .../json_schema/openehr_api_1.0.2_all.json | 3 +- .../openehr/opt/ValidationFlowTest.groovy | 109 +++++++++++++++++- 5 files changed, 123 insertions(+), 13 deletions(-) diff --git a/gradle.properties b/gradle.properties index 19c19b92..1f128273 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,2 +1,2 @@ -version = 1.8.28 +version = 1.8.29 group = com.cabolabs \ No newline at end of file diff --git a/src/main/groovy/com/cabolabs/openehr/formats/OpenEhrJsonParserQuick.groovy b/src/main/groovy/com/cabolabs/openehr/formats/OpenEhrJsonParserQuick.groovy index 5602e1a6..cc36884f 100644 --- a/src/main/groovy/com/cabolabs/openehr/formats/OpenEhrJsonParserQuick.groovy +++ b/src/main/groovy/com/cabolabs/openehr/formats/OpenEhrJsonParserQuick.groovy @@ -665,7 +665,7 @@ class OpenEhrJsonParserQuick { } def method = 'parse'+ type +'Dto' - this."$method"(map) + return this."$method"(map) } private PersonDto parsePERSONDto(Map map) @@ -866,12 +866,11 @@ class OpenEhrJsonParserQuick { if (!type) { - throw new JsonParseException("_type required for PARTY_IDNETITY.details") + throw new JsonParseException("_type required for PARTY_IDENTITY.details") } def method = 'parse'+ type - - this."$method"(map.details, pi) + pi.details = this."$method"(map.details, pi) } return pi diff --git a/src/main/groovy/com/cabolabs/openehr/formats/OpenEhrJsonSerializer.groovy b/src/main/groovy/com/cabolabs/openehr/formats/OpenEhrJsonSerializer.groovy index 295018bd..6dc5904d 100644 --- a/src/main/groovy/com/cabolabs/openehr/formats/OpenEhrJsonSerializer.groovy +++ b/src/main/groovy/com/cabolabs/openehr/formats/OpenEhrJsonSerializer.groovy @@ -190,11 +190,24 @@ class OpenEhrJsonSerializer { out.roles = [] a.roles.each { role -> - out.roles << this.serializeRole(role) + out.roles << this.serializeRoleDto(role) } } } + private Map serializeRoleDto(Role r) + { + def out = [:] + + out._type = 'ROLE' + + this.fillParty(r, out) + + //out.performer = this.serializePartyRef(r.performer) + + return out + } + private void fillActor(Actor a, Map out) { this.fillParty(a, out) diff --git a/src/main/resources/json_schema/openehr_api_1.0.2_all.json b/src/main/resources/json_schema/openehr_api_1.0.2_all.json index 57358a03..34900f87 100644 --- a/src/main/resources/json_schema/openehr_api_1.0.2_all.json +++ b/src/main/resources/json_schema/openehr_api_1.0.2_all.json @@ -5557,7 +5557,8 @@ "required": [ "archetype_node_id", "archetype_details", - "name" + "name", + "identities" ], "properties": { "uid": { diff --git a/src/test/groovy/com/cabolabs/openehr/opt/ValidationFlowTest.groovy b/src/test/groovy/com/cabolabs/openehr/opt/ValidationFlowTest.groovy index 951ddc91..7f794ded 100644 --- a/src/test/groovy/com/cabolabs/openehr/opt/ValidationFlowTest.groovy +++ b/src/test/groovy/com/cabolabs/openehr/opt/ValidationFlowTest.groovy @@ -3,8 +3,7 @@ package com.cabolabs.openehr.opt import groovy.util.GroovyTestCase import com.cabolabs.testing.TestUtils import static com.cabolabs.testing.TestUtils.PS as PS -import com.cabolabs.openehr.formats.OpenEhrJsonParser -import com.cabolabs.openehr.formats.OpenEhrJsonParserQuick +import com.cabolabs.openehr.formats.* import com.cabolabs.openehr.validation.* import com.cabolabs.openehr.opt.manager.* import com.cabolabs.openehr.rm_1_0_2.ehr.Ehr @@ -18,7 +17,6 @@ import com.cabolabs.openehr.rm_1_0_2.demographic.Group import com.cabolabs.openehr.rm_1_0_2.demographic.Agent import com.cabolabs.openehr.rm_1_0_2.data_types.text.DvText import com.cabolabs.openehr.rm_1_0_2.support.identification.* - import com.cabolabs.openehr.dto_1_0_2.ehr.* import com.cabolabs.openehr.dto_1_0_2.demographic.* @@ -1147,7 +1145,39 @@ class ValidationFlowTest extends GroovyTestCase { }, "rm_version": "1.0.2" }, - "archetype_node_id": "openEHR-DEMOGRAPHIC-ROLE.generic.v1" + "archetype_node_id": "openEHR-DEMOGRAPHIC-ROLE.generic.v1", + "identities": [ + { + "_type": "PARTY_IDENTITY", + "name": { + "_type": "DV_TEXT", + "value": "identity" + }, + "archetype_node_id": "at0004", + "details": { + "_type": "ITEM_TREE", + "name": { + "_type": "DV_TEXT", + "value": "tree" + }, + "archetype_node_id": "at0005", + "items": [ + { + "_type": "ELEMENT", + "name": { + "_type": "DV_TEXT", + "value": "name" + }, + "archetype_node_id": "at0006", + "value": { + "_type": "DV_TEXT", + "value": "patient" + } + } + ] + } + } + ] } ], "identities": [ @@ -1256,7 +1286,39 @@ class ValidationFlowTest extends GroovyTestCase { } } ] - } + }, + "identities": [ + { + "_type": "PARTY_IDENTITY", + "name": { + "_type": "DV_TEXT", + "value": "identity" + }, + "archetype_node_id": "at0004", + "details": { + "_type": "ITEM_TREE", + "name": { + "_type": "DV_TEXT", + "value": "tree" + }, + "archetype_node_id": "at0005", + "items": [ + { + "_type": "ELEMENT", + "name": { + "_type": "DV_TEXT", + "value": "name" + }, + "archetype_node_id": "at0006", + "value": { + "_type": "DV_TEXT", + "value": "patient" + } + } + ] + } + } + ] } ], "identities": [ @@ -1313,6 +1375,9 @@ class ValidationFlowTest extends GroovyTestCase { RmValidationReport report = validator.dovalidate(person, 'com.cabolabs.openehr_opt.namespaces.default') assert !report.errors + + def serializer = new OpenEhrJsonSerializer() + println serializer.serialize(person) } void test_generic_group_api_valid() @@ -1410,7 +1475,39 @@ class ValidationFlowTest extends GroovyTestCase { }, "rm_version": "1.0.2" }, - "archetype_node_id": "openEHR-DEMOGRAPHIC-ROLE.generic.v1" + "archetype_node_id": "openEHR-DEMOGRAPHIC-ROLE.generic.v1", + "identities": [ + { + "_type": "PARTY_IDENTITY", + "name": { + "_type": "DV_TEXT", + "value": "identity" + }, + "archetype_node_id": "at0004", + "details": { + "_type": "ITEM_TREE", + "name": { + "_type": "DV_TEXT", + "value": "tree" + }, + "archetype_node_id": "at0005", + "items": [ + { + "_type": "ELEMENT", + "name": { + "_type": "DV_TEXT", + "value": "name" + }, + "archetype_node_id": "at0006", + "value": { + "_type": "DV_TEXT", + "value": "patient" + } + } + ] + } + } + ] } ] }