use of com.nedap.archie.rm.composition.Composition in project openEHR_SDK by ehrbase.
the class FlatJsonMarshallerTest method toFlatJsonAllTypes.
@Test
public void toFlatJsonAllTypes() throws IOException, XmlException {
OPERATIONALTEMPLATE template = TemplateDocument.Factory.parse(OperationalTemplateTestData.ALL_TYPES.getStream()).getTemplate();
Composition composition = new CanonicalJson().unmarshal(IOUtils.toString(CompositionTestDataCanonicalJson.ALL_TYPES.getStream(), StandardCharsets.UTF_8), Composition.class);
FlatJsonMarshaller cut = new FlatJsonMarshaller();
String actual = cut.toFlatJson(composition, new OPTParser(template).parse());
assertThat(actual).isNotNull();
String expected = IOUtils.toString(CompositionTestDataSimSDTJson.ALL_TYPES.getStream(), StandardCharsets.UTF_8);
List<String> errors = compere(actual, expected);
checkErrors(errors, new String[] { "Missing path: test_all_types/test_all_types:0/identifier|id, value: 55175056", "Missing path: test_all_types/test_all_types:0/proportion_any|type, value: 1", "Missing path: test_all_types/test_all_types:0/proportion_any|precision, value: 1", "Missing path: test_all_types/test_all_types:0/duration_any, value: P1Y2M10DT2H30M", "Missing path: test_all_types/test_all_types2:0/uri, value: www.iana.org" }, new String[] { "Extra path: test_all_types/test_all_types:0/duration_any, value: PT30M", "Extra path: test_all_types/test_all_types:0/identifier, value: 55175056", "Extra path: test_all_types/test_all_types:0/proportion_any|type, value: 1.0" });
}
use of com.nedap.archie.rm.composition.Composition in project openEHR_SDK by ehrbase.
the class FlatJsonUnmarshallerTest method unmarshal.
@Test
public void unmarshal() throws IOException, XmlException {
OPERATIONALTEMPLATE template = TemplateDocument.Factory.parse(OperationalTemplateTestData.CORONA_ANAMNESE.getStream()).getTemplate();
WebTemplate webTemplate = new OPTParser(template).parse();
FlatJsonUnmarshaller cut = new FlatJsonUnmarshaller();
String flat = IOUtils.toString(CompositionTestDataSimSDTJson.CORONA.getStream(), StandardCharsets.UTF_8);
Composition actual = cut.unmarshal(flat, webTemplate);
assertThat(actual).isNotNull();
Observation observation = (Observation) actual.itemAtPath("/content[openEHR-EHR-OBSERVATION.story.v1]");
assertThat(observation.getData().getOrigin().getValue()).hasToString("2020-05-11T22:53:12.039139+02:00");
assertThat(observation.getSubject()).isNotNull();
assertThat(observation.getSubject().getClass()).isEqualTo(PartySelf.class);
}
use of com.nedap.archie.rm.composition.Composition in project openEHR_SDK by ehrbase.
the class RawJsonTest method marshallEmptyState.
@Test
public void marshallEmptyState() throws Exception {
String json = IOUtils.toString(CompositionTestDataCanonicalJson.GECCO_LABORBEFUND.getStream(), UTF_8);
Composition composition = new CanonicalJson().unmarshal(json, Composition.class);
RawJson rawJson = new RawJson();
String actual = rawJson.marshal(composition);
assertThat(actual).isNotNull();
}
use of com.nedap.archie.rm.composition.Composition in project openEHR_SDK by ehrbase.
the class FlatJsonTest method check.
private void check(String templateId, CompositionTestDataSimSDTJson testData, String[] expectedMissing, String[] expectedExtra) throws IOException {
RMDataFormat cut = new FlatJasonProvider(templateProvider).buildFlatJson(FlatFormat.SIM_SDT, templateId);
String flat = IOUtils.toString(testData.getStream(), StandardCharsets.UTF_8);
Composition unmarshal = cut.unmarshal(flat);
SoftAssertions softAssertions = new SoftAssertions();
softAssertions.assertThat(unmarshal).isNotNull();
RMObjectValidator rmObjectValidator = new RMObjectValidator(ArchieRMInfoLookup.getInstance(), s -> null);
softAssertions.assertThat(rmObjectValidator.validate(unmarshal)).filteredOn(m -> !m.getMessage().contains("Inv_null_flavour_indicated")).containsExactlyInAnyOrder();
String actual = cut.marshal(unmarshal);
String expected = IOUtils.toString(testData.getStream(), StandardCharsets.UTF_8);
List<String> errors = compere(actual, expected);
softAssertions.assertThat(errors).filteredOn(s -> s.startsWith("Missing")).containsExactlyInAnyOrder(expectedMissing);
softAssertions.assertThat(errors).filteredOn(s -> s.startsWith("Extra")).containsExactlyInAnyOrder(expectedExtra);
softAssertions.assertAll();
}
use of com.nedap.archie.rm.composition.Composition in project openEHR_SDK by ehrbase.
the class FlatJsonTest method roundTripRaw.
@Test
public void roundTripRaw() throws IOException {
CompositionTestDataSimSDTJson testData = CompositionTestDataSimSDTJson.CORONA_WITH_RAW;
String templateId = "Corona_Anamnese";
RMDataFormat cut = new FlatJasonProvider(templateProvider).buildFlatJson(FlatFormat.SIM_SDT, templateId);
String flat = IOUtils.toString(testData.getStream(), StandardCharsets.UTF_8);
Composition unmarshal = cut.unmarshal(flat);
SoftAssertions softAssertions = new SoftAssertions();
softAssertions.assertThat(unmarshal).isNotNull();
RMObjectValidator rmObjectValidator = new RMObjectValidator(ArchieRMInfoLookup.getInstance(), s -> null);
softAssertions.assertThat(rmObjectValidator.validate(unmarshal)).filteredOn(m -> !m.getMessage().contains("Inv_null_flavour_indicated")).containsExactlyInAnyOrder();
String actual = cut.marshal(unmarshal);
String expected = IOUtils.toString(CompositionTestDataSimSDTJson.CORONA.getStream(), StandardCharsets.UTF_8);
List<String> errors = compere(actual, expected);
softAssertions.assertThat(errors).filteredOn(s -> s.startsWith("Missing")).containsExactlyInAnyOrder();
softAssertions.assertThat(errors).filteredOn(s -> s.startsWith("Extra")).containsExactlyInAnyOrder();
softAssertions.assertAll();
}
Aggregations