use of com.nedap.archie.rm.datatypes.CodePhrase in project openEHR_SDK by ehrbase.
the class WebTemplateSkeletonBuilder method build.
@SuppressWarnings("unchecked")
public static <T> T build(WebTemplateNode node, boolean withChildren, Class<T> clazz) {
String rmclass = node.getRmType();
CComplexObject elementConstraint = new CComplexObject();
elementConstraint.setRmTypeName(rmclass);
Object skeleton;
switch(rmclass) {
case "UID_BASED_ID":
skeleton = new HierObjectId();
break;
case "PARTY_PROXY":
skeleton = new PartyIdentified();
break;
case "STRING":
case "LONG":
skeleton = null;
break;
case "BOOLEAN":
skeleton = false;
break;
default:
skeleton = RM_OBJECT_CREATOR.create(elementConstraint);
break;
}
if (withChildren) {
node.getChildren().stream().filter(n -> !List.of("name", "archetype_node_id", "offset").contains(n.getId())).forEach(c -> {
Object childObject = build(c, true, Object.class);
insert(node, (RMObject) skeleton, c, childObject);
});
}
if (skeleton instanceof Locatable) {
Optional<WebTemplateNode> name = node.findChildById("name");
if (name.isPresent()) {
if (name.get().getRmType().equals(RmConstants.DV_CODED_TEXT)) {
((Locatable) skeleton).setName(extractDefault(name.get(), DvCodedText.class).orElseThrow());
} else {
((Locatable) skeleton).setName(extractDefault(name.get(), DvText.class).orElse(new DvText(node.getName())));
}
} else {
((Locatable) skeleton).setName(new DvText(node.getName()));
}
((Locatable) skeleton).setArchetypeNodeId(node.getNodeId());
}
if (skeleton instanceof Entry) {
((Entry) skeleton).setEncoding(new CodePhrase(new TerminologyId("IANA_character-sets"), "UTF-8"));
node.findChildById("subject").map(n -> build(n, false, PartyProxy.class)).ifPresent(((Entry) skeleton)::setSubject);
}
if (skeleton instanceof Composition) {
node.findChildById("category").flatMap(n -> extractDefault(n, DvCodedText.class)).ifPresent(((Composition) skeleton)::setCategory);
}
if (skeleton instanceof DvInterval) {
((DvInterval<?>) skeleton).setLowerIncluded(true);
((DvInterval<?>) skeleton).setUpperIncluded(true);
}
if (skeleton instanceof PartyRelated) {
node.findChildById("relationship").flatMap(n -> extractDefault(n, DvCodedText.class)).ifPresent(((PartyRelated) skeleton)::setRelationship);
}
if (skeleton == null || clazz.isAssignableFrom(skeleton.getClass())) {
return (T) skeleton;
} else {
throw new SdkException(String.format("%s not assignable from %s", skeleton.getClass(), clazz));
}
}
use of com.nedap.archie.rm.datatypes.CodePhrase in project openEHR_SDK by ehrbase.
the class WebTemplateSkeletonBuilder method extractDefault.
public static <T> Optional<T> extractDefault(WebTemplateNode node, Class<T> clazz) {
String rmclass = node.getRmType();
Object defaultValue = null;
switch(rmclass) {
case "DV_CODED_TEXT":
if (node.getMin() > 0) {
Optional<WebTemplateInput> code = node.getInputs().stream().filter(i -> i.getSuffix().equals("code")).filter(i -> i.getList().size() == 1).findAny();
if (code.isPresent()) {
defaultValue = new DvCodedText(code.get().getList().get(0).getLabel(), new CodePhrase(new TerminologyId(code.get().getTerminology()), code.get().getList().get(0).getValue()));
}
}
break;
default:
defaultValue = null;
}
return Optional.ofNullable((T) defaultValue);
}
use of com.nedap.archie.rm.datatypes.CodePhrase in project openEHR_SDK by ehrbase.
the class WebTemplateSkeletonBuilderTest method build.
@Test
public void build() throws XmlException, IOException {
org.openehr.schemas.v1.TemplateDocument document = org.openehr.schemas.v1.TemplateDocument.Factory.parse(OperationalTemplateTestData.BLOOD_PRESSURE_SIMPLE.getStream());
OPERATIONALTEMPLATE operationaltemplate = document.getTemplate();
WebTemplate webTemplate = new OPTParser(operationaltemplate).parse();
Composition generate = WebTemplateSkeletonBuilder.build(webTemplate, true);
assertThat(generate).isNotNull();
assertThat(generate.getCategory().getDefiningCode()).extracting(CodePhrase::getCodeString, c -> c.getTerminologyId().getValue()).containsExactly("433", "openehr");
assertThat(generate.itemAtPath("/composer")).isNotNull();
assertThat(generate.itemAtPath("/context/end_time")).isNotNull();
assertThat(generate.itemAtPath("/content[openEHR-EHR-OBSERVATION.sample_blood_pressure.v1]")).isNotNull();
assertThat(((Observation) generate.itemAtPath("/content[openEHR-EHR-OBSERVATION.sample_blood_pressure.v1]")).getEncoding()).extracting(CodePhrase::getCodeString, c -> c.getTerminologyId().getValue()).containsExactly("UTF-8", "IANA_character-sets");
assertThat(generate.itemAtPath("/content[openEHR-EHR-OBSERVATION.sample_blood_pressure.v1]/data[at0001]/events[at0002]/state[at0007]/items[at1005]/value")).isNotNull();
}
use of com.nedap.archie.rm.datatypes.CodePhrase in project openEHR_SDK by ehrbase.
the class DvCodedTextIT method testValidate_FhirCodeSystem_WrongTerminologyId.
@Test
void testValidate_FhirCodeSystem_WrongTerminologyId() throws Exception {
var codePhrase = new CodePhrase(new TerminologyId("http://hl7.org/fhir/name-use"), "usual");
var node = parseNode("/webtemplate_nodes/dv_codedtext_fhir_codesystem.json");
var result = validator.validate(new DvCodedText("Usual", codePhrase), node);
assertEquals(1, result.size());
}
use of com.nedap.archie.rm.datatypes.CodePhrase in project openEHR_SDK by ehrbase.
the class DvCodedTextIT method testValidate_FhirValueSet.
@Test
void testValidate_FhirValueSet() throws Exception {
var codePhrase = new CodePhrase(new TerminologyId("http://terminology.hl7.org/CodeSystem/v3-EntityNameUseR2"), "ANON");
var node = parseNode("/webtemplate_nodes/dv_codedtext_fhir_valueset.json");
var result = validator.validate(new DvCodedText("Anonymous", codePhrase), node);
assertTrue(result.isEmpty());
}
Aggregations