Example #1
0
        /// <summary>
        /// Writes the inserted date value to the client.
        /// </summary>
        private void UpdateStopDateAndReturn()
        {
            string newDate = string.Empty;

            // validate required mappings
            if (TABLE_MAPPINGS.ContainsKey(Table) && BusinessObjectFactory.CanBuildBusinessObject(Table) && PriKey.HasValue)
            {
                int patientId = int.Parse(Session[SessionKey.PatientId].ToString());

                // create instance
                IBusinessObject biz = BusinessObjectFactory.BuildBusinessObject(Table);
                // load record and validate
                biz.Get(PriKey.Value);
                if (!biz.IsEmpty)
                {
                    // turn on validation of patient
                    biz.EnableSaveValidation(patientId);

                    // the date field representing the stop date
                    string dateField = TABLE_MAPPINGS[Table];
                    // check for date text field
                    string dateTextField = dateField + "Text";
                    if (biz.HasField(dateField))
                    {
                        // determine if updating stop date of nullifying
                        bool doStop = Checked;
                        if (doStop)
                        {
                            // set date fields
                            DateTime date = QueryDate.HasValue ? QueryDate.Value : DateTime.Today; // ?? use DateTime.Today for normalization
                            biz[dateField] = date;
                            if (biz.HasField(dateTextField))
                            {
                                biz[dateTextField] = date.ToShortDateString();
                            }
                            // set short date
                            newDate = date.ToShortDateString();
                        }
                        // nullify stop date fields
                        else
                        {
                            biz[dateField] = null;
                            if (biz.HasField(dateTextField))
                            {
                                biz[dateTextField] = null;
                            }
                            newDate = string.Empty;
                        }
                    }
                    // update
                    biz.Save();
                }
            }
            else
            {
                newDate = string.Empty;
            }
            // write the new short stop date
            Response.Write(newDate);
        }
Example #2
0
        private void WriteChildRecordResponse()
        {
            string response = "";

            if (TABLE_MAPPINGS.ContainsKey(Table) && BusinessObjectFactory.CanBuildBusinessObject(Table) && PriKey.HasValue)
            {
                string childTable = TABLE_MAPPINGS[Table];
                if (BusinessObjectFactory.CanBuildBusinessObject(childTable))
                {
                    int patientId = int.Parse(Session[SessionKey.PatientId].ToString());

                    // load parent
                    BusinessObject parent = BusinessObjectFactory.BuildBusinessObject(Table);
                    parent.Get(PriKey.Value);
                    if (!parent.IsEmpty)
                    {
                        // get prefix (i.e. "MedTx", "RadTx")
                        string prefix = childTable.Substring(0, childTable.IndexOf("Tx") + 2);
                        // turn on validation of patient
                        parent.EnableSaveValidation(patientId);

                        // create child instance
                        BusinessObject child = BusinessObjectFactory.BuildBusinessObject(childTable);
                        child.EnableSaveValidation(patientId);

                        // set foreign key
                        child[child.ParentKeyName] = parent[parent.PrimaryKeyName];

                        // set fields
                        foreach (string field in COPY_FIELDS)
                        {
                            string parentField = prefix + field;
                            string childField  = prefix + "Admin" + field;
                            if (parent.FieldNames.Contains(parentField) && child.FieldNames.Contains(childField))
                            {
                                child[childField] = parent[parentField];
                            }
                        }
                        // sepcial date fields
                        DateTime date = QueryDate.HasValue ? QueryDate.Value : DateTime.Today;
                        child[prefix + "AdminStartDateText"] = date.ToShortDateString();
                        child[prefix + "AdminStartDate"]     = date;

                        // insert
                        child.Save();

                        response = "- Administered " + (DateTime.Today.Date == date.Date ? "Today" : date.ToShortDateString()) + " -";
                    }
                }
            }
            Response.Write(response);
        }
Example #3
0
 /// <summary>
 /// Adds a grid based on the current table name
 /// </summary>
 /// <param name="tableName"></param>
 public virtual void BuildLayout(string tableName)
 {
     // validate table
     if (BusinessObjectFactory.CanBuildBusinessObject(tableName))
     {
         // get config
         Caisis.Controller.PatientDataEntryController pdec = new Caisis.Controller.PatientDataEntryController();
         int totalBlankRows        = pdec.GetTotalBlankGridRows(tableName);
         int totalVisibleBlankRows = pdec.GetVisibleBlankGridRows(tableName);
         var tableFieldsMetadata   = pdec.GetTableFieldsMetadata(tableName);
         BuildLayout(tableName, totalBlankRows, totalVisibleBlankRows, tableFieldsMetadata);
     }
 }
Example #4
0
        private void BuildEformPreview(string eformName)
        {
            Caisis.Security.SecurityController sc = new Caisis.Security.SecurityController();
            string          disease         = sc.GetViewMode();
            EFormController ec              = new EFormController();
            var             eFormComponents = GetEformComponents(Page, disease, eformName);

            // DEBUG INFO

            // get all input controls across eform
            var map = from entry in eFormComponents
                      select new
            {
                SectionName                          = entry.Key,
                Components                           = from component in entry.Value
                                          let inputs = CICHelper.GetCaisisInputControls(component).OfType <IEformInputField>()
                                                       let inputTypes = from i in inputs
                                                                        group i by i.GetType().Name into g
                                                                        select g.Key + ": " + g.Count()
                                                                        select new
                {
                    Component          = component,
                    Title              = component.Title,
                    InputControls      = inputs,
                    InputControlsCount = inputs.Count(),
                    InputControlsStats = string.Join(" | ", inputTypes.ToArray())
                }
            };
            var allEformInputControls = map.SelectMany(a => a.Components.SelectMany(b => b.InputControls));

            foreach (var inputControl in allEformInputControls)
            {
                var debugInfo = new Dictionary <string, string>();
                // add standard debug
                debugInfo.Add("Table", inputControl.Table);
                debugInfo.Add("Field", inputControl.Field);
                debugInfo.Add("Record Id", inputControl.RecordId);
                debugInfo.Add("Parent Record Id", inputControl.ParentRecordId);
                // only show required if field is actually required
                if (inputControl.Required)
                {
                    debugInfo.Add("Required", inputControl.Required.ToString());
                }
                // type info
                debugInfo.Add("Control Type", inputControl.GetType().Name);
                // lookup code fix
                if (inputControl is ICaisisLookupControl)
                {
                    var    lkpControl  = inputControl as ICaisisLookupControl;
                    string lkpCode     = lkpControl.LookupCode;
                    string lkpDistinct = lkpControl.LookupDistinct;
                    debugInfo.Add("Lookup Code", lkpCode);
                    debugInfo.Add("Lookup Distinct", lkpDistinct);
                    // supress @PatientId lookup
                    if ((!string.IsNullOrEmpty(lkpCode) && lkpCode.Contains("@PatientId")) || (!string.IsNullOrEmpty(lkpDistinct) && lkpDistinct.Contains("@PatientId")))
                    {
                        lkpControl.LookupCode     = string.Empty;
                        lkpControl.LookupDistinct = string.Empty;
                    }
                }

                // set debug info
                if (inputControl is WebControl)
                {
                    WebControl iWebControl = inputControl as WebControl;
                    // cleanup attributes ( no need to show empty attributes)
                    var tooltipInfo = from info in debugInfo
                                      where !string.IsNullOrEmpty(info.Value)
                                      select string.Format("{0}: {1}", info.Key, info.Value);

                    // set tooltip
                    iWebControl.Attributes["title"] = string.Join(" | ", tooltipInfo.ToArray());
                }
            }

            // build navigation
            EformSectionNaviation.DataSource = map;
            EformSectionNaviation.DataBind();

            // build UI
            EformSectionRptr.DataSource = map;
            EformSectionRptr.DataBind();

            // debug XML
            EformConfig config = EformConfig.GetByName(eformName);

            var elements = from eControl in allEformInputControls
                           let table = eControl.Table + ""
                                       let recordId = eControl.RecordId + ""
                                                      let parentRecordId                         = eControl.ParentRecordId + ""
                                                                                       let depth = BOL.BusinessObjectFactory.CanBuildBusinessObject(table) ? BOL.BusinessObject.GetTableDepth(table) : int.MaxValue
                                                                                                   group eControl by new { Table = table, RecordId = recordId, ParentRecordId = parentRecordId, Depth = depth } into g
            let recordSort = !string.IsNullOrEmpty(g.Key.RecordId) ? int.Parse(g.Key.RecordId) : 0
                             orderby g.Key.Depth ascending, g.Key.Table ascending, recordSort ascending
                select new
            {
                Table          = g.Key.Table,
                Depth          = g.Key.Depth,
                RecordId       = g.Key.RecordId,
                ParentRecordId = g.Key.ParentRecordId,
                Fields         = (from e in g
                                  orderby e.Field ascending
                                  select new
                {
                    Field = e.Field.Trim()
                }).Distinct()
            };

            var nodesWithChildren = from child in elements
                                    let childTableName = child.Table
                                                         where BusinessObjectFactory.CanBuildBusinessObject(childTableName)
                                                         let childParentTableName = BusinessObject.GetParentTablename(childTableName)
                                                                                    join parent in elements on new { table = childParentTableName, b = child.ParentRecordId } equals new { table = parent.Table, b = parent.RecordId } into results
            let p = results.FirstOrDefault()
                    where p != null
                    select new
            {
                Parent = p,
                Child  = child
            };
            var nodesWithoutChildren = elements.Except(nodesWithChildren.Select(a => a.Parent));
            // init a list of top level nodes, with those w/o child records
            List <XElement> topLevelNodes = new List <XElement>(from element in nodesWithoutChildren
                                                                select new XElement(element.Table,
                                                                                    new XAttribute("Depth", element.Depth),
                                                                                    new XAttribute("RecordId", element.RecordId),
                                                                                    new XAttribute("ParentRecordId", element.ParentRecordId),
                                                                                    from e in element.Fields
                                                                                    orderby e.Field ascending
                                                                                    select new XElement(e.Field.Trim())
                                                                                    ));
            // create a lookup for finding parent node
            var lookup = new Dictionary <KeyValuePair <string, string>, XElement>();

            foreach (var a in nodesWithChildren)
            {
                var      child        = a.Child;
                var      parent       = a.Parent;
                var      testKey      = new KeyValuePair <string, string>(parent.Table, parent.RecordId);
                var      testChildKey = new KeyValuePair <string, string>(child.Table, child.ParentRecordId + "_" + child.RecordId);
                XElement parentNode   = null;
                XElement childNode    = null;
                if (lookup.ContainsKey(testKey))
                {
                    parentNode = lookup[testKey];
                }
                else
                {
                    parentNode = new XElement(parent.Table,
                                              new XAttribute("Depth", parent.Depth),
                                              new XAttribute("RecordId", parent.RecordId),
                                              new XAttribute("ParentRecordId", parent.ParentRecordId),
                                              from e in parent.Fields
                                              orderby e.Field ascending
                                              select new XElement(e.Field.Trim())
                                              );
                    // add lookup entry
                    lookup.Add(testKey, parentNode);
                    topLevelNodes.Add(parentNode);
                }
                // add child
                if (lookup.ContainsKey(testChildKey))
                {
                    childNode = lookup[testChildKey];
                }
                else
                {
                    childNode = new XElement(child.Table,
                                             new XAttribute("Depth", child.Depth),
                                             new XAttribute("RecordId", child.RecordId),
                                             new XAttribute("ParentRecordId", child.ParentRecordId),
                                             from e in child.Fields
                                             orderby e.Field ascending
                                             select new XElement(e.Field.Trim())
                                             );
                    // add lookup entry
                    lookup.Add(testChildKey, childNode);
                    parentNode.Add(childNode);
                }
            }

            // order all top level nodes
            var orderedContent = from element in topLevelNodes
                                 let recordSort = !string.IsNullOrEmpty(element.Attribute("RecordId").Value) ? int.Parse(element.Attribute("RecordId").Value) : 0
                                                  orderby int.Parse(element.Attribute("Depth").Value) ascending, element.Name.LocalName ascending, recordSort ascending
                select new XElement(element.Name.LocalName,
                                    element.Attributes().Where(a => a.Name.LocalName != "Depth" && !string.IsNullOrEmpty(a.Value)),
                                    element.Descendants());

            // finally build XML document
            var debugXML = new XDocument(
                // declaration
                new XDeclaration("1.0", "utf-8", "yes"),
                // root with attributes
                new XElement("eform",
                             new XAttribute("name", eformName), new XAttribute("displayName", config.DisplayName),
                             // eform content
                             orderedContent)
                );

            // write to text box (for some reason, no declaration outpout by default)
            var outputWriter = new System.IO.StringWriter();

            debugXML.Save(outputWriter);
            EformDebug.Text = outputWriter.ToString();

            // cleanup
            outputWriter.Flush();
            outputWriter.Close();
        }