Skip to content
This repository was archived by the owner on Mar 5, 2026. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 9 additions & 4 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -108,15 +108,14 @@
<artifactId>jjwt</artifactId>
<version>${jjwt.version}</version>
</dependency>

<!-- JUnit -->
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>${junit.version}</version>
<scope>test</scope>
</dependency>

<!-- EHRBase -->
<dependency>
<groupId>org.ehrbase.openehr.sdk</groupId>
Expand All @@ -133,7 +132,7 @@
<artifactId>web-template</artifactId>
<version>${ehrbase.version}</version>
</dependency>


<!-- JSON Schema Validator -->
<dependency>
Expand Down Expand Up @@ -241,7 +240,7 @@
<groupId>com.github.java-json-tools</groupId>
<artifactId>json-schema-validator</artifactId>
</dependency>
<dependency>
<dependency>
<groupId>org.pf4j</groupId>
<artifactId>pf4j</artifactId>
<version>3.11.0</version>
Expand All @@ -251,6 +250,12 @@
<artifactId>openfhir-plugin-api</artifactId>
<version>1.0.0</version>
</dependency>
<dependency>
<groupId>org.skyscreamer</groupId>
<artifactId>jsonassert</artifactId>
<version>2.0-rc1</version>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<pluginManagement>
Expand Down
49 changes: 49 additions & 0 deletions src/test/java/com/medblocks/openfhir/StandardsAsserter.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
package com.medblocks.openfhir;

import ca.uhn.fhir.context.FhirContext;
import ca.uhn.fhir.parser.IParser;
import com.google.gson.*;
import com.nedap.archie.rm.composition.Composition;
import org.ehrbase.openehr.sdk.serialisation.jsonencoding.CanonicalJson;
import org.hl7.fhir.r4.model.Bundle;
import org.json.JSONObject;
import org.junit.Assert;
import org.skyscreamer.jsonassert.JSONAssert;

import java.io.InputStream;
import java.io.InputStreamReader;
import java.nio.charset.StandardCharsets;
import java.util.*;

public class StandardsAsserter {

private static final Gson GSON = new Gson();

public void assertComposition(Composition composition, String expectedClasspathJson) {
JSONObject actual = new JSONObject(new CanonicalJson().marshal(composition));
JSONObject expected = loadJsonObject(expectedClasspathJson);
JSONAssert.assertEquals(expected, actual, true);
}

public void assertBundle(Bundle bundle, String expectedClasspathJson) {
FhirContext ctx = FhirContext.forR4();
IParser parser = ctx.newJsonParser();
JSONObject actual = new JSONObject(parser.encodeResourceToString(bundle));

JSONObject expected = loadJsonObject(expectedClasspathJson);

JSONAssert.assertEquals(expected, actual, true);

}

private JSONObject loadJsonObject(String classpathLocation) {
InputStream is = getClass().getResourceAsStream(classpathLocation);
try {
String json = new String(is.readAllBytes(), StandardCharsets.UTF_8);
return new JSONObject(json);
} catch (Exception e) {
throw new RuntimeException("Failed to parse JSON file", e);
}
}

}
58 changes: 30 additions & 28 deletions src/test/java/com/medblocks/openfhir/kds/KdsBidirectionalTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import com.google.gson.Gson;
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import com.medblocks.openfhir.StandardsAsserter;
import com.medblocks.openfhir.OpenEhrRmWorker;
import com.medblocks.openfhir.TestOpenFhirMappingContext;
import com.medblocks.openfhir.fc.schema.context.FhirConnectContext;
Expand All @@ -29,9 +30,8 @@
import jakarta.annotation.Nullable;
import java.io.IOException;
import java.io.InputStream;
import java.util.Arrays;
import java.util.Map;
import java.util.TimeZone;
import java.util.*;

import lombok.extern.slf4j.Slf4j;
import org.apache.commons.io.IOUtils;
import org.ehrbase.openehr.sdk.serialisation.flatencoding.std.marshal.FlatJsonMarshaller;
Expand All @@ -47,7 +47,7 @@
import org.openehr.schemas.v1.OPERATIONALTEMPLATE;
import org.openehr.schemas.v1.TemplateDocument;
import org.springframework.http.ResponseEntity;
import org.yaml.snakeyaml.Yaml;


@Slf4j
public abstract class KdsBidirectionalTest {
Expand All @@ -57,27 +57,28 @@ public abstract class KdsBidirectionalTest {
* to automatically be created against a running (by yourself) EHRBase instance. Meant for an integration
* test and implicit validation of the mapped Composition.
*/
final boolean TEST_AGAINST_EHRBASE = false;
final String EHRBASE_BASIC_USERNAME = "ehrbase-user";
final String EHRBASE_BASIC_PASSWORD = "SuperSecretPassword";
final String EHRBASE_HOST = "http://localhost:8081";
public final boolean TEST_AGAINST_EHRBASE = false;
public final String EHRBASE_BASIC_USERNAME = "ehrbase-user";
public final String EHRBASE_BASIC_PASSWORD = "SuperSecretPassword";
public final String EHRBASE_HOST = "http://localhost:8081";

final OpenFhirStringUtils openFhirStringUtils = new OpenFhirStringUtils();
final OpenFhirMapperUtils openFhirMapperUtils = new OpenFhirMapperUtils();
final FhirConnectModelMerger fhirConnectModelMerger = new FhirConnectModelMerger();
final FhirPathR4 fhirPath = new FhirPathR4(FhirContext.forR4());
final JsonParser jsonParser = (JsonParser) FhirContext.forR4().newJsonParser();
public final OpenFhirStringUtils openFhirStringUtils = new OpenFhirStringUtils();
public final OpenFhirMapperUtils openFhirMapperUtils = new OpenFhirMapperUtils();
public final FhirConnectModelMerger fhirConnectModelMerger = new FhirConnectModelMerger();
public final FhirPathR4 fhirPath = new FhirPathR4(FhirContext.forR4());
public final JsonParser jsonParser = (JsonParser) FhirContext.forR4().newJsonParser();

TestOpenFhirMappingContext repo;
OpenEhrToFhir openEhrToFhir;
FhirToOpenEhr fhirToOpenEhr;
public TestOpenFhirMappingContext repo;
public OpenEhrToFhir openEhrToFhir;
public FhirToOpenEhr fhirToOpenEhr;

FhirConnectContext context;
OPERATIONALTEMPLATE operationaltemplate;
String operationaltemplateSerialized;
WebTemplate webTemplate;
public FhirConnectContext context;
public OPERATIONALTEMPLATE operationaltemplate;
public String operationaltemplateSerialized;
public WebTemplate webTemplate;
public StandardsAsserter standardsAsserter = new StandardsAsserter();

protected abstract void prepareState();
public abstract void prepareState();

@Before
public void init() {
Expand Down Expand Up @@ -152,13 +153,13 @@ public void toOpenEhrTest() {
}
}

protected abstract JsonObject toOpenEhr();
public abstract JsonObject toOpenEhr();

protected boolean testAgainstEhrBase() {
boolean testAgainstEhrBase() {
return TEST_AGAINST_EHRBASE;
}

protected String getFlat(final String path) {
protected String getFile(final String path) {
final InputStream inputStream = this.getClass().getResourceAsStream(path);
try {
return IOUtils.toString(inputStream);
Expand All @@ -167,7 +168,7 @@ protected String getFlat(final String path) {
}
}

protected void compareJsonObjects(final JsonObject initial, final JsonObject expected) {
public void compareJsonObjects(final JsonObject initial, final JsonObject expected) {
for (Map.Entry<String, JsonElement> initialEntrySet : expected.entrySet()) {
final String initialKey = initialEntrySet.getKey();
final String initialValue = initialEntrySet.getValue().getAsString();
Expand All @@ -179,12 +180,12 @@ protected void compareJsonObjects(final JsonObject initial, final JsonObject exp
}
}

protected org.hl7.fhir.r4.model.Bundle getTestBundle(final String path) {
public org.hl7.fhir.r4.model.Bundle getTestBundle(final String path) {
final InputStream inputStream = this.getClass().getResourceAsStream(path);
return (org.hl7.fhir.r4.model.Bundle) jsonParser.parseResource(inputStream);
}

protected FhirConnectContext getContext(final String path) {
public FhirConnectContext getContext(final String path) {
final ObjectMapper yaml = OpenFhirTestUtility.getYaml();
final InputStream inputStream = this.getClass().getResourceAsStream(path);
try {
Expand All @@ -194,11 +195,12 @@ protected FhirConnectContext getContext(final String path) {
}
}

protected OPERATIONALTEMPLATE getOperationalTemplate() {
public OPERATIONALTEMPLATE getOperationalTemplate() {
try {
return TemplateDocument.Factory.parse(operationaltemplateSerialized).getTemplate();
} catch (final Exception e) {
throw new RuntimeException(e);
}
}

}
Loading
Loading