Beispiel #1
0
        void WriteCArchetypeRoot(XmlWriter writer, CArchetypeRoot cArchetypeRoot)
        {
            Check.Require(cArchetypeRoot != null, string.Format(CommonStrings.XMustNotBeNull, "cArchetypeRoot"));
            Check.Require(cArchetypeRoot.ArchetypeId != null, string.Format(CommonStrings.XMustNotBeNull, "cArchetypeRoot.ArchetypeId"));

            string openEhrPrefix = UseOpenEhrPrefix(writer);

            WriteCComplexObject(writer, cArchetypeRoot);

            writer.WriteStartElement(RmXmlSerializer.UseOpenEhrPrefix(writer), "archetype_id", OpenEhrNamespace);
            cArchetypeRoot.ArchetypeId.WriteXml(writer);
            writer.WriteEndElement();

            if (cArchetypeRoot.TemplateId != null)
            {
                writer.WriteStartElement(RmXmlSerializer.UseOpenEhrPrefix(writer), "template_id", OpenEhrNamespace);
                cArchetypeRoot.TemplateId.WriteXml(writer);
                writer.WriteEndElement();
            }

            if (cArchetypeRoot.TermDefinitions != null && cArchetypeRoot.TermDefinitions.Count > 0)
            {
                foreach (System.Collections.Generic.KeyValuePair <string, ArchetypeTerm> item in  cArchetypeRoot.TermDefinitions)
                {
                    writer.WriteStartElement(openEhrPrefix, "term_definitions", OpenEhrNamespace);
                    amSerializer.WriteArchetypeTerm(writer, item.Value);
                    writer.WriteEndElement();
                }
            }

            if (cArchetypeRoot.TermBindings != null && cArchetypeRoot.TermBindings.Count > 0)
            {
                foreach (string terminology in cArchetypeRoot.TermBindings.Keys)
                {
                    writer.WriteStartElement(openEhrPrefix, "term_bindings", OpenEhrNamespace);

                    writer.WriteAttributeString("terminology", terminology);

                    AssumedTypes.Hash <CodePhrase, string> eachTermBindingItem = cArchetypeRoot.TermBindings.Item(terminology);

                    foreach (string code in eachTermBindingItem.Keys)
                    {
                        writer.WriteStartElement(openEhrPrefix, "items", OpenEhrNamespace);

                        writer.WriteAttributeString("code", code);


                        writer.WriteStartElement(openEhrPrefix, "value", OpenEhrNamespace);

                        eachTermBindingItem.Item(code).WriteXml(writer);

                        writer.WriteEndElement();
                        writer.WriteEndElement();
                    }
                    writer.WriteEndElement();
                }
            }
        }
        // TODO: this must be reinstated when ConfigurationSource is able to be specified

        #endregion



        void ReadCAttribute(XmlReader reader, CAttribute cAttribute)
        {
            Check.Require(cAttribute != null, string.Format(CommonStrings.XMustNotBeNull, "cAttribute"));

            if (reader.LocalName != "rm_attribute_name")
            {
                throw new InvalidXmlException("rm_attribute_name", reader.LocalName);
            }
            cAttribute.RmAttributeName = reader.ReadElementContentAsString("rm_attribute_name", OpenEhrNamespace);
            reader.MoveToContent();

            if (reader.LocalName != "existence")
            {
                throw new InvalidXmlException("existence", reader.LocalName);
            }
            cAttribute.Existence = new Interval <int>();
            amSerializer.ReadExistence(reader, cAttribute.Existence);

            if (reader.LocalName == "children")
            {
                cAttribute.Children = new OpenEhr.AssumedTypes.List <CObject>();
                do
                {
                    string cObjectType = reader.GetAttribute("type", RmXmlSerializer.XsiNamespace);
                    DesignByContract.Check.Assert(!string.IsNullOrEmpty(cObjectType), "cObjectType must not be null or empty.");

                    CObject cObj;
                    switch (cObjectType)
                    {
                    case "C_ARCHETYPE_ROOT":

                        CArchetypeRoot archetypeRoot = new CArchetypeRoot();
                        ReadCArchetypeRoot(reader, archetypeRoot);
                        cObj = archetypeRoot;
                        break;

                    case "C_COMPLEX_OBJECT":
                        CComplexObject complexObject = new CComplexObject();
                        ReadCComplexObject(reader, complexObject);
                        cObj = complexObject;
                        break;

                    default:
                        cObj = AmFactory.CObject(cObjectType);
                        amSerializer.ReadCObject(reader, cObj);
                        break;
                    }

                    cObj.Parent = cAttribute;
                    cAttribute.Children.Add(cObj);
                } while (reader.LocalName == "children" && reader.NodeType != XmlNodeType.EndElement);
            }
        }
        protected virtual string CArchetypeRootPredicate(CArchetypeRoot cArchetypeRoot)
        {
            string result = "";
            string name = GetName(cArchetypeRoot);

            if (!string.IsNullOrEmpty(name))
                result = string.Format("[{0} and name/value='{1}']", cArchetypeRoot.ArchetypeId, name);
            else
                result = string.Format("[{0}]", cArchetypeRoot.ArchetypeNodeId);

            Check.Ensure(result != null);
            return result;
        }
        void ReadCArchetypeRoot(XmlReader reader, CArchetypeRoot node)
        {
            ReadCComplexObject(reader, node);

            ArchetypeId archetypeId = new ArchetypeId();

            archetypeId.ReadXml(reader);
            node.ArchetypeId = archetypeId;

            if (reader.LocalName == "template_id")
            {
                TemplateId templateId = new TemplateId();
                templateId.ReadXml(reader);
                node.TemplateId = templateId;
            }

            if (reader.LocalName == "default_values")
            {
                throw new NotImplementedException(CommonStrings.DefaultsSerialisationNotImplemented);
            }

            if (reader.LocalName == "term_definitions")
            {
                System.Collections.Generic.Dictionary <string, AM.Archetype.Ontology.ArchetypeTerm> termDefimitionItemDic
                    = new System.Collections.Generic.Dictionary <string, AM.Archetype.Ontology.ArchetypeTerm>();

                while (reader.LocalName == "term_definitions")
                {
                    AM.Archetype.Ontology.ArchetypeTerm archetypeTerm = new AM.Archetype.Ontology.ArchetypeTerm();
                    amSerializer.ReadArchetypeTerm(reader, archetypeTerm);

                    termDefimitionItemDic.Add(archetypeTerm.Code, archetypeTerm);
                }
                node.TermDefinitions
                    = new Hash <AM.Archetype.Ontology.ArchetypeTerm, string>(termDefimitionItemDic);
            }

            if (reader.LocalName == "term_bindings")
            {
                if (reader.IsEmptyElement)
                {
                    reader.Skip();
                    reader.MoveToContent();
                }
                else
                {
                    System.Collections.Generic.Dictionary <string, Hash <CodePhrase, string> > termBindingDic =
                        new System.Collections.Generic.Dictionary <string, Hash <CodePhrase, string> >();
                    do
                    {
                        System.Collections.Generic.Dictionary <string, CodePhrase> termBindingItemDic
                            = new System.Collections.Generic.Dictionary <string, CodePhrase>();

                        string terminologyString = reader.GetAttribute("terminology");
                        DesignByContract.Check.Assert(!string.IsNullOrEmpty(terminologyString), "terminologyString must not be null or empty.");

                        reader.ReadStartElement();
                        reader.MoveToContent();

                        while (reader.LocalName == "items")
                        {
                            string hashId = reader.GetAttribute("code");

                            reader.ReadStartElement();
                            reader.MoveToContent();

                            CodePhrase codePhrase = new CodePhrase();
                            codePhrase.ReadXml(reader);

                            reader.ReadEndElement();
                            reader.MoveToContent();

                            termBindingItemDic.Add(hashId, codePhrase);
                        }

                        reader.ReadEndElement();
                        reader.MoveToContent();

                        DesignByContract.Check.Assert(termBindingItemDic.Count > 0, "termBindingItemDic must not be empty.");

                        Hash <CodePhrase, string> termBindingItemHash
                            = new Hash <CodePhrase, string>(termBindingItemDic);

                        termBindingDic.Add(terminologyString, termBindingItemHash);
                    } while (reader.LocalName == "term_bindings");

                    DesignByContract.Check.Assert(termBindingDic.Count > 0, "termBindingDic must not be empty.");

                    node.TermBindings = new Hash <Hash <CodePhrase, string>, string>(termBindingDic);
                }
            }

            Check.Assert(reader.NodeType == System.Xml.XmlNodeType.EndElement, "Expected endElement of CArchetypeRoot");

            reader.ReadEndElement();
            reader.MoveToContent();
        }
        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();
        }
        void WriteCArchetypeRoot(XmlWriter writer, CArchetypeRoot cArchetypeRoot)
        {
            Check.Require(cArchetypeRoot != null, string.Format(CommonStrings.XMustNotBeNull, "cArchetypeRoot"));
            Check.Require(cArchetypeRoot.ArchetypeId != null, string.Format(CommonStrings.XMustNotBeNull, "cArchetypeRoot.ArchetypeId"));

            string openEhrPrefix = UseOpenEhrPrefix(writer);
            WriteCComplexObject(writer, cArchetypeRoot);

            writer.WriteStartElement(RmXmlSerializer.UseOpenEhrPrefix(writer), "archetype_id", OpenEhrNamespace);
            cArchetypeRoot.ArchetypeId.WriteXml(writer);
            writer.WriteEndElement();

            if (cArchetypeRoot.TemplateId != null)
            {
                writer.WriteStartElement(RmXmlSerializer.UseOpenEhrPrefix(writer), "template_id", OpenEhrNamespace);
                cArchetypeRoot.TemplateId.WriteXml(writer);
                writer.WriteEndElement();
            }

            if (cArchetypeRoot.TermDefinitions != null && cArchetypeRoot.TermDefinitions.Count > 0)
            {
                foreach (System.Collections.Generic.KeyValuePair<string, ArchetypeTerm> item in  cArchetypeRoot.TermDefinitions)
                {
                    writer.WriteStartElement(openEhrPrefix, "term_definitions", OpenEhrNamespace);
                    amSerializer.WriteArchetypeTerm(writer, item.Value);
                    writer.WriteEndElement();

                }
            }

            if (cArchetypeRoot.TermBindings != null && cArchetypeRoot.TermBindings.Count > 0)
            {

                foreach (string terminology in cArchetypeRoot.TermBindings.Keys)
                {
                    writer.WriteStartElement(openEhrPrefix, "term_bindings", OpenEhrNamespace);

                    writer.WriteAttributeString("terminology", terminology);

                    AssumedTypes.Hash<CodePhrase, string> eachTermBindingItem = cArchetypeRoot.TermBindings.Item(terminology);

                    foreach (string code in eachTermBindingItem.Keys)
                    {
                        writer.WriteStartElement(openEhrPrefix, "items", OpenEhrNamespace);

                        writer.WriteAttributeString("code", code);

                        writer.WriteStartElement(openEhrPrefix, "value", OpenEhrNamespace);

                        eachTermBindingItem.Item(code).WriteXml(writer);

                        writer.WriteEndElement();
                        writer.WriteEndElement();
                    }
                    writer.WriteEndElement();
                }
            }
        }
Beispiel #7
0
        internal void AddSlotFiller(CArchetypeRoot filler)
        {
            Check.Require(filler != null, string.Format(CommonStrings.XMustNotBeNull, "filler"));
            Check.Require(!IsFull, AmValidationStrings.SlotMustNotBeFull);

            numberOfFillers++;
        }