use of org.ehrbase.client.flattener.Unflattener in project openEHR_SDK by ehrbase.
the class DefaultRestCompositionEndpoint method mergeCompositionEntity.
@Override
public <T> T mergeCompositionEntity(T entity) {
Composition composition = (Composition) new Unflattener(defaultRestClient.getTemplateProvider(), defaultRestClient.getDefaultValuesProvider()).unflatten(entity);
Optional<VersionUid> versionUid = extractVersionUid(entity);
final VersionUid updatedVersion = internalMerge(composition, versionUid.orElse(null));
Flattener.addVersion(entity, updatedVersion);
entity = (T) new Flattener(defaultRestClient.getTemplateProvider()).flatten(composition, entity.getClass());
Flattener.addVersion(entity, updatedVersion);
return entity;
}
use of org.ehrbase.client.flattener.Unflattener in project fhir-bridge by ehrbase.
the class CompositionProducer method debugMapping.
private void debugMapping(CompositionEntity composition) {
ResourceTemplateProvider resourceTemplateProvider = new ResourceTemplateProvider("classpath:/opt/");
resourceTemplateProvider.afterPropertiesSet();
Unflattener unflattener = new Unflattener(resourceTemplateProvider);
RMObject rmObject = unflattener.unflatten(composition);
CanonicalJson canonicalJson = new CanonicalJson();
String compositionJson = canonicalJson.marshal(rmObject);
writeToFile(compositionJson);
}
use of org.ehrbase.client.flattener.Unflattener in project openEHR_SDK by ehrbase.
the class OldDtoModelTest method testUnflattenCorona.
@Test
public void testUnflattenCorona() throws IOException {
Composition expected = new CanonicalJson().unmarshal(IOUtils.toString(CompositionTestDataCanonicalJson.CORONA.getStream(), StandardCharsets.UTF_8), Composition.class);
Flattener flattener = new Flattener(new TestDataTemplateProvider());
CoronaAnamneseComposition coronaAnamneseComposition = flattener.flatten(expected, CoronaAnamneseComposition.class);
Unflattener cut = new Unflattener(new TestDataTemplateProvider());
Composition actual = (Composition) cut.unflatten(coronaAnamneseComposition);
assertThat(actual).isNotNull();
assertThat(actual.getContent()).extracting(Locatable::getNameAsString, Locatable::getArchetypeNodeId).containsExactlyInAnyOrder(actual.getContent().stream().map(c -> new Tuple(c.getNameAsString(), c.getArchetypeNodeId())).toArray(Tuple[]::new));
}
use of org.ehrbase.client.flattener.Unflattener in project openEHR_SDK by ehrbase.
the class OldDtoModelTest method checkTestCase.
public void checkTestCase(TestCase testCase, SoftAssertions softly) throws IOException {
String value = IOUtils.toString(testCase.simSDTJson.getStream(), UTF_8);
RMDataFormat flatJson = new FlatJasonProvider(new TestDataTemplateProvider()).buildFlatJson(FlatFormat.SIM_SDT, testCase.templateId);
Composition composition = flatJson.unmarshal(value);
Flattener flattener = new Flattener(new TestDataTemplateProvider());
Object flatten = flattener.flatten(composition, testCase.dtoClass);
Unflattener unflattener = new Unflattener(new TestDataTemplateProvider());
RMObject actual = unflattener.unflatten(flatten);
String actualFlat = flatJson.marshal(actual);
List<String> errors = compere(actualFlat, value);
softly.assertThat(errors).filteredOn(s -> s.startsWith("Missing")).as("Test Case %s", testCase.id).containsExactlyInAnyOrder(testCase.missing);
softly.assertThat(errors).filteredOn(s -> s.startsWith("Extra")).as("Test Case %s", testCase.id).containsExactlyInAnyOrder(testCase.extra);
}
Aggregations