public static void TestCanGetElements(IStructureDefinitionSummaryProvider provider) { var p = provider.Provide("Patient"); // Simple element (repeating) checkType(p, "identifier", true, "Identifier"); // Simple element checkType(p, "active", false, "boolean"); // Element with multiple reference types checkType(p, "careProvider", true, "Reference"); // Backbone element (repeating) var bbe = checkBBType(p, "contact", "BackboneElement", true); // Navigate into the backbone element checkType(bbe, "relationship", true, "CodeableConcept"); // Choice type checkType(p, "deceased", false, "boolean", "dateTime"); // Get base elements checkType(p, "text", false, "Narrative"); checkType(p, "contained", true, "Resource"); checkType(p, "extension", true, "Extension"); checkType(p, "id", false, "id"); checkType(p, "meta", false, "Meta"); // Should not have the special "value" attribute Assert.IsFalse(p.GetElements().Any(c => c.ElementName == "value")); var b = provider.Provide("Bundle"); checkType(b, "total", false, "unsignedInt"); checkType(b, "type", false, "code"); // Test types using nameReference var q = provider.Provide("Questionnaire"); var qgroup = checkBBType(q, "group", "BackboneElement", false); checkType(qgroup, "linkId", false, "string"); var qgroupgroup = checkBBType(qgroup, "group", "BackboneElement", true); checkType(qgroupgroup, "linkId", false, "string"); // Backbone elements within datatypes var tm = provider.Provide("Timing"); checkBBType(tm, "repeat", "Element", false); }
//[TestMethod] //public void TestResourceInfo() //{ // var ip = new PocoModelMetadataProvider(); // Assert.IsTrue(ip.IsResource("Patient")); // Assert.IsTrue(ip.IsResource("DomainResource")); // Assert.IsTrue(ip.IsResource("Resource")); // Assert.IsFalse(ip.IsResource("Identifier")); //} public static void TestCanLocateTypes(IStructureDefinitionSummaryProvider provider) { // Try getting a resource tryGetType("Patient"); // Try getting an abstract resource tryGetType("DomainResource", isAbstract: true); tryGetType("Resource", isAbstract: true); // Try a complex datatype tryGetType("HumanName"); // Try getting an abstract datatype tryGetType("Element", isAbstract: true); // Try a primitive tryGetType("string"); // Try constrained quantities tryGetType("SimpleQuantity", "Quantity"); tryGetType("Distance", "Quantity"); // The weird xhtml datatype tryGetType("xhtml"); void tryGetType(string typename, string baseTypeName = null, bool isAbstract = false) { var si = provider.Provide(typename); Assert.IsNotNull(si); Assert.AreEqual(baseTypeName ?? typename, si.TypeName); Assert.AreEqual(isAbstract, si.IsAbstract); } }
public static void TestValueIsNotAChild(IStructureDefinitionSummaryProvider provider) { var p = provider.Provide("string"); var children = p.GetElements(); Assert.IsFalse(children.Any(c => c.ElementName == "value")); }
public static void TestProvidedOrder(IStructureDefinitionSummaryProvider provider) { hasCorrectOrder("Patient"); hasCorrectOrder("DomainResource"); hasCorrectOrder("HumanName"); hasCorrectOrder("Element"); hasCorrectOrder("string"); hasCorrectOrder("SimpleQuantity"); hasCorrectOrder("Distance"); hasCorrectOrder("xhtml"); void hasCorrectOrder(string typename) { var si = provider.Provide(typename); var children = si.GetElements(); var max = children.Aggregate(0, (a, i) => i.Order > a ? i.Order : fail($"Order of {i.ElementName} is out of order")); int fail(string message) { Assert.Fail(message); return(0); // will never be reached } } }
public static void TestSpecialTypes(IStructureDefinitionSummaryProvider provider) { // Narrative.div var div = provider.Provide("Narrative"); Assert.IsNotNull(div); checkType(div, "div", false, "xhtml"); // Element.id checkType(div, "id", false, "id"); var ext = provider.Provide("Extension"); // Extension.url checkType(ext, "url", false, "uri"); }
private NavigatorPosition buildRootPosition(ISourceNode element, string type, IStructureDefinitionSummaryProvider provider) { var rootType = type ?? element.GetResourceTypeIndicator(); if (rootType == null) { if (_settings.ErrorMode == TypedElementSettings.TypeErrorMode.Report) { throw Error.Argument(nameof(type), $"Cannot determine the type of the root element at '{element.Location}', " + $"please supply a type argument."); } else { return(NavigatorPosition.ForRoot(element, null, element.Name)); } } var elementType = provider.Provide(rootType); if (elementType == null) { if (_settings.ErrorMode == TypedElementSettings.TypeErrorMode.Report) { throw Error.Argument(nameof(type), $"Cannot locate type information for type '{rootType}'"); } else { return(NavigatorPosition.ForRoot(element, null, element.Name)); } } return(NavigatorPosition.ForRoot(element, elementType, element.Name)); }
private ElementDefinitionSummaryCache down(NavigatorPosition current) { if (!current.IsTracking || current.InstanceType == null) { return(ElementDefinitionSummaryCache.Empty); } // If this is a backbone element, the child type is the nested complex type if (current.SerializationInfo.Type[0] is IStructureDefinitionSummary be) { return(ElementDefinitionSummaryCache.ForType(be)); } else { var si = Provider.Provide(current.InstanceType); return(si == null ? ElementDefinitionSummaryCache.Empty : ElementDefinitionSummaryCache.ForType(si)); } }
public static ElementNode Root(IStructureDefinitionSummaryProvider provider, string type, string name = null, object value = null) { if (provider == null) { throw Error.ArgumentNull(nameof(provider)); } if (type == null) { throw Error.ArgumentNull(nameof(type)); } var sd = provider.Provide(type); IElementDefinitionSummary definition = null; // Should we throw if type is not found? if (sd != null) { definition = ElementDefinitionSummary.ForRoot(sd); } return(new ElementNode(name ?? type, value, type, definition)); }