Exemplo n.º 1
0
 private static IEnumerable <ExpressionDef> ReadExpressionDefs(XNamespace ns, XNamespace elmns, IEnumerable <XElement> expressionDefs)
 {
     return
         (from expressionDef in expressionDefs
          select new ExpressionDef {
         Name = expressionDef.Attribute("name").Value, Expression = NodeReader.ReadASTNode(expressionDef.Element(elmns + "expression"))
     });
 }
Exemplo n.º 2
0
 private static IEnumerable <ExpressionDef> ReadTriggers(XNamespace ns, XNamespace elmns, IEnumerable <XElement> triggers)
 {
     return
         (from trigger in triggers
          let triggerDef = trigger.Element(ns + "def")
                           select new ExpressionDef {
         Name = triggerDef.Attribute("name").Value, Expression = NodeReader.ReadASTNode(triggerDef.Element(elmns + "expression"))
     });
 }
Exemplo n.º 3
0
 private static IEnumerable <ASTNode> ReadConditions(XNamespace ns, XNamespace elmns, IEnumerable <XElement> conditions)
 {
     return
         (from condition in conditions
          select NodeReader.ReadASTNode(condition.Element(ns + "logic")));
 }
Exemplo n.º 4
0
        public static Artifact Read(XDocument artifact, XmlSchemaSet schemas, string sourcePath)
        {
            artifact.Validate(schemas, onValidationEvent, true);

            if (artifact.Root.GetSchemaInfo().Validity != XmlSchemaValidity.Valid)
            {
                throw new InvalidOperationException("Artifact does not conform to the schema.");
            }

            var result = new Artifact();

            var ns    = artifact.Root.GetDefaultNamespace();
            var elmns = XNamespace.Get("urn:hl7-org:elm:r1");

            var metaData = artifact.Root.Element(ns + "metadata");

            if (metaData != null)
            {
                result.MetaData = NodeReader.ReadNode(metaData);
            }

            // Pull models
            var dataModelsElement = artifact.Root.Element(ns + "metadata").Element(ns + "dataModels");

            if (dataModelsElement != null)
            {
                result.Models = ReadModels(ns, dataModelsElement.Elements(ns + "modelReference")).ToList();
            }
            else
            {
                result.Models = new List <ModelRef>();
            }

            // TODO: Add default model of HeDSchema?

            // Pull libraries
            var librariesElement = artifact.Root.Element(ns + "metadata").Element(ns + "libraries");

            if (librariesElement != null)
            {
                result.Libraries = ReadLibraries(ns, librariesElement.Elements(ns + "libraryReference"), sourcePath).ToList();
            }
            else
            {
                result.Libraries = new List <LibraryRef>();
            }

            var externalData = artifact.Root.Element(ns + "externalData");

            if (externalData != null)
            {
                // Pull Codesystems
                result.CodeSystems = ReadCodeSystems(ns, externalData.Elements(ns + "codesystem")).ToList();

                // Pull valuesets
                result.ValueSets = ReadValueSets(ns, externalData.Elements(ns + "valueset")).ToList();

                // Pull parameters
                result.Parameters = ReadParameters(ns, elmns, externalData.Elements(ns + "parameter")).ToList();

                // Pull external defs
                var externalDefs = ReadExpressionDefs(ns, elmns, externalData.Elements(ns + "def"));

                // Pull triggers
                var triggers = ReadTriggers(ns, elmns, externalData.Elements(ns + "trigger"));

                result.Expressions = externalDefs.Concat(triggers).ToList();
            }
            else
            {
                result.Parameters  = new List <ParameterDef>();
                result.Expressions = new List <ExpressionDef>();
            }

            // Pull expressions
            var expressionsElement = artifact.Root.Element(ns + "expressions");

            if (expressionsElement != null)
            {
                var expressions = ReadExpressionDefs(ns, elmns, expressionsElement.Elements(ns + "def"));

                result.Expressions = result.Expressions.Concat(expressions).ToList();
            }

            // Pull conditions
            var conditionsElement = artifact.Root.Element(ns + "conditions");

            if (conditionsElement != null)
            {
                result.Conditions = ReadConditions(ns, elmns, conditionsElement.Elements(ns + "condition")).ToList();
            }
            else
            {
                result.Conditions = new List <ASTNode>();
            }

            // Pull actions
            var actionGroupElement = artifact.Root.Element(ns + "actionGroup");

            if (actionGroupElement != null)
            {
                result.ActionGroup = NodeReader.ReadNode(actionGroupElement);
            }

            return(result);
        }
Exemplo n.º 5
0
 private static IEnumerable <ParameterDef> ReadParameters(XNamespace ns, XNamespace elmns, IEnumerable <XElement> parameters)
 {
     return
         (from parameter in parameters
          let defaultNode = parameter.Element(elmns + "expression")
                            select new ParameterDef {
         Name = parameter.Attribute("name").Value, TypeName = parameter.ExpandName(parameter.Attribute("parameterType").Value), Default = defaultNode != null?NodeReader.ReadASTNode(defaultNode) : null
     });
 }
Exemplo n.º 6
0
 private static IEnumerable <Node> ReadTriggers(XNamespace ns, IEnumerable <XElement> triggers)
 {
     return
         (from trigger in triggers
          select NodeReader.ReadNode(trigger));
 }