internal Dictionary <string, object> toMdo(string[] response, VistaFile theFile)
        {
            if (response == null || response.Length == 0)
            {
                return(null);
            }
            Dictionary <string, object> result = new Dictionary <string, object>(response.Length);

            for (int lineIdx = 0; lineIdx < response.Length; lineIdx++)
            {
                //Need to instantiate the mdo here
                Object   theMdo   = Activator.CreateInstance(Type.GetType(theFile.MdoName), new object[] { });
                Type     theClass = theMdo.GetType();
                string[] flds     = StringUtils.split(response[lineIdx], StringUtils.CARET);
                for (int fldIdx = 0; fldIdx < flds.Length; fldIdx++)
                {
                    VistaField vf       = (VistaField)((DictionaryEntry)theFile.Fields[fldIdx]).Value;
                    FieldInfo  theField = theClass.GetField(vf.MdoName, BindingFlags.NonPublic | BindingFlags.Instance);
                    if (vf.MdoType == "string")
                    {
                        if (vf.Mapping != null && vf.Mapping.Type == "decode")
                        {
                            if (vf.Mapping.DecodeMap.ContainsKey(flds[fldIdx]))
                            {
                                theField.SetValue(theMdo, vf.Mapping.DecodeMap[flds[fldIdx]]);
                            }
                            else
                            {
                                theField.SetValue(theMdo, flds[fldIdx]);
                            }
                        }
                        else
                        {
                            theField.SetValue(theMdo, flds[fldIdx]);
                        }
                    }
                    else if (vf.MdoType == "kvp")
                    {
                        string key   = flds[fldIdx];
                        string value = "";
                        if (vf.Mapping != null && vf.Mapping.Type == "decode")
                        {
                            value = vf.Mapping.DecodeMap[key];
                        }
                        else
                        {
                            StringDictionary lookupTbl = getLookupTable(vf.Mapping.VistaFileNumber);
                            if (lookupTbl.ContainsKey(key))
                            {
                                value = lookupTbl[key];
                            }
                        }
                        theField.SetValue(theMdo, new KeyValuePair <string, string>(key, value));
                        //KeyValuePair<string, string> kvp = new KeyValuePair<string, string>(key, value);
                    }
                }
                result.Add(flds[0], theMdo);
            }
            return(result);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Get a VistA file - details include file name and globoal as well as all VistA fields (each field has detailed info such as name, number, transforms and type).
        ///
        /// This call can be long running depending on the size of the file (the PATIENT file contains over 500 fields which currently means over 500 RPCs
        /// will be executed to retrieve all the information - this file can take nearly a minute at an average site)
        /// </summary>
        /// <param name="fileNumber">The Vista file number (e.g. "2")</param>
        /// <param name="includeXRefs">If true, fetches cross refs for files</param>
        /// <returns>VistaFile</returns>
        public VistaFile getFile(string fileNumber, bool includeXRefs)
        {
            VistaFile result = new VistaFile()
            {
                FileNumber = fileNumber
            };

            string fileNameQuery   = String.Format("$P($G(^DIC({0},0)),U,1)", fileNumber);
            string fileGlobalQuery = String.Format("$G(^DIC({0},0,\"GL\"))", fileNumber);
            string combinedQueries = new StringBuilder().Append(fileNameQuery).Append("_\"|^|\"_").Append(fileGlobalQuery).ToString();
            string combinedResult  = getVariableValue(combinedQueries);

            string[] pieces = StringUtils.split(combinedResult, "|^|");
            result.FileName   = pieces[0];
            result.Global     = pieces[1];
            result.FieldsDict = getFields(result);

            if (includeXRefs)
            {
                Dictionary <string, CrossRef> xrefs = getXRefs(result);
                result.XRefs = new List <CrossRef>();
                foreach (CrossRef xref in xrefs.Values)
                {
                    result.XRefs.Add(xref);
                }
            }

            return(result);
        }
        internal DdrLister buildFileQuery(VistaFile file)
        {
            DdrLister query = new DdrLister(myCxn);

            query.File   = file.FileNumber;
            query.Fields = file.getFieldString();
            query.Flags  = "IP";
            query.Xref   = "#";
            return(query);
        }
 public Dictionary <string, object> getFile(string fileNum)
 {
     if (!files.ContainsKey(fileNum))
     {
         VistaFile theFile  = (VistaFile)fileDefs[fileNum];
         DdrLister query    = buildFileQuery(theFile);
         string[]  response = query.execute();
         files.Add(fileNum, toMdo(response, theFile));
     }
     return((Dictionary <string, object>)files[fileNum]);
 }
Exemplo n.º 5
0
        public Dictionary <string, VistaField> getFields(VistaFile file)
        {
            Dictionary <string, VistaField> result = new Dictionary <string, VistaField>();

            string currentFieldName = getVariableValue(String.Format("$O(^DD({0},\"B\",\"{1}\"))", file.FileNumber, ""));

            while (!String.IsNullOrEmpty(currentFieldName))
            {
                VistaField currentField = getField(file, currentFieldName, ref currentFieldName); // passed by reference because RPC below fetches next field name for loop
                if (!result.ContainsKey(currentField.VistaNumber))
                {
                    result.Add(currentField.VistaNumber, currentField);
                }

                //currentFieldName = getVariableValue(String.Format("$O(^DD({0},\"B\",\"{1}\"))", file.FileNumber, currentFieldName));
            }

            return(result);
        }
Exemplo n.º 6
0
        public Dictionary <string, CrossRef> getXRefs(VistaFile file)
        {
            Dictionary <string, CrossRef> result = new Dictionary <string, CrossRef>();

            string currentXRefName = getVariableValue(String.Format("$O(^DD({0},0,\"IX\",\"\"))", file.FileNumber));

            while (!String.IsNullOrEmpty(currentXRefName))
            {
                if (!result.ContainsKey(currentXRefName))
                {
                    result.Add(currentXRefName, new CrossRef()
                    {
                        Name = currentXRefName
                    });
                }

                // cut number of queries by 3 for each pass - 1/4 as many RPC calls to Vista
                string combinedQuery = String.Format("$O(^DD({0},0,\"IX\",\"{1}\"))_\"|^|\"_" +                                                                                                                        // get next xref name
                                                     "$O(^DD({0},0,\"IX\",\"{1}\",\"\"))_\"|^|\"_" +                                                                                                                   // get DD
                                                     "$O(^DD({0},0,\"IX\",\"{1}\",$O(^DD({0},0,\"IX\",\"{1}\",\"\")),\"\"))_\"|^|\"_" +                                                                                // get field number
                                                     "$P($G(^DD($O(^DD({0},0,\"IX\",\"{1}\",\"\")),$O(^DD({0},0,\"IX\",\"{1}\",$O(^DD({0},0,\"IX\",\"{1}\",\"\")),\"\")),0)),U,1)", file.FileNumber, currentXRefName); // get fieldName
                //string dd = getVariableValue(String.Format("$O(^DD({0},0,\"IX\",\"{1}\",\"\"))", file.FileNumber, currentXRefName));
                //string fieldNumber = getVariableValue(String.Format("$O(^DD({0},0,\"IX\",\"{1}\",\"{2}\",\"\"))", file.FileNumber, currentXRefName, dd));
                //string fieldName = getVariableValue(String.Format("$P($G(^DD(\"{0}\",\"{1}\",0)),U,1)", dd, fieldNumber));
                string   combinedResults = getVariableValue(combinedQuery);
                string[] pieces          = StringUtils.split(combinedResults, "|^|");
                string   dd          = pieces[1];
                string   fieldNumber = pieces[2];
                string   fieldName   = pieces[3];

                result[currentXRefName].FieldNumber = fieldNumber;
                result[currentXRefName].FieldName   = fieldName;
                result[currentXRefName].DD          = dd;

                currentXRefName = pieces[0];
                //currentXRefName = getVariableValue(String.Format("$O(^DD({0},0,\"IX\",\"{1}\"))", file.FileNumber, currentXRefName));
            }

            return(result);
        }
        internal void getFileDefs()
        {
            VistaFile  currentFile = null;
            VistaField currentFld  = null;

            fileDefs = new Hashtable();

            XmlReader reader = new XmlTextReader(VistaConstants.VISTA_FILEDEFS_PATH);

            while (reader.Read())
            {
                switch ((int)reader.NodeType)
                {
                case (int)XmlNodeType.Element:
                    string name = reader.Name;
                    if (name == "File")
                    {
                        currentFile            = new VistaFile();
                        currentFile.FileName   = reader.GetAttribute("name");
                        currentFile.FileNumber = reader.GetAttribute("number");
                        currentFile.Global     = reader.GetAttribute("global");
                        currentFile.MdoName    = reader.GetAttribute("mdo");
                    }
                    else if (name == "fields")
                    {
                        currentFile.Fields = new DictionaryHashList();
                    }
                    else if (name == "field")
                    {
                        currentFld     = new VistaField();
                        currentFld.Pos = Convert.ToInt16(reader.GetAttribute("pos"));
                    }
                    else if (name == "vista")
                    {
                        currentFld.VistaName   = reader.GetAttribute("name");
                        currentFld.VistaNumber = reader.GetAttribute("number");
                        currentFld.VistaNode   = reader.GetAttribute("node");
                        currentFld.VistaPiece  = reader.GetAttribute("piece");
                        currentFile.Fields.Add(currentFld.Pos.ToString(), currentFld);
                    }
                    else if (name == "mdo")
                    {
                        currentFld.MdoName = reader.GetAttribute("name");
                        currentFld.MdoType = reader.GetAttribute("type");
                    }
                    else if (name == "mapping")
                    {
                        string mappingType = reader.GetAttribute("type");
                        currentFld.Mapping = new VistaFieldMapping(mappingType);
                        if (currentFld.Mapping.Type == "pointer")
                        {
                            currentFld.Mapping.VistaFileNumber = reader.GetAttribute("file");
                        }
                        else if (currentFld.Mapping.Type == "decode")
                        {
                            currentFld.Mapping.DecodeMap = new StringDictionary();
                        }
                    }
                    else if (name == "map")
                    {
                        currentFld.Mapping.DecodeMap.Add(reader.GetAttribute("code"), reader.GetAttribute("value"));
                    }
                    break;

                case (int)XmlNodeType.EndElement:
                    name = reader.Name;
                    if (name == "File")
                    {
                        fileDefs.Add(currentFile.FileNumber, currentFile);
                    }
                    else if (name == "fields")
                    {
                    }
                    else if (name == "field")
                    {
                    }
                    else if (name == "vista")
                    {
                    }
                    else if (name == "mdo")
                    {
                    }
                    else if (name == "mapping")
                    {
                    }
                    else if (name == "map")
                    {
                    }
                    break;
                }
            }
        }
Exemplo n.º 8
0
 internal DdrLister buildFileQuery(VistaFile file)
 {
     DdrLister query = new DdrLister(myCxn);
     query.File = file.FileNumber;
     query.Fields = file.getFieldString();
     query.Flags = "IP";
     query.Xref = "#";
     return query;
 }
Exemplo n.º 9
0
 internal Dictionary<string, object> toMdo(string[] response, VistaFile theFile)
 {
     if (response == null || response.Length == 0)
     {
         return null;
     }
     Dictionary<string, object> result = new Dictionary<string, object>(response.Length);
     for (int lineIdx = 0; lineIdx < response.Length; lineIdx++)
     {
         //Need to instantiate the mdo here
         Object theMdo = Activator.CreateInstance(Type.GetType(theFile.MdoName), new object[] { });
         Type theClass = theMdo.GetType();
         string[] flds = StringUtils.split(response[lineIdx], StringUtils.CARET);
         for (int fldIdx = 0; fldIdx < flds.Length; fldIdx++)
         {
             VistaField vf = (VistaField)((DictionaryEntry)theFile.Fields[fldIdx]).Value;
             FieldInfo theField = theClass.GetField(vf.MdoName, BindingFlags.NonPublic | BindingFlags.Instance);
             if (vf.MdoType == "string")
             {
                 if (vf.Mapping != null && vf.Mapping.Type == "decode")
                 {
                     if (vf.Mapping.DecodeMap.ContainsKey(flds[fldIdx]))
                     {
                         theField.SetValue(theMdo, vf.Mapping.DecodeMap[flds[fldIdx]]);
                     }
                     else
                     {
                         theField.SetValue(theMdo, flds[fldIdx]);
                     }
                 }
                 else
                 {
                     theField.SetValue(theMdo, flds[fldIdx]);
                 }
             }
             else if (vf.MdoType == "kvp")
             {
                 string key = flds[fldIdx];
                 string value = "";
                 if (vf.Mapping != null && vf.Mapping.Type == "decode")
                 {
                     value = vf.Mapping.DecodeMap[key];
                 }
                 else
                 {
                     StringDictionary lookupTbl = getLookupTable(vf.Mapping.VistaFileNumber);
                     if (lookupTbl.ContainsKey(key))
                     {
                         value = lookupTbl[key];
                     }
                 }
                 theField.SetValue(theMdo, new KeyValuePair<string, string>(key, value));
                 //KeyValuePair<string, string> kvp = new KeyValuePair<string, string>(key, value);
             }
         }
         result.Add(flds[0], theMdo);
     }
     return result;
 }
Exemplo n.º 10
0
        internal void getFileDefs()
        {
            VistaFile currentFile = null;
            VistaField currentFld = null;
            fileDefs = new Hashtable();

            XmlReader reader = new XmlTextReader(VistaConstants.VISTA_FILEDEFS_PATH);
            while (reader.Read())
            {
                switch ((int)reader.NodeType)
                {
                    case (int)XmlNodeType.Element:
                        string name = reader.Name;
                        if (name == "File")
                        {
                            currentFile = new VistaFile();
                            currentFile.FileName = reader.GetAttribute("name");
                            currentFile.FileNumber = reader.GetAttribute("number");
                            currentFile.Global = reader.GetAttribute("global");
                            currentFile.MdoName = reader.GetAttribute("mdo");
                        }
                        else if (name == "fields")
                        {
                            currentFile.Fields = new DictionaryHashList();
                        }
                        else if (name == "field")
                        {
                            currentFld = new VistaField();
                            currentFld.Pos = Convert.ToInt16(reader.GetAttribute("pos"));
                        }
                        else if (name == "vista")
                        {
                            currentFld.VistaName = reader.GetAttribute("name");
                            currentFld.VistaNumber = reader.GetAttribute("number");
                            currentFld.VistaNode = reader.GetAttribute("node");
                            currentFld.VistaPiece = reader.GetAttribute("piece");
                            currentFile.Fields.Add(currentFld.Pos.ToString(), currentFld);
                        }
                        else if (name == "mdo")
                        {
                            currentFld.MdoName = reader.GetAttribute("name");
                            currentFld.MdoType = reader.GetAttribute("type");
                        }
                        else if (name == "mapping")
                        {
                            string mappingType = reader.GetAttribute("type");
                            currentFld.Mapping = new VistaFieldMapping(mappingType);
                            if (currentFld.Mapping.Type == "pointer")
                            {
                                currentFld.Mapping.VistaFileNumber = reader.GetAttribute("file");
                            }
                            else if (currentFld.Mapping.Type == "decode")
                            {
                                currentFld.Mapping.DecodeMap = new StringDictionary();
                            }
                        }
                        else if (name == "map")
                        {
                            currentFld.Mapping.DecodeMap.Add(reader.GetAttribute("code"), reader.GetAttribute("value"));
                        }
                        break;
                    case (int)XmlNodeType.EndElement:
                        name = reader.Name;
                        if (name == "File")
                        {
                            fileDefs.Add(currentFile.FileNumber, currentFile);
                        }
                        else if (name == "fields")
                        {
                        }
                        else if (name == "field")
                        {
                        }
                        else if (name == "vista")
                        {
                        }
                        else if (name == "mdo")
                        {
                        }
                        else if (name == "mapping")
                        {
                        }
                        else if (name == "map")
                        {
                        }
                        break;
                }
            }
        }
Exemplo n.º 11
0
        internal VistaField getField(VistaFile file, string fieldName, ref string nextField)
        {
            VistaField result = new VistaField();

            result.VistaName = fieldName;

            // get next field, get field number and get field props with one combined query delimited with the |^| string
            string combinedQuery   = String.Format("$O(^DD({0},\"B\",\"{1}\"))_\"|^|\"_$O(^DD({0},\"B\",\"{1}\",0))_\"|^|\"_$G(^DD({0},$O(^DD({0},\"B\",\"{1}\",0)),0))", file.FileNumber, fieldName);
            string combinedResults = getVariableValue(combinedQuery);

            string[] pieces = StringUtils.split(combinedResults, "|^|");

            nextField          = pieces[0];
            result.VistaNumber = pieces[1];
            string fieldProps = pieces[2];

            //result.VistaNumber = getVariableValue(String.Format("$O(^DD({0},\"B\",\"{1}\",0))", file.FileNumber, fieldName));
            //string fieldProps = getVariableValue(String.Format("$G(^DD({0},{1},0))", file.FileNumber, result.VistaNumber));
            string[] propPieces = StringUtils.split(fieldProps, StringUtils.CARET);
            if (propPieces.Length < 4)
            {
                return(result);
            }
            result.Type      = propPieces[1];
            result.VistaNode = String.Concat("(", propPieces[3], ")");

            if (propPieces.Length > 2 && !String.IsNullOrEmpty(propPieces[1]))
            {
                if (propPieces[1].Contains("P") && !String.IsNullOrEmpty(propPieces[2]))
                {
                    result.IsPointer = true;
                    string   pointedToFileHeader       = getVariableValue(String.Format("$G(^{0}0))", propPieces[2])); // need to put carat back in because string split removes it
                    string[] pointedToFileHeaderPieces = StringUtils.split(pointedToFileHeader, StringUtils.CARET);
                    result.PointsTo = new VistaFile()
                    {
                        Global     = "^" + propPieces[2], // need to put carat back in because string split removes it
                        FileName   = pointedToFileHeaderPieces[0],
                        FileNumber = pointedToFileHeaderPieces[1]
                    };
                }
                else if (String.Equals(propPieces[1], "S", StringComparison.CurrentCultureIgnoreCase))
                {
                    if (!String.IsNullOrEmpty(propPieces[2]))
                    {
                        result.Externals = new Dictionary <string, string>();
                        String[] externalsKeysAndVals = propPieces[2].Split(new String[] { ";" }, StringSplitOptions.RemoveEmptyEntries);
                        foreach (String individual in externalsKeysAndVals)
                        {
                            String[] keyAndVal = individual.Split(new String[] { ":" }, StringSplitOptions.RemoveEmptyEntries);
                            if (!result.Externals.ContainsKey(keyAndVal[0]))
                            {
                                result.Externals.Add(keyAndVal[0], keyAndVal[1]);
                            }
                            else
                            {
                                System.Console.WriteLine("Found dupe: " + keyAndVal[0] + " - " + keyAndVal[1] + " which was a duplicate of: " + keyAndVal[0] + ":" + result.Externals[keyAndVal[0]]);
                            }
                        }
                    }
                }
            }
            if (propPieces.Length == 4) // multiple or WP - Need to do some work figuring out what all these characters mean - here??? -> http://www.hardhats.org/fileman/u2/fa_cond.htm
            {
                decimal trash = 0;
                if (Decimal.TryParse(propPieces[1], out trash))
                {
                    result.IsMultiple = true;
                    result.Multiple   = new VistaFile()
                    {
                        FileNumber = propPieces[1]
                    };
                    //result.Multiple.FieldsDict = getFields(result.Multiple);
                }
                else
                {
                    result.IsWordProc = true;
                }
            }

            // re-assemble transform
            if (propPieces.Length > 4)
            {
                StringBuilder sb = new StringBuilder();
                for (int i = 4; i < propPieces.Length; i++)
                {
                    sb.Append(propPieces[i]);
                    sb.Append("^");
                }
                sb = sb.Remove(sb.Length - 1, 1);
                result.Transform = sb.ToString();
            }

            return(result);
        }