Skip to content

Commit

Permalink
hapifhir#1699 Testcase for numberChildren
Browse files Browse the repository at this point in the history
  • Loading branch information
mrunibe committed Nov 2, 2024
1 parent d90c6b3 commit f909a0c
Showing 1 changed file with 27 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ public void testCast() throws IOException, FHIRException {
StructureMap structureMap = scu.parse(fileMap, "cast");
Element target = Manager.build(context, scu.getTargetType(structureMap));
scu.transform(null, source, structureMap, target);
checkNumberChildren(target, "");
FHIRPathEngine fp = new FHIRPathEngine(context);
Assertions.assertEquals("implicit",fp.evaluateToString(target, "extension[0].value"));
Assertions.assertEquals("explicit",fp.evaluateToString(target, "extension[1].value"));
Expand All @@ -68,6 +69,7 @@ public void testDateOpVariables() throws IOException, FHIRException {
StructureMap structureMap = scu.parse(fileMap, "qr2patfordates");
Element target = Manager.build(context, scu.getTargetType(structureMap));
scu.transform(null, source, structureMap, target);
checkNumberChildren(target, "");
FHIRPathEngine fp = new FHIRPathEngine(context);
assertEquals("2023-10-26", fp.evaluateToString(target, "birthDate"));
assertEquals("2023-09-20T13:19:13.502Z", fp.evaluateToString(target, "deceased"));
Expand All @@ -82,6 +84,7 @@ public void testWhereClause() throws IOException, FHIRException {
StructureMap structureMap = scu.parse(fileMap, "whereclause");
Element target = Manager.build(context, scu.getTargetType(structureMap));
scu.transform(null, source, structureMap, target);
checkNumberChildren(target, "");
FHIRPathEngine fp = new FHIRPathEngine(context);
assertEquals("true", fp.evaluateToString(target, "rest.resource.interaction.where(code='create').exists()"));
}
Expand Down Expand Up @@ -135,6 +138,30 @@ public void testSourceElementDelimiter() throws IOException, FHIRException {
Assertions.assertEquals("-quote", structureMap.getGroup().get(0).getRule().get(1).getSourceFirstRep().getElement());
Assertions.assertEquals("-backtick", structureMap.getGroup().get(0).getRule().get(2).getSourceFirstRep().getElement());
}

// assert indices are equal to Element.numberChildren()
private void checkNumberChildren(Element e, String indent) {
System.out.println(indent + e + ", index: " + e.getIndex());
String last = "";
int index = 0;
for (Element child : e.getChildren()) {
if (child.getProperty().isList()) {
if (last.equals(child.getName())) {
index++;
} else {
last = child.getName();
index = 0;
}
// child.index = index;
Assertions.assertEquals(index, child.getIndex());
} else {
// child.index = -1;
Assertions.assertEquals(-1, child.getIndex());
}
checkNumberChildren(child, indent + " ");
}
}


@Override
public void log(String message) {
Expand Down

0 comments on commit f909a0c

Please sign in to comment.