Skip to content

Commit

Permalink
Merge branch 'release/v0.30.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
bot committed Aug 16, 2023
2 parents 88ad672 + c1395b5 commit 7070caa
Show file tree
Hide file tree
Showing 27 changed files with 1,860 additions and 131 deletions.
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,13 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres
to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [0.30.0]
### Added
### Changed
- Upgrade openEHR_SDK to version 2.2.0 see https://github.com/ehrbase/openEHR_SDK/blob/develop/CHANGELOG.md
### Fixed
- Fix storing attributes of Locatable.name ([#1161](https://github.com/ehrbase/ehrbase/pull/1161))

## [0.29.0]
### Added
### Changed
Expand Down Expand Up @@ -677,3 +684,4 @@ the next release this file will provide a proper overview.
[0.27.4]: https://github.com/ehrbase/ehrbase/compare/v0.27.3...v0.27.4
[0.28.0]: https://github.com/ehrbase/ehrbase/compare/v0.27.4...v0.28.0
[0.29.0]: https://github.com/ehrbase/ehrbase/compare/v0.28.0...v0.29.0
[0.30.0]: https://github.com/ehrbase/ehrbase/compare/v0.29.0...v0.30.0
11 changes: 11 additions & 0 deletions UPDATING.md
Original file line number Diff line number Diff line change
Expand Up @@ -108,3 +108,14 @@ If exception occurs during the migration script execution (`V85__enforce_unique_

Action Required:
Ensure that the **ehr.template_store.id** and **ehr.template_store.template_id** columns have unique values within the tenant.

## EHRbase 0.30.0

### Fix storage of Locatable.name
An error in the encoding for Locatable.name was fixed.
With the fixed encoding Locatable.name.mappings and Locatable.name.defining_code are now stored correctly in the DB and Locatable.name.defining_code can also be queried using AQL.
There is a manual migration script available at `base/db-setup/fix-dv_coded_text-locatable-names.sql` which will fix the existing compositions.
This migration is only needed if Locatable.name.defining_code is used in any composition.
Be aware that this migration might take a while, as it will affect every composition in the database.
It will replace the Strings `"codeString":` and `"terminologyId":` with `"code_string":` and `"terminology_id":`.
This replacement is done over the whole JSON stored in the database, so there is a small chance that not only the broken JSON keys are affected.
2 changes: 1 addition & 1 deletion api/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
<parent>
<groupId>org.ehrbase.openehr</groupId>
<artifactId>server</artifactId>
<version>0.29.0</version>
<version>0.30.0</version>
</parent>

<artifactId>api</artifactId>
Expand Down
2 changes: 1 addition & 1 deletion application/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
<parent>
<groupId>org.ehrbase.openehr</groupId>
<artifactId>server</artifactId>
<version>0.29.0</version>
<version>0.30.0</version>
</parent>

<artifactId>application</artifactId>
Expand Down
69 changes: 69 additions & 0 deletions base/db-setup/fix-dv_coded_text-locatable-names.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
/*
* Copyright (c) 2023 vitasystems GmbH and Hannover Medical School.
*
* This file is part of project EHRbase
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

ALTER TABLE ehr.entry
DISABLE ROW LEVEL SECURITY;
ALTER TABLE ehr.entry_history
DISABLE ROW LEVEL SECURITY;
ALTER TABLE ehr.event_context
DISABLE ROW LEVEL SECURITY;
ALTER TABLE ehr.event_context_history
DISABLE ROW LEVEL SECURITY;
ALTER TABLE ehr.status
DISABLE ROW LEVEL SECURITY;
ALTER TABLE ehr.status_history
DISABLE ROW LEVEL SECURITY;

--composition content
UPDATE ehr.entry
SET entry=REPLACE(REPLACE(entry::text,'"codeString":', '"code_string":'),'"terminologyId":', '"terminology_id":')::jsonb;

UPDATE ehr.entry_history
SET entry=REPLACE(REPLACE(entry::text,'"codeString":', '"code_string":'),'"terminologyId":', '"terminology_id":')::jsonb
WHERE entry IS NOT NULL;

--event_context.other_context
UPDATE ehr.event_context
SET other_context=REPLACE(REPLACE(other_context::text,'"codeString":', '"code_string":'),'"terminologyId":', '"terminology_id":')::jsonb
WHERE other_context IS NOT NULL;

UPDATE ehr.event_context_history
SET other_context=REPLACE(REPLACE(other_context::text,'"codeString":', '"code_string":'),'"terminologyId":', '"terminology_id":')::jsonb
WHERE other_context IS NOT NULL;

--status.other_details
UPDATE ehr.status
SET other_details=REPLACE(REPLACE(other_details::text,'"codeString":', '"code_string":'),'"terminologyId":', '"terminology_id":')::jsonb
WHERE other_details IS NOT NULL;

UPDATE ehr.status_history
SET other_details=REPLACE(REPLACE(other_details::text,'"codeString":', '"code_string":'),'"terminologyId":', '"terminology_id":')::jsonb
WHERE other_details IS NOT NULL;

ALTER TABLE ehr.entry
ENABLE ROW LEVEL SECURITY;
ALTER TABLE ehr.entry_history
ENABLE ROW LEVEL SECURITY;
ALTER TABLE ehr.event_context
ENABLE ROW LEVEL SECURITY;
ALTER TABLE ehr.event_context_history
ENABLE ROW LEVEL SECURITY;
ALTER TABLE ehr.status
ENABLE ROW LEVEL SECURITY;
ALTER TABLE ehr.status_history
ENABLE ROW LEVEL SECURITY;
2 changes: 1 addition & 1 deletion base/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
<parent>
<groupId>org.ehrbase.openehr</groupId>
<artifactId>server</artifactId>
<version>0.29.0</version>
<version>0.30.0</version>
</parent>

<artifactId>base</artifactId>
Expand Down
10 changes: 5 additions & 5 deletions bom/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@

<groupId>org.ehrbase.openehr</groupId>
<artifactId>bom</artifactId>
<version>0.29.0</version>
<version>0.30.0</version>
<packaging>pom</packaging>

<name>EHRbase</name>
Expand Down Expand Up @@ -102,13 +102,13 @@
<antlr4.version>4.11.1</antlr4.version>
<archie.version>3.3.0</archie.version>
<commons-io.version>2.13.0</commons-io.version>
<commons-lang3.version>3.12.0</commons-lang3.version>
<ehrbase.sdk.version>2.1.0</ehrbase.sdk.version>
<commons-lang3.version>3.13.0</commons-lang3.version>
<ehrbase.sdk.version>2.2.0</ehrbase.sdk.version>
<flyway.version>8.5.13</flyway.version>
<jackson-bom.version>2.15.0</jackson-bom.version>
<javamelody.version>1.94.0</javamelody.version>
<javamelody.version>1.95.0</javamelody.version>
<joda.version>2.12.5</joda.version>
<jooq.version>3.18.5</jooq.version>
<jooq.version>3.18.6</jooq.version>
<json-path.version>2.8.0</json-path.version>
<junit.version>5.7.2</junit.version>
<maven-dependency-plugin.version>3.6.0</maven-dependency-plugin.version>
Expand Down
2 changes: 1 addition & 1 deletion jooq-pq/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
<parent>
<groupId>org.ehrbase.openehr</groupId>
<artifactId>server</artifactId>
<version>0.29.0</version>
<version>0.30.0</version>
</parent>

<artifactId>jooq-pg</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import com.nedap.archie.rm.datatypes.CodePhrase;
import com.nedap.archie.rm.datavalues.DvCodedText;
import com.nedap.archie.rm.datavalues.DvText;
import com.nedap.archie.rm.datavalues.TermMapping;
import com.nedap.archie.rm.datavalues.quantity.datetime.DvDate;
import com.nedap.archie.rm.datavalues.quantity.datetime.DvDateTime;
import com.nedap.archie.rm.datavalues.quantity.datetime.DvDuration;
Expand All @@ -41,6 +42,7 @@
import org.ehrbase.jooq.dbencoding.wrappers.json.writer.ParticipationAdapter;
import org.ehrbase.jooq.dbencoding.wrappers.json.writer.PartyIdentifiedAdapter;
import org.ehrbase.jooq.dbencoding.wrappers.json.writer.PartyRefAdapter;
import org.ehrbase.jooq.dbencoding.wrappers.json.writer.TermMappingAdapter;
import org.ehrbase.jooq.dbencoding.wrappers.json.writer.translator_db2raw.ArrayListAdapter;
import org.ehrbase.jooq.dbencoding.wrappers.json.writer.translator_db2raw.LinkedTreeMapAdapter;

Expand All @@ -67,7 +69,8 @@ public static GsonBuilder getGsonBuilderInstance() {
.registerTypeAdapter(CodePhrase.class, new CodePhraseAdapter())
.registerTypeAdapter(Participation.class, new ParticipationAdapter())
.registerTypeAdapter(PartyIdentified.class, new PartyIdentifiedAdapter())
.registerTypeAdapter(PartyRef.class, new PartyRefAdapter());
.registerTypeAdapter(PartyRef.class, new PartyRefAdapter())
.registerTypeAdapter(TermMapping.class, new TermMappingAdapter(AdapterType.PG_JSONB));
}

public static GsonBuilder getGsonBuilderInstance(AdapterType dbjson2rawjson) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,9 @@ public Map<String, Object> toMap() {
}
if (aName != null) {
nameMap.put("value", aName.getValue());
if (aName.getMappings() != null) {
nameMap.put("mappings", aName.getMappings());
}
}
nameMap.put(I_DvTypeAdapter.AT_TYPE, new SnakeCase(DvText.class.getSimpleName()).camelToUpperSnake());
return nameMap;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,34 +17,31 @@
*/
package org.ehrbase.jooq.dbencoding.wrappers.json.writer;

import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import com.google.gson.stream.JsonReader;
import com.google.gson.stream.JsonWriter;
import com.nedap.archie.rm.datatypes.CodePhrase;
import com.nedap.archie.rm.support.identification.TerminologyId;
import java.io.IOException;
import java.util.Optional;
import org.ehrbase.jooq.dbencoding.wrappers.json.I_DvTypeAdapter;
import org.ehrbase.openehr.sdk.util.ObjectSnakeCase;
import org.ehrbase.openehr.sdk.util.SnakeCase;

/**
* GSON adapter for DvDateTime
* Required since JSON does not support natively a DateTime data type
*/
public class CodePhraseAdapter extends DvTypeAdapter<CodePhrase> {

private Gson gson;
private TerminologyIDAdapter terminologyIDAdapter;

public CodePhraseAdapter(AdapterType adapterType) {
super(adapterType);
gson = new GsonBuilder()
.registerTypeAdapter(TerminologyId.class, new TerminologyIDAdapter(adapterType))
.setPrettyPrinting()
.create();
terminologyIDAdapter = new TerminologyIDAdapter(adapterType);
}

public CodePhraseAdapter() {}
public CodePhraseAdapter() {
super();
terminologyIDAdapter = new TerminologyIDAdapter(adapterType);
}

@Override
public CodePhrase read(JsonReader arg0) throws IOException {
Expand All @@ -58,23 +55,17 @@ public void write(JsonWriter writer, CodePhrase codePhrase) throws IOException {
writer.nullValue();
return;
}

if (adapterType == I_DvTypeAdapter.AdapterType.PG_JSONB) {
writer.beginObject();
writer.name("codeString").value(codePhrase.getCodeString());
writer.name(TAG_CLASS_RAW_JSON).value(new SnakeCase(CodePhrase.class.getSimpleName()).camelToUpperSnake());
writer.name("terminologyId");
writer.beginObject();
writer.name("value").value(codePhrase.getTerminologyId().getValue());
writer.name(TAG_CLASS_RAW_JSON)
.value(new SnakeCase(TerminologyId.class.getSimpleName()).camelToUpperSnake());
writer.endObject();
writer.endObject();
} else if (adapterType == I_DvTypeAdapter.AdapterType.RAW_JSON) {
Optional<String> preferredTerm = Optional.of(codePhrase).map(CodePhrase::getPreferredTerm);
if (adapterType == I_DvTypeAdapter.AdapterType.PG_JSONB
|| adapterType == I_DvTypeAdapter.AdapterType.RAW_JSON) {
writer.beginObject();
writer.name(TAG_CLASS_RAW_JSON).value(new ObjectSnakeCase(codePhrase).camelToUpperSnake());
writer.name("code_string").value(codePhrase.getCodeString());
writer.name("terminology_id").value(gson.toJson(codePhrase.getTerminologyId()));
writer.name("terminology_id");
terminologyIDAdapter.write(writer, codePhrase.getTerminologyId());
if (preferredTerm.isPresent()) {
writer.name("preferred_term").value(preferredTerm.get());
}
writer.endObject();
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,36 +17,31 @@
*/
package org.ehrbase.jooq.dbencoding.wrappers.json.writer;

import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import com.google.gson.stream.JsonReader;
import com.google.gson.stream.JsonWriter;
import com.nedap.archie.rm.datatypes.CodePhrase;
import com.nedap.archie.rm.datavalues.DvCodedText;
import com.nedap.archie.rm.support.identification.TerminologyId;
import java.io.IOException;
import java.util.Optional;
import org.ehrbase.jooq.dbencoding.wrappers.json.I_DvTypeAdapter;
import org.ehrbase.openehr.sdk.util.ObjectSnakeCase;
import org.ehrbase.openehr.sdk.util.SnakeCase;

/**
* GSON adapter for DvDateTime
* Required since JSON does not support natively a DateTime data type
*/
public class DvCodedTextAdapter extends DvTypeAdapter<DvCodedText> {

private Gson gson;
private final CodePhraseAdapter codePhraseAdapter;

public DvCodedTextAdapter(AdapterType adapterType) {
super(adapterType);
gson = new GsonBuilder()
.registerTypeAdapter(CodePhrase.class, new CodePhraseAdapter(adapterType))
.setPrettyPrinting()
.create();
codePhraseAdapter = new CodePhraseAdapter(adapterType);
}

public DvCodedTextAdapter() {}
public DvCodedTextAdapter() {
super();
codePhraseAdapter = new CodePhraseAdapter(adapterType);
}

@Override
public DvCodedText read(JsonReader arg0) {
Expand All @@ -64,33 +59,21 @@ public void write(JsonWriter writer, DvCodedText dvalue) throws IOException {
return;
}

TermMappingAdapter termMappingAdapter = new TermMappingAdapter();

if (adapterType == I_DvTypeAdapter.AdapterType.PG_JSONB) {
writer.beginObject();
writer.name(VALUE).value(dvalue.getValue());
writer.name(TAG_CLASS_RAW_JSON).value(new SnakeCase(DvCodedText.class.getSimpleName()).camelToUpperSnake());
writer.name("definingCode");
writer.beginObject();
writer.name("codeString").value(dvalue.getDefiningCode().getCodeString());
writer.name("terminologyId");
writer.beginObject();
writer.name(VALUE).value(dvalue.getDefiningCode().getTerminologyId().getValue());
writer.name(TAG_CLASS_RAW_JSON)
.value(new SnakeCase(TerminologyId.class.getSimpleName()).camelToUpperSnake());
writer.endObject();
writer.name(TAG_CLASS_RAW_JSON).value(new SnakeCase(CodePhrase.class.getSimpleName()).camelToUpperSnake());
writer.endObject();
termMappingAdapter.write(writer, dvalue.getMappings());
writer.endObject();
} else if (adapterType == I_DvTypeAdapter.AdapterType.RAW_JSON) {
writer.beginObject();
writer.name(TAG_CLASS_RAW_JSON).value(new ObjectSnakeCase(dvalue).camelToUpperSnake());
writer.name(VALUE).value(dvalue.getValue());
CodePhrase codePhrase = dvalue.getDefiningCode();
writer.name("defining_code").value(gson.toJson(codePhrase));
writer.name(TAG_CLASS_RAW_JSON).value(new SnakeCase(CodePhrase.class.getSimpleName()).camelToUpperSnake());
writer.endObject();
TermMappingAdapter termMappingAdapter = new TermMappingAdapter(adapterType);
if (adapterType == I_DvTypeAdapter.AdapterType.PG_JSONB
|| adapterType == I_DvTypeAdapter.AdapterType.RAW_JSON) {
writeDvCodedText(writer, dvalue, termMappingAdapter);
}
}

private void writeDvCodedText(JsonWriter writer, DvCodedText dvalue, TermMappingAdapter termMappingAdapter)
throws IOException {
writer.beginObject();
writer.name(TAG_CLASS_RAW_JSON).value(new ObjectSnakeCase(dvalue).camelToUpperSnake());
writer.name(VALUE).value(dvalue.getValue());
writer.name("defining_code");
codePhraseAdapter.write(writer, dvalue.getDefiningCode());
termMappingAdapter.write(writer, dvalue.getMappings());
writer.endObject();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
import java.io.IOException;
import org.ehrbase.jooq.dbencoding.wrappers.json.I_DvTypeAdapter;
import org.ehrbase.openehr.sdk.util.ObjectSnakeCase;
import org.ehrbase.openehr.sdk.util.SnakeCase;

/**
* GSON adapter for DvDateTime
Expand All @@ -49,18 +48,13 @@ public void write(JsonWriter writer, DvText dvalue) throws IOException {
return;
}

if (adapterType == I_DvTypeAdapter.AdapterType.PG_JSONB) {
TermMappingAdapter termMappingAdapter = new TermMappingAdapter();
TermMappingAdapter termMappingAdapter = new TermMappingAdapter(adapterType);
if (adapterType == I_DvTypeAdapter.AdapterType.PG_JSONB
|| adapterType == I_DvTypeAdapter.AdapterType.RAW_JSON) {
writer.beginObject();
writer.name("value").value(dvalue.getValue());
writer.name(I_DvTypeAdapter.TAG_CLASS_RAW_JSON)
.value(new SnakeCase(DvText.class.getSimpleName()).camelToUpperSnake());
termMappingAdapter.write(writer, dvalue.getMappings());
writer.endObject();
} else if (adapterType == I_DvTypeAdapter.AdapterType.RAW_JSON) {
writer.beginObject();
writer.name(I_DvTypeAdapter.TAG_CLASS_RAW_JSON).value(new ObjectSnakeCase(dvalue).camelToUpperSnake());
writer.name("value").value(dvalue.getValue());
termMappingAdapter.write(writer, dvalue.getMappings());
writer.endObject();
}
}
Expand Down
Loading

0 comments on commit 7070caa

Please sign in to comment.