Skip to content

Commit

Permalink
added missing type attribute in jsonb encoding (#303)
Browse files Browse the repository at this point in the history
  • Loading branch information
chevalleyc authored Jan 21, 2022
1 parent 2b0bd5f commit 48eb398
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 9 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
*/
public class PartyRefAdapter extends DvTypeAdapter<PartyRef> {

private Gson gson;
private final Gson gson;

public PartyRefAdapter(AdapterType adapterType) {
super(adapterType);
Expand Down Expand Up @@ -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(); //}
}

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}

}

0 comments on commit 48eb398

Please sign in to comment.