use of com.nedap.archie.rm.composition.Composition in project openEHR_SDK by ehrbase.
the class FlatJsonUnmarshaller method unmarshal.
/**
* Unmarshal flat Json to Composition
*
* @param flat the flat Json
* @param introspect the introspect belonging to the template
* @return
*/
public Composition unmarshal(String flat, WebTemplate introspect) {
Set<String> consumedPath;
Map<String, String> currentValues;
consumedPath = new HashSet<>();
try {
currentValues = new HashMap<>();
for (Iterator<Map.Entry<String, JsonNode>> it = OBJECT_MAPPER.readTree(flat).fields(); it.hasNext(); ) {
Map.Entry<String, JsonNode> e = it.next();
currentValues.put(e.getKey(), e.getValue().toString());
}
Composition generate = WebTemplateSkeletonBuilder.build(introspect, false);
StdToCompositionWalker walker = new StdToCompositionWalker();
DefaultValues defaultValues = new DefaultValues(currentValues);
// put default for the defaults
if (!defaultValues.containsDefaultValue(DefaultValuePath.TIME)) {
defaultValues.addDefaultValue(DefaultValuePath.TIME, OffsetDateTime.now());
}
if (!defaultValues.containsDefaultValue(DefaultValuePath.SETTING)) {
defaultValues.addDefaultValue(DefaultValuePath.SETTING, Setting.OTHER_CARE);
}
String templateId = generate.getArchetypeDetails().getTemplateId().getValue();
walker.walk(generate, currentValues.entrySet().stream().collect(Collectors.toMap(e1 -> new FlatPathDto(e1.getKey()), Map.Entry::getValue)), introspect, defaultValues, templateId);
consumedPath = walker.getConsumedPaths();
if (!CollectionUtils.isEmpty(getUnconsumed(consumedPath, currentValues))) {
throw new UnmarshalException(String.format("Could not consume Parts %s", getUnconsumed(consumedPath, currentValues)));
}
return generate;
} catch (JsonProcessingException e) {
throw new UnmarshalException(e.getMessage(), e);
}
}
use of com.nedap.archie.rm.composition.Composition in project openEHR_SDK by ehrbase.
the class DefaultValuesTest 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_WITH_CONTEXT.getStream(), StandardCharsets.UTF_8);
Composition actual = cut.unmarshal(flat, webTemplate);
assertThat(actual).isNotNull();
assertThat(actual.getCategory()).isNotNull();
assertThat(actual.getCategory().getValue()).isEqualTo("event");
assertThat(actual.getLanguage()).isNotNull();
assertThat(actual.getLanguage().getCodeString()).isEqualTo(Language.DE.getCode());
assertThat(actual.getComposer()).isNotNull();
assertThat(actual.getComposer()).getClass().isAssignableFrom(PartyIdentified.class);
assertThat(((PartyIdentified) actual.getComposer()).getName()).isEqualTo("Silvia Blake");
assertThat(actual.getComposer().getExternalRef().getNamespace()).isEqualTo("HOSPITAL-NS");
assertThat(((GenericId) actual.getComposer().getExternalRef().getId()).getScheme()).isEqualTo("HOSPITAL-NS");
assertThat(((GenericId) actual.getComposer().getExternalRef().getId()).getValue()).isEqualTo("123");
assertThat(actual.getContext().getHealthCareFacility().getName()).isEqualTo("Hospital");
assertThat(actual.getContext().getStartTime()).isNotNull();
assertThat(actual.getContext().getStartTime().getValue()).isEqualTo(OffsetDateTime.of(2021, 4, 1, 12, 40, 31, 418954000, ZoneOffset.ofHours(2)));
assertThat(actual.getContext().getParticipations()).extracting(p -> ((PartyIdentified) p.getPerformer())).flatExtracting(p -> p.getIdentifiers()).extracting(DvIdentifier::getAssigner, DvIdentifier::getId, DvIdentifier::getIssuer, DvIdentifier::getType).containsExactlyInAnyOrder(new Tuple("assigner1", "id1", "issuer1", "PERSON"), new Tuple("assigner2", "id2", "issuer2", "PERSON"), new Tuple("assigner3", "id3", "issuer3", "PERSON"), new Tuple("assigner4", "id4", "issuer4", "PERSON"));
Observation observation = actual.getContent().stream().filter(c -> Observation.class.isAssignableFrom(c.getClass())).map(Observation.class::cast).findAny().orElse(null);
assertThat(observation).isNotNull();
assertThat(observation.getData()).isNotNull();
assertThat(observation.getData().getOrigin().getValue()).isEqualTo(OffsetDateTime.of(2021, 4, 1, 12, 40, 31, 418954000, ZoneOffset.ofHours(2)));
assertThat(observation.getData().getEvents().get(0).getTime().getValue()).isEqualTo(OffsetDateTime.of(2021, 4, 1, 12, 40, 31, 418954000, ZoneOffset.ofHours(2)));
assertThat(observation.getOtherParticipations()).extracting(p -> p.getFunction().getValue(), p -> ((PartyIdentified) p.getPerformer()).getName(), p -> p.getPerformer().getExternalRef().getNamespace()).containsExactlyInAnyOrder(new Tuple("requester", "Dr. Marcus Johnson", "HOSPITAL-NS"), new Tuple("performer", "Lara Markham", "HOSPITAL-NS"));
assertThat(observation.getOtherParticipations()).extracting(p -> ((PartyIdentified) p.getPerformer())).flatExtracting(p -> p.getIdentifiers()).extracting(DvIdentifier::getAssigner, DvIdentifier::getId, DvIdentifier::getIssuer, DvIdentifier::getType).containsExactlyInAnyOrder(new Tuple("assigner1", "id1", "issuer1", "PERSON"), new Tuple("assigner2", "id2", "issuer2", "PERSON"), new Tuple("assigner3", "id3", "issuer3", "PERSON"), new Tuple("assigner4", "id4", "issuer4", "PERSON"));
assertThat(observation.getWorkflowId()).isNotNull();
assertThat(observation.getWorkflowId().getNamespace()).isEqualTo("HOSPITAL-NS");
assertThat(observation.getWorkflowId().getId().getValue()).isEqualTo("567");
assertThat(observation.getWorkflowId().getType()).isEqualTo("ORGANISATION");
}
use of com.nedap.archie.rm.composition.Composition in project openEHR_SDK by ehrbase.
the class CanonicalXMLTest method unmarshalWithDefaultSchema.
@Test
public void unmarshalWithDefaultSchema() throws IOException {
String value = IOUtils.toString(CompositionTestDataCanonicalXML.DIADEM_DEFAULT_SCHEMA.getStream(), UTF_8);
CanonicalXML cut = new CanonicalXML();
Composition composition = cut.unmarshal(value, Composition.class);
assertThat(composition).isNotNull();
// assertThat(composition.getArchetypeDetails().getTemplateId().getValue()).isEqualTo("test_all_types.en.v1");
}
use of com.nedap.archie.rm.composition.Composition in project openEHR_SDK by ehrbase.
the class CanonicalXMLTest method marshal.
@Test
public void marshal() throws IOException {
String value = IOUtils.toString(CompositionTestDataCanonicalXML.ALL_TYPES.getStream(), UTF_8);
CanonicalXML cut = new CanonicalXML();
Composition composition = cut.unmarshal(value, Composition.class);
String marshal = cut.marshal(composition);
assertThat(marshal).isNotEmpty();
}
use of com.nedap.archie.rm.composition.Composition in project openEHR_SDK by ehrbase.
the class CanonicalXMLTest method unmarshal.
@Test
public void unmarshal() throws IOException {
String value = IOUtils.toString(CompositionTestDataCanonicalXML.ALL_TYPES.getStream(), UTF_8);
CanonicalXML cut = new CanonicalXML();
Composition composition = cut.unmarshal(value, Composition.class);
assertThat(composition).isNotNull();
assertThat(composition.getArchetypeDetails().getTemplateId().getValue()).isEqualTo("test_all_types.en.v1");
}
Aggregations