Ejemplo n.º 1
0
        private void backgroundWorker2_DoWork(object sender, DoWorkEventArgs e)
        {
            List <Appointment> appts = (List <Appointment>)e.Argument;

            try
            {
                foreach (object o in appts)
                {
                    Appointment appt = (Appointment)o;
                    if (appt.CloudWebQueueState == CREATE_NEW_APPT || appt.CloudWebQueueState == SYNCH_APPT)
                    {
                        backgroundWorker2.ReportProgress(2, "Retrieving Patient Record: " + appt.PatientName + " - " + appt.Dob);
                        XmlNode xml = cloud.FetchPatientRecord(appt.apptID);

                        MemoryStream stm = new MemoryStream();
                        StreamWriter stw = new StreamWriter(stm);
                        stw.Write(xml.OuterXml);
                        stw.Flush();
                        stm.Position = 0;

                        backgroundWorker2.ReportProgress(2, "Saving Data: " + appt.PatientName + " - " + appt.Dob);
                        DataContractSerializer ds = new DataContractSerializer(typeof(Patient));
                        Patient p2 = (Patient)ds.ReadObject(stm);

                        if (appt.CloudWebQueueState == CREATE_NEW_APPT)
                        {
                            SurveyResponse newMRN = (SurveyResponse)p2.SurveyReponses.Find(g => ((SurveyResponse)g).responseTag == "PatientReportedMRN");

                            if (!String.IsNullOrEmpty(newMRN.SurveyResponse_responseValue))
                            {
                                using (CloudMRNReconcile reconcileForm = new CloudMRNReconcile(newMRN.SurveyResponse_responseValue, p2.name, p2.apptid, appt.clinicID))
                                {
                                    reconcileForm.ShowDialog();

                                    if ((reconcileForm.retMRN != "Cancel") && (!String.IsNullOrEmpty(reconcileForm.retMRN)))
                                    {
                                        p2.unitnum = reconcileForm.retMRN;
                                    }
                                    else
                                    {
                                        break;
                                    }
                                }
                            }

                            Utilities.ParameterCollection pc = new RiskApps3.Utilities.ParameterCollection();
                            pc.Add("unitnum", p2.unitnum);
                            pc.Add("patientname", p2.name);
                            pc.Add("dob", p2.dob);
                            pc.Add("clinicId", appt.ClinicId);
                            object newApptId = BCDB2.Instance.ExecuteSpWithRetValAndParams("sp_createMasteryAppointment", SqlDbType.Int, pc);
                            p2.apptid = (int)newApptId;
                        }
                        else
                        {
                            if (appt.CloudWebQueueState == SYNCH_APPT)
                            {
                                p2.apptid = appt.CloudWebQueueSynchId;
                            }
                        }

                        p2.FHx.proband = p2;
                        p2.PersistFullObject(new RiskApps3.Model.HraModelChangedEventArgs(null));

                        if (checkBox4.Checked)
                        {
                            backgroundWorker2.ReportProgress(2, "Marking Complete and updating meta data: " + appt.PatientName + " - " + appt.Dob);
                            ParameterCollection pc = new ParameterCollection("apptID", p2.apptid);
                            BCDB2.Instance.RunSPWithParams("sp_markRiskDataCompleted", pc);
                        }


                        if (checkBox1.Checked)
                        {
                            backgroundWorker2.ReportProgress(2, "Running Risk Models: " + appt.PatientName + " - " + appt.Dob);
                            p2.RecalculateRisk();

                            ParameterCollection pc = new ParameterCollection("unitnum", p2.unitnum);
                            BCDB2.Instance.RunSPWithParams("sp_3_populateBigQueue", pc);
                        }

                        if (checkBox2.Checked)
                        {
                            backgroundWorker2.ReportProgress(2, "Printing Automation Documents: " + appt.PatientName + " - " + appt.Dob);

                            p2.RunAutomation();

                            //ParameterCollection printDocArgs = new ParameterCollection();
                            //printDocArgs.Add("apptid", p2.apptid);
                            //SqlDataReader reader = BCDB2.Instance.ExecuteReaderSPWithParams("sp_AutomationHtmlDocsToPrint", printDocArgs);
                            //while (reader.Read())
                            //{
                            //    int templateID = -1;
                            //    if (reader.IsDBNull(0) == false)
                            //    {
                            //        templateID = reader.GetInt32(0);
                            //    }
                            //    SessionManager.Instance.SetActivePatientNoCallback(p2.unitnum, p2.apptid);
                            //    DocumentTemplate template = new DocumentTemplate();
                            //    template.documentTemplateID = templateID;
                            //    template.BackgroundLoadWork();
                            //    template.OpenHTML();
                            //    template.ProcessDocument();
                            //    htmlInProgress = true;
                            //    backgroundWorker2.ReportProgress(1, template.htmlText);
                            //    while (htmlInProgress)
                            //    {
                            //        Application.DoEvents();
                            //        Thread.Sleep(500);
                            //    }

                            //}
                        }
                        if (checkBox5.Checked)
                        {
                            backgroundWorker2.ReportProgress(2, "Removing Web Survey: " + appt.PatientName + " - " + appt.Dob);
                            backgroundWorker2.ReportProgress(4, appt);
                            cloud.DeleteSurvey(appt.apptID);
                        }
                        backgroundWorker2.ReportProgress(2, "Precessing Queue Documents: " + appt.PatientName + " - " + appt.Dob);
                        if (checkBox3.Checked)
                        {
                            ParameterCollection pc = new ParameterCollection("apptID", p2.apptid);
                            BCDB2.Instance.RunSPWithParams("sp_processQueueDocuments", pc);
                        }
                    }
                    else if (appt.CloudWebQueueState == DELETE_APPT)
                    {
                        backgroundWorker2.ReportProgress(2, "Removing Web Survey: " + appt.PatientName + " - " + appt.Dob);
                        backgroundWorker2.ReportProgress(4, appt);
                        cloud.DeleteSurvey(appt.apptID);
                    }
                    backgroundWorker2.ReportProgress(3, o);
                }
            }
            catch (Exception exc)
            {
                Logger.Instance.WriteToLog(exc.ToString());
            }
        }
Ejemplo n.º 2
0
        private void backgroundWorker2_DoWork(object sender, DoWorkEventArgs e)
        {
            List<Appointment> appts = (List<Appointment>)e.Argument;
            try
            {
                foreach (object o in appts)
                {
                    Appointment appt = (Appointment)o;
                    if (appt.CloudWebQueueState == CREATE_NEW_APPT || appt.CloudWebQueueState == SYNCH_APPT)
                    {
                        backgroundWorker2.ReportProgress(2, "Retrieving Patient Record: " + appt.PatientName + " - " + appt.Dob);
                        XmlNode xml = cloud.FetchPatientRecord(appt.apptID);

                        MemoryStream stm = new MemoryStream();
                        StreamWriter stw = new StreamWriter(stm);
                        stw.Write(xml.OuterXml);
                        stw.Flush();
                        stm.Position = 0;

                        backgroundWorker2.ReportProgress(2, "Saving Data: " + appt.PatientName + " - " + appt.Dob);
                        DataContractSerializer ds = new DataContractSerializer(typeof(Patient));
                        Patient p2 = (Patient)ds.ReadObject(stm);

                        if (appt.CloudWebQueueState == CREATE_NEW_APPT)
                        {

                            SurveyResponse newMRN = (SurveyResponse)p2.SurveyReponses.Find(g => ((SurveyResponse)g).responseTag == "PatientReportedMRN");

                            if (!String.IsNullOrEmpty(newMRN.SurveyResponse_responseValue))
                            {
                                using (CloudMRNReconcile reconcileForm = new CloudMRNReconcile(newMRN.SurveyResponse_responseValue, p2.name, p2.apptid, appt.clinicID))
                                {
                                    reconcileForm.ShowDialog();

                                    if ((reconcileForm.retMRN != "Cancel") && (!String.IsNullOrEmpty(reconcileForm.retMRN)))
                                        p2.unitnum = reconcileForm.retMRN;
                                    else
                                        break;
                                }
                            }

                            Utilities.ParameterCollection pc = new RiskApps3.Utilities.ParameterCollection();
                            pc.Add("unitnum", p2.unitnum);
                            pc.Add("patientname", p2.name);
                            pc.Add("dob", p2.dob);
                            pc.Add("clinicId", appt.ClinicId);
                            object newApptId = BCDB2.Instance.ExecuteSpWithRetValAndParams("sp_createMasteryAppointment", SqlDbType.Int, pc);
                            p2.apptid = (int)newApptId;
                        }
                        else
                        {
                            if (appt.CloudWebQueueState == SYNCH_APPT)
                            {
                                p2.apptid = appt.CloudWebQueueSynchId;
                            }
                        }

                        p2.FHx.proband = p2;
                        p2.PersistFullObject(new RiskApps3.Model.HraModelChangedEventArgs(null));

                        if (checkBox4.Checked)
                        {
                            backgroundWorker2.ReportProgress(2, "Marking Complete and updating meta data: " + appt.PatientName + " - " + appt.Dob);
                            ParameterCollection pc = new ParameterCollection("apptID", p2.apptid);
                            BCDB2.Instance.RunSPWithParams("sp_markRiskDataCompleted", pc);
                        }

                        if (checkBox1.Checked)
                        {
                            backgroundWorker2.ReportProgress(2, "Running Risk Models: " + appt.PatientName + " - " + appt.Dob);
                            p2.RecalculateRisk();

                            ParameterCollection pc = new ParameterCollection("unitnum", p2.unitnum);
                            BCDB2.Instance.RunSPWithParams("sp_3_populateBigQueue", pc);
                        }

                        if (checkBox2.Checked)
                        {
                            backgroundWorker2.ReportProgress(2, "Printing Automation Documents: " + appt.PatientName + " - " + appt.Dob);

                            p2.RunAutomation();

                            //ParameterCollection printDocArgs = new ParameterCollection();
                            //printDocArgs.Add("apptid", p2.apptid);
                            //SqlDataReader reader = BCDB2.Instance.ExecuteReaderSPWithParams("sp_AutomationHtmlDocsToPrint", printDocArgs);
                            //while (reader.Read())
                            //{
                            //    int templateID = -1;
                            //    if (reader.IsDBNull(0) == false)
                            //    {
                            //        templateID = reader.GetInt32(0);
                            //    }
                            //    SessionManager.Instance.SetActivePatientNoCallback(p2.unitnum, p2.apptid);
                            //    DocumentTemplate template = new DocumentTemplate();
                            //    template.documentTemplateID = templateID;
                            //    template.BackgroundLoadWork();
                            //    template.OpenHTML();
                            //    template.ProcessDocument();
                            //    htmlInProgress = true;
                            //    backgroundWorker2.ReportProgress(1, template.htmlText);
                            //    while (htmlInProgress)
                            //    {
                            //        Application.DoEvents();
                            //        Thread.Sleep(500);
                            //    }

                            //}
                        }
                        if (checkBox5.Checked)
                        {
                            backgroundWorker2.ReportProgress(2, "Removing Web Survey: " + appt.PatientName + " - " + appt.Dob);
                            backgroundWorker2.ReportProgress(4, appt);
                            cloud.DeleteSurvey(appt.apptID);
                        }
                        backgroundWorker2.ReportProgress(2, "Precessing Queue Documents: " + appt.PatientName + " - " + appt.Dob);
                        if (checkBox3.Checked)
                        {
                            ParameterCollection pc = new ParameterCollection("apptID", p2.apptid);
                            BCDB2.Instance.RunSPWithParams("sp_processQueueDocuments", pc);
                        }
                    }
                    else if (appt.CloudWebQueueState == DELETE_APPT)
                    {
                        backgroundWorker2.ReportProgress(2, "Removing Web Survey: " + appt.PatientName + " - " + appt.Dob);
                        backgroundWorker2.ReportProgress(4, appt);
                        cloud.DeleteSurvey(appt.apptID);
                    }
                    backgroundWorker2.ReportProgress(3,o);
                }
            }
            catch (Exception exc)
            {
                Logger.Instance.WriteToLog(exc.ToString());
            }
        }