diff --git a/CHANGELOG.md b/CHANGELOG.md index 27a51d286..3770024b9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -16,6 +16,7 @@ Note: version releases in the 0.x.y range may introduce breaking changes. - Fix issue when template does not contain list of values for DV_ORDINAL (https://github.com/ehrbase/openEHR_SDK/pull/295) - Fix issue in AQL regarding LIMIT and OFFSET (https://github.com/ehrbase/openEHR_SDK/pull/296) - Fix issue while unmarshalling FLAT composition that contains ELEMENT with children DV_CODED_TEXT and DV_TEXT (https://github.com/ehrbase/openEHR_SDK/pull/300) +- Fix missing 'type' attribute in ExternalRef encoding (https://github.com/ehrbase/openEHR_SDK/pull/303) - ## 1.16.0 diff --git a/serialisation/src/main/java/org/ehrbase/serialisation/dbencoding/wrappers/json/writer/PartyRefAdapter.java b/serialisation/src/main/java/org/ehrbase/serialisation/dbencoding/wrappers/json/writer/PartyRefAdapter.java index 353e0d3d7..0ab9bd4f9 100644 --- a/serialisation/src/main/java/org/ehrbase/serialisation/dbencoding/wrappers/json/writer/PartyRefAdapter.java +++ b/serialisation/src/main/java/org/ehrbase/serialisation/dbencoding/wrappers/json/writer/PartyRefAdapter.java @@ -33,7 +33,7 @@ */ public class PartyRefAdapter extends DvTypeAdapter { - private Gson gson; + private final Gson gson; public PartyRefAdapter(AdapterType adapterType) { super(adapterType); @@ -66,20 +66,13 @@ public void write(JsonWriter writer, PartyRef partyRef) throws IOException { if (adapterType == AdapterType.PG_JSONB) { writer.beginObject(); writer.name("namespace").value(partyRef.getNamespace()); + writer.name("type").value(partyRef.getType()); writer.name(CompositionSerializer.TAG_CLASS).value(PartyRef.class.getSimpleName()); if (partyRef.getId() != null){ writer.name("id").jsonValue(gson.toJson(partyRef.getId())); } //TODO: add Identifiers writer.endObject(); - } else if (adapterType == AdapterType.RAW_JSON) { -// -// writer.beginObject(); //{ -// writer.name(I_DvTypeAdapter.TAG_CLASS_RAW_JSON).value(new ObjectSnakeCase(participation).camelToUpperSnake()); -// writer.name("value").value(participation.getValue()); -// CodePhrase codePhrase = participation.getDefiningCode(); -// writer.name("defining_code").value(gson.toJson(codePhrase)); -// writer.endObject(); //} } } diff --git a/serialisation/src/test/java/org/ehrbase/serialisation/dbencoding/DBEncodeTest.java b/serialisation/src/test/java/org/ehrbase/serialisation/dbencoding/DBEncodeTest.java index cf750890d..61a7cac53 100644 --- a/serialisation/src/test/java/org/ehrbase/serialisation/dbencoding/DBEncodeTest.java +++ b/serialisation/src/test/java/org/ehrbase/serialisation/dbencoding/DBEncodeTest.java @@ -847,4 +847,26 @@ public void testDBEncodeDecodeInstruction() throws IOException { Assert.assertNotNull(expiryTime); Assert.assertEquals(OffsetDateTime.parse("2021-05-18T13:13:09.780+03:00"), expiryTime.getValue()); } + + @Test + public void testOtherParticipationsPartyRef() throws IOException { + Composition composition = new CanonicalJson().unmarshal(IOUtils.toString(CompositionTestDataCanonicalJson.OTHER_PARTICIPATIONS.getStream(), UTF_8),Composition.class); + + assertNotNull(composition); + + CompositionSerializer compositionSerializerRawJson = new CompositionSerializer(); + + String db_encoded = compositionSerializerRawJson.dbEncode(composition); + assertNotNull(db_encoded); + + JsonElement converted = new LightRawJsonEncoder(db_encoded).encodeContentAsJson("composition"); + + //see if this can be interpreted by Archie + Composition composition2 = new CanonicalJson().unmarshal(converted.toString(), Composition.class); + + assertNotNull(composition2); + + assertEquals("PERSON",composition2.itemsAtPath("/content[openEHR-EHR-ACTION.minimal.v1]/other_participations/performer/external_ref/type").get(0)); + } + }