Extending Typed Documents

Index

    Extending Typed Documents

    Typed Documents support the loading of HIPAA 5010 and all 4010 transactions. However the situation may arise where more guides or custom documents may need to be supported. Typed Documents allows full customization to support any standard.

    Step 1 – Create your custom segments class

    public class CustomSegment1 : DocumentSegment
    {
        public CustomSegment1()
        {
            Name = “CS1”;
        }
     
        // Add properties you need
        public string ID { get; set; }
        public string RefID { get; set; }
     
        // Override this method and add your custom properties to the Values list
        public override void Write(WriteArguments wargs)
        {
            base.Write(wargs);
     
            wargs.Values.Add(Name);
            wargs.Values.Add(ID);
            wargs.Values.Add(RefID);
     
            WriteToBuffer(wargs);
        }
     
        // Override this method if you also want to load your document from EDILightWeightDocument
        public override void Load(LightWeightSegment segment)
        {
            for (int i = 0; i < segment.Elements.Count; i++)
            {
                LightWeightElement element = segment.Elements[i];
     
                switch (i)
                {
                    case 0:
                        {
                            ID = GetValue(element);
                            break;
                        }
                    case 1:
                        {
                            RefID = GetValue(element);
                            break;
                        }
                }
            }
        }
    }

    Step 2 – Derive from TypeDocument

    public class MyTypedDocument : TypedDocument
    {
        public MyTypedDocument()
        {
        }
     
        protected override DocumentSegmentGetDocumentSegment(string segmentName)
        {
              switch (segmentName)
                {
                    case “CS1”:
                        {
                            return new CustomSegment1();
                        }
                 }
     
                return null;    }
    }

    Step 3 – Use your TypedDocument

    MyTypedDocument customDocument = new MyTypedDocument();
     
    DocumentLoop mainLoop = customDocument.MainSection.CreateLoop(“Header”);
     
    CustomSegment1 cs1 = mainLoop.CreateSegment<CustomSegment1>();
    cs1.ID = “ID123”;
    cs1.RefID = “RefID 12345”;
     
    string ediData = customDocument.ToEDIString(new Delimiters());
    in Typed Documents
    Did this article answer your question?