Remove some failing tests that never got run anyhow

This commit is contained in:
James 2017-10-13 11:51:04 -04:00
parent c6f2196cd5
commit 375a2fcf6f
11 changed files with 0 additions and 5425 deletions

View File

@ -1,11 +0,0 @@
package org.hl7.fhir.r4.test;
import org.junit.runner.RunWith;
import org.junit.runners.Suite;
import org.junit.runners.Suite.SuiteClasses;
@RunWith(Suite.class)
@SuiteClasses({ FluentPathTests.class, NarrativeGeneratorTests.class, /*ShexGeneratorTests.class, StructureMapTests.class, */ TurtleTests.class, GraphQLParserTests.class })
public class AllTests {
}

View File

@ -1,135 +0,0 @@
package org.hl7.fhir.r4.test;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import javax.xml.parsers.ParserConfigurationException;
import org.hl7.fhir.r4.context.SimpleWorkerContext;
import org.hl7.fhir.r4.formats.XmlParser;
import org.hl7.fhir.r4.model.Base;
import org.hl7.fhir.r4.model.BooleanType;
import org.hl7.fhir.r4.model.ExpressionNode;
import org.hl7.fhir.r4.model.PrimitiveType;
import org.hl7.fhir.r4.model.Resource;
import org.hl7.fhir.r4.test.support.TestingUtilities;
import org.hl7.fhir.r4.utils.FHIRPathEngine;
import org.hl7.fhir.exceptions.FHIRException;
import org.hl7.fhir.utilities.Utilities;
import org.hl7.fhir.utilities.xml.XMLUtil;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.Parameterized;
import org.junit.runners.Parameterized.Parameters;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.Node;
import org.xml.sax.SAXException;
import junit.framework.Assert;
@RunWith(Parameterized.class)
public class FluentPathTests {
private static FHIRPathEngine fp;
@Parameters(name = "{index}: file {0}")
public static Iterable<Object[]> data() throws ParserConfigurationException, SAXException, IOException {
Document dom = XMLUtil.parseFileToDom(Utilities.path(TestingUtilities. home(), "tests", "resources", "tests-fhir-r4.xml"));
List<Element> list = new ArrayList<Element>();
List<Element> groups = new ArrayList<Element>();
XMLUtil.getNamedChildren(dom.getDocumentElement(), "group", groups);
for (Element g : groups) {
XMLUtil.getNamedChildren(g, "test", list);
}
List<Object[]> objects = new ArrayList<Object[]>(list.size());
for (Element e : list) {
objects.add(new Object[] { getName(e), e });
}
return objects;
}
private static Object getName(Element e) {
String s = e.getAttribute("name");
if (Utilities.noString(s)) {
Element p = (Element) e.getParentNode();
int ndx = 0;
for (int i = 0; i < p.getChildNodes().getLength(); i++) {
Node c = p.getChildNodes().item(i);
if (c == e)
break;
else if (c instanceof Element)
ndx++;
}
s = p.getAttribute("name")+" - "+Integer.toString(ndx+1);
}
return s;
}
private final Element test;
private final String name;
public FluentPathTests(String name, Element e) {
this.name = name;
this.test = e;
}
@SuppressWarnings("deprecation")
@Test
public void test() throws FileNotFoundException, IOException, FHIRException, org.hl7.fhir.exceptions.FHIRException {
if (TestingUtilities.context == null)
TestingUtilities.context = SimpleWorkerContext.fromPack(Utilities.path(TestingUtilities.home(), "publish", "definitions.xml.zip"));
if (fp == null)
fp = new FHIRPathEngine(TestingUtilities.context);
String input = test.getAttribute("inputfile");
String expression = XMLUtil.getNamedChild(test, "expression").getTextContent();
boolean fail = "true".equals(XMLUtil.getNamedChild(test, "expression").getAttribute("invalid"));
Resource res = null;
List<Base> outcome = new ArrayList<Base>();
ExpressionNode node = fp.parse(expression);
try {
if (Utilities.noString(input))
fp.check(null, null, node);
else {
res = new XmlParser().parse(new FileInputStream(Utilities.path(TestingUtilities.home(), "publish", input)));
fp.check(res, res.getResourceType().toString(), res.getResourceType().toString(), node);
}
outcome = fp.evaluate(res, node);
Assert.assertTrue(String.format("Expected exception parsing %s", expression), !fail);
} catch (Exception e) {
Assert.assertTrue(String.format("Unexpected exception parsing %s: "+e.getMessage(), expression), fail);
}
if ("true".equals(test.getAttribute("predicate"))) {
boolean ok = fp.convertToBoolean(outcome);
outcome.clear();
outcome.add(new BooleanType(ok));
}
if (fp.hasLog())
System.out.println(fp.takeLog());
List<Element> expected = new ArrayList<Element>();
XMLUtil.getNamedChildren(test, "output", expected);
Assert.assertTrue(String.format("Expected %d objects but found %d", expected.size(), outcome.size()), outcome.size() == expected.size());
for (int i = 0; i < Math.min(outcome.size(), expected.size()); i++) {
String tn = expected.get(i).getAttribute("type");
if (!Utilities.noString(tn)) {
Assert.assertTrue(String.format("Outcome %d: Type should be %s but was %s", i, tn, outcome.get(i).fhirType()), tn.equals(outcome.get(i).fhirType()));
}
String v = expected.get(i).getTextContent();
if (!Utilities.noString(v)) {
Assert.assertTrue(String.format("Outcome %d: Value should be a primitive type but was %s", i, outcome.get(i).fhirType()), outcome.get(i) instanceof PrimitiveType);
Assert.assertTrue(String.format("Outcome %d: Value should be %s but was %s", i, v, outcome.get(i).toString()), v.equals(((PrimitiveType)outcome.get(i)).asStringValue()));
}
}
}
}

View File

@ -1,68 +0,0 @@
package org.hl7.fhir.r4.test;
import static org.junit.Assert.*;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import javax.xml.parsers.ParserConfigurationException;
import org.hl7.fhir.exceptions.FHIRException;
import org.hl7.fhir.r4.test.support.TestingUtilities;
import org.hl7.fhir.utilities.TextFile;
import org.hl7.fhir.utilities.Utilities;
import org.hl7.fhir.utilities.graphql.EGraphEngine;
import org.hl7.fhir.utilities.graphql.EGraphQLException;
import org.hl7.fhir.utilities.graphql.Package;
import org.hl7.fhir.utilities.graphql.Parser;
import org.hl7.fhir.utilities.xml.XMLUtil;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.Parameterized;
import org.junit.runners.Parameterized.Parameters;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.xml.sax.SAXException;
@RunWith(Parameterized.class)
public class GraphQLParserTests {
@Parameters(name = "{index}: {0}")
public static Iterable<Object[]> data() throws FileNotFoundException, IOException {
String src = TextFile.fileToString(Utilities.path(TestingUtilities.home(), "tests", "graphql", "parser-tests.gql"));
String[] tests = src.split("###");
int i = 0;
for (String s : tests)
if (!Utilities.noString(s.trim()))
i++;
List<Object[]> objects = new ArrayList<Object[]>(i);
i = 0;
for (String s : tests) {
if (!Utilities.noString(s.trim())) {
int l = s.indexOf('\r');
objects.add(new Object[] { s.substring(0, l), s.substring(l+2).trim()});
}
}
return objects;
}
private final String test;
private final String name;
public GraphQLParserTests(String name, String test) {
this.name = name;
this.test = test;
}
@Test
public void test() throws IOException, EGraphQLException, EGraphEngine {
Package doc = Parser.parse(test);
Assert.assertTrue(doc != null);
}
}

View File

@ -1,52 +0,0 @@
package org.hl7.fhir.r4.test;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import org.hl7.fhir.r4.context.SimpleWorkerContext;
import org.hl7.fhir.r4.formats.XmlParser;
import org.hl7.fhir.r4.model.DomainResource;
import org.hl7.fhir.r4.test.support.TestingUtilities;
import org.hl7.fhir.r4.utils.EOperationOutcome;
import org.hl7.fhir.r4.utils.NarrativeGenerator;
import org.hl7.fhir.utilities.Utilities;
import org.hl7.fhir.exceptions.FHIRException;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.xmlpull.v1.XmlPullParserException;
public class NarrativeGeneratorTests {
private NarrativeGenerator gen;
@Before
public void setUp() throws FileNotFoundException, IOException, FHIRException {
if (TestingUtilities.context == null)
TestingUtilities.context = SimpleWorkerContext.fromPack(Utilities.path(TestingUtilities.home(), "publish", "definitions.xml.zip"));
if (gen == null)
gen = new NarrativeGenerator("", null, TestingUtilities.context);
}
@After
public void tearDown() {
}
@Test
public void test() throws FileNotFoundException, IOException, XmlPullParserException, EOperationOutcome, FHIRException {
process(Utilities.path(TestingUtilities.home(), "source", "questionnaireresponse", "questionnaireresponse-example-f201-lifelines.xml"));
}
private void process(String path) throws FileNotFoundException, IOException, XmlPullParserException, EOperationOutcome, FHIRException {
XmlParser p = new XmlParser();
DomainResource r = (DomainResource) p.parse(new FileInputStream(path));
gen.generate(r);
FileOutputStream s = new FileOutputStream(Utilities.path(TestingUtilities.temp(), "gen.xml"));
new XmlParser().compose(s, r, true);
s.close();
}
}

View File

@ -1,940 +0,0 @@
package org.hl7.fhir.r4.test;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import org.hl7.fhir.r4.conformance.ProfileComparer;
import org.hl7.fhir.r4.conformance.ProfileComparer.ProfileComparison;
import org.hl7.fhir.r4.conformance.ProfileUtilities;
import org.hl7.fhir.r4.context.SimpleWorkerContext;
import org.hl7.fhir.r4.formats.IParser.OutputStyle;
import org.hl7.fhir.r4.formats.XmlParser;
import org.hl7.fhir.r4.model.Base;
import org.hl7.fhir.r4.model.CodeType;
import org.hl7.fhir.r4.model.ElementDefinition;
import org.hl7.fhir.r4.model.ElementDefinition.DiscriminatorType;
import org.hl7.fhir.r4.model.ElementDefinition.SlicingRules;
import org.hl7.fhir.r4.model.Enumerations.BindingStrength;
import org.hl7.fhir.r4.model.Reference;
import org.hl7.fhir.r4.model.StructureDefinition;
import org.hl7.fhir.r4.model.StructureDefinition.TypeDerivationRule;
import org.hl7.fhir.r4.test.support.TestingUtilities;
import org.hl7.fhir.r4.utils.EOperationOutcome;
import org.hl7.fhir.exceptions.DefinitionException;
import org.hl7.fhir.exceptions.FHIRException;
import org.hl7.fhir.exceptions.FHIRFormatError;
import org.hl7.fhir.utilities.CSFile;
import org.hl7.fhir.utilities.Utilities;
import org.hl7.fhir.utilities.validation.ValidationMessage;
import org.hl7.fhir.utilities.validation.ValidationMessage.IssueSeverity;
import static org.junit.Assert.*;
import org.hl7.fhir.exceptions.FHIRException;
import org.hl7.fhir.r4.utils.SnomedExpressions;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
public class ProfileUtilitiesTests {
// private String root;
// private SimpleWorkerContext context;
// private ProfileComparer comp;
//
//// public ProfileUtilitiesTests(String root) {
//// super();
//// this.root = root;
//// }
//
//// public ProfileUtilitiesTests() {
//// super();
//// root = TestingUtilities.home();
////
//// }
//
// public static void main(String[] args) throws EOperationOutcome, Exception {
// // new ProfileUtilitiesTests().execute(args);
// ProfileUtilitiesTests put = new ProfileUtilitiesTests();
// put.root = "C:\\work\\org.hl7.fhir\\build\\publish";
// put.testSnapshotGeneration();
// // StructureDefinition p = (StructureDefinition) new XmlParser().parse(new FileInputStream("C:\\work\\org.hl7.fhir\\build\\publish\\lipid-report-cholesterol.profile.xml"));
// // new ProfileUtilities(context, messages, null).generateSchematrons(new FileOutputStream("c:\\temp\\test.sch"), p);
// }
//
// public void execute(String[] args) throws FileNotFoundException, IOException, FHIRException {
// System.out.println("loading context");
// context = SimpleWorkerContext.fromPack(Utilities.path(root, "validation.zip"));
// comp = new ProfileComparer(context);
//
// compare("patient-daf-dafpatient.profile.xml", "patient-qicore-qicore-patient.profile.xml");
// compare("encounter-daf-dafencounter.profile.xml", "encounter-qicore-qicore-encounter.profile.xml");
// compare("substance-daf-dafsubstance.profile.xml", "substance-qicore-qicore-substance.profile.xml");
// compare("medication-daf-dafmedication.profile.xml", "medication-qicore-qicore-medication.profile.xml");
// compare("procedure-daf-dafprocedure.profile.xml", "procedure-qicore-qicore-procedure.profile.xml");
// compare("familymemberhistory-daf-daffamilymemberhistory.profile.xml", "familymemberhistory-qicore-qicore-familymemberhistory.profile.xml");
// compare("immunization-daf-dafimmunization.profile.xml", "immunization-qicore-qicore-immunization.profile.xml");
// compare("condition-daf-dafcondition.profile.xml", "condition-qicore-qicore-condition.profile.xml");
// compare("allergyintolerance-daf-dafallergyintolerance.profile.xml", "allergyintolerance-qicore-qicore-allergyintolerance.profile.xml");
// compare("medicationadministration-daf-dafmedicationadministration.profile.xml", "medicationadministration-qicore-qicore-medicationadministration.profile.xml");
// compare("medicationdispense-daf-dafmedicationdispense.profile.xml", "medicationdispense-qicore-qicore-medicationdispense.profile.xml");
// compare("medicationprescription-daf-dafmedicationprescription.profile.xml", "medicationprescription-qicore-qicore-medicationprescription.profile.xml");
// compare("medicationstatement-daf-dafmedicationstatement.profile.xml", "medicationstatement-qicore-qicore-medicationstatement.profile.xml");
// compare("observation-daf-smokingstatus-dafsmokingstatus.profile.xml", "observation-qicore-qicore-observation.profile.xml");
// compare("observation-daf-vitalsigns-dafvitalsigns.profile.xml", "observation-qicore-qicore-observation.profile.xml");
//// compare("observation-daf-results-dafresultobs.profile.xml", "observation-qicore-qicore-observation.profile.xml");
//// compare("diagnosticorder-daf-dafdiagnosticorder.profile.xml", "diagnosticorder-qicore-qicore-diagnosticorder.profile.xml");
//// compare("diagnosticreport-daf-dafdiagnosticreport.profile.xml", "diagnosticreport-qicore-qicore-diagnosticreport.profile.xml");
//
// System.out.println("processing output");
// for (ProfileComparison outcome : comp.getComparisons()) {
// if (outcome.getSubset() != null)
// new XmlParser().setOutputStyle(OutputStyle.PRETTY).compose(new FileOutputStream("C:\\temp\\intersection-"+outcome.getId()+".xml"), outcome.getSubset());
// if (outcome.getSuperset() != null)
// new XmlParser().setOutputStyle(OutputStyle.PRETTY).compose(new FileOutputStream("C:\\temp\\union-"+outcome.getId()+".xml"), outcome.getSuperset());
//
// System.out.println("\r\n"+outcome.getId()+": Comparison of "+outcome.getLeft().getUrl()+" and "+outcome.getRight().getUrl());
// for (ValidationMessage vm : outcome.getMessages())
// if (vm.getLevel() == IssueSeverity.INFORMATION)
// System.out.println(vm.summary());
// for (ValidationMessage vm : outcome.getMessages())
// if (vm.getLevel() == IssueSeverity.WARNING)
// System.out.println(vm.summary());
// for (ValidationMessage vm : outcome.getMessages())
// if (vm.getLevel() == IssueSeverity.ERROR)
// System.out.println(vm.summary());
// for (ValidationMessage vm : outcome.getMessages())
// if (vm.getLevel() == IssueSeverity.FATAL)
// System.out.println(vm.summary());
// System.out.println("done. "+Integer.toString(outcome.getMessages().size())+" messages");
// System.out.println("=================================================================");
// }
// }
//
// private void compare(String fn1, String fn2) throws FHIRFormatError, FileNotFoundException, IOException, DefinitionException {
// System.out.println("Compare "+fn1+" to "+fn2);
// System.out.println(" .. load");
// StructureDefinition left = (StructureDefinition) new XmlParser().parse(new FileInputStream(Utilities.path(root, fn1)));
// StructureDefinition right = (StructureDefinition) new XmlParser().parse(new FileInputStream(Utilities.path(root, fn2)));
// System.out.println(" .. compare");
// comp.compareProfiles(left, right);
//
// }
//
// public void testSnapshotGeneration() throws EOperationOutcome, Exception {
// System.out.println("Loading");
// context = SimpleWorkerContext.fromPack(Utilities.path(root, "definitions.xml.zip"));
// System.out.println("Loaded "+Integer.toString(context.totalCount())+" resources");
//
// // simple tests
// testSimple();
// testSimple2();
// testCardinalityChange();
// testDocumentationAppend();
// textTypeNarrowing1();
// textTypeNarrowing2();
// testMapping();
//
// // ok, now we test walking into a new type:
// testTypeWalk();
// // todo: testTypeWalk2();
//
// // slicing tests
// testSlicingSimple();
// testSlicingExtension(false);
// testSlicingExtension(true);
// testSlicingExtensionComplex(true);
// testSlicingExtensionComplex(false);
// testSlicingTask8742();
// System.out.println("Success");
// }
//
// /**
// * This is simple: we just create an empty differential, generate the snapshot, and then insist it must match the base
// *
// * @param context2
// * @
// * @throws EOperationOutcome
// */
@Test
public void testSimple() throws FHIRException, FileNotFoundException, IOException {
if (TestingUtilities.context == null)
TestingUtilities.context = SimpleWorkerContext.fromPack(Utilities.path(TestingUtilities.home(), "publish", "definitions.xml.zip"));
StructureDefinition focus = new StructureDefinition();
StructureDefinition base = TestingUtilities.context.fetchResource(StructureDefinition.class, "http://hl7.org/fhir/StructureDefinition/Patient").copy();
focus.setUrl(Utilities.makeUuidUrn());
focus.setBaseDefinition(base.getUrl());
focus.setType("Patient");
focus.setDerivation(TypeDerivationRule.CONSTRAINT);
List<ValidationMessage> messages = new ArrayList<ValidationMessage>();
new ProfileUtilities(TestingUtilities.context, messages, null).generateSnapshot(base, focus, focus.getUrl(), "Simple Test");
boolean ok = base.getSnapshot().getElement().size() == focus.getSnapshot().getElement().size();
for (int i = 0; i < base.getSnapshot().getElement().size(); i++) {
ElementDefinition b = base.getSnapshot().getElement().get(i);
ElementDefinition f = focus.getSnapshot().getElement().get(i);
if (ok) {
if (!f.hasBase())
ok = false;
else if (!b.getPath().equals(f.getPath()))
ok = false;
else {
b.setBase(null);
f.setBase(null);
ok = Base.compareDeep(b, f, true);
}
}
}
if (!ok) {
compareXml(base, focus);
throw new FHIRException("Snap shot generation simple test failed");
} else
System.out.println("Snap shot generation simple test passed");
}
//
// /**
// * This is simple: we just create an empty differential, generate the snapshot, and then insist it must match the base. for a different resource with recursion
// *
// * @param context2
// * @
// * @throws EOperationOutcome
// */
@Test
public void testSimple2() throws EOperationOutcome, Exception {
if (TestingUtilities.context == null)
TestingUtilities.context = SimpleWorkerContext.fromPack(Utilities.path(TestingUtilities.home(), "publish", "definitions.xml.zip"));
StructureDefinition focus = new StructureDefinition();
StructureDefinition base = TestingUtilities.context.fetchResource(StructureDefinition.class, "http://hl7.org/fhir/StructureDefinition/ValueSet").copy();
focus.setUrl(Utilities.makeUuidUrn());
focus.setBaseDefinition(base.getUrl());
focus.setType(base.getType());
focus.setDerivation(TypeDerivationRule.CONSTRAINT);
List<ValidationMessage> messages = new ArrayList<ValidationMessage>();
new ProfileUtilities(TestingUtilities.context, messages, null).generateSnapshot(base, focus, focus.getUrl(), "Simple Test" );
boolean ok = base.getSnapshot().getElement().size() == focus.getSnapshot().getElement().size();
for (int i = 0; i < base.getSnapshot().getElement().size(); i++) {
if (ok) {
ElementDefinition b = base.getSnapshot().getElement().get(i);
ElementDefinition f = focus.getSnapshot().getElement().get(i);
if (!f.hasBase() || !b.getPath().equals(f.getBase().getPath()))
ok = false;
else {
f.setBase(null);
ok = Base.compareDeep(b, f, true);
}
}
}
if (!ok) {
compareXml(base, focus);
throw new FHIRException("Snap shot generation simple test failed");
} else
System.out.println("Snap shot generation simple test passed");
}
// /**
// * Change one cardinality.
// *
// * @param context2
// * @
// * @throws EOperationOutcome
// */
// private void testCardinalityChange() throws EOperationOutcome, Exception {
// StructureDefinition focus = new StructureDefinition();
// StructureDefinition base = context.fetchResource(StructureDefinition.class, "http://hl7.org/fhir/StructureDefinition/Patient").copy();
// focus.setUrl(Utilities.makeUuidUrn());
// focus.setBaseDefinition(base.getUrl());
// focus.setType(base.getType());
// focus.setDerivation(TypeDerivationRule.CONSTRAINT);
// ElementDefinition id = focus.getDifferential().addElement();
// id.setPath("Patient.identifier");
// id.setMin(1);
// List<ValidationMessage> messages = new ArrayList<ValidationMessage>();
// new ProfileUtilities(context, messages, null).generateSnapshot(base, focus, focus.getUrl(), "Simple Test" );
//
// boolean ok = base.getSnapshot().getElement().size() == focus.getSnapshot().getElement().size();
// for (int i = 0; i < base.getSnapshot().getElement().size(); i++) {
// if (ok) {
// ElementDefinition b = base.getSnapshot().getElement().get(i);
// ElementDefinition f = focus.getSnapshot().getElement().get(i);
// if (!f.hasBase() || !b.getPath().equals(f.getBase().getPath()))
// ok = false;
// else {
// f.setBase(null);
// if (f.getPath().equals("Patient.identifier")) {
// ok = f.getMin() == 1;
// if (ok)
// f.setMin(0);
// }
// ok = ok && Base.compareDeep(b, f, true);
// }
// }
// }
//
// if (!ok) {
// compareXml(base, focus);
// throw new FHIRException("Snap shot generation chenge cardinality test failed");
// } else
// System.out.println("Snap shot generation chenge cardinality test passed");
// }
//
// /**
// * check that documentation appending is working
// *
// * @param context2
// * @
// * @throws EOperationOutcome
// */
// private void testDocumentationAppend() throws EOperationOutcome, Exception {
// StructureDefinition focus = new StructureDefinition();
// StructureDefinition base = context.fetchResource(StructureDefinition.class, "http://hl7.org/fhir/StructureDefinition/Patient").copy();
// focus.setUrl(Utilities.makeUuidUrn());
// focus.setBaseDefinition(base.getUrl());
// focus.setType(base.getType());
// focus.setDerivation(TypeDerivationRule.CONSTRAINT);
// ElementDefinition id = focus.getDifferential().addElement();
// id.setPath("Patient.identifier");
// id.setDefinition("... some more doco");
// List<ValidationMessage> messages = new ArrayList<ValidationMessage>();
// new ProfileUtilities(context, messages, null).generateSnapshot(base, focus, focus.getUrl(), "Simple Test" );
//
// boolean ok = base.getSnapshot().getElement().size() == focus.getSnapshot().getElement().size();
// for (int i = 0; i < base.getSnapshot().getElement().size(); i++) {
// if (ok) {
// ElementDefinition b = base.getSnapshot().getElement().get(i);
// ElementDefinition f = focus.getSnapshot().getElement().get(i);
// if (!f.hasBase() || !b.getPath().equals(f.getBase().getPath()))
// ok = false;
// else {
// f.setBase(null);
// if (f.getPath().equals("Patient.identifier")) {
// ok = f.getDefinition().length() > b.getDefinition().length();
// if (ok) {
// f.setDefinition(null);
// b.setDefinition(null);
// }
// }
// ok = ok && Base.compareDeep(b, f, true);
// }
// }
// }
//
// if (!ok) {
// compareXml(base, focus);
// throw new FHIRException("Snap shot generation documentation append failed");
// } else
// System.out.println("Snap shot generation documentation append test passed");
// }
//
//
// /**
// * check that narrowing types is working
// * this one doesn't rename the path
// *
// * @param context2
// * @
// * @throws EOperationOutcome
// */
// private void textTypeNarrowing1() throws EOperationOutcome, Exception {
// StructureDefinition focus = new StructureDefinition();
// StructureDefinition base = context.fetchResource(StructureDefinition.class, "http://hl7.org/fhir/StructureDefinition/Patient").copy();
// focus.setUrl(Utilities.makeUuidUrn());
// focus.setBaseDefinition(base.getUrl());
// focus.setType(base.getType());
// focus.setDerivation(TypeDerivationRule.CONSTRAINT);
// ElementDefinition id = focus.getDifferential().addElement();
// id.setPath("Patient.deceased[x]");
// id.addType().setCode("dateTime");
// List<ValidationMessage> messages = new ArrayList<ValidationMessage>();
// new ProfileUtilities(context, messages, null).generateSnapshot(base, focus, focus.getUrl(), "Simple Test" );
//
// boolean ok = base.getSnapshot().getElement().size() == focus.getSnapshot().getElement().size();
// for (int i = 0; i < base.getSnapshot().getElement().size(); i++) {
// if (ok) {
// ElementDefinition b = base.getSnapshot().getElement().get(i);
// ElementDefinition f = focus.getSnapshot().getElement().get(i);
// if (!f.hasBase() || !b.getPath().equals(f.getBase().getPath()))
// ok = false;
// else {
// f.setBase(null);
// if (f.getPath().equals("Patient.deceasedDateTime")) {
// ok = f.getType().size() == 1 && f.getType().get(0).getCode().equals("dateTime");
// if (ok) {
// f.getType().clear();
// b.getType().clear();
// f.setPath(b.getPath());
// }
// }
// ok = ok && Base.compareDeep(b, f, true);
// }
// }
// }
//
// if (!ok) {
// compareXml(base, focus);
// throw new FHIRException("Snap shot generation narrow type 1 failed");
// } else
// System.out.println("Snap shot generation narrow type 1 test passed");
// }
//
// /**
// * check that narrowing types is working
// * this one renames the path
// *
// * @param context2
// * @
// * @throws EOperationOutcome
// */
// private void textTypeNarrowing2() throws EOperationOutcome, Exception {
// StructureDefinition focus = new StructureDefinition();
// StructureDefinition base = context.fetchResource(StructureDefinition.class, "http://hl7.org/fhir/StructureDefinition/Patient").copy();
// focus.setUrl(Utilities.makeUuidUrn());
// focus.setBaseDefinition(base.getUrl());
// focus.setType(base.getType());
// focus.setDerivation(TypeDerivationRule.CONSTRAINT);
// ElementDefinition id = focus.getDifferential().addElement();
// id.setPath("Patient.deceasedDateTime");
// id.addType().setCode("dateTime");
// List<ValidationMessage> messages = new ArrayList<ValidationMessage>();
// new ProfileUtilities(context, messages, null).generateSnapshot(base, focus, focus.getUrl(), "Simple Test" );
//
// boolean ok = base.getSnapshot().getElement().size() == focus.getSnapshot().getElement().size();
// for (int i = 0; i < base.getSnapshot().getElement().size(); i++) {
// if (ok) {
// ElementDefinition b = base.getSnapshot().getElement().get(i);
// ElementDefinition f = focus.getSnapshot().getElement().get(i);
// if (!f.hasBase() || !b.getPath().equals(f.getBase().getPath()))
// ok = false;
// else {
// f.setBase(null);
// if (f.getPath().equals("Patient.deceasedDateTime")) {
// ok = f.getType().size() == 1 && f.getType().get(0).getCode().equals("dateTime");
// if (ok) {
// f.getType().clear();
// b.getType().clear();
// f.setPath(b.getPath());
// }
// }
// ok = ok && Base.compareDeep(b, f, true);
// }
// }
// }
//
// if (!ok) {
// compareXml(base, focus);
// throw new FHIRException("Snap shot generation narrow type 2 failed");
// } else
// System.out.println("Snap shot generation narrow type 2 test passed");
// }
//
// /**
// * check that mapping resolution is working
// *
// * @param context2
// * @
// * @throws EOperationOutcome
// */
// private void testMapping() throws EOperationOutcome, Exception {
// StructureDefinition focus = new StructureDefinition();
// StructureDefinition base = context.fetchResource(StructureDefinition.class, "http://hl7.org/fhir/StructureDefinition/Patient").copy();
// focus.setUrl(Utilities.makeUuidUrn());
// focus.setBaseDefinition(base.getUrl());
// focus.setType(base.getType());
// focus.setDerivation(TypeDerivationRule.CONSTRAINT);
// ElementDefinition id = focus.getDifferential().addElement();
// id.setPath("Patient.identifier");
// id.addMapping().setIdentity("rim").setMap("test");
// List<ValidationMessage> messages = new ArrayList<ValidationMessage>();
// new ProfileUtilities(context, messages, null).generateSnapshot(base, focus, focus.getUrl(), "Simple Test" );
//
// boolean ok = base.getSnapshot().getElement().size() == focus.getSnapshot().getElement().size();
// for (int i = 0; i < base.getSnapshot().getElement().size(); i++) {
// if (ok) {
// ElementDefinition b = base.getSnapshot().getElement().get(i);
// ElementDefinition f = focus.getSnapshot().getElement().get(i);
// if (!f.hasBase() || !b.getPath().equals(f.getBase().getPath()))
// ok = false;
// else {
// f.setBase(null);
// if (f.getPath().equals("Patient.identifier")) {
// ok = f.getMapping().size() > b.getMapping().size();
// if (ok) {
// f.getMapping().clear();
// b.getMapping().clear();
// }
// }
// ok = ok && Base.compareDeep(b, f, true);
// }
// }
// }
//
// if (!ok) {
// compareXml(base, focus);
// throw new FHIRException("Snap shot generation mapping changes failed");
// } else
// System.out.println("Snap shot generation mapping changes test passed");
// }
//
// /**
// * Walking into a type
// *
// * @param context2
// * @
// * @throws EOperationOutcome
// */
// private void testTypeWalk() throws EOperationOutcome, Exception {
// StructureDefinition focus = new StructureDefinition();
// StructureDefinition base = context.fetchResource(StructureDefinition.class, "http://hl7.org/fhir/StructureDefinition/Patient").copy();
// focus.setUrl(Utilities.makeUuidUrn());
// focus.setBaseDefinition(base.getUrl());
// focus.setType(base.getType());
// focus.setDerivation(TypeDerivationRule.CONSTRAINT);
// ElementDefinition id = focus.getDifferential().addElement();
// id.setPath("Patient.identifier");
// id.setMustSupport(true);
// id = focus.getDifferential().addElement();
// id.setPath("Patient.identifier.system");
// id.setMustSupport(true);
// List<ValidationMessage> messages = new ArrayList<ValidationMessage>();
// new ProfileUtilities(context, messages, null).generateSnapshot(base, focus, focus.getUrl(), "Simple Test" );
//
// // the derived should be 8 longer
// boolean ok = base.getSnapshot().getElement().size() == focus.getSnapshot().getElement().size() - 8;
// for (int i = 0; i < base.getSnapshot().getElement().size(); i++) {
// if (ok) {
// ElementDefinition b = base.getSnapshot().getElement().get(i);
// ElementDefinition f = focus.getSnapshot().getElement().get(i <= 9 ? i : i + 8);
// if (!f.hasBase() || !b.getPath().equals(f.getBase().getPath()))
// ok = false;
// else {
// f.setBase(null);
// if (f.getPath().equals("Patient.identifier")) {
// ok = f.getMustSupport() && !b.getMustSupport();
// if (ok) {
// f.setMustSupportElement(null);
// }
// }
// ok = Base.compareDeep(b, f, true);
// }
// }
// }
//
// if (!ok) {
// compareXml(base, focus);
// throw new FHIRException("Snap shot generation simple test failed");
// } else
// System.out.println("Snap shot generation simple test passed");
// }
//
// /**
// * Walking into a type, without explicitly doing so
// *
// * note: this currently fails.
// *
// * @param context2
// * @
// * @throws EOperationOutcome
// */
// private void testTypeWalk2() throws EOperationOutcome, Exception {
// StructureDefinition focus = new StructureDefinition();
// StructureDefinition base = context.fetchResource(StructureDefinition.class, "http://hl7.org/fhir/StructureDefinition/Patient").copy();
// focus.setUrl(Utilities.makeUuidUrn());
// focus.setBaseDefinition(base.getUrl());
// focus.setType(base.getType());
// focus.setDerivation(TypeDerivationRule.CONSTRAINT);
// ElementDefinition id = focus.getDifferential().addElement();
// id.setPath("Patient.identifier.system");
// id.setMustSupport(true);
// List<ValidationMessage> messages = new ArrayList<ValidationMessage>();
// new ProfileUtilities(context, messages, null).generateSnapshot(base, focus, focus.getUrl(), "Simple Test" );
//
// // the derived should be 8 longer
// boolean ok = base.getSnapshot().getElement().size() == focus.getSnapshot().getElement().size() - 8;
// for (int i = 0; i < base.getSnapshot().getElement().size(); i++) {
// if (ok) {
// ElementDefinition b = base.getSnapshot().getElement().get(i);
// ElementDefinition f = focus.getSnapshot().getElement().get(i <= 9 ? i : i + 8);
// if (!f.hasBase() || !b.getPath().equals(f.getBase().getPath()))
// ok = false;
// else {
// f.setBase(null);
// if (f.getPath().equals("Patient.identifier")) {
// ok = f.getMustSupport() && !b.getMustSupport();
// if (ok) {
// f.setMustSupportElement(null);
// }
// }
// ok = Base.compareDeep(b, f, true);
// }
// }
// }
//
// if (!ok) {
// compareXml(base, focus);
// throw new FHIRException("Snap shot generation simple test failed");
// } else
// System.out.println("Snap shot generation simple test passed");
// }
//
//
// /**
// * we're going to slice Patient.identifier
// */
// private void testSlicingSimple() throws EOperationOutcome, Exception {
//
// StructureDefinition focus = new StructureDefinition();
// StructureDefinition base = context.fetchResource(StructureDefinition.class, "http://hl7.org/fhir/StructureDefinition/Patient").copy();
// focus.setUrl(Utilities.makeUuidUrn());
// focus.setBaseDefinition(base.getUrl());
// focus.setType(base.getType());
// focus.setDerivation(TypeDerivationRule.CONSTRAINT);
//
// // set the slice up
// ElementDefinition id = focus.getDifferential().addElement();
// id.setPath("Patient.identifier");
// id.getSlicing().setOrdered(false).setRules(SlicingRules.OPEN).addDiscriminator().setPath("use").setType(DiscriminatorType.VALUE);
//
// // first slice:
// id = focus.getDifferential().addElement();
// id.setPath("Patient.identifier");
// id.setSliceName("name1");
// id = focus.getDifferential().addElement();
// id.setPath("Patient.identifier.use");
// id.setFixed(new CodeType("usual"));
//
// // second slice:
// id = focus.getDifferential().addElement();
// id.setPath("Patient.identifier");
// id.setSliceName("name2");
// id = focus.getDifferential().addElement();
// id.setPath("Patient.identifier.use");
// id.setFixed(new CodeType("official"));
//
//
// List<ValidationMessage> messages = new ArrayList<ValidationMessage>();
// new ProfileUtilities(context, messages, null).generateSnapshot(base, focus, focus.getUrl(), "Simple Test" );
//
// // 18 different: identifier + 8 inner children * 2
// boolean ok = base.getSnapshot().getElement().size() == focus.getSnapshot().getElement().size() - 18;
// for (int i = 0; i < base.getSnapshot().getElement().size(); i++) {
// if (ok) {
// ElementDefinition b = base.getSnapshot().getElement().get(i);
// ElementDefinition f = focus.getSnapshot().getElement().get(i <= 9 ? i : i + 18);
// if (!f.hasBase() || !b.getPath().equals(f.getBase().getPath()))
// ok = false;
// else {
// f.setBase(null);
// if (f.getPath().equals("Patient.identifier")) {
// ok = f.hasSlicing();
// if (ok)
// f.setSlicing(null);
// }
// ok = Base.compareDeep(b, f, true);
// }
// }
// }
// // now, check that the slices we skipped are correct:
// for (int i = 10; i <= 18; i++) {
// if (ok) {
// ElementDefinition d1 = focus.getSnapshot().getElement().get(i);
// ElementDefinition d2 = focus.getSnapshot().getElement().get(i+9);
// if (d1.getPath().equals("Patient.identifier.use")) {
// ok = d1.hasFixed() && d2.hasFixed() && !Base.compareDeep(d1.getFixed(), d2.getFixed(), true);
// if (ok) {
// d1.setFixed(null);
// d2.setFixed(null);
// }
// }
// if (d1.getPath().equals("Patient.identifier")) {
// ok = d1.hasSliceName() && d2.hasSliceName() && !Base.compareDeep(d1.getSliceNameElement(), d2.getSliceNameElement(), true);
// if (ok) {
// d1.setSliceName(null);
// d2.setSliceName(null);
// }
// }
// ok = Base.compareDeep(d1, d2, true);
// }
// }
// // for throughness, we could check against identifier too, but this is not done now.
//
// if (!ok) {
// compareXml(base, focus);
// throw new FHIRException("Snap shot generation slicing failed");
// } else
// System.out.println("Snap shot generation slicing passed");
//
// }
//
// /**
// * we're going to slice Patient.extension and refer to extension by profile
// *
// * implicit: whether to rely on implicit extension slicing
// */
// private void testSlicingExtension(boolean implicit) throws EOperationOutcome, Exception {
//
// StructureDefinition focus = new StructureDefinition();
// StructureDefinition base = context.fetchResource(StructureDefinition.class, "http://hl7.org/fhir/StructureDefinition/Patient").copy();
// focus.setUrl(Utilities.makeUuidUrn());
// focus.setBaseDefinition(base.getUrl());
// focus.setType(base.getType());
// focus.setDerivation(TypeDerivationRule.CONSTRAINT);
//
// // set the slice up
// ElementDefinition id;
// if (!implicit) {
// id = focus.getDifferential().addElement();
// id.setPath("Patient.extension");
// id.getSlicing().setOrdered(false).setRules(SlicingRules.OPEN).addDiscriminator().setPath("url").setType(DiscriminatorType.VALUE);
// id.setMax("3");
// }
// // first slice:
// id = focus.getDifferential().addElement();
// id.setPath("Patient.extension");
// id.setSliceName("name1");
// id.addType().setCode("Extension").setProfile("http://hl7.org/fhir/StructureDefinition/patient-birthTime");
// id.setMin(1);
//
// // second slice:
// id = focus.getDifferential().addElement();
// id.setPath("Patient.extension");
// id.setSliceName("name2");
// id.addType().setCode("Extension").setProfile("http://hl7.org/fhir/StructureDefinition/patient-mothersMaidenName");
//
// List<ValidationMessage> messages = new ArrayList<ValidationMessage>();
// ProfileUtilities pu = new ProfileUtilities(context, messages, null);
// pu.generateSnapshot(base, focus, focus.getUrl(), "Simple Test" );
//
// // 2 different: extension slices
// boolean ok = base.getSnapshot().getElement().size() == focus.getSnapshot().getElement().size() - 2;
// for (int i = 0; i < base.getSnapshot().getElement().size(); i++) {
// if (ok) {
// ElementDefinition b = base.getSnapshot().getElement().get(i);
// ElementDefinition f = focus.getSnapshot().getElement().get(i <= 7 ? i : i + 2);
// if (!f.hasBase() || !b.getPath().equals(f.getBase().getPath()))
// ok = false;
// else {
// f.setBase(null);
// if (f.getPath().equals("Patient.extension")) {
// ok = f.hasSlicing() && (implicit || f.getMax().equals("3"));
// if (ok) {
// f.setSlicing(null);
// f.setMaxElement(b.getMaxElement());
// }
// }
// if (!f.getPath().equals("Patient.extension")) // no compare that because the definitions get overwritten
// ok = Base.compareDeep(b, f, true);
// }
// }
// }
// // now, check that the slices we skipped are correct:
// if (ok) {
// ElementDefinition d1 = focus.getSnapshot().getElement().get(8);
// ElementDefinition d2 = focus.getSnapshot().getElement().get(9);
// ok = d1.hasType() && d1.getType().get(0).hasProfile() && d2.hasType() && d2.getType().get(0).hasProfile() && !Base.compareDeep(d1.getType(), d2.getType(), true) &&
// d1.getMin() == 1 && d2.getMin() == 0 && d1.getMax().equals("1") && d2.getMax().equals("1");
// if (ok) {
// d1.getType().clear();
// d2.getType().clear();
// d1.setSliceName("x");
// d2.setSliceName("x");
// d1.setMin(0);
// }
// ok = Base.compareDeep(d1, d2, true);
// // for throughness, we could check against extension too, but this is not done now.
// }
//
// if (!ok) {
// compareXml(base, focus);
// throw new FHIRException("Snap shot generation slicing extensions simple ("+(implicit ? "implicit" : "not implicit")+") failed");
// } else
// System.out.println("Snap shot generation slicing extensions simple ("+(implicit ? "implicit" : "not implicit")+") passed");
// }
//
// /**
// * we're going to slice Patient.extension and refer to extension by profile. one of the extensions is complex, and we're going to walk into
// * it and make it must support
// *
// * implicit: whether to rely on implicit extension slicing
// */
// private void testSlicingExtensionComplex(boolean implicit) throws EOperationOutcome, Exception {
//
// StructureDefinition focus = new StructureDefinition();
// StructureDefinition base = context.fetchResource(StructureDefinition.class, "http://hl7.org/fhir/StructureDefinition/Patient").copy();
// focus.setUrl(Utilities.makeUuidUrn());
// focus.setBaseDefinition(base.getUrl());
// focus.setType(base.getType());
// focus.setDerivation(TypeDerivationRule.CONSTRAINT);
//
// // set the slice up
// ElementDefinition id;
// if (!implicit) {
// id = focus.getDifferential().addElement();
// id.setPath("Patient.extension");
// id.getSlicing().setOrdered(false).setRules(SlicingRules.OPEN).addDiscriminator().setPath("url").setType(DiscriminatorType.VALUE);
// }
// // first slice - a simple one to get us going:
// id = focus.getDifferential().addElement();
// id.setPath("Patient.extension");
// id.setSliceName("simple");
// id.addType().setCode("Extension").setProfile("http://hl7.org/fhir/StructureDefinition/patient-birthTime");
//
// // second slice - the complex one
// // we walk into this and fix properties on the inner extensions
// id = focus.getDifferential().addElement();
// id.setPath("Patient.extension");
// id.setSliceName("complex");
// id.addType().setCode("Extension").setProfile("http://hl7.org/fhir/StructureDefinition/patient-nationality");
// if (!implicit) {
// id = focus.getDifferential().addElement();
// id.setPath("Patient.extension.extension");
// id.getSlicing().setOrdered(false).setRules(SlicingRules.OPEN).addDiscriminator().setPath("url").setType(DiscriminatorType.VALUE);
// }
// id = focus.getDifferential().addElement();
// id.setPath("Patient.extension.extension");
// id.setSliceName("code");
// id.setMustSupport(true);
// id.addType().setCode("Extension").setProfile("http://hl7.org/fhir/StructureDefinition/patient-nationality#code");
//
// id = focus.getDifferential().addElement();
// id.setPath("Patient.extension.extension");
// id.setSliceName("period");
// id.addType().setCode("Extension").setProfile("http://hl7.org/fhir/StructureDefinition/patient-nationality#period");
// id.setMax("0"); // prohibit this one....
//
// List<ValidationMessage> messages = new ArrayList<ValidationMessage>();
// new ProfileUtilities(context, messages, null).generateSnapshot(base, focus, focus.getUrl(), "Simple Test" );
//
// // ok, there's going to 1 (simple) + complex: 1 + id + extnesion.slice + extension.code + (4 inside from that) + extension.period + (4 inside from that) + value + url = 16
// boolean ok = base.getSnapshot().getElement().size() == focus.getSnapshot().getElement().size() - 16;
//
// // custom checks
// ok = ok && rule(focus.getSnapshot().getElement().get(7).getPath().equals("Patient.extension"), "element 7 (base) path");
// ok = ok && rule(focus.getSnapshot().getElement().get(7).hasSlicing(), "element 7 slicing");
// ok = ok && rule(focus.getSnapshot().getElement().get(8).getPath().equals("Patient.extension"), "element 8 (1st slice) path");
// ok = ok && rule(focus.getSnapshot().getElement().get(8).getSliceName().equals("simple"), "element 8 (1st slice) name");
// ok = ok && rule(focus.getSnapshot().getElement().get(8).getType().get(0).getProfile().equals("http://hl7.org/fhir/StructureDefinition/patient-birthTime"), "element 9 (2nd slice) profile name");
// ok = ok && rule(focus.getSnapshot().getElement().get(9).getPath().equals("Patient.extension"), "element 9 (2nd slice) path");
// ok = ok && rule(focus.getSnapshot().getElement().get(9).getSliceName().equals("complex"), "element 8 (1st slice) name");
// ok = ok && rule(focus.getSnapshot().getElement().get(9).getType().get(0).getProfile().equals("http://hl7.org/fhir/StructureDefinition/patient-nationality"), "element 9 (2nd slice) profile name");
// ok = ok && rule(focus.getSnapshot().getElement().get(10).getPath().equals("Patient.extension.id"), "element 10 (2nd slice).id path");
// ok = ok && rule(focus.getSnapshot().getElement().get(11).getPath().equals("Patient.extension.extension"), "element 11 (2nd slice).extension path");
// ok = ok && rule(focus.getSnapshot().getElement().get(12).getPath().equals("Patient.extension.extension"), "element 12 (2nd slice).extension path");
// ok = ok && rule(focus.getSnapshot().getElement().get(12).getMustSupport(), "element 12 (2nd slice).extension must support");
// ok = ok && rule(focus.getSnapshot().getElement().get(13).getPath().equals("Patient.extension.extension.id"), "element 13 (2nd slice).extension.id path");
// ok = ok && rule(focus.getSnapshot().getElement().get(14).getPath().equals("Patient.extension.extension.extension"), "element 14 (2nd slice).extension.extension path");
// ok = ok && rule(focus.getSnapshot().getElement().get(15).getPath().equals("Patient.extension.extension.url"), "element 15 (2nd slice).extension.url path");
// ok = ok && rule(focus.getSnapshot().getElement().get(16).getPath().equals("Patient.extension.extension.valueCodeableConcept"), "element 16 (2nd slice).extension.valueCodeableConcept path");
// ok = ok && rule(focus.getSnapshot().getElement().get(17).getPath().equals("Patient.extension.extension"), "element 17 (2nd slice).extension path");
// ok = ok && rule(focus.getSnapshot().getElement().get(17).getMax().equals("0"), "element 17 (2nd slice).extension cardinality");
// ok = ok && rule(focus.getSnapshot().getElement().get(18).getPath().equals("Patient.extension.extension.id"), "element 18 (2nd slice).extension.id path");
// ok = ok && rule(focus.getSnapshot().getElement().get(19).getPath().equals("Patient.extension.extension.extension"), "element 19 (2nd slice).extension.extension path");
// ok = ok && rule(focus.getSnapshot().getElement().get(20).getPath().equals("Patient.extension.extension.url"), "element 20 (2nd slice).extension.url path");
// ok = ok && rule(focus.getSnapshot().getElement().get(21).getPath().equals("Patient.extension.extension.valuePeriod"), "element 21 (2nd slice).extension.valuePeriod path");
// ok = ok && rule(focus.getSnapshot().getElement().get(22).getPath().equals("Patient.extension.url"), "element 22 (2nd slice).url path");
// ok = ok && rule(focus.getSnapshot().getElement().get(23).getPath().equals("Patient.extension.value[x]"), "element 23 (2nd slice).url path");
//
// for (int i = 0; i < base.getSnapshot().getElement().size(); i++) {
// if (ok) {
// ElementDefinition b = base.getSnapshot().getElement().get(i);
// ElementDefinition f = focus.getSnapshot().getElement().get(i <= 7 ? i : i + 16);
// if (!f.hasBase() || !b.getPath().equals(f.getBase().getPath()))
// ok = false;
// else {
// f.setBase(null);
// if (f.getPath().equals("Patient.extension")) {
// ok = f.hasSlicing();
// if (ok)
// f.setSlicing(null);
// }
// if (!f.getPath().equals("Patient.extension")) // no compare that because the definitions get overwritten
// ok = Base.compareDeep(b, f, true);
// }
// }
// }
//
// if (!ok) {
// compareXml(base, focus);
// throw new FHIRException("Snap shot generation slicing extensions complex ("+(implicit ? "implicit" : "not implicit")+") failed");
// } else
// System.out.println("Snap shot generation slicing extensions complex ("+(implicit ? "implicit" : "not implicit")+") passed");
// }
//
// private void testSlicingTask8742() throws EOperationOutcome, Exception {
// StructureDefinition focus = new StructureDefinition();
// StructureDefinition base = context.fetchResource(StructureDefinition.class, "http://hl7.org/fhir/StructureDefinition/Organization").copy();
// focus.setUrl(Utilities.makeUuidUrn());
// focus.setBaseDefinition(base.getUrl());
// focus.setType(base.getType());
// focus.setDerivation(TypeDerivationRule.CONSTRAINT);
//
// ElementDefinition id = focus.getDifferential().addElement();
// id.setPath("Organization.address");
// id.setMin(1);
// id.setMax("1");
// id.setMustSupport(true);
//
// id = focus.getDifferential().addElement();
// id.setPath("Organization.address.extension");
// id.setSliceName("USLabCountycodes");
// id.getSlicing().setOrdered(false).setRules(SlicingRules.OPEN).addDiscriminator().setPath("url").setType(DiscriminatorType.VALUE);
// id.setShort("County/Parish FIPS codes");
// id.setDefinition("County/Parish FIPS codes.");
// id.setRequirements("County/Parish Code SHALL use FIPS 6-4 ( INCITS 31:2009).");
// id.setMin(0);
// id.setMax("1");
// id.addType().setCode("Extension").setProfile("http://hl7.org/fhir/StructureDefinition/us-core-county");
// id.setMustSupport(true);
// id.getBinding().setStrength(BindingStrength.REQUIRED).setDescription("FIPS codes for US counties and county equivalent entities.").setValueSet(new Reference().setReference("http://hl7.org/fhir/ValueSet/fips-county"));
// List<ValidationMessage> messages = new ArrayList<ValidationMessage>();
//
// new ProfileUtilities(context, messages, null).generateSnapshot(base, focus, focus.getUrl(), "Simple Test" );
//
// // 14 for address with one sliced extension
// boolean ok = base.getSnapshot().getElement().size() == focus.getSnapshot().getElement().size() - 13;
//
// if (!ok) {
// compareXml(base, focus);
// throw new FHIRException("Snap shot generation test 8742 failed");
// } else
// System.out.println("Snap shot generation test 8742 passed");
// }
//
//
// private boolean rule(boolean ok, String message) {
// if (!ok)
// System.out.println("Test failed: " + message);
// return ok;
// }
//
private void compareXml(StructureDefinition base, StructureDefinition focus) throws FileNotFoundException, IOException {
base.setText(null);
focus.setText(null);
base.setDifferential(null);
// focus.setDifferential(null);
String f1 = Utilities.path("c:", "temp", "base.xml");
String f2 = Utilities.path("c:", "temp", "derived.xml");
new XmlParser().setOutputStyle(OutputStyle.PRETTY).compose(new FileOutputStream(f1), base);;
new XmlParser().setOutputStyle(OutputStyle.PRETTY).compose(new FileOutputStream(f2), focus);;
String diff = Utilities.path(System.getenv("ProgramFiles(X86)"), "WinMerge", "WinMergeU.exe");
List<String> command = new ArrayList<String>();
command.add("\"" + diff + "\" \"" + f1 + "\" \"" + f2 + "\"");
ProcessBuilder builder = new ProcessBuilder(command);
builder.directory(new CSFile("c:\\temp"));
builder.start();
}
}

View File

@ -1,39 +0,0 @@
package org.hl7.fhir.r4.test;
import static org.junit.Assert.*;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import org.hl7.fhir.r4.context.IWorkerContext;
import org.hl7.fhir.r4.context.SimpleWorkerContext;
import org.hl7.fhir.r4.formats.IParser.OutputStyle;
import org.hl7.fhir.r4.formats.XmlParser;
import org.hl7.fhir.r4.model.DomainResource;
import org.hl7.fhir.r4.model.Resource;
import org.hl7.fhir.r4.test.support.TestingUtilities;
import org.hl7.fhir.r4.utils.EOperationOutcome;
import org.hl7.fhir.r4.utils.NarrativeGenerator;
import org.hl7.fhir.utilities.Utilities;
import org.hl7.fhir.exceptions.FHIRException;
import org.junit.Before;
import org.junit.Test;
public class ResourceRoundTripTests {
@Before
public void setUp() throws Exception {
}
@Test
public void test() throws FileNotFoundException, IOException, FHIRException, EOperationOutcome {
if (TestingUtilities.context == null)
TestingUtilities.context = SimpleWorkerContext.fromPack(Utilities.path(TestingUtilities.home(), "publish", "definitions.xml.zip"));
Resource res = new XmlParser().parse(new FileInputStream(Utilities.path(TestingUtilities.home(), "tests", "resources", "unicode.xml")));
new NarrativeGenerator("", "", TestingUtilities.context).generate((DomainResource) res);
new XmlParser().setOutputStyle(OutputStyle.PRETTY).compose(new FileOutputStream(Utilities.path(TestingUtilities.home(), "tests", "resources","unicode.out.xml")), res);
}
}

View File

@ -1,85 +0,0 @@
package org.hl7.fhir.r4.test;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.nio.file.FileSystems;
import java.nio.file.Path;
import org.hl7.fhir.r4.conformance.ShExGenerator;
import org.hl7.fhir.r4.conformance.ShExGenerator.HTMLLinkPolicy;
import org.hl7.fhir.r4.context.SimpleWorkerContext;
import org.hl7.fhir.r4.model.StructureDefinition;
import org.hl7.fhir.r4.test.support.TestingUtilities;
import org.hl7.fhir.exceptions.FHIRException;
import org.hl7.fhir.utilities.TextFile;
import org.junit.Test;
public class ShexGeneratorTests {
private void doTest(String name) throws FileNotFoundException, IOException, FHIRException {
String workingDirectory = "C:\\work\\org.hl7.fhir\\build\\publish"; // FileSystems.getDefault().getPath(System.getProperty("user.dir"), "data").toString();
// String workingDirectory = FileSystems.getDefault().getPath(System.getProperty("user.dir"), "..", "..", "..", "publish").toString();
if (TestingUtilities.context == null) {
// For the time being, put the validation entry in org/hl7/fhir/r4/data
Path path = FileSystems.getDefault().getPath(workingDirectory, "definitions.xml.zip");
TestingUtilities.context = SimpleWorkerContext.fromPack(path.toString());
}
StructureDefinition sd = TestingUtilities.context.fetchResource(StructureDefinition.class, "http://hl7.org/fhir/StructureDefinition/"+name);
if(sd == null) {
throw new FHIRException("StructuredDefinition for " + name + "was null");
}
Path outPath = FileSystems.getDefault().getPath(workingDirectory, name.toLowerCase()+".shex");
TextFile.stringToFile(new ShExGenerator(TestingUtilities.context).generate(HTMLLinkPolicy.NONE, sd), outPath.toString());
}
@Test
public void testId() throws FHIRException, IOException {
doTest("id");
}
@Test
public void testUri() throws FHIRException, IOException {
doTest("uri");
}
@Test
public void testObservation() throws FHIRException, IOException {
doTest("Observation");
}
@Test
public void testRef() throws FHIRException, IOException {
doTest("Reference");
}
@Test
public void testAccount() throws FHIRException, IOException {
doTest("Account");
}
@Test
public void testMedicationOrder() throws FHIRException, IOException {
doTest("MedicationOrder");
}
@Test
public void testAllergyIntolerance() throws FHIRException, IOException {
doTest("AllergyIntolerance");
}
@Test
public void testCoding() throws FHIRException, IOException {
doTest("Coding");
}
@Test
public void testTiming() throws FHIRException, IOException {
doTest("Timing");
}
@Test
public void testSignature() throws FHIRException, IOException {
doTest("Signature");
}
}

View File

@ -1,338 +0,0 @@
package org.hl7.fhir.r4.test;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import javax.xml.parsers.ParserConfigurationException;
import org.hl7.fhir.r4.conformance.ProfileUtilities;
import org.hl7.fhir.r4.context.SimpleWorkerContext;
import org.hl7.fhir.r4.formats.IParser.OutputStyle;
import org.hl7.fhir.r4.formats.XmlParser;
import org.hl7.fhir.r4.model.Base;
import org.hl7.fhir.r4.model.BooleanType;
import org.hl7.fhir.r4.model.Coding;
import org.hl7.fhir.r4.model.ExpressionNode;
import org.hl7.fhir.r4.model.MetadataResource;
import org.hl7.fhir.r4.model.ExpressionNode.CollectionStatus;
import org.hl7.fhir.r4.model.PrimitiveType;
import org.hl7.fhir.r4.model.Resource;
import org.hl7.fhir.r4.model.StructureDefinition;
import org.hl7.fhir.r4.model.TestScript;
import org.hl7.fhir.r4.model.TestScript.SetupActionAssertComponent;
import org.hl7.fhir.r4.model.TestScript.SetupActionComponent;
import org.hl7.fhir.r4.model.TestScript.SetupActionOperationComponent;
import org.hl7.fhir.r4.model.TestScript.TestActionComponent;
import org.hl7.fhir.r4.model.TestScript.TestScriptFixtureComponent;
import org.hl7.fhir.r4.model.TestScript.TestScriptTestComponent;
import org.hl7.fhir.r4.model.TypeDetails;
import org.hl7.fhir.r4.test.support.TestingUtilities;
import org.hl7.fhir.r4.utils.CodingUtilities;
import org.hl7.fhir.r4.utils.FHIRPathEngine;
import org.hl7.fhir.r4.utils.FHIRPathEngine.IEvaluationContext;
import org.hl7.fhir.exceptions.DefinitionException;
import org.hl7.fhir.exceptions.FHIRException;
import org.hl7.fhir.exceptions.FHIRFormatError;
import org.hl7.fhir.exceptions.PathEngineException;
import org.hl7.fhir.utilities.Utilities;
import org.hl7.fhir.utilities.xml.XMLUtil;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.Parameterized;
import org.junit.runners.Parameterized.Parameters;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.Node;
import junit.framework.Assert;
@RunWith(Parameterized.class)
public class SnapShotGenerationTests {
private static class SnapShotGenerationTestsContext implements IEvaluationContext {
private Map<String, Resource> fixtures;
private Map<String, StructureDefinition> snapshots = new HashMap<String, StructureDefinition>();
public TestScript tests;
public void checkTestsDetails() {
if (!"http://hl7.org/fhir/tests/snapshotgeneration".equals(tests.getUrl()))
throw new Error("Wrong URL on test script");
if (!tests.getSetup().isEmpty())
throw new Error("Setup is not supported");
if (!tests.getTeardown().isEmpty())
throw new Error("Teardown is not supported");
Set<String> ids = new HashSet<String>();
Set<String> urls = new HashSet<String>();
for (Resource r : tests.getContained()) {
if (ids.contains(r.getId()))
throw new Error("Unsupported: duplicate contained resource on fixture id "+r.getId());
ids.add(r.getId());
if (r instanceof MetadataResource) {
MetadataResource md = (MetadataResource) r;
if (urls.contains(md.getUrl()))
throw new Error("Unsupported: duplicate canonical url "+md.getUrl()+" on fixture id "+r.getId());
urls.add(md.getUrl());
}
}
for (TestScriptFixtureComponent r : tests.getFixture()) {
if (ids.contains(r.getId()))
throw new Error("Unsupported: duplicate contained resource or fixture id "+r.getId());
ids.add(r.getId());
}
Set<String> names = new HashSet<String>();
for (TestScriptTestComponent test : tests.getTest()) {
if (names.contains(test.getName()))
throw new Error("Unsupported: duplicate name "+test.getName());
names.add(test.getName());
if (test.getAction().size() < 2)
throw new Error("Unsupported: multiple actions required");
if (!test.getActionFirstRep().hasOperation())
throw new Error("Unsupported: first action must be an operation");
for (int i = 0; i < test.getAction().size(); i++) {
// if (!test.getAction().get(i).hasAssert())
// throw new Error("Unsupported: following actions must be an asserts");
TestActionComponent action = test.getAction().get(i);
if (action.hasOperation()) {
SetupActionOperationComponent op = test.getActionFirstRep().getOperation();
if (!CodingUtilities.matches(op.getType(), "http://hl7.org/fhir/testscript-operation-codes", "snapshot")
&& !CodingUtilities.matches(op.getType(), "http://hl7.org/fhir/testscript-operation-codes", "sortDifferential"))
throw new Error("Unsupported action operation type "+CodingUtilities.present(op.getType()));
if (!"StructureDefinition".equals(op.getResource()))
throw new Error("Unsupported action operation resource "+op.getResource());
if (!op.hasResponseId())
throw new Error("Unsupported action operation: no response id");
if (!op.hasSourceId())
throw new Error("Unsupported action operation: no source id");
if (!hasSource(op.getSourceId()))
throw new Error("Unsupported action operation: source id could not be resolved");
} else if (action.hasAssert()) {
SetupActionAssertComponent a = action.getAssert();
if (!a.hasLabel())
throw new Error("Unsupported: actions must have a label");
if (!a.hasDescription())
throw new Error("Unsupported: actions must have a description");
if (!a.hasExpression())
throw new Error("Unsupported: actions must have an expression");
} else {
throw new Error("Unsupported: Unrecognized action type");
}
}
}
}
private boolean hasSource(String sourceId) {
for (TestScriptFixtureComponent ds : tests.getFixture()) {
if (sourceId.equals(ds.getId()))
return true;
}
for (Resource r : tests.getContained()) {
if (sourceId.equals(r.getId()))
return true;
}
return false;
}
public Resource fetchFixture(String id) {
if (fixtures.containsKey(id))
return fixtures.get(id);
for (TestScriptFixtureComponent ds : tests.getFixture()) {
if (id.equals(ds.getId()))
throw new Error("not done yet");
}
for (Resource r : tests.getContained()) {
if (id.equals(r.getId()))
return r;
}
return null;
}
// FHIRPath methods
@Override
public Base resolveConstant(Object appContext, String name) throws PathEngineException {
return null;
}
@Override
public TypeDetails resolveConstantType(Object appContext, String name) throws PathEngineException {
return null;
}
@Override
public boolean log(String argument, List<Base> focus) {
System.out.println(argument+": "+fp.convertToString(focus));
return true;
}
@Override
public FunctionDetails resolveFunction(String functionName) {
if ("fixture".equals(functionName))
return new FunctionDetails("Access a fixture defined in the testing context", 0, 1);
return null;
}
@Override
public TypeDetails checkFunction(Object appContext, String functionName, List<TypeDetails> parameters) throws PathEngineException {
if ("fixture".equals(functionName))
return new TypeDetails(CollectionStatus.SINGLETON, TestingUtilities.context.getResourceNamesAsSet());
return null;
}
@Override
public List<Base> executeFunction(Object appContext, String functionName, List<List<Base>> parameters) {
if ("fixture".equals(functionName)) {
String id = fp.convertToString(parameters.get(0));
Resource res = fetchFixture(id);
if (res != null) {
List<Base> list = new ArrayList<Base>();
list.add(res);
return list;
}
}
return null;
}
@Override
public Base resolveReference(Object appContext, String url) {
// TODO Auto-generated method stub
return null;
}
}
private static FHIRPathEngine fp;
@Parameters(name = "{index}: file {0}")
public static Iterable<Object[]> data() throws ParserConfigurationException, IOException, FHIRFormatError {
SnapShotGenerationTestsContext context = new SnapShotGenerationTestsContext();
context.tests = (TestScript) new XmlParser().parse(new FileInputStream(Utilities.path(TestingUtilities.home(), "tests", "resources", "snapshot-generation-tests.xml")));
context.checkTestsDetails();
List<Object[]> objects = new ArrayList<Object[]>(context.tests.getTest().size());
for (TestScriptTestComponent e : context.tests.getTest()) {
objects.add(new Object[] { e.getName(), e, context });
}
return objects;
}
private final TestScriptTestComponent test;
private final String name;
private SnapShotGenerationTestsContext context;
public SnapShotGenerationTests(String name, TestScriptTestComponent e, SnapShotGenerationTestsContext context) {
this.name = name;
this.test = e;
this.context = context;
}
@SuppressWarnings("deprecation")
@Test
public void test() throws FileNotFoundException, IOException, FHIRException, org.hl7.fhir.exceptions.FHIRException {
if (TestingUtilities.context == null)
TestingUtilities.context = SimpleWorkerContext.fromPack(Utilities.path(TestingUtilities.home(), "publish", "definitions.xml.zip"));
if (fp == null)
fp = new FHIRPathEngine(TestingUtilities.context);
fp.setHostServices(context);
resolveFixtures();
for (int i = 0; i < test.getAction().size(); i++) {
TestActionComponent action = test.getAction().get(i);
if (action.hasOperation()) {
SetupActionOperationComponent op = action.getOperation();
Coding opType = op.getType();
if (opType.getSystem().equals("http://hl7.org/fhir/testscript-operation-codes") && opType.getCode().equals("snapshot")) {
StructureDefinition source = (StructureDefinition) context.fetchFixture(op.getSourceId());
StructureDefinition base = getSD(source.getBaseDefinition());
StructureDefinition output = source.copy();
ProfileUtilities pu = new ProfileUtilities(TestingUtilities.context, null, null);
pu.setIds(source, false);
if ("sort=true".equals(op.getParams())) {
List<String> errors = new ArrayList<String>();
pu.sortDifferential(base, output, source.getName(), errors);
if (errors.size() > 0)
throw new FHIRException("Sort failed: "+errors.toString());
}
pu.generateSnapshot(base, output, source.getUrl(), source.getName());
context.fixtures.put(op.getResponseId(), output);
context.snapshots.put(output.getUrl(), output);
new XmlParser().setOutputStyle(OutputStyle.PRETTY).compose(new FileOutputStream(Utilities.path(System.getProperty("java.io.tmpdir"), op.getResponseId()+".xml")), output);
} else if (opType.getSystem().equals("http://hl7.org/fhir/testscript-operation-codes") && opType.getCode().equals("sortDifferential")) {
StructureDefinition source = (StructureDefinition) context.fetchFixture(op.getSourceId());
StructureDefinition base = getSD(source.getBaseDefinition());
StructureDefinition output = source.copy();
ProfileUtilities pu = new ProfileUtilities(TestingUtilities.context, null, null);
pu.setIds(source, false);
List<String> errors = new ArrayList<String>();
pu.sortDifferential(base, output, output.getUrl(), errors);
if (!errors.isEmpty())
throw new FHIRException(errors.get(0));
context.fixtures.put(op.getResponseId(), output);
context.snapshots.put(output.getUrl(), output);
new XmlParser().setOutputStyle(OutputStyle.PRETTY).compose(new FileOutputStream(Utilities.path(System.getProperty("java.io.tmpdir"), op.getResponseId()+".xml")), output);
} else {
throw new Error("Unsupported operation: " + opType.getSystem() + " : " + opType.getCode());
}
} else if (action.hasAssert()) {
SetupActionAssertComponent a = action.getAssert();
Assert.assertTrue(a.getLabel()+": "+a.getDescription(), fp.evaluateToBoolean(new StructureDefinition(), new StructureDefinition(), a.getExpression()));
}
}
}
private StructureDefinition getSD(String url) throws DefinitionException, FHIRException {
StructureDefinition sd = TestingUtilities.context.fetchResource(StructureDefinition.class, url);
if (sd == null)
sd = context.snapshots.get(url);
if (sd == null)
sd = findContainedProfile(url);
return sd;
}
private StructureDefinition findContainedProfile(String url) throws DefinitionException, FHIRException {
for (Resource r : context.tests.getContained()) {
if (r instanceof StructureDefinition) {
StructureDefinition sd = (StructureDefinition) r;
if (sd.getUrl().equals(url)) {
StructureDefinition p = sd.copy();
ProfileUtilities pu = new ProfileUtilities(TestingUtilities.context, null, null);
pu.setIds(p, false);
List<String> errors = new ArrayList<String>();
pu.sortDifferential(getSD(p.getBaseDefinition()), p, url, errors);
if (!errors.isEmpty())
throw new FHIRException(errors.get(0));
pu.generateSnapshot(getSD(p.getBaseDefinition()), p, p.getUrl(), p.getName());
return p;
}
}
}
return null;
}
private void resolveFixtures() {
if (context.fixtures == null) {
context.fixtures = new HashMap<String, Resource>();
for (TestScriptFixtureComponent fd : context.tests.getFixture()) {
Resource r = TestingUtilities.context.fetchResource(Resource.class, fd.getResource().getReference());
context.fixtures.put(fd.getId(), r);
}
}
}
}

View File

@ -1,60 +0,0 @@
package org.hl7.fhir.r4.test;
import static org.junit.Assert.*;
import org.hl7.fhir.exceptions.FHIRException;
import org.hl7.fhir.r4.utils.SnomedExpressions;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
public class SnomedExpressionsTests {
@Before
public void setUp() throws Exception {
}
@Test
public void test() throws FHIRException {
p("116680003");
p("128045006:{363698007=56459004}");
p("128045006|cellulitis (disorder)|:{363698007|finding site|=56459004|foot structure|}");
p("31978002: 272741003=7771000");
p("31978002|fracture of tibia|: 272741003|laterality|=7771000|left|");
p("64572001|disease|:{116676008|associated morphology|=72704001|fracture|,363698007|finding site|=(12611008|bone structure of tibia|:272741003|laterality|=7771000|left|)}");
p("417662000|past history of clinical finding|:246090004|associated finding|= (31978002|fracture of tibia|: 272741003|laterality|=7771000|left|)");
p("243796009|situation with explicit context|:246090004|associated finding|= (64572001|disease|:{116676008|associated morphology|=72704001|fracture|,"+" 363698007|finding site|=(12611008|bone structure of tibia|: 272741003|laterality|=7771000|left|)}),408729009|finding context|= "+"410515003|known present|,408731000|temporal context|=410513005|past|, 408732007|subject relationship context|=410604004|subject of record|");
// from IHTSDO expression documentation:
p("125605004 |fracture of bone|");
p("284003005 |bone injury| :{ 363698007 |finding site| = 272673000 |bone structure|,116676008 |associated morphology| = 72704001 |fracture| }");
p("421720008 |spray dose form| + 7946007 |drug suspension|");
p("182201002 |hip joint| : 272741003 |laterality| = 24028007 |right|");
p("397956004 |prosthetic arthroplasty of the hip| : 363704007 |procedure site| = (182201002 |hip joint| : 272741003 |laterality| = 24028007 |right|)");
p("71388002 |procedure| : {260686004 |method| = 129304002 |excision - action|, 405813007 |procedure site - direct| = 28231008 |gallbladder structure|}, {260686004 |method| = 281615006 "+"|exploration|, 405813007 |procedure site - direct| = 28273000 |bile duct structure|}");
p("27658006 |amoxicillin|:411116001 |has dose form| = 385049006 |capsule|,{ 127489000 |has active ingredient| = 372687004 |amoxicillin|,111115 |has basis of strength| = (111115 |"+"amoxicillin only|:111115 |strength magnitude| = #500,111115 |strength unit| = 258684004 |mg|)}");
p("91143003 |albuterol|:411116001 |has dose form| = 385023001 |oral solution|,{ 127489000 |has active ingredient| = 372897005 |albuterol|,111115 |has basis of strength| = (111115 |a"+"lbuterol only|:111115 |strength magnitude| = #0.083,111115 |strength unit| = 118582008 |%|)}");
p("322236009 |paracetamol 500mg tablet| : 111115 |trade name| = \"PANADOL\"");
p("=== 46866001 |fracture of lower limb| + 428881005 |injury of tibia| :116676008 |associated morphology| = 72704001 |fracture|,363698007 |finding site| = 12611008 |bone structure of tibia|");
p("<<< 73211009 |diabetes mellitus| : 363698007 |finding site| = 113331007 |endocrine system|");
// from Overview of Expression Normalization, Equivalence and Subsumption Testing
p("28012007 |Closed fracture of shaft of tibia|");
p("125605004 |Fracture of bone| :{ 363698007 |Finding site| = 52687003 |Bone structure of shaft of tibia|,116676008 |Associated morphology| = 20946005 |Fracture, closed | }");
p("423125000 |Closed fracture of bone|:363698007 |Finding site| = 52687003 |Bone structure of shaft of tibia|");
p("6990005 |Fracture of shaft of tibia |: 116676008 |Associated morphology| = 20946005 |Fracture, closed |");
p("64572001 |Disease| : { 363698007 |Finding site| = 52687003 |Bone structure of shaft of tibia|, 116676008 |Associated morphology| = 20946005 |Fracture, closed | }");
// p("10925361000119108 |Closed fracture of shaft of left tibia|"); // US Extension
p("28012007 |Closed fracture of shaft of tibia| : 363698007 |Finding site| = (52687003 |Bone structure of shaft of tibia| : 272741003 |Laterality|= 7771000 |Left|)");
p("28012007 |Closed fracture of shaft of tibia| : 272741003 |Laterality|= 7771000 |Left|"); //Close to user form omits restatement of finding site");
p("64572001 |Disease| : {363698007 |Finding site| = (52687003 |Bone structure of shaft of tibia| : 272741003 |Laterality|= 7771000 |Left|), 116676008 |Associated morphology| = 20946005 |Fracture, closed | }");
p("28012007 |Closed fracture of shaft of tibia| : 363698007 |Finding site| = 31156008 |Structure of left half of body|");
}
private void p(String expression) throws FHIRException {
Assert.assertNotNull("must be present", SnomedExpressions.parse(expression));
}
}

View File

@ -1,145 +0,0 @@
package org.hl7.fhir.r4.test;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.hl7.fhir.r4.context.SimpleWorkerContext;
import org.hl7.fhir.r4.elementmodel.Element;
import org.hl7.fhir.r4.elementmodel.Manager;
import org.hl7.fhir.r4.elementmodel.Manager.FhirFormat;
import org.hl7.fhir.r4.formats.IParser.OutputStyle;
import org.hl7.fhir.r4.formats.XmlParser;
import org.hl7.fhir.r4.model.Bundle;
import org.hl7.fhir.r4.model.StructureDefinition;
import org.hl7.fhir.r4.model.StructureMap;
import org.hl7.fhir.r4.test.support.TestingUtilities;
import org.hl7.fhir.r4.utils.StructureMapUtilities;
import org.hl7.fhir.exceptions.FHIRException;
import org.hl7.fhir.utilities.TextFile;
import org.hl7.fhir.utilities.Utilities;
import org.junit.Test;
public class StructureMapTests {
private void testParse(String path) throws FileNotFoundException, IOException, FHIRException {
if (TestingUtilities.context == null)
TestingUtilities.context = SimpleWorkerContext.fromPack(Utilities.path(TestingUtilities.home(), "publish", "definitions.xml.zip"));
StructureMapUtilities scm = new StructureMapUtilities(TestingUtilities.context, null, null);
StructureMap map = scm.parse(TextFile.fileToString(Utilities.path(TestingUtilities.home(), path)));
TextFile.stringToFile(scm.render(map), Utilities.path(TestingUtilities.home(), path+".out"));
}
// @Test
// public void testParseAny() throws FHIRException, IOException {
// testParse("guides\\ccda2\\mapping\\map\\any.map");
// }
//
// @Test
// public void testParseBL() throws FHIRException, IOException {
// testParse("guides\\ccda2\\mapping\\map\\bl.map");
// }
//
// @Test
// public void testParseED() throws FHIRException, IOException {
// testParse("guides\\ccda2\\mapping\\map\\ed.map");
// }
//
// @Test
// public void testParseCD() throws FHIRException, IOException {
// testParse("guides\\ccda2\\mapping\\map\\cd.map");
// }
//
// @Test
// public void testParseAD() throws FHIRException, IOException {
// testParse("guides\\ccda2\\mapping\\map\\ad.map");
// }
//
// @Test
// public void testParsePQ() throws FHIRException, IOException {
// testParse("guides\\ccda2\\mapping\\map\\pq.map");
// }
//
// @Test
// public void testParseIVLTS() throws FHIRException, IOException {
// testParse("guides\\ccda2\\mapping\\map\\ivl-ts.map");
// }
//
// @Test
// public void testParseCDA() throws FHIRException, IOException {
// testParse("guides\\ccda2\\mapping\\map\\cda.map");
// }
// @Test
// public void testTransformCDA() throws FileNotFoundException, Exception {
// Map<String, StructureMap> maps = new HashMap<String, StructureMap>();
//
// if (TestingUtilities.context == null)
// TestingUtilities.context = SimpleWorkerContext.fromPack(Utilities.path(TestingUtilities.home(), "publish", "definitions.xml.zip"));
//
// StructureMapUtilities scu = new StructureMapUtilities(TestingUtilities.context, maps, null);
//
// for (String f : new File(Utilities.path(TestingUtilities.home(), "guides", "ccda2", "mapping", "logical")).list()) {
// try {
// StructureDefinition sd = (StructureDefinition) new XmlParser().parse(new FileInputStream(Utilities.path(TestingUtilities.home(), "guides", "ccda2", "mapping", "logical", f)));
// ((SimpleWorkerContext) TestingUtilities.context).seeResource(sd.getUrl(), sd);
// } catch (Exception e) {
// e.printStackTrace();
// }
// }
//
// for (String f : new File(Utilities.path(TestingUtilities.home(), "guides", "ccda2", "mapping", "map")).list()) {
// try {
// StructureMap map = scu.parse(TextFile.fileToString(Utilities.path(TestingUtilities.home(), "guides", "ccda2", "mapping", "map", f)));
// maps.put(map.getUrl(), map);
// } catch (Exception e) {
// e.printStackTrace();
// }
// }
//
// Element cda = Manager.parse(TestingUtilities.context, new FileInputStream("C:\\work\\org.hl7.fhir\\build\\guides\\ccda2\\mapping\\example\\ccd.xml"), FhirFormat.XML);
// Manager.compose(TestingUtilities.context, cda, new FileOutputStream("C:\\work\\org.hl7.fhir\\build\\guides\\ccda2\\mapping\\example\\ccd.out.json"), FhirFormat.JSON, OutputStyle.PRETTY, null);
// Manager.compose(TestingUtilities.context, cda, new FileOutputStream("C:\\work\\org.hl7.fhir\\build\\guides\\ccda2\\mapping\\example\\ccd.out.xml"), FhirFormat.XML, OutputStyle.PRETTY, null);
// Bundle bundle = new Bundle();
// scu.transform(null, cda, maps.get("http://hl7.org/fhir/StructureMap/cda"), bundle);
// new XmlParser().setOutputStyle(OutputStyle.PRETTY).compose(new FileOutputStream("c:\\temp\\bundle.xml"), bundle);
// }
//
// @Test
// public void testTransformProfilesCDA() throws FileNotFoundException, Exception {
// Map<String, StructureMap> maps = new HashMap<String, StructureMap>();
//
// if (TestingUtilities.context == null)
// TestingUtilities.context = SimpleWorkerContext.fromPack("C:\\work\\org.hl7.fhir\\build\\publish\\validation-min.xml.zip");
//
// StructureMapUtilities scu = new StructureMapUtilities(TestingUtilities.context, maps, null);
//
// for (String f : new File("C:\\work\\org.hl7.fhir\\build\\guides\\ccda\\CDA").list()) {
// try {
// StructureDefinition sd = (StructureDefinition) new XmlParser().parse(new FileInputStream("C:\\work\\org.hl7.fhir\\build\\guides\\ccda\\CDA\\"+f));
// ((SimpleWorkerContext) TestingUtilities.context).seeResource(sd.getUrl(), sd);
// } catch (Exception e) {
// }
// }
//
// for (String f : new File("C:\\work\\org.hl7.fhir\\build\\guides\\ccda2\\mapping\\map").list()) {
// try {
// StructureMap map = scu.parse(TextFile.fileToString("C:\\work\\org.hl7.fhir\\build\\guides\\ccda2\\mapping\\map\\"+ f));
// maps.put(map.getUrl(), map);
// } catch (Exception e) {
// }
// }
//
// List<StructureDefinition> result = scu.analyse(null, maps.get("http://hl7.org/fhir/StructureMap/cda")).getProfiles();
// for (StructureDefinition sd : result)
// new XmlParser().setOutputStyle(OutputStyle.PRETTY).compose(new FileOutputStream("c:\\temp\\res-"+sd.getId()+".xml"), sd);
// }
//
}