query() public method

public query ( MdoQuery request, AbstractPermission permission = null ) : object
request MdoQuery
permission AbstractPermission
return object
Example #1
0
        public Visit[] getMentalHealthVisits(string pid)
        {
            SqlDataAdapter adapter = buildMentalHealthVisitsRequest(pid);
            IDataReader    reader  = (IDataReader)_cxn.query(adapter);

            return(toVisitsFromDataReader(reader));
        }
Example #2
0
        internal Immunizations getImmunizations(string icn, string startDate, string stopDate)
        {
            SqlDataAdapter adapter = buildGetImmunizationsQuery(icn, startDate, stopDate);
            IDataReader    reader  = (IDataReader)_cxn.query(adapter);

            return(toImmunizations(reader));
        }
Example #3
0
        public Dictionary <string, HashSet <string> > getNewChemHemReports(DateTime start)
        {
            if (DateTime.Now.Subtract(start).TotalDays > 30)
            {
                throw new ArgumentException("Only the last 30 days can be retrieved");
            }
            string commandText = "SELECT DISTINCT chem.Sta3n, patient.PatientICN " +
                                 "FROM Chem.LabChem AS chem " +
                                 "RIGHT OUTER JOIN SPatient.SPatient AS patient " +
                                 "ON chem.PatientSID=patient.PatientSID " +
                                 "WHERE " +
                                 "( " +
                                 "	( "+
                                 "		chem.LabChemCompleteDateTime>=DATEADD(DAY, -30, GETDATE()) AND  "+
                                 "		chem.VistaEditDate>=@start "+
                                 "	) "+
                                 "	OR "+
                                 "	( "+
                                 "		chem.LabChemCompleteDateTime IS NULL AND  "+
                                 "		chem.VistaEditDate>=@start "+
                                 "	) "+
                                 ") " +
                                 ";";
            SqlDataAdapter adapter = new SqlDataAdapter();

            adapter.SelectCommand = new SqlCommand(commandText);

            SqlParameter startParam = new SqlParameter("@start", SqlDbType.DateTime);

            startParam.Value = start;
            adapter.SelectCommand.Parameters.Add(startParam);
            adapter.SelectCommand.CommandTimeout = 600; // allow query to run for up to 10 minutes

            using (_cxn)
            {
                IDataReader reader = (IDataReader)_cxn.query(adapter);

                Dictionary <string, HashSet <string> > results = new Dictionary <string, HashSet <string> >();

                while (reader.Read())
                {
                    if (reader.IsDBNull(1))
                    {
                        continue;
                    }
                    string sitecode   = reader.GetInt16(0).ToString();
                    string patientICN = reader.GetString(1);

                    if (!results.ContainsKey(sitecode))
                    {
                        results.Add(sitecode, new HashSet <string>());
                    }
                    if (!results[sitecode].Contains(patientICN))
                    {
                        results[sitecode].Add(patientICN);
                    }
                }
                return(results);
            }
        }
Example #4
0
        public Problem[] getProblemList(string type)
        {
            SqlDataAdapter adapter = buildProblemListRequest(_cxn.Pid);
            IDataReader    reader  = (IDataReader)_cxn.query(adapter);

            return(toProblemList(reader));
        }
        public Dictionary <string, HashSet <string> > getUpdatedFutureAppointments(DateTime updatedSince)
        {
            if (DateTime.Now.Subtract(updatedSince).TotalDays > 30)
            {
                throw new ArgumentException("Can not ask for more than 30 days of updates");
            }

            string commandText = "SELECT DISTINCT appt.Sta3n, patient.PatientICN FROM Appt.Appointment as appt " +
                                 "RIGHT OUTER JOIN SPatient.SPatient as patient " +
                                 "ON appt.PatientSID=patient.PatientSID " +
                                 "WHERE AppointmentDateTime>GETDATE() " +
                                 "AND appt.VistaEditDate>@updatedSince;";

            SqlDataAdapter adapter = new SqlDataAdapter();

            adapter.SelectCommand = new SqlCommand(commandText);

            SqlParameter startParam = new SqlParameter("@updatedSince", SqlDbType.DateTime);

            startParam.Value = updatedSince;
            adapter.SelectCommand.Parameters.Add(startParam);
            adapter.SelectCommand.CommandTimeout = 600; // allow query to run for up to 10 minutes

            using (_cxn)
            {
                SqlDataReader reader = (SqlDataReader)_cxn.query(adapter);

                Dictionary <string, HashSet <string> > results = new Dictionary <string, HashSet <string> >();

                while (reader.Read())
                {
                    if (reader.IsDBNull(1))
                    {
                        continue;
                    }
                    string sitecode   = reader.GetSqlInt16(0).ToString();
                    string patientICN = reader.GetString(1);

                    if (!results.ContainsKey(sitecode))
                    {
                        results.Add(sitecode, new HashSet <string>());
                    }
                    if (!results[sitecode].Contains(patientICN))
                    {
                        results[sitecode].Add(patientICN);
                    }
                }
                return(results);
            }
        }
Example #6
0
        public RadiologyReport[] getRadiologyReportsBySite(string fromDate, string toDate, string siteCode)
        {
            SqlDataAdapter adapter = buildRadiologyReportRequest(siteCode, _cxn.Pid, fromDate, toDate);
            IDataReader    reader  = (IDataReader)_cxn.query(adapter);

            return(toRadiologyReports(reader));
        }
Example #7
0
        public Note[] getNotes(string fromDate, string toDate, int nNotes)
        {
            SqlDataAdapter request  = buildGetNotesQuery(_cxn.Pid, fromDate, toDate, nNotes);
            IDataReader    response = (IDataReader)_cxn.query(request);

            return(toNotesFromReader(response));
        }
Example #8
0
        public Medication[] getAllMeds(string icn)
        {
            SqlDataAdapter adapter = buildGetAllMedsRequest(icn);
            SqlDataReader  reader  = (SqlDataReader)_cxn.query(adapter);

            return(toMeds(reader));
        }
Example #9
0
        public VitalSign[] getLatestVitalSigns(string pid)
        {
            SqlDataAdapter adapter = buildVitalSignsRequest(pid);
            IDataReader    reader  = _cxn.query(adapter) as IDataReader;

            return(toVitalSigns(reader));
        }
Example #10
0
        public Patient[] match(string target)
        {
            if (!SocSecNum.isValid(target))
            {
                throw new NotImplementedException("non-SSN matches are currently not supported by CDW");
            }

            SqlCommand   cmd         = new SqlCommand("SELECT * FROM SPatient.SPatient WHERE PatientSSN=@target;");
            SqlParameter targetParam = new SqlParameter("@target", System.Data.SqlDbType.VarChar, 9);

            targetParam.Value = target;

            SqlDataAdapter adapter = new SqlDataAdapter(cmd);

            adapter.SelectCommand = new SqlCommand(cmd.CommandText);
            adapter.SelectCommand.Parameters.Add(targetParam);

            IDataReader reader = (IDataReader)_cxn.query(adapter);
            IDictionary <string, Patient> patients = new Dictionary <string, Patient>();

            //if (!reader..HasRows)
            //{
            //    return new Patient[0];
            //}
            while (reader.Read())
            {
                Patient p = new Patient();
                p.LocalSiteId = (reader.GetInt16(reader.GetOrdinal("Sta3n"))).ToString();
                p.LocalPid    = reader.GetString(reader.GetOrdinal("PatientIEN"));

                p.Name = new PersonName(reader.GetString(reader.GetOrdinal("PatientName")));
                if (!reader.IsDBNull(reader.GetOrdinal("PatientSSN")))
                {
                    p.SSN = new SocSecNum(reader.GetString(reader.GetOrdinal("PatientSSN")));
                }

                if (!reader.IsDBNull(reader.GetOrdinal("Gender")))
                {
                    p.Gender = reader.GetString(reader.GetOrdinal("Gender"));
                }
                else
                {
                    p.Gender = "";
                }
                if (!reader.IsDBNull(reader.GetOrdinal("DateOfBirthText")))
                {
                    p.DOB = reader.GetString(reader.GetOrdinal("DateOfBirthText"));
                }
                if (!reader.IsDBNull(reader.GetOrdinal("PatientICN")))
                {
                    p.MpiPid = (reader.GetString(reader.GetOrdinal("PatientICN"))).ToString();
                }
                else
                {
                    // use SSN for patient ICN
                    if (p.SSN == null || String.IsNullOrEmpty(p.SSN.toString()))
                    {
                        throw new MdoException(MdoExceptionCode.DATA_MISSING_REQUIRED, "Unable to process results for " + target + " - CDW record contains no ICN and no SSN");
                    }
                    p.MpiPid = p.SSN.toString();
                }

                p.Demographics = new Dictionary <string, DemographicSet>();
                DemographicSet demogs = new DemographicSet();
                demogs.PhoneNumbers    = new List <PhoneNum>();
                demogs.EmailAddresses  = new List <EmailAddress>();
                demogs.StreetAddresses = new List <Address>();

                if (!reader.IsDBNull(reader.GetOrdinal("PhoneResidence")))
                {
                    demogs.PhoneNumbers.Add(new PhoneNum(reader.GetString(reader.GetOrdinal("PhoneResidence"))));
                }
                if (!reader.IsDBNull(reader.GetOrdinal("PhoneWork")))
                {
                    demogs.PhoneNumbers.Add(new PhoneNum(reader.GetString(reader.GetOrdinal("PhoneWork"))));
                }

                Address address = new Address();
                if (!reader.IsDBNull(reader.GetOrdinal("StreetAddress1")))
                {
                    address.Street1 = reader.GetString(reader.GetOrdinal("StreetAddress1"));
                }
                if (!reader.IsDBNull(reader.GetOrdinal("StreetAddress2")))
                {
                    address.Street2 = reader.GetString(reader.GetOrdinal("StreetAddress2"));
                }
                if (!reader.IsDBNull(reader.GetOrdinal("StreetAddress3")))
                {
                    address.Street3 = reader.GetString(reader.GetOrdinal("StreetAddress3"));
                }
                if (!reader.IsDBNull(reader.GetOrdinal("City")))
                {
                    address.City = reader.GetString(reader.GetOrdinal("City"));
                }
                if (!reader.IsDBNull(reader.GetOrdinal("county")))
                {
                    address.County = reader.GetString(reader.GetOrdinal("county"));
                }
                if (!reader.IsDBNull(reader.GetOrdinal("State")))
                {
                    address.State = reader.GetString(reader.GetOrdinal("State"));
                }
                if (!reader.IsDBNull(reader.GetOrdinal("Zip")))
                {
                    address.Zipcode = reader.GetString(reader.GetOrdinal("Zip"));
                }
                demogs.StreetAddresses.Add(address);

                p.Demographics.Add(p.LocalSiteId, demogs);

                if (!patients.ContainsKey(p.MpiPid))
                {
                    p.SitePids = new System.Collections.Specialized.StringDictionary();
                    p.SitePids.Add(p.LocalSiteId, p.LocalPid);
                    patients.Add(p.MpiPid, p);
                }
                else
                {
                    if (!(patients[p.MpiPid].SitePids.ContainsKey(p.LocalSiteId)))
                    {
                        patients[p.MpiPid].SitePids.Add(p.LocalSiteId, p.LocalPid);
                    }

                    patients[p.MpiPid].Demographics.Add(p.LocalSiteId, p.Demographics[p.LocalSiteId]);
                }
            }

            // cleanup - need to set all temp ICNs back to null
            foreach (string key in patients.Keys)
            {
                if (!(patients[key].SSN == null) && !String.IsNullOrEmpty(patients[key].SSN.toString()) &&
                    !String.IsNullOrEmpty(patients[key].MpiPid) && String.Equals(patients[key].MpiPid, patients[key].SSN.toString()))
                {
                    patients[key].MpiPid = null;
                }
            }

            Patient[] result = new Patient[patients.Count];
            patients.Values.CopyTo(result, 0);
            return(result);
        }