private void ReadTView(XmlReader reader, TView view)
        {
            Check.Require(view != null, string.Format(CommonStrings.XMustNotBeNull, "view"));

            List <TViewConstraint> viewConstraints = new List <TViewConstraint>();

            reader.ReadStartElement(); // view
            reader.MoveToContent();
            while (reader.LocalName == "constraints")
            {
                TViewConstraint viewConstraint = new TViewConstraint();

                viewConstraint.Path = reader.GetAttribute("path");
                Check.Assert(!string.IsNullOrEmpty(viewConstraint.Path), "Path must not be null or empty.");

                reader.ReadStartElement(); // constraints
                reader.MoveToContent();
                if (reader.LocalName != "items")
                {
                    throw new InvalidXmlException("items", reader.LocalName);
                }

                System.Collections.Generic.Dictionary <string, string> hashTable =
                    new System.Collections.Generic.Dictionary <string, string>();
                while (reader.LocalName == "items")
                {
                    string hashId = reader.GetAttribute("id");
                    reader.ReadStartElement();
                    reader.MoveToContent();
                    string hashValue = reader.ReadElementContentAsString();
                    hashTable.Add(hashId, hashValue);
                    reader.ReadEndElement();
                    reader.MoveToContent();
                }

                viewConstraint.Items =
                    new OpenEhr.AssumedTypes.Hash <string, string>(hashTable);
                viewConstraints.Add(viewConstraint);

                Check.Assert(reader.NodeType == System.Xml.XmlNodeType.EndElement,
                             "Expected endElement");
                reader.ReadEndElement();
                reader.MoveToContent();
            }

            view.Constraints = viewConstraints;
        }
示例#2
0
        private void WriteTView(XmlWriter writer, TView tView)
        {
            Check.Require(tView != null);

            string openEhrPrefix = UseOpenEhrPrefix(writer);

            if (tView.Constraints != null && tView.Constraints.Count > 0)
            {
                foreach (TViewConstraint viewConstraint in tView.Constraints)
                {
                    writer.WriteStartElement(openEhrPrefix, "constraints", OpenEhrNamespace);
                    writer.WriteAttributeString("path", viewConstraint.Path);

                    foreach (string key in viewConstraint.Items.Keys)
                    {
                        writer.WriteStartElement(openEhrPrefix, "items", OpenEhrNamespace);
                        writer.WriteAttributeString("id", key);
                        writer.WriteElementString("value", viewConstraint.Items.Item(key));
                        writer.WriteEndElement();
                    }
                    writer.WriteEndElement();
                }
            }
        }
        public void ReadOperationalTemplate(XmlReader reader, OperationalTemplate template)
        {
            Check.Require(reader != null, string.Format(CommonStrings.XMustNotBeNull, "reader"));
            Check.Require(template != null, string.Format(CommonStrings.XMustNotBeNull, "template"));

            reader.ReadStartElement();  //template
            reader.MoveToContent();

            CodePhrase language = new CodePhrase();

            language.ReadXml(reader);
            template.Language = language;

            if (reader.LocalName == "is_controlled")
            {
                reader.ReadElementContentAsBoolean("is_controlled", RmXmlSerializer.OpenEhrNamespace);
                reader.MoveToContent();
            }

            if (reader.LocalName == "description")
            {
                ResourceDescription description = new ResourceDescription();
                description.ReadXml(reader);
                template.Description = description;
            }

            if (reader.LocalName == "revision_history")
            {
                RevisionHistory revisionHistory = new RevisionHistory();
                revisionHistory.ReadXml(reader);
                template.RevisionHistory = revisionHistory;
            }

            if (reader.LocalName == "uid")
            {
                HierObjectId uid = new HierObjectId();
                uid.ReadXml(reader);
                template.Uid = uid;
            }

            TemplateId templateId = new TemplateId();

            templateId.ReadXml(reader);
            template.TemplateId = templateId;

            template.Concept = reader.ReadElementContentAsString("concept", RmXmlSerializer.OpenEhrNamespace);
            reader.MoveToContent();

            CArchetypeRoot definition = new CArchetypeRoot();

            ReadCArchetypeRoot(reader, definition);
            template.Definition = definition;

            // LMT added 12 May 2010 for TMP-1252
            if (reader.LocalName == "annotations")
            {
                template.Annotations =
                    new List <OpenEhr.RM.Common.Resource.Annotation>();
                OpenEhr.RM.Common.Resource.Annotation currentAnnotation;
                while (reader.LocalName == "annotations")
                {
                    currentAnnotation = ReadAnnotation(reader);
                    template.Annotations.Add(currentAnnotation);
                    reader.MoveToContent();
                }
            }

            if (reader.LocalName == "constraints")
            {
                TConstraint constraints = new TConstraint();
                ReadTConstraint(reader, constraints);
                template.Constraints = constraints;
            }

            if (reader.LocalName == "view")
            {
                TView view = new TView();
                ReadTView(reader, view);
                template.View = view;
            }

            reader.ReadEndElement();    // template
            reader.MoveToContent();
        }
        private void WriteTView(XmlWriter writer, TView tView)
        {
            Check.Require(tView != null);

            string openEhrPrefix = UseOpenEhrPrefix(writer);
            if (tView.Constraints != null && tView.Constraints.Count > 0)
            {
                foreach (TViewConstraint viewConstraint in tView.Constraints)
                {
                    writer.WriteStartElement(openEhrPrefix, "constraints", OpenEhrNamespace);
                    writer.WriteAttributeString("path", viewConstraint.Path);

                    foreach (string key in viewConstraint.Items.Keys)
                    {
                        writer.WriteStartElement(openEhrPrefix, "items", OpenEhrNamespace);
                        writer.WriteAttributeString("id", key);
                        writer.WriteElementString("value", viewConstraint.Items.Item(key));
                        writer.WriteEndElement();
                    }
                    writer.WriteEndElement();
                }
            }
        }