Beispiel #1
0
        public static void WriteToXml(ItemProtocol itemProtocol, string path)
        {
            System.Xml.XmlWriterSettings xmlWriterSettings = new System.Xml.XmlWriterSettings()
            {
                Indent      = true,
                IndentChars = "  "
            };

            using (System.Xml.XmlWriter writer = System.Xml.XmlWriter.Create(path + itemProtocol.SheetName + ".xml", xmlWriterSettings)) {
                writer.WriteStartDocument();
                writer.WriteStartElement("WorkPlace");

                writer.WriteAttributeString("PLACEID", itemProtocol.PlaceId.ToString());
                writer.WriteAttributeString("NAMEPLACE", itemProtocol.Postfix + " " + itemProtocol.ProtocolName);
                writer.WriteAttributeString("F25_NAMEPLACE", "Протокол телемедицинской консультации");
                writer.WriteAttributeString("PARENTPLACEID", "-1");
                writer.WriteAttributeString("PLACETYPE", "0");
                writer.WriteAttributeString("NAPRAVPRINTTYPE", "0");
                writer.WriteAttributeString("BOLPRINTTYPE", "0");
                writer.WriteAttributeString("DIAGPRINTTYPE", "0");
                writer.WriteAttributeString("RECIPEPRINTTYPE", "0");

                foreach (ItemGroup itemGroup in itemProtocol.ListOfItemGroup)
                {
                    writer.WriteStartElement("Grp" + itemGroup.GroupId.ToString());

                    writer.WriteAttributeString("GROUPID", itemGroup.GroupId.ToString());
                    writer.WriteAttributeString("GROUPNAME", itemGroup.GroupName);
                    writer.WriteAttributeString("F25_GROUPNAME", "");
                    writer.WriteAttributeString("VIEWINWEB", "1");

                    foreach (ItemParameter itemParameter in itemGroup.ListOfItemParameter)
                    {
                        writer.WriteStartElement("Prm" + itemParameter.CodeParams.ToString());

                        writer.WriteAttributeString("CODEPARAMS", itemParameter.CodeParams.ToString());
                        writer.WriteAttributeString("NAMEPARAMS", itemParameter.ParameterName + itemProtocol.Postfix);
                        writer.WriteAttributeString("TYPEPARAMS", "6");
                        writer.WriteAttributeString("REFTODICT", itemParameter.ReftToDict.ToString());
                        writer.WriteAttributeString("COMMENT", "");
                        writer.WriteAttributeString("DEFAULTVALUE", "");
                        writer.WriteAttributeString("MTYPEID", "990000021");
                        writer.WriteAttributeString("F25_STYLE_N", "1");
                        writer.WriteAttributeString("F25_NAMEPARAMS", itemParameter.ParameterName);
                        writer.WriteAttributeString("PARAMWRAP", "1");

                        writer.WriteEndElement();
                    }

                    writer.WriteEndElement();
                }

                writer.WriteStartElement("Reference");

                foreach (ItemGroup itemGroup in itemProtocol.ListOfItemGroup)
                {
                    foreach (ItemParameter itemParameter in itemGroup.ListOfItemParameter)
                    {
                        writer.WriteStartElement("Ref" + itemParameter.ReftToDict.ToString());

                        writer.WriteAttributeString("REFID", itemParameter.ReftToDict.ToString());
                        writer.WriteAttributeString("REFNAME", itemParameter.ParameterName + itemProtocol.Postfix);

                        int order = 0;
                        foreach (ItemDictionary itemDictionary in itemParameter.Dictionary)
                        {
                            writer.WriteStartElement("Dic" + itemDictionary.DicId.ToString());

                            writer.WriteAttributeString("DICID", itemDictionary.DicId.ToString());
                            writer.WriteAttributeString("PARENTDICID", "0");
                            writer.WriteAttributeString("REFID", itemParameter.ReftToDict.ToString());
                            writer.WriteAttributeString("DICNAME", itemDictionary.DictionaryValue);
                            writer.WriteAttributeString("DICORDER", order.ToString());

                            writer.WriteEndElement();

                            order++;
                        }

                        writer.WriteEndElement();
                    }
                }

                writer.WriteEndElement();

                writer.WriteStartElement("ParamNorm");
                writer.WriteEndElement();

                writer.WriteStartElement("Templates");
                writer.WriteEndElement();

                writer.WriteStartElement("ExportInfo");
                writer.WriteAttributeString("ComputerName", "MSCS-TSERVER5");
                writer.WriteAttributeString("WindowsUserName", "vyatkin");
                writer.WriteEndElement();

                writer.WriteEndElement();
                writer.WriteEndDocument();
            }
        }
        private static ItemProtocol ReadProtocol(KeyValuePair <string, DataTable> keyValuePair, IdGenerator idGenerator)
        {
            DataRowCollection rows          = keyValuePair.Value.Rows;
            bool         isMainBlockStarted = false;
            ItemProtocol itemProtocol       = new ItemProtocol();

            for (int rowGroup = 0; rowGroup < rows.Count; rowGroup++)
            {
                string groupName = rows[rowGroup][0].ToString();
                if (string.IsNullOrEmpty(groupName))
                {
                    continue;
                }

                if (!isMainBlockStarted)
                {
                    if (groupName.ToLower().StartsWith("жалобы (со слов пациента):"))
                    {
                        isMainBlockStarted        = true;
                        itemProtocol.ProtocolName = rows[rowGroup][2].ToString();
                        itemProtocol.PlaceId      = idGenerator.Id;
                        itemProtocol.SheetName    = keyValuePair.Key;
                        itemProtocol.Postfix      = new String(keyValuePair.Key.Where(Char.IsDigit).ToArray());
                    }

                    continue;
                }

                ItemGroup itemGroup = new ItemGroup()
                {
                    GroupName = groupName,
                    GroupId   = idGenerator.Id
                };

                for (int rowParameter = rowGroup; rowParameter < rows.Count; rowParameter++)
                {
                    string groupNameInner = rows[rowParameter][0].ToString();

                    if (!string.IsNullOrEmpty(groupNameInner) &&
                        !groupNameInner.Equals(groupName))
                    {
                        rowGroup = rowParameter - 1;
                        break;
                    }

                    string parameterName = rows[rowParameter][1].ToString();
                    if (string.IsNullOrEmpty(parameterName))
                    {
                        parameterName = itemGroup.GroupName;
                    }

                    ItemParameter itemParameter = new ItemParameter()
                    {
                        ParameterName = parameterName,
                        CodeParams    = idGenerator.Id,
                        ReftToDict    = idGenerator.Id
                    };

                    for (int rowDictionary = rowParameter; rowDictionary < rows.Count; rowDictionary++)
                    {
                        string parameterNameInner = rows[rowDictionary][1].ToString();
                        string groupNameInner2    = rows[rowDictionary][0].ToString();

                        if (!string.IsNullOrEmpty(groupNameInner2) &&
                            !groupNameInner2.Equals(groupName))
                        {
                            rowParameter = rowDictionary - 1;
                            break;
                        }

                        if (!string.IsNullOrEmpty(parameterNameInner) &&
                            !parameterNameInner.Equals(parameterName))
                        {
                            rowParameter = rowDictionary - 1;
                            break;
                        }

                        string dictionaryValue = rows[rowDictionary][2].ToString();
                        if (string.IsNullOrEmpty(dictionaryValue))
                        {
                            continue;
                        }

                        Regex regex = new Regex("[ ]{2,}", RegexOptions.None);
                        dictionaryValue = dictionaryValue.TrimStart(' ').TrimEnd(' ');
                        dictionaryValue = regex.Replace(dictionaryValue, " ");
                        dictionaryValue = dictionaryValue.Replace("\r\n", " ");
                        dictionaryValue = dictionaryValue.Replace(Environment.NewLine, " ");
                        dictionaryValue = dictionaryValue.Replace("\n", " ");

                        itemParameter.Dictionary.Add(new ItemDictionary()
                        {
                            DictionaryValue = dictionaryValue,
                            DicId           = idGenerator.Id
                        });

                        if (rowDictionary == rows.Count - 1)
                        {
                            rowParameter = rowDictionary;
                            break;
                        }
                    }

                    if (itemParameter.Dictionary.Count > 0)
                    {
                        itemGroup.ListOfItemParameter.Add(itemParameter);
                    }
                }

                itemProtocol.ListOfItemGroup.Add(itemGroup);
            }

            return(itemProtocol);
        }