Ejemplo n.º 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);
        }
Ejemplo n.º 2
0
        // shouldn't this be a member of BusinessObject?
        private IEnumerable <object> SubPath(IBusinessObject b, XElement metadata)
        {
            // traverse the query (recursively) and yield the matching field of the BusinessObject
            int i = 0;

            //return
            //    query.Fieldnames.Select(f => b[f]).Union(
            //        query.Children.SelectMany(q => SubPath(b.Children.ElementAt(i++), q)));

            // TODO: algorithm is redundant with above; extract and use delegates
            foreach (XElement child in metadata.Elements())
            {
                string s = child.Name.LocalName;

                if (b.HasField(s))
                {
                    yield return(b[s]);
                }
                else
                {
                    // child represents a table
                    foreach (object o in SubPath(b.Children.ElementAt(i++), child))
                    {
                        yield return(o);
                    }
                }
            }
        }
Ejemplo n.º 3
0
        private void PopulateProtocolId(IBusinessObject b, int id)
        {
            if (!b.IsEmpty && b.HasField(BOL.Protocol.ProtocolId))
            {
                b[BOL.Protocol.ProtocolId] = id;
            }

            b.Children.ForEach(x => PopulateProtocolId(x, id));
        }
Ejemplo n.º 4
0
 /// <summary>
 /// Populate the fields by bizo
 /// </summary>
 /// <param name="ibo"></param>
 /// <param name="controls"></param>
 private void SetFieldValues(IBusinessObject ibo, IEnumerable <ICaisisInputControl> controls)
 {
     foreach (ICaisisInputControl cic in controls)
     {
         if (cic.Table == ibo.TableName && ibo.HasField(cic.Field))
         {
             cic.Value = ibo[cic.Field].ToString();
         }
     }
 }
Ejemplo n.º 5
0
        /// <summary>
        /// Populates the biz object based on input fields of biz table
        /// </summary>
        /// <param name="ibo"></param>
        /// <param name="controls"></param>
        private void SetBizoValues(IBusinessObject ibo, IEnumerable <ICaisisInputControl> controls)
        {
            foreach (ICaisisInputControl cic in controls)
            {
                // readonly text boxes shouldn't be modified, won't retain client values
                if (cic is CaisisTextBox && (cic as CaisisTextBox).ReadOnly)
                {
                    continue;
                }

                if (cic.Table == ibo.TableName && ibo.HasField(cic.Field))
                {
                    ibo[cic.Field] = cic.Value;
                }
            }
        }
Ejemplo n.º 6
0
 private static int?GetParentKey(List <IBusinessObject> list, IBusinessObject b)
 {
     for (int i = list.Count - 1; i >= 0; i--)
     {
         IBusinessObject ib = list[i];
         if (ib.TableName == b.ParentTableName && ib.HasField(b.ParentKeyName))
         {
             if (!ib.IsNull(b.ParentKeyName))
             {
                 return((int)ib[b.ParentKeyName]);
             }
             else
             {
                 return(null);
             }
         }
     }
     return(null);
 }
Ejemplo n.º 7
0
        public static List <IBusinessObject> ReadXml(string xml, out string notes, out string notesTable, out string notesField)
        {
            List <IBusinessObject> list        = new List <IBusinessObject>();
            StringBuilder          notesBuffer = new StringBuilder();

            XmlReader reader = XmlNodeReader.Create(new StringReader(xml));

            string          currentElementName = null;
            IBusinessObject currentBO          = null;
            bool            currentBOHasData   = false;
            bool            recordNotes        = false;

            // we have to handle Status, PathTest, QOL_Therapy as special cases, since they have fieldnames = tablenames
            bool insideSpecialTable = false;

            notesTable = null;
            notesField = null;

            Truncator truncator = null;

            while (reader.Read())
            {
                // state machine: every tag hit either forks or saves
                switch (reader.NodeType)
                {
                case XmlNodeType.EndElement:
                    if (insideSpecialTable && reader.Name == currentBO.TableName)
                    {
                        insideSpecialTable = false;
                    }
                    break;

                case XmlNodeType.Element:
                    currentElementName = reader.Name;
                    //if ((!insideSpecialTable && BOFactory.CanBuild(currentElementName)) || currentElementName == "NoTable")
                    if ((!insideSpecialTable && BusinessObjectFactory.CanBuildBusinessObject(currentElementName)) || currentElementName == "NoTable")
                    {
                        if (currentBOHasData)
                        {
                            list.Add(currentBO);

                            if (truncator != null)
                            {
                                truncator.Finish();
                            }
                        }

                        if (currentElementName == "NoTable")
                        {
                            notesTable  = reader.GetAttribute("PutDataInTable");
                            notesField  = reader.GetAttribute("PutDataInField");
                            currentBO   = null;
                            recordNotes = true;
                        }
                        else
                        {
                            //currentBO = BOFactory.GetBO(currentElementName);
                            currentBO   = BusinessObjectFactory.BuildBusinessObject(currentElementName);
                            recordNotes = false;
                            //if (currentBO.HasColumn(currentBO.Tablename))
                            if (currentBO.HasField(currentBO.TableName))
                            {
                                insideSpecialTable = true;
                            }

                            truncator = new Truncator(currentBO);
                        }

                        currentBOHasData = false;
                    }
                    break;

                case XmlNodeType.Text:
                    if (reader.Value != null && reader.Value != "")
                    {
                        // if (recordNotes) // OR !currentBO.HasField(currentElementName)
                        if (recordNotes || !currentBO.HasField(currentElementName))
                        {
                            notesBuffer.Append(" | ");
                            notesBuffer.Append(currentElementName);
                            notesBuffer.Append(" :: ");
                            notesBuffer.Append(reader.Value);
                        }
                        else
                        {
                            currentBO[currentElementName] = truncator.HandleValue(currentElementName, reader.Value);
                            currentBOHasData = true;
                        }
                    }
                    break;
                }
            }

            // finishing up
            if (currentBOHasData)
            {
                list.Add(currentBO);

                if (truncator != null)
                {
                    truncator.Finish();
                }
            }

            reader.Close();

            if (notesBuffer.Length > 0)
            {
                notes = "OTHER EFORM DATA: " + notesBuffer.ToString();
            }
            else
            {
                notes = null;
            }

            return(list);
        }