xmlxml-serializationcda

xsi:type= wont serialize properly


I'm used xsd.exe to serialize the CDA xsd into csharp classes and am trying to build a CCD document. The document has to pass through a validation process (http://xreg2.nist.gov/cda-validation/validation.html) and is failing because one element is not serializing correctly.

Any help would be greatly appreciated on how to make it work!! Thanks!

I need it to include the xsi:type="PIVL_TS" but for some reason it doesn't.

<effectiveTime xsi:type="PIVL_TS">
    <period value="6" unit="h"/>
</effectiveTime>

I get this instead

<effectiveTime>
    <period value="6" unit="h"/>
</effectiveTime>

The csharp class that was generated look like below

    [System.CodeDom.Compiler.GeneratedCodeAttribute("xsd", "4.0.30319.1")]
    [System.SerializableAttribute()]
    [System.Diagnostics.DebuggerStepThroughAttribute()]
    [System.ComponentModel.DesignerCategoryAttribute("code")]
    [System.Xml.Serialization.XmlTypeAttribute(Namespace = "urn:hl7-org:v3")]
    public partial class PIVL_TS : SXCM_TS {

        private IVL_TS phaseField;

        private PQ periodField;

        private string alignmentField;

        private bool institutionSpecified1Field;

        public PIVL_TS() {
            this.institutionSpecified1Field = false;
        }

        /// <remarks/>
        public IVL_TS phase {
            get {
                return this.phaseField;
            }
            set {
                this.phaseField = value;
            }
        }

        /// <remarks/>
        public PQ period {
            get {
                return this.periodField;
            }
            set {
                this.periodField = value;
            }
        }

        /// <remarks/>
        [System.Xml.Serialization.XmlAttributeAttribute()]
        public string alignment {
            get {
                return this.alignmentField;
            }
            set {
                this.alignmentField = value;
            }
        }

        /// <remarks/>
        [System.Xml.Serialization.XmlAttributeAttribute("institutionSpecified")]
        [System.ComponentModel.DefaultValueAttribute(false)]
        public bool institutionSpecified1 {
            get {
                return this.institutionSpecified1Field;
            }
            set {
                this.institutionSpecified1Field = value;
            }
        }
    }

Solution

  • I found if i changed the parent class to type ANY[] it would add what i need. See commented code below.

     public partial class POCD_MT000040SubstanceAdministration {
    
            private CS[] realmCodeField;
    
            private POCD_MT000040InfrastructureRoottypeId typeIdField;
    
            private II[] templateIdField;
    
            private II[] idField;
    
            private CD codeField;
    
            private ED textField;
    
            private CS statusCodeField;
    
            //private PIVL_TS[] effectiveTimeField;
            private ANY[] effectiveTimeField;