예제 #1
0
        public static bool Validate(Composition composition, OperationalTemplate template,
                                    AcceptValidationError acceptErrorDelegate)
        {
            Check.Require(composition != null, "composition must not be null.");
            Check.Require(template != null, "template must not be null.");

            template.Definition.SetValidationContext(new ValidationContext(acceptErrorDelegate, null));

            return(template.Definition.ValidValue(composition));
        }
예제 #2
0
        public static bool Validate(Composition composition, OperationalTemplate template,
                                    string context, System.Collections.Generic.List <string> validationErrors)
        {
            Check.Require(composition != null, "composition must not be null.");
            Check.Require(template != null, "template must not be null.");

            ErrorLog errorLog = new ErrorLog(context);
            bool     isValid  = true;

            if (string.IsNullOrEmpty(composition.ArchetypeDetails.TemplateId.Value))
            {
                errorLog.LogError("Composition TemplateId is missing for " + composition.Concept);
                isValid = false;
            }
            if (string.IsNullOrEmpty(template.TemplateId.Value))
            {
                errorLog.LogError("Operational template TemplateId is missing for " + template.Concept);
                isValid = false;
            }
            if (isValid && composition.ArchetypeDetails.TemplateId.Value != template.TemplateId.Value)
            {
                errorLog.LogError(string.Format("Operational TemplateId {0} does not match Composition TemplateId {1}",
                                                template.TemplateId.Value, composition.ArchetypeDetails.TemplateId.Value));

                isValid = false;
            }

            isValid &= Validate(composition, template,
                                delegate(object sender, ValidationEventArgs e) { errorLog.LogError(e); });

            if (!isValid && errorLog.Log.Count <= 0)
            {
                errorLog.LogError("The composition was invalid and no validation errors were logged.");
            }

            if (!isValid)
            {
                validationErrors.AddRange(errorLog.Log);
            }

            return(isValid);
        }
예제 #3
0
        public static OperationalTemplate Parse(string operationalTemplateXmlString)
        {
            var ot = new OperationalTemplate();

            using (var textReader = new StringReader(operationalTemplateXmlString))
            {
                var templateModel = template.Load(textReader);

                if (templateModel.Content.uid != null)
                {
                    ot.Uid = new HierObjectId(templateModel.Content.uid.value);
                }
                if (templateModel.Content.template_id != null)
                {
                    ot.TemplateId = new TemplateId(templateModel.Content.template_id.value);
                }
                ot.Concept = templateModel.Content.concept;
                if (templateModel.Content.is_controlled.HasValue)
                {
                    ot.IsControlled = templateModel.Content.is_controlled.Value;
                }
                if (templateModel.Content.language != null)
                {
                    ot.Language = templateModel.Content.language.Map();
                }
                if (templateModel.Content.description != null)
                {
                    ot.Description = templateModel.Content.description.Map();
                }
                // TODO: parse revisionhistory
                //ot.RevisionHistory = templateModel.Content.revision_history.Map();
                if (templateModel.Content.definition != null)
                {
                    ot.Definition = templateModel.Content.definition.Map();
                }
                if (templateModel.Content.constraints != null)
                {
                    ot.Constraints = templateModel.Content.constraints.Map();
                }
                if (templateModel.Content.view != null)
                {
                    ot.View = templateModel.Content.view.Map();
                }
                if (templateModel.Content.annotations != null)
                {
                    foreach (var annotation in templateModel.Content.annotations)
                    {
                        ot.Annotations.Add(annotation.Map());
                    }
                }
                if (templateModel.Content.ontology != null)
                {
                    ot.Ontology = templateModel.Content.ontology.Map();
                }
                if (templateModel.Content.component_ontologies != null)
                {
                    foreach (var ontology in templateModel.Content.component_ontologies)
                    {
                        ot.ComponentOntologies.Add(ontology.Map());
                    }
                }
            }
            return(ot);
        }