public static void SerializeXdsEntry(XdsEntry value, IFhirWriter writer)
        {
            writer.WriteStartRootObject("XdsEntry");
            writer.WriteStartComplexContent();

            // Serialize element's localId attribute
            if( value.InternalId != null && !String.IsNullOrEmpty(value.InternalId.Contents) )
                writer.WriteRefIdContents(value.InternalId.Contents);

            // Serialize element extension
            if(value.Extension != null && value.Extension.Count > 0)
            {
                writer.WriteStartArrayElement("extension");
                foreach(var item in value.Extension)
                {
                    writer.WriteStartArrayMember("extension");
                    ExtensionSerializer.SerializeExtension(item, writer);
                    writer.WriteEndArrayMember();
                }
                writer.WriteEndArrayElement();
            }

            // Serialize element language
            if(value.Language != null)
            {
                writer.WriteStartElement("language");
                CodeSerializer.SerializeCode(value.Language, writer);
                writer.WriteEndElement();
            }

            // Serialize element text
            if(value.Text != null)
            {
                writer.WriteStartElement("text");
                NarrativeSerializer.SerializeNarrative(value.Text, writer);
                writer.WriteEndElement();
            }

            // Serialize element contained
            if(value.Contained != null && value.Contained.Count > 0)
            {
                writer.WriteStartArrayElement("contained");
                foreach(var item in value.Contained)
                {
                    writer.WriteStartArrayMember("contained");
                    FhirSerializer.SerializeResource(item, writer);
                    writer.WriteEndArrayMember();
                }
                writer.WriteEndArrayElement();
            }

            // Serialize element url
            if(value.Url != null)
            {
                writer.WriteStartElement("url");
                FhirUriSerializer.SerializeFhirUri(value.Url, writer);
                writer.WriteEndElement();
            }

            // Serialize element repositoryId
            if(value.RepositoryId != null)
            {
                writer.WriteStartElement("repositoryId");
                FhirUriSerializer.SerializeFhirUri(value.RepositoryId, writer);
                writer.WriteEndElement();
            }

            // Serialize element mimeType
            if(value.MimeType != null)
            {
                writer.WriteStartElement("mimeType");
                FhirStringSerializer.SerializeFhirString(value.MimeType, writer);
                writer.WriteEndElement();
            }

            // Serialize element format
            if(value.Format != null)
            {
                writer.WriteStartElement("format");
                CodingSerializer.SerializeCoding(value.Format, writer);
                writer.WriteEndElement();
            }

            // Serialize element class
            if(value.Class != null)
            {
                writer.WriteStartElement("class");
                CodingSerializer.SerializeCoding(value.Class, writer);
                writer.WriteEndElement();
            }

            // Serialize element type
            if(value.Type != null)
            {
                writer.WriteStartElement("type");
                CodingSerializer.SerializeCoding(value.Type, writer);
                writer.WriteEndElement();
            }

            // Serialize element title
            if(value.Title != null)
            {
                writer.WriteStartElement("title");
                FhirStringSerializer.SerializeFhirString(value.Title, writer);
                writer.WriteEndElement();
            }

            // Serialize element documentId
            if(value.DocumentId != null)
            {
                writer.WriteStartElement("documentId");
                FhirUriSerializer.SerializeFhirUri(value.DocumentId, writer);
                writer.WriteEndElement();
            }

            // Serialize element availability
            if(value.Availability != null)
            {
                writer.WriteStartElement("availability");
                CodeSerializer.SerializeCode<XdsEntry.XdsEntryAvailability>(value.Availability, writer);
                writer.WriteEndElement();
            }

            // Serialize element confidentialityCode
            if(value.ConfidentialityCode != null)
            {
                writer.WriteStartElement("confidentialityCode");
                CodingSerializer.SerializeCoding(value.ConfidentialityCode, writer);
                writer.WriteEndElement();
            }

            // Serialize element created
            if(value.Created != null)
            {
                writer.WriteStartElement("created");
                InstantSerializer.SerializeInstant(value.Created, writer);
                writer.WriteEndElement();
            }

            // Serialize element event
            if(value.Event != null && value.Event.Count > 0)
            {
                writer.WriteStartArrayElement("event");
                foreach(var item in value.Event)
                {
                    writer.WriteStartArrayMember("event");
                    CodingSerializer.SerializeCoding(item, writer);
                    writer.WriteEndArrayMember();
                }
                writer.WriteEndArrayElement();
            }

            // Serialize element hash
            if(value.Hash != null)
            {
                writer.WriteStartElement("hash");
                FhirStringSerializer.SerializeFhirString(value.Hash, writer);
                writer.WriteEndElement();
            }

            // Serialize element size
            if(value.Size != null)
            {
                writer.WriteStartElement("size");
                FhirStringSerializer.SerializeFhirString(value.Size, writer);
                writer.WriteEndElement();
            }

            // Serialize element lang
            if(value.Lang != null)
            {
                writer.WriteStartElement("lang");
                FhirStringSerializer.SerializeFhirString(value.Lang, writer);
                writer.WriteEndElement();
            }

            // Serialize element folder
            if(value.Folder != null && value.Folder.Count > 0)
            {
                writer.WriteStartArrayElement("folder");
                foreach(var item in value.Folder)
                {
                    writer.WriteStartArrayMember("folder");
                    ResourceReferenceSerializer.SerializeResourceReference(item, writer);
                    writer.WriteEndArrayMember();
                }
                writer.WriteEndArrayElement();
            }

            // Serialize element patientId
            if(value.PatientId != null)
            {
                writer.WriteStartElement("patientId");
                IdentifierSerializer.SerializeIdentifier(value.PatientId, writer);
                writer.WriteEndElement();
            }

            // Serialize element sourcePatientId
            if(value.SourcePatientId != null)
            {
                writer.WriteStartElement("sourcePatientId");
                IdentifierSerializer.SerializeIdentifier(value.SourcePatientId, writer);
                writer.WriteEndElement();
            }

            // Serialize element patientInfo
            if(value.PatientInfo != null)
            {
                writer.WriteStartElement("patientInfo");
                ResourceReferenceSerializer.SerializeResourceReference(value.PatientInfo, writer);
                writer.WriteEndElement();
            }

            // Serialize element author
            if(value.Author != null && value.Author.Count > 0)
            {
                writer.WriteStartArrayElement("author");
                foreach(var item in value.Author)
                {
                    writer.WriteStartArrayMember("author");
                    XdsEntrySerializer.SerializeXdsEntryAuthorComponent(item, writer);
                    writer.WriteEndArrayMember();
                }
                writer.WriteEndArrayElement();
            }

            // Serialize element authenticator
            if(value.Authenticator != null)
            {
                writer.WriteStartElement("authenticator");
                XdsEntrySerializer.SerializeXdsEntryAuthenticatorComponent(value.Authenticator, writer);
                writer.WriteEndElement();
            }

            // Serialize element facilityType
            if(value.FacilityType != null)
            {
                writer.WriteStartElement("facilityType");
                CodingSerializer.SerializeCoding(value.FacilityType, writer);
                writer.WriteEndElement();
            }

            // Serialize element practiceSetting
            if(value.PracticeSetting != null)
            {
                writer.WriteStartElement("practiceSetting");
                CodingSerializer.SerializeCoding(value.PracticeSetting, writer);
                writer.WriteEndElement();
            }

            // Serialize element homeCommunity
            if(value.HomeCommunity != null)
            {
                writer.WriteStartElement("homeCommunity");
                FhirUriSerializer.SerializeFhirUri(value.HomeCommunity, writer);
                writer.WriteEndElement();
            }

            // Serialize element service
            if(value.Service != null)
            {
                writer.WriteStartElement("service");
                XdsEntrySerializer.SerializeXdsEntryServiceComponent(value.Service, writer);
                writer.WriteEndElement();
            }

            // Serialize element comments
            if(value.Comments != null)
            {
                writer.WriteStartElement("comments");
                FhirStringSerializer.SerializeFhirString(value.Comments, writer);
                writer.WriteEndElement();
            }

            writer.WriteEndComplexContent();
            writer.WriteEndRootObject();
        }
        public static void SerializeXdsEntryServiceComponent(XdsEntry.XdsEntryServiceComponent value, IFhirWriter writer)
        {
            writer.WriteStartComplexContent();

            // Serialize element's localId attribute
            if( value.InternalId != null && !String.IsNullOrEmpty(value.InternalId.Contents) )
                writer.WriteRefIdContents(value.InternalId.Contents);

            // Serialize element extension
            if(value.Extension != null && value.Extension.Count > 0)
            {
                writer.WriteStartArrayElement("extension");
                foreach(var item in value.Extension)
                {
                    writer.WriteStartArrayMember("extension");
                    ExtensionSerializer.SerializeExtension(item, writer);
                    writer.WriteEndArrayMember();
                }
                writer.WriteEndArrayElement();
            }

            // Serialize element start
            if(value.Start != null)
            {
                writer.WriteStartElement("start");
                FhirDateTimeSerializer.SerializeFhirDateTime(value.Start, writer);
                writer.WriteEndElement();
            }

            // Serialize element stop
            if(value.Stop != null)
            {
                writer.WriteStartElement("stop");
                FhirDateTimeSerializer.SerializeFhirDateTime(value.Stop, writer);
                writer.WriteEndElement();
            }

            writer.WriteEndComplexContent();
        }
        public static void SerializeXdsEntryAuthorInstitutionComponent(XdsEntry.XdsEntryAuthorInstitutionComponent value, IFhirWriter writer)
        {
            writer.WriteStartComplexContent();

            // Serialize element's localId attribute
            if( value.InternalId != null && !String.IsNullOrEmpty(value.InternalId.Contents) )
                writer.WriteRefIdContents(value.InternalId.Contents);

            // Serialize element extension
            if(value.Extension != null && value.Extension.Count > 0)
            {
                writer.WriteStartArrayElement("extension");
                foreach(var item in value.Extension)
                {
                    writer.WriteStartArrayMember("extension");
                    ExtensionSerializer.SerializeExtension(item, writer);
                    writer.WriteEndArrayMember();
                }
                writer.WriteEndArrayElement();
            }

            // Serialize element id
            if(value.Id != null)
            {
                writer.WriteStartElement("id");
                IdentifierSerializer.SerializeIdentifier(value.Id, writer);
                writer.WriteEndElement();
            }

            // Serialize element name
            if(value.Name != null)
            {
                writer.WriteStartElement("name");
                FhirStringSerializer.SerializeFhirString(value.Name, writer);
                writer.WriteEndElement();
            }

            writer.WriteEndComplexContent();
        }
        /// <summary>
        /// Parse XdsEntry
        /// </summary>
        public static XdsEntry ParseXdsEntry(IFhirReader reader, ErrorList errors, XdsEntry existingInstance = null )
        {
            XdsEntry result = existingInstance != null ? existingInstance : new XdsEntry();
            try
            {
                string currentElementName = reader.CurrentElementName;
                reader.EnterElement();

                while (reader.HasMoreElements())
                {
                    // Parse element extension
                    if( ParserUtils.IsAtFhirElement(reader, "extension") )
                    {
                        result.Extension = new List<Extension>();
                        reader.EnterArray();

                        while( ParserUtils.IsAtArrayElement(reader, "extension") )
                            result.Extension.Add(ExtensionParser.ParseExtension(reader, errors));

                        reader.LeaveArray();
                    }

                    // Parse element language
                    else if( ParserUtils.IsAtFhirElement(reader, "language") )
                        result.Language = CodeParser.ParseCode(reader, errors);

                    // Parse element text
                    else if( ParserUtils.IsAtFhirElement(reader, "text") )
                        result.Text = NarrativeParser.ParseNarrative(reader, errors);

                    // Parse element contained
                    else if( ParserUtils.IsAtFhirElement(reader, "contained") )
                    {
                        result.Contained = new List<Resource>();
                        reader.EnterArray();

                        while( ParserUtils.IsAtArrayElement(reader, "contained") )
                            result.Contained.Add(ParserUtils.ParseContainedResource(reader,errors));

                        reader.LeaveArray();
                    }

                    // Parse element internalId
                    else if( reader.IsAtRefIdElement() )
                        result.InternalId = Id.Parse(reader.ReadRefIdContents());

                    // Parse element url
                    else if( ParserUtils.IsAtFhirElement(reader, "url") )
                        result.Url = FhirUriParser.ParseFhirUri(reader, errors);

                    // Parse element repositoryId
                    else if( ParserUtils.IsAtFhirElement(reader, "repositoryId") )
                        result.RepositoryId = FhirUriParser.ParseFhirUri(reader, errors);

                    // Parse element mimeType
                    else if( ParserUtils.IsAtFhirElement(reader, "mimeType") )
                        result.MimeType = FhirStringParser.ParseFhirString(reader, errors);

                    // Parse element format
                    else if( ParserUtils.IsAtFhirElement(reader, "format") )
                        result.Format = CodingParser.ParseCoding(reader, errors);

                    // Parse element class
                    else if( ParserUtils.IsAtFhirElement(reader, "class") )
                        result.Class = CodingParser.ParseCoding(reader, errors);

                    // Parse element type
                    else if( ParserUtils.IsAtFhirElement(reader, "type") )
                        result.Type = CodingParser.ParseCoding(reader, errors);

                    // Parse element title
                    else if( ParserUtils.IsAtFhirElement(reader, "title") )
                        result.Title = FhirStringParser.ParseFhirString(reader, errors);

                    // Parse element documentId
                    else if( ParserUtils.IsAtFhirElement(reader, "documentId") )
                        result.DocumentId = FhirUriParser.ParseFhirUri(reader, errors);

                    // Parse element availability
                    else if( ParserUtils.IsAtFhirElement(reader, "availability") )
                        result.Availability = CodeParser.ParseCode<XdsEntry.XdsEntryAvailability>(reader, errors);

                    // Parse element confidentialityCode
                    else if( ParserUtils.IsAtFhirElement(reader, "confidentialityCode") )
                        result.ConfidentialityCode = CodingParser.ParseCoding(reader, errors);

                    // Parse element created
                    else if( ParserUtils.IsAtFhirElement(reader, "created") )
                        result.Created = InstantParser.ParseInstant(reader, errors);

                    // Parse element event
                    else if( ParserUtils.IsAtFhirElement(reader, "event") )
                    {
                        result.Event = new List<Coding>();
                        reader.EnterArray();

                        while( ParserUtils.IsAtArrayElement(reader, "event") )
                            result.Event.Add(CodingParser.ParseCoding(reader, errors));

                        reader.LeaveArray();
                    }

                    // Parse element hash
                    else if( ParserUtils.IsAtFhirElement(reader, "hash") )
                        result.Hash = FhirStringParser.ParseFhirString(reader, errors);

                    // Parse element size
                    else if( ParserUtils.IsAtFhirElement(reader, "size") )
                        result.Size = FhirStringParser.ParseFhirString(reader, errors);

                    // Parse element lang
                    else if( ParserUtils.IsAtFhirElement(reader, "lang") )
                        result.Lang = FhirStringParser.ParseFhirString(reader, errors);

                    // Parse element folder
                    else if( ParserUtils.IsAtFhirElement(reader, "folder") )
                    {
                        result.Folder = new List<ResourceReference>();
                        reader.EnterArray();

                        while( ParserUtils.IsAtArrayElement(reader, "folder") )
                            result.Folder.Add(ResourceReferenceParser.ParseResourceReference(reader, errors));

                        reader.LeaveArray();
                    }

                    // Parse element patientId
                    else if( ParserUtils.IsAtFhirElement(reader, "patientId") )
                        result.PatientId = IdentifierParser.ParseIdentifier(reader, errors);

                    // Parse element sourcePatientId
                    else if( ParserUtils.IsAtFhirElement(reader, "sourcePatientId") )
                        result.SourcePatientId = IdentifierParser.ParseIdentifier(reader, errors);

                    // Parse element patientInfo
                    else if( ParserUtils.IsAtFhirElement(reader, "patientInfo") )
                        result.PatientInfo = ResourceReferenceParser.ParseResourceReference(reader, errors);

                    // Parse element author
                    else if( ParserUtils.IsAtFhirElement(reader, "author") )
                    {
                        result.Author = new List<XdsEntry.XdsEntryAuthorComponent>();
                        reader.EnterArray();

                        while( ParserUtils.IsAtArrayElement(reader, "author") )
                            result.Author.Add(XdsEntryParser.ParseXdsEntryAuthorComponent(reader, errors));

                        reader.LeaveArray();
                    }

                    // Parse element authenticator
                    else if( ParserUtils.IsAtFhirElement(reader, "authenticator") )
                        result.Authenticator = XdsEntryParser.ParseXdsEntryAuthenticatorComponent(reader, errors);

                    // Parse element facilityType
                    else if( ParserUtils.IsAtFhirElement(reader, "facilityType") )
                        result.FacilityType = CodingParser.ParseCoding(reader, errors);

                    // Parse element practiceSetting
                    else if( ParserUtils.IsAtFhirElement(reader, "practiceSetting") )
                        result.PracticeSetting = CodingParser.ParseCoding(reader, errors);

                    // Parse element homeCommunity
                    else if( ParserUtils.IsAtFhirElement(reader, "homeCommunity") )
                        result.HomeCommunity = FhirUriParser.ParseFhirUri(reader, errors);

                    // Parse element service
                    else if( ParserUtils.IsAtFhirElement(reader, "service") )
                        result.Service = XdsEntryParser.ParseXdsEntryServiceComponent(reader, errors);

                    // Parse element comments
                    else if( ParserUtils.IsAtFhirElement(reader, "comments") )
                        result.Comments = FhirStringParser.ParseFhirString(reader, errors);

                    else
                    {
                        errors.Add(String.Format("Encountered unknown element {0} while parsing {1}", reader.CurrentElementName, currentElementName), reader);
                        reader.SkipSubElementsFor(currentElementName);
                        result = null;
                    }
                }

                reader.LeaveElement();
            }
            catch (Exception ex)
            {
                errors.Add(ex.Message, reader);
            }
            return result;
        }
        /// <summary>
        /// Parse XdsEntryServiceComponent
        /// </summary>
        public static XdsEntry.XdsEntryServiceComponent ParseXdsEntryServiceComponent(IFhirReader reader, ErrorList errors, XdsEntry.XdsEntryServiceComponent existingInstance = null )
        {
            XdsEntry.XdsEntryServiceComponent result = existingInstance != null ? existingInstance : new XdsEntry.XdsEntryServiceComponent();
            try
            {
                string currentElementName = reader.CurrentElementName;
                reader.EnterElement();

                while (reader.HasMoreElements())
                {
                    // Parse element extension
                    if( ParserUtils.IsAtFhirElement(reader, "extension") )
                    {
                        result.Extension = new List<Extension>();
                        reader.EnterArray();

                        while( ParserUtils.IsAtArrayElement(reader, "extension") )
                            result.Extension.Add(ExtensionParser.ParseExtension(reader, errors));

                        reader.LeaveArray();
                    }

                    // Parse element internalId
                    else if( reader.IsAtRefIdElement() )
                        result.InternalId = Id.Parse(reader.ReadRefIdContents());

                    // Parse element start
                    else if( ParserUtils.IsAtFhirElement(reader, "start") )
                        result.Start = FhirDateTimeParser.ParseFhirDateTime(reader, errors);

                    // Parse element stop
                    else if( ParserUtils.IsAtFhirElement(reader, "stop") )
                        result.Stop = FhirDateTimeParser.ParseFhirDateTime(reader, errors);

                    else
                    {
                        errors.Add(String.Format("Encountered unknown element {0} while parsing {1}", reader.CurrentElementName, currentElementName), reader);
                        reader.SkipSubElementsFor(currentElementName);
                        result = null;
                    }
                }

                reader.LeaveElement();
            }
            catch (Exception ex)
            {
                errors.Add(ex.Message, reader);
            }
            return result;
        }
        /// <summary>
        /// Parse XdsEntryAuthorComponent
        /// </summary>
        public static XdsEntry.XdsEntryAuthorComponent ParseXdsEntryAuthorComponent(IFhirReader reader, ErrorList errors, XdsEntry.XdsEntryAuthorComponent existingInstance = null )
        {
            XdsEntry.XdsEntryAuthorComponent result = existingInstance != null ? existingInstance : new XdsEntry.XdsEntryAuthorComponent();
            try
            {
                string currentElementName = reader.CurrentElementName;
                reader.EnterElement();

                while (reader.HasMoreElements())
                {
                    // Parse element extension
                    if( ParserUtils.IsAtFhirElement(reader, "extension") )
                    {
                        result.Extension = new List<Extension>();
                        reader.EnterArray();

                        while( ParserUtils.IsAtArrayElement(reader, "extension") )
                            result.Extension.Add(ExtensionParser.ParseExtension(reader, errors));

                        reader.LeaveArray();
                    }

                    // Parse element internalId
                    else if( reader.IsAtRefIdElement() )
                        result.InternalId = Id.Parse(reader.ReadRefIdContents());

                    // Parse element name
                    else if( ParserUtils.IsAtFhirElement(reader, "name") )
                        result.Name = HumanNameParser.ParseHumanName(reader, errors);

                    // Parse element id
                    else if( ParserUtils.IsAtFhirElement(reader, "id") )
                        result.Id = IdentifierParser.ParseIdentifier(reader, errors);

                    // Parse element role
                    else if( ParserUtils.IsAtFhirElement(reader, "role") )
                    {
                        result.Role = new List<FhirString>();
                        reader.EnterArray();

                        while( ParserUtils.IsAtArrayElement(reader, "role") )
                            result.Role.Add(FhirStringParser.ParseFhirString(reader, errors));

                        reader.LeaveArray();
                    }

                    // Parse element specialty
                    else if( ParserUtils.IsAtFhirElement(reader, "specialty") )
                    {
                        result.Specialty = new List<FhirString>();
                        reader.EnterArray();

                        while( ParserUtils.IsAtArrayElement(reader, "specialty") )
                            result.Specialty.Add(FhirStringParser.ParseFhirString(reader, errors));

                        reader.LeaveArray();
                    }

                    // Parse element institution
                    else if( ParserUtils.IsAtFhirElement(reader, "institution") )
                    {
                        result.Institution = new List<XdsEntry.XdsEntryAuthorInstitutionComponent>();
                        reader.EnterArray();

                        while( ParserUtils.IsAtArrayElement(reader, "institution") )
                            result.Institution.Add(XdsEntryParser.ParseXdsEntryAuthorInstitutionComponent(reader, errors));

                        reader.LeaveArray();
                    }

                    // Parse element contact
                    else if( ParserUtils.IsAtFhirElement(reader, "contact") )
                    {
                        result.Contact = new List<Contact>();
                        reader.EnterArray();

                        while( ParserUtils.IsAtArrayElement(reader, "contact") )
                            result.Contact.Add(ContactParser.ParseContact(reader, errors));

                        reader.LeaveArray();
                    }

                    else
                    {
                        errors.Add(String.Format("Encountered unknown element {0} while parsing {1}", reader.CurrentElementName, currentElementName), reader);
                        reader.SkipSubElementsFor(currentElementName);
                        result = null;
                    }
                }

                reader.LeaveElement();
            }
            catch (Exception ex)
            {
                errors.Add(ex.Message, reader);
            }
            return result;
        }