12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826 |
- using System;
- using System.Collections.Generic;
- using System.Windows;
- using System.Windows.Controls;
- using System.IO;
- using System.Windows.Input;
- using MahApps.Metro.Controls;
- using MahApps.Metro.Controls.Dialogs;
- using System.Data;
- using WpfTest1.SQLite;
- using WpfTest1.Toolkits;
- using LitJson;
- using System.ComponentModel;
- using System.Windows.Media.Imaging;
- using System.Windows.Documents;
- using System.Windows.Media;
- using WpfTest1.ComAgent;
- using System.Collections;
- using Com = WpfTest1.ComAgent.ComAgent;
- using System.Diagnostics;
- namespace WpfTest1
- {
- /// <summary>
- /// MainWindow.xaml 的交互逻辑
- /// </summary>
- public partial class MainWindow : MetroWindow
- {
- #region 系统基本参数
- System.Data.SQLite.SQLiteDataAdapter daHistoryRecord; //选择记录页面查询记录条目的数据集容器
- public doctor loginDoctor = null; //所登录的医师
- DataSet ds; //其他界面的DataSet
- System.Data.SQLite.SQLiteDataAdapter da; //其他界面的DataAdapter
- //double highBp; //BP界面高压
- //double lowBp; //BP界面低压
- DateTime lastSettingLogin; //上一次在系统设置界面登录的时间
- public Toolkits.Config cfg; //从数据库取配置的类
- DogOperator dop = new DogOperator(Constants.registerPid, Constants.registerUid);
- Patient filterPatient;
- Patient evaluationPatient;
- Patient historyPatient;
- Record filterReportForEvaluation;
- bool flagEvaluationWithoutFilter = true;
- List<QuestionAnswerPair> filterQuestionaire = new List<QuestionAnswerPair>();
- List<QuestionAnswerPair> evaluationQuestionaire = new List<QuestionAnswerPair>();
- List<UserSelection> filterUserSelection = new List<UserSelection>();
- List<UserSelection> evaluationUserSelection = new List<UserSelection>();
- string resultsFilter;
- string resultsEvaluation;
- int currentFilterCount = 0;
- int currentEvaluationCount = 0;
- List<Record> recordsFromOnePatient;
- BindingList<Record> bindingRecords;
- Dictionary<string, int> mapKeyToDigit = new Dictionary<string, int>();
- Treatment targetTreatment = null;
- List <TreatmentCustomItem> treatmentCustomModeList;
- //DataTable treatmentCustomDataTable;
- #endregion
- public MainWindow()
- {
- InitializeComponent();
- //加载配置
- cfg = new Toolkits.Config();
- //绑定三个selectUser的父类
- //selectUserMeasure.setMainWindow(this);
- selectUserPatientManagent.setMainWindow(this);
- selectUserfilter.setMainWindow(this);
- selectUserevaluation.setMainWindow(this);
- selectUserHistory.setMainWindow(this);
- treatmentPlanPage.setMainWindow(this);
- textBoxOrganizationName.Text = cfg.organization_name;
- }
- #region 初始化与系统调用部分
- //初始化全部组件后需要先输入医生密码才能进入
- private void mainWndGrid_Loaded(object sender, RoutedEventArgs e)
- {
- //Application.Current.Dispatcher.UnhandledException += Dispatcher_UnhandledException;
- labelHomepageCversion.Content = "编译日期:" + Toolkits.Constants.compileDate;
- labelSoftwareName.Content = String.Format("欢迎使用{0}", Constants.softwareName);
- //之后测试登录
- SmallDialogs.LoginWindow lw = new SmallDialogs.LoginWindow(this);
- lw.ShowDialog();
- if (loginDoctor == null)
- {
- this.Close();
- }
- bool registerFlag = dop.checkSoftwareRegister();
- if (!registerFlag && Constants.productionEnvironment)
- {
- MessageBox.Show("未找到硬件授权Key,请确认插入后重试", "错误");
- this.Close();
- }
- loadUSBDogStatus();
- string datestr = "2050-12-31 00:00:00";
- DateTime dtStandard = DateTime.Parse(datestr);
- DateTime now = DateTime.Now;
- if(DateTime.Compare(dtStandard, now) < 0)
- {
- MessageBox.Show("系统数据异常,请联系管理员", "错误");
- this.Close();
- }
- //显示医生姓名
- if (loginDoctor != null)
- {
- loginedDoctorName.Content = "欢迎您, " + loginDoctor.name;
- return;
- }
- loadQuestionaire(filterQuestionaire, "filter");
- loadQuestionaire(evaluationQuestionaire, "evaluation");
- }
- private void Dispatcher_UnhandledException(object sender, System.Windows.Threading.DispatcherUnhandledExceptionEventArgs e)
- {
- Debug.WriteLine(e.ToString());
- }
- private void loadUSBDogStatus()
- {
- int[] timesLimit = dop.getTimesCount();
- if(timesLimit[0] != -1 && timesLimit[1]!= -1)
- {
- labelHomepageUSBDogStatus.Content = String.Format("系统Key已授权,当前Key可使用{0}次,已使用{1}次", timesLimit[0], timesLimit[1]);
- labelHomepageUSBDogStatus.Visibility = Visibility.Visible;
- }
- else
- {
- labelHomepageUSBDogStatus.Visibility = Visibility.Hidden;
- }
- }
- private void loadQuestionaire(List<QuestionAnswerPair> oneQuestionaire, string type = "filter")
- {
- oneQuestionaire.Clear();
- List<Question> questions = SQLite.SQLiteModel.getQuestions(type);
- foreach (Question oneQuestion in questions)
- {
- List<Answer> answers = SQLite.SQLiteModel.getAnswersByQid(oneQuestion.q_id);
- QuestionAnswerPair temp = new QuestionAnswerPair(oneQuestion, answers);
- oneQuestionaire.Add(temp);
- }
- }
- /// <summary>
- /// 筛查或评估流程页面识别快捷键的操作
- /// </summary>
- /// <param name="sender">默认</param>
- /// <param name="e">默认</param>
- private void processGrid_KeyDown(object sender, KeyEventArgs e)
- {
- //System.Console.WriteLine(String.Format("KeyDown detected. {0} is detected.", e.Key.ToString()));
- if (tabControlGeneral.SelectedIndex == 2 && tabFilter.SelectedIndex == 1)
- {
- /*//筛查流程中
- if (e.Key == Key.N && buttonFilterNext.IsEnabled)
- {
- buttonFilterNext_Click(sender, (RoutedEventArgs)e);
- return;
- }
- if (e.Key == Key.P && buttonFilterPrevious.IsEnabled)
- {
- buttonFilterPrevious_Click(sender, (RoutedEventArgs)e);
- return;
- }
- if (e.Key == Key.E)
- {
- buttonAbortFilter_Click(sender, (RoutedEventArgs)e);
- return;
- }
- if(e.Key == Key.S && buttonSubmitFilter.IsEnabled)
- {
- buttonSubmitFilter_Click(sender, (RoutedEventArgs)e);
- return;
- }
- if (Constants.keyboardToDigit.ContainsKey(e.Key.ToString()))
- {
- int numInput = Constants.keyboardToDigit[e.Key.ToString()];
- try
- {
- RadioButton rbTemp = (RadioButton)gridFilterSelection.Children[numInput - 1];
- rbTemp.IsChecked = true;
- radioButtonFilter_Checked(rbTemp, e);
- }
- catch (Exception)
- {
- return;
- }
-
- return;
- }*/
- }
- else if(tabControlGeneral.SelectedIndex == 3 && tabEvaluation.SelectedIndex == 1)
- {
- //评估流程中
- if (e.Key == Key.N && buttonEvaluationNext.IsEnabled)
- {
- buttonEvaluationNext_Click(sender, (RoutedEventArgs)e);
- return;
- }
- if (e.Key == Key.E)
- {
- buttonAbortEvaluation_Click(sender, (RoutedEventArgs)e);
- return;
- }
- if (e.Key == Key.S && buttonSubmitEvaluation.IsEnabled)
- {
- buttonSubmitEvaluation_Click(sender, (RoutedEventArgs)e);
- return;
- }
- if (Constants.keyboardToDigit.ContainsKey(e.Key.ToString()))
- {
- int numInput = Constants.keyboardToDigit[e.Key.ToString()];
- try
- {
- RadioButton rbTemp = (RadioButton)gridEvaluationSelection.Children[numInput - 1];
- rbTemp.IsChecked = true;
- radioButtonEvaluation_Checked(rbTemp, e);
- }
- catch (Exception)
- {
- return;
- }
- }
- }
- else
- {
- return;
- }
- }
- #endregion
- #region 首页功能
- //标题栏快速添加病例的接口
- private void Fast_Add_Patient_Button_Click(object sender, RoutedEventArgs e)
- {
- buttonAddPatient_Click(this, e);
- }
- //首页--新建用户
- private void buttonHomePageAddPatient_Click(object sender, RoutedEventArgs e)
- {
- buttonAddPatient_Click(this, e);
- }
- //首页--用户管理
- private void buttonHomePagePatientManagent_Click(object sender, RoutedEventArgs e)
- {
- tabControlGeneral.SelectedIndex = 1;
- }
- private void buttonHomePageFilterFunction_Click(object sender, RoutedEventArgs e)
- {
- tabControlGeneral.SelectedIndex = 2;
- }
- private void buttonHomePageEvaluationFunction_Click(object sender, RoutedEventArgs e)
- {
- tabControlGeneral.SelectedIndex = 3;
- }
- //首页--检测报告
- private void buttonHomeHistoryRecords_Click(object sender, RoutedEventArgs e)
- {
- tabControlGeneral.SelectedIndex = 4;
- }
- //首页--系统设置
- private void buttonHomePageSystemSettings_Click(object sender, RoutedEventArgs e)
- {
- tabControlGeneral.SelectedIndex = 5;
- }
- //首页--诊疗记录
- private void buttonHomePageTreatmentRecords_Click(object sender, RoutedEventArgs e)
- {
- tabControlGeneral.SelectedIndex = 6;
- }
- //首页--诊疗记录
- private void buttonHomePageTreatmentPlan_Click(object sender, RoutedEventArgs e)
- {
- tabControlGeneral.SelectedIndex = 7;
- }
-
- //关于程序
- private void buttonHomePageDataTransfer_Click(object sender, RoutedEventArgs e)
- {
- SmallDialogs.AboutBox ab = new SmallDialogs.AboutBox();
- ab.Show();
- }
- //首页--操作帮助
- private void buttonHomePageHelp_Click(object sender, RoutedEventArgs e)
- {
- System.Diagnostics.Process.Start(Constants.template_custom + "\\" + "manual.pdf");
- //manual.pdf
- //Record one_record = SQLiteModel.getRecordByID(24);
- //Patient one_patient = SQLiteModel.getPatientById("5");
- //ReportGenerater.generateReport_constum(one_record, one_patient,cfg);
- }
-
- #endregion
- #region 病例管理
- //病例管理
- //病例管理--病例管理
- #region 病例管理--添加病例
- //添加病例
- private void buttonAddPatient_Click(object sender, RoutedEventArgs e)
- {
- AddPatient a_new_one = new AddPatient(this);
- a_new_one.Show();
- //selectUserPatientManagent.LoadDataGrid();
- }
- #endregion
- #region 病例管理--修改病例
- //修改病例
- public void buttonModifyPatient_Click(object sender, RoutedEventArgs e)
- {
- try
- {
- var target = (DataRowView)this.selectUserPatientManagent.dataGrid.SelectedItem;
- //MessageBox.Show(target["id"].ToString());
- ModifyUser modify_one = new ModifyUser(this, target["p_id"].ToString());
- modify_one.Show();
- }
- catch(Exception err)
- {
- //this.ShowMessageAsync("警告","请选择一个病例进行修改\r\n调试信息:" + err.Message + "\r\n" + err.StackTrace );
- MessageBox.Show("请选择一个病例进行修改\r\n调试信息:" + err.Message + "\r\n" + err.StackTrace,"警告");
- }
- }
- #endregion
- #region 病例管理--删除病例
- //删除病例
- private void buttonDeletePatient_Click(object sender, RoutedEventArgs e)
- {
- try
- {
- var target = (DataRowView)this.selectUserPatientManagent.dataGrid.SelectedItem;
- if(target == null)
- {
- MessageBox.Show("请选择一个病例进行删除", "提示");
- return;
- }
- MessageBoxResult clickresult = MessageBox.Show("确认删除该病例?", "提示", MessageBoxButton.OKCancel);
- if (clickresult == MessageBoxResult.OK)
- {
- int status = SQLite.SQLiteModel.DeletePatientItem(target["p_id"].ToString());
- if (status > 0)
- {
- MessageBox.Show("删除成功","提示");
- }
- else
- {
- MessageBox.Show("已删除", "提示");
- }
- }
- else if (clickresult == MessageBoxResult.Cancel)
- {
- return;
- }
- }
- catch (Exception err)
- {
- MessageBox.Show("数据库故障\r\n调试信息:" + err.Message + "\r\n" + err.StackTrace, "错误");
- }
-
- selectUserPatientManagent.LoadDataGrid();
-
- }
- #endregion
- #endregion
- #region 治疗功能 原筛查功能
- /// <summary>
- /// 点击治疗后触发的事件
- /// </summary>
- /// <param name="sender">默认</param>
- /// <param name="e">默认</param>
- public void buttonFilterSelectTreatment_Click(object sender, RoutedEventArgs e)
- {
- try
- {
- var target = (DataRowView)this.selectUserfilter.dataGrid.SelectedItem;
- if (target == null)
- {
- MessageBox.Show("请先选择病人!");
- return;
- }
- filterPatient = SQLite.SQLiteModel.getPatientById(target["p_id"].ToString());
- }
- catch (Exception err)
- {
- MessageBox.Show("请选择一个病例进行修改\r\n调试信息:" + err.Message + "\r\n" + err.StackTrace, "警告");
- return;
- }
- if(filterPatient == null)
- {
- MessageBox.Show("数据库加载异常", "错误");
- return;
- }
- try
- {
- loadQuestionaire(filterQuestionaire, "filter");
- filterUserSelection.Clear();
- foreach(QuestionAnswerPair qa in filterQuestionaire)
- {
- filterUserSelection.Add(new UserSelection(qa.question.q_id, 0));
- }
- }
- catch (Exception err)
- {
- MessageBox.Show("治疗数据加载失败\r\n调试信息:" + err.Message + "\r\n" + err.StackTrace, "错误");
- return;
- }
- currentFilterCount = 1;
- tabFilter.SelectedIndex += 1;
- textBoxCaseId.Text = filterPatient.p_record_id;
- textBoxGender.Text = filterPatient.p_gender;
- textBoxName.Text = filterPatient.p_name;
- textBoxHeight.Text = filterPatient.p_height.ToString();
- textBoxWeight.Text = filterPatient.p_weight.ToString();
- textBoxPregnancyTimes.Text = filterPatient.p_pregnancy_time.ToString();
- textBoxBirthDate.Text = filterPatient.p_birthdate.ToString("yyyy/M/d");
- textBoxMobile.Text = filterPatient.p_phone;
- textBoxAddress.Text = filterPatient.p_address;
- textBoxHistory.Text = filterPatient.p_history;
- textBoxDiagnosis.Text = filterPatient.p_diagnosis;
- //*/
- treatmentCustomModeList = new List<TreatmentCustomItem>();
- //dataGridCustomMode.ItemsSource = treatmentCustomModeList;/*/
- //treatmentCustomDataTable = new DataTable();
- //treatmentCustomDataTable.Columns.Add("tcID", typeof(int));
- //treatmentCustomDataTable.Columns.Add("tcRate", typeof(double));
- //treatmentCustomDataTable.Columns.Add("tcActiveTime", typeof(double));
- //treatmentCustomDataTable.Columns.Add("tcInactiveTime", typeof(double));
- //dataGridCustomMode.ItemsSource = treatmentCustomDataTable.DefaultView;//*/
- }
- /// <summary>
- /// 重选用户
- /// </summary>
- /// <param name="sender">默认</param>
- /// <param name="e">默认</param>
- private void buttonFilterBackToSelectUser_Click(object sender, RoutedEventArgs e)
- {
- tabFilter.SelectedIndex = 0;
- }
- /// <summary>
- /// 治疗方案
- /// </summary>
- /// <param name="sender">默认</param>
- /// <param name="e">默认</param>
- //private void buttonChooseTreatmentPlan_Click(object sender, RoutedEventArgs e)
- //{
- // TreatmentPlan a_new_one = new TreatmentPlan(this);
- // a_new_one.Show();
- //}
- public void setTreatment(Treatment target)
- {
- targetTreatment = target;
- labelTreatmentName.Content = targetTreatment.disease;
- sliderStrength.Value = 100;
- }
- private void sliderStrength_ValueChanged(object sender, RoutedPropertyChangedEventArgs<double> e)
- {
- labelStrength.Content = sliderStrength.Value.ToString("0.");
- comAgent.enqueueCommand(Com.createChangeStrongthCommand((byte)sliderStrength.Value));
- }
- /// <summary>
- /// 自定义模式
- /// </summary>
- /// <param name="sender">默认</param>
- /// <param name="e">默认</param>
- //private void checkBoxCustomMode_CheckedChanged(object sender, RoutedEventArgs e)
- //{
- // if (checkBoxCustomMode.IsChecked == true) {
- // labelTreatmentName.Content = "自定义模式";
- // buttonSelectTreatment.IsEnabled = false;
- // dataGridCustomMode.IsEnabled = true;
- // //dataGridCustomMode.CanUserAddRows = true;
- // //dataGridCustomMode.CanUserDeleteRows = true;
- // buttonAddCustomModeItem.IsEnabled = true;
- // buttonDelCustomModeItem.IsEnabled = true;
- // } else {
- // if (targetTreatment == null) {
- // labelTreatmentName.Content = "请选择治疗方案";
- // } else {
- // labelTreatmentName.Content = targetTreatment.disease;
- // }
- // buttonSelectTreatment.IsEnabled = true;
- // dataGridCustomMode.IsEnabled = false;
- // buttonAddCustomModeItem.IsEnabled = false;
- // buttonDelCustomModeItem.IsEnabled = false;
- // }
- //}
- //private void buttonAddCustomModeItem_Click(object sender, RoutedEventArgs e)
- //{
- // TreatmentCustomItem item = new TreatmentCustomItem();
- // item.tcID = treatmentCustomModeList.Count + 1;
- // treatmentCustomModeList.Add(item);
- // dataGridCustomMode.ItemsSource = null;
- // dataGridCustomMode.ItemsSource = treatmentCustomModeList;
- //}
- //private void buttonDelCustomModeItem_Click(object sender, RoutedEventArgs e)
- //{
- // int index = dataGridCustomMode.SelectedIndex;
- // if (index == -1) { return; }
- // treatmentCustomModeList.RemoveAt(index);
- // for (int i = 0; i < treatmentCustomModeList.Count; i++)
- // {
- // treatmentCustomModeList[i].tcID = i + 1;
- // }
- // dataGridCustomMode.ItemsSource = null;
- // dataGridCustomMode.ItemsSource = treatmentCustomModeList;
- //}
- private void dataGridCustomMode_SelectionChanged(object sender, SelectionChangedEventArgs e)
- {
- //System.Console.WriteLine("asdasdasd");
- }
- private void dataGridCustomMode_RowEditEnding(object sender, DataGridRowEditEndingEventArgs e)
- {
- //System.Console.WriteLine("asdasdasd");
- }
- /// <summary>
- /// 点击筛查上一步后触发的事件
- /// </summary>
- /// <param name="sender">默认</param>
- /// <param name="e">默认</param>
- /*private void buttonFilterPrevious_Click(object sender, RoutedEventArgs e)
- {
- currentFilterCount -= 1;
- loadQuestionViewFilter(currentFilterCount);
- checkFilterButtonStatues();
- }*/
- /// <summary>
- /// 点击筛查下一步后触发的事件
- /// </summary>
- /// <param name="sender">默认</param>
- /// <param name="e">默认</param>
- /*private void buttonFilterNext_Click(object sender, RoutedEventArgs e)
- {
- checkFilterButtonStatues();
- }*/
- /// <summary>
- /// 确认筛查阶段各个按钮应当处于的状态
- /// </summary>
- /*private void checkFilterButtonStatues()
- {
- bool radioCheckFlag = false;
- foreach(RadioButton rb in gridFilterSelection.Children){
- if(rb.IsChecked == true)
- {
- radioCheckFlag = true;
- }
- }
- if (radioCheckFlag && currentFilterCount < filterQuestionaire.Count)
- buttonFilterNext.IsEnabled = true;
- else
- buttonFilterNext.IsEnabled = false;
- if (currentFilterCount > 1)
- buttonFilterPrevious.IsEnabled = true;
- else
- buttonFilterPrevious.IsEnabled = false;
- bool allFilledFlag = true;
- foreach (UserSelection us in filterUserSelection)
- {
- if (us.a_id == 0)
- allFilledFlag = false;
- }
- if (allFilledFlag)
- buttonSubmitFilter.IsEnabled = true;
- else
- buttonSubmitFilter.IsEnabled = false;
- }*/
- /// <summary>
- /// 加载题目和选项界面
- /// </summary>
- /*private void loadQuestionViewFilter(int currentIndex)
- {
- labelFilterNumberofTotalQuestions.Content = filterQuestionaire.Count.ToString();
- labelFilterNumberofCurrentQuestion.Content = currentIndex.ToString();
- labelFilterQuestionTitle.Content = filterQuestionaire[currentIndex - 1].question.q_title;
- textBlockFilterQuetionContent.Text = "";
- string[] splitedContentTemp = filterQuestionaire[currentIndex - 1].question.q_content.Split('$');
- for(int i = 0;i< splitedContentTemp.Length; ++i)
- {
- Run aRunTemp = new Run();
- aRunTemp.Text = splitedContentTemp[i];
-
- if (i % 2 == 0)
- {
- textBlockFilterQuetionContent.Inlines.Add(aRunTemp);
- }
- else
- {
- aRunTemp.Foreground = Brushes.Red;
- textBlockFilterQuetionContent.Inlines.Add(aRunTemp);
- }
- }
- string quetionPic_start = Constants.imgPath + "\\" + filterQuestionaire[currentIndex - 1].question.q_id.ToString() + "-起始位.png";
- if (File.Exists(quetionPic_start))
- {
- BitmapImage bi = new BitmapImage();
- bi.BeginInit();
- bi.UriSource = new Uri(quetionPic_start, UriKind.RelativeOrAbsolute);
- bi.EndInit();
- imageFilterQuestion_start.Source = bi;
- }
- else
- {
- imageFilterQuestion_start.Source = null;
- }
- string quetionPic_active = Constants.imgPath + "\\" + filterQuestionaire[currentIndex - 1].question.q_id.ToString() + "-动作位.png";
- if (File.Exists(quetionPic_active))
- {
- BitmapImage bi = new BitmapImage();
- bi.BeginInit();
- bi.UriSource = new Uri(quetionPic_active, UriKind.RelativeOrAbsolute);
- bi.EndInit();
- imageFilterQuestion_active.Source = bi;
- }
- else
- {
- imageFilterQuestion_active.Source = null;
- }
- int countOptions = filterQuestionaire[currentIndex - 1].answers.Count;
- gridFilterSelection.Children.Clear();
- for (int i = 0; i< countOptions; ++i)
- {
- RadioButton oneOption = new RadioButton();
- oneOption.Height = 30;
- oneOption.HorizontalAlignment = HorizontalAlignment.Left;
- oneOption.VerticalAlignment = VerticalAlignment.Top;
- oneOption.Margin = new Thickness(i/6*300, i%6*30, 0, 0);
- if(filterUserSelection[currentIndex-1].a_id == filterQuestionaire[currentIndex - 1].answers[i].a_id)
- oneOption.IsChecked = true;
- else
- oneOption.IsChecked = false;
- oneOption.Content = String.Format("[选项{0}]:{1}", i+1, filterQuestionaire[currentIndex - 1].answers[i].a_content) ;
- oneOption.Checked += radioButtonFilter_Checked;
- oneOption.GroupName = "filterOption";
- oneOption.FontSize = 18;
- oneOption.Name = "rbf" + filterQuestionaire[currentIndex - 1].answers[i].a_id.ToString();
- gridFilterSelection.Children.Add(oneOption);
- }
- }*/
- /*private void radioButtonFilter_Checked(object sender, RoutedEventArgs e)
- {
- //首先,记录该选择
- RadioButton oneSelection = (RadioButton)sender;
- filterUserSelection[currentFilterCount - 1].a_id = Convert.ToInt32(oneSelection.Name.Substring(3));
- //MessageBox.Show(filterUserSelection[currentFilterCount - 1].a_id.ToString());
- //然后,确认各个按钮状态
- checkFilterButtonStatues();
- }*/
- /// <summary>
- /// 点击筛查提交后触发的事件
- /// </summary>
- /// <param name="sender">默认</param>
- /// <param name="e">默认</param>
- /*private void buttonSubmitFilter_Click(object sender, RoutedEventArgs e)
- {
- int[] timesLimit = dop.getTimesCount();
- if (Constants.productionEnvironment && (timesLimit[1] >= timesLimit[0]))
- {
- MessageBox.Show("此功能已超过Key授权次数,请使用一个新的Key进行操作。", "提示");
- return;
- }
- int inserted_r_id;
- resultsFilter = JsonMapper.ToJson(filterUserSelection);
- //MessageBox.Show(results);
- try
- {
- inserted_r_id = SQLiteModel.insertRecord(1, filterPatient.p_id, loginDoctor.id, 0, DateTime.Now, 0, resultsFilter);
- SQLiteModel.UpdatePatientDataWithLastDate(filterPatient.p_id, "p_last_filter_time", DateTime.Now);
- }
- catch (Exception err)
- {
- MessageBox.Show("储存筛查报告错误\r\n调试信息:" + err.Message + "\r\n" + err.StackTrace, "错误");
- return;
- }
- dop.addOneCount();
- MessageBoxResult dr = MessageBox.Show("保存筛查结果成功,是否生成报告?", "提示", MessageBoxButton.OKCancel, MessageBoxImage.Question);
- if (dr == MessageBoxResult.OK)
- {
- try
- {
- Record targetRecord = SQLiteModel.getRecordByID(inserted_r_id);
- //ReportGenerater.generateReport(1, filterPatient, loginDoctor, targetRecord, cfg.organization_name);
- ReportGenerater.generateReport_constum(targetRecord, filterPatient, cfg);
- SQLiteModel.plusOneCountOnRecordByRid(inserted_r_id);
- }
- catch (Exception err)
- {
- MessageBox.Show("报告生成异常,可能是这份报告当前已被打开无法写入,请尝试关闭该报告后重试。\r\n调试信息:" + err.Message + "\r\n" + err.StackTrace, "错误");
- return;
- }
- tabFilter.SelectedIndex = 2;
- }
- else
- {
- buttonAbortFilter_Click(sender, e);
- }
- return;
- }*/
- #endregion
- #region 评估功能
- /// <summary>
- /// 点击开始评估后触发的事件
- /// </summary>
- /// <param name="sender">默认</param>
- /// <param name="e">默认</param>
- public void buttonEvaluationSelectPatient_Click(object sender, RoutedEventArgs e)
- {
- //基本逻辑如下:先找七天内与病例相匹配的筛查记录,如果有,那么要取出结果一题一题比对
- //如果没有,那么应当把筛查题进行加载处理
- try
- {
- var target = (DataRowView)this.selectUserevaluation.dataGrid.SelectedItem;
- evaluationPatient = SQLite.SQLiteModel.getPatientById(target["p_id"].ToString());
- }
- catch (Exception err)
- {
- MessageBox.Show("请选择一个病例进行修改\r\n调试信息:" + err.Message + "\r\n" + err.StackTrace, "警告");
- return;
- }
- if (evaluationPatient == null)
- {
- MessageBox.Show("数据库加载异常", "错误");
- return;
- }
- try
- {
- loadQuestionaire(filterQuestionaire, "filter");
- evaluationQuestionaire.Clear();
- filterUserSelection.Clear();
- evaluationUserSelection.Clear();
- //这里尝试加载用户的筛查记录
- /*20200507:根据甲方要求不再提供初筛功能,这里停止加载最新的筛查记录,所有人都做最复杂的问卷*/
- //filterReportForEvaluation = SQLiteModel.getLatestXTypeRecordInYDays(evaluationPatient.p_id, 1, 7);
- filterReportForEvaluation = null;
- if (filterReportForEvaluation == null)
- {
- flagEvaluationWithoutFilter = true;
- foreach (QuestionAnswerPair qa in filterQuestionaire)
- {
- filterUserSelection.Add(new UserSelection(qa.question.q_id, 0));
- }
- }
- else
- {
- var jsonUserSelections = filterReportForEvaluation.r_selection;
- filterUserSelection = JsonMapper.ToObject<List<UserSelection>>(jsonUserSelections);
- flagEvaluationWithoutFilter = false;
- }
-
- }
- catch (Exception err)
- {
- MessageBox.Show("筛查题目加载失败\r\n调试信息:" + err.Message + "\r\n" + err.StackTrace, "错误");
- return;
- }
- if (filterQuestionaire.Count == 0)
- {
- MessageBox.Show("筛查题目加载失败\r\n数据库中无有效问卷", "错误");
- return;
- }
- if (flagEvaluationWithoutFilter)
- {
- /*20200507:根据甲方要求不再提供初筛功能,这里停止加载最新的筛查记录,所有人都做最复杂的问卷*/
- //MessageBox.Show("发现该病例一周内未进行初筛,评估过程中将自动进行初筛。","提示");
- }
- else
- {
- MessageBox.Show("发现该病例于"+ filterReportForEvaluation.r_time.ToString("yyyy-MM-dd HH:mm:ss") +"进行过初筛,评估过程中将使用此初筛结果。", "提示");
- }
- labelEvaluationName.Content = evaluationPatient.p_name;
- labelEvaluationRecordid.Content = evaluationPatient.p_record_id;
- currentFilterCount = 1;
- currentEvaluationCount = 1;
- evaluationQuestionaire.Add(filterQuestionaire[currentFilterCount - 1]);
- evaluationUserSelection.Add(filterUserSelection[currentFilterCount - 1]);
- tabEvaluation.SelectedIndex += 1;
- checkStatusEvaluation();
- }
- /// <summary>
- /// 加载currentIndex的评估题目功能
- /// </summary>
- /// <param name="currentIndex">需要显示题目的题号</param>
- private void loadQuestionViewEvaluation(int currentIndex)
- {
- labelQuestionNumberofCurrentQuestion.Content = currentIndex.ToString();
- labelEvaluationQuestionTitle.Content = evaluationQuestionaire[currentIndex - 1].question.q_title;
- textBlockEvaluationQuetionContent.Text = "";
- string[] splitedContentTemp = evaluationQuestionaire[currentIndex - 1].question.q_content.Split('$');
- for (int i = 0; i < splitedContentTemp.Length; ++i)
- {
- Run aRunTemp = new Run();
- aRunTemp.Text = splitedContentTemp[i];
- if (i % 2 == 0)
- {
- textBlockEvaluationQuetionContent.Inlines.Add(aRunTemp);
- }
- else
- {
- //aRunTemp.Foreground = Brushes.Red;
- aRunTemp.FontWeight = FontWeights.Bold;
- aRunTemp.Text = "· " + aRunTemp.Text;
- textBlockEvaluationQuetionContent.Inlines.Add(aRunTemp);
- }
- }
- string quetionPic_start = Constants.imgPath + "\\" + evaluationQuestionaire[currentIndex - 1].question.q_id.ToString() + "-起始位.png";
- if (File.Exists(quetionPic_start))
- {
- BitmapImage bi = new BitmapImage();
- bi.BeginInit();
- bi.UriSource = new Uri(quetionPic_start, UriKind.RelativeOrAbsolute);
- bi.EndInit();
- imageEvaluationQuestion_start.Source = bi;
- }
- else
- {
- imageEvaluationQuestion_start.Source = null;
- }
- string quetionPic_active = Constants.imgPath + "\\" + evaluationQuestionaire[currentIndex - 1].question.q_id.ToString() + "-动作位.png";
- if (File.Exists(quetionPic_active))
- {
- BitmapImage bi = new BitmapImage();
- bi.BeginInit();
- bi.UriSource = new Uri(quetionPic_active, UriKind.RelativeOrAbsolute);
- bi.EndInit();
- imageEvaluationQuestion_active.Source = bi;
- }
- else
- {
- imageEvaluationQuestion_active.Source = null;
- }
- int countOptions = evaluationQuestionaire[currentIndex - 1].answers.Count;
- gridEvaluationSelectionNormalOptions.Children.Clear();
- gridEvaluationSelection.Children.Clear();
-
- //i=0,添加一个正常选项
- if (countOptions > 0)
- {
- Label normalWithoutPain = new Label();
- normalWithoutPain.HorizontalAlignment = HorizontalAlignment.Center;
- normalWithoutPain.VerticalAlignment = VerticalAlignment.Top;
- normalWithoutPain.Margin = new Thickness(0, 0, 0, 0);
- normalWithoutPain.Content = "动作标准";
- normalWithoutPain.Foreground = new SolidColorBrush(Color.FromRgb(39, 64, 90));
- normalWithoutPain.FontWeight = FontWeights.Bold;
- normalWithoutPain.FontSize = 20;
- gridEvaluationSelectionNormalOptions.Children.Add(normalWithoutPain);
- RadioButton oneOption = new RadioButton();
- oneOption.Height = 30;
- oneOption.HorizontalAlignment = HorizontalAlignment.Center;
- oneOption.VerticalAlignment = VerticalAlignment.Center;
- oneOption.Margin = new Thickness(0, 0, 0, 0);
- if (evaluationUserSelection[currentIndex - 1].a_id == evaluationQuestionaire[currentIndex - 1].answers[0].a_id)
- oneOption.IsChecked = true;
- else
- oneOption.IsChecked = false;
- oneOption.Content = String.Format("{0}", evaluationQuestionaire[currentIndex - 1].answers[0].a_content);
- oneOption.Checked += radioButtonEvaluation_Checked;
- oneOption.GroupName = "evaluationOption";
- oneOption.FontSize = 18;
- oneOption.Name = "rbe" + evaluationQuestionaire[currentIndex - 1].answers[0].a_id.ToString();
- gridEvaluationSelectionNormalOptions.Children.Add(oneOption);
- }
- //i>=1
- for (int i = 1; i < countOptions; ++i)
- {
- Label abnormalWithPain = new Label();
- abnormalWithPain.HorizontalAlignment = HorizontalAlignment.Center;
- abnormalWithPain.VerticalAlignment = VerticalAlignment.Top;
- abnormalWithPain.Margin = new Thickness(0, 0, 0, 0);
- abnormalWithPain.Content = "动作不标准";
- abnormalWithPain.Foreground = new SolidColorBrush(Color.FromRgb(39, 64, 90));
- abnormalWithPain.FontWeight = FontWeights.Bold;
- abnormalWithPain.FontSize = 20;
- gridEvaluationSelection.Children.Add(abnormalWithPain);
- RadioButton oneOption = new RadioButton();
- oneOption.Height = 30;
- oneOption.HorizontalAlignment = HorizontalAlignment.Left;
- oneOption.VerticalAlignment = VerticalAlignment.Top;
- oneOption.Margin = new Thickness( (i-1)/ 3 * 170 + 30, (i-1) % 3 * 30+40, 0, 0);
- if (evaluationUserSelection[currentIndex - 1].a_id == evaluationQuestionaire[currentIndex - 1].answers[i].a_id)
- oneOption.IsChecked = true;
- else
- oneOption.IsChecked = false;
- oneOption.Content = String.Format("{0}", evaluationQuestionaire[currentIndex - 1].answers[i].a_content);
- oneOption.Checked += radioButtonEvaluation_Checked;
- oneOption.GroupName = "evaluationOption";
- oneOption.FontSize = 18;
- oneOption.Name = "rbe" + evaluationQuestionaire[currentIndex - 1].answers[i].a_id.ToString();
- gridEvaluationSelection.Children.Add(oneOption);
- }
- }
- /// <summary>
- /// 检查当前答题状态,判断是否需要跳过该题和控制加载题目的功能,能够维护userselection和questionaire
- /// </summary>
- private void checkStatusEvaluation()
- {
- if(!flagEvaluationWithoutFilter && evaluationQuestionaire[currentEvaluationCount-1].question.q_type == 1)
- {
- //有预加载的筛查报告且当前问题是一道筛查题
- Answer aTemp = SQLiteModel.getAnswerById(filterUserSelection[currentFilterCount - 1].a_id);
- if (aTemp == null || aTemp.next_q_id == 0)
- {
- if(currentFilterCount == filterQuestionaire.Count)
- {
- //当前所有题目都已经做完了
- buttonEvaluationNext.IsEnabled = false;
- bool allQuestionAreSeleceted = true;
- foreach (UserSelection us in evaluationUserSelection)
- {
- if (us.a_id == 0)
- allQuestionAreSeleceted = false;
- }
- //经过检查可以提交
- buttonSubmitEvaluation.IsEnabled = allQuestionAreSeleceted;
- }
- else
- {
- //还有剩下的筛选题没有过
- QuestionAnswerPair qaPairEvaluation = filterQuestionaire[currentFilterCount];
- //当前元素后面的题目和选项都清空
- for (int i = evaluationQuestionaire.Count - 1; i > currentEvaluationCount - 1; --i)
- {
- evaluationQuestionaire.RemoveAt(i);
- evaluationUserSelection.RemoveAt(i);
- }
- evaluationQuestionaire.Add(qaPairEvaluation);
- evaluationUserSelection.Add(filterUserSelection[currentFilterCount]);
- //再刷新一次
- ++currentFilterCount;
- ++currentEvaluationCount;
- checkStatusEvaluation();
- }
- }
- else
- {
- //否则还有评估题没做
- Question aEvaluationQuestion = SQLiteModel.getQuestionById(aTemp.next_q_id);
- List<Answer> answersToTheEvaluation = SQLiteModel.getAnswersByQid(aEvaluationQuestion.q_id);
- QuestionAnswerPair qaPairEvaluation = new QuestionAnswerPair(aEvaluationQuestion, answersToTheEvaluation);
- //当前元素后面的题目和选项都清空
- for(int i= evaluationQuestionaire.Count - 1; i > currentEvaluationCount - 1; --i)
- {
- evaluationQuestionaire.RemoveAt(i);
- evaluationUserSelection.RemoveAt(i);
- }
- evaluationQuestionaire.Add(qaPairEvaluation);
- evaluationUserSelection.Add(new UserSelection(aEvaluationQuestion.q_id, 0));
- //再刷新一次
- ++currentEvaluationCount;
- checkStatusEvaluation();
- }
- }
- else
- {
- //其他情况:没有预加载的筛选题或者有预加载的筛选题但是是一道评估题
- loadQuestionViewEvaluation(currentEvaluationCount);
- buttonEvaluationNext.IsEnabled = false;
- buttonSubmitEvaluation.IsEnabled = false;
- }
- }
- /// <summary>
- /// 评估单选选项被选中的触发事件,主要是修改内存中的选择和判断下一题及提交按钮是否可用
- /// </summary>
- /// <param name="sender">默认</param>
- /// <param name="e">默认</param>
- private void radioButtonEvaluation_Checked(object sender, RoutedEventArgs e)
- {
- //首先,记录该选择
- RadioButton oneSelection = (RadioButton)sender;
- evaluationUserSelection[currentEvaluationCount - 1].a_id = Convert.ToInt32(oneSelection.Name.Substring(3));
- if (flagEvaluationWithoutFilter && evaluationQuestionaire[currentEvaluationCount-1].question.q_type ==1)
- {
- filterUserSelection[currentFilterCount - 1].a_id = Convert.ToInt32(oneSelection.Name.Substring(3));
- }
- //MessageBox.Show(filterUserSelection[currentFilterCount - 1].a_id.ToString());
- Answer oneAnswer = SQLiteModel.getAnswerById(evaluationUserSelection[currentEvaluationCount - 1].a_id);
- if(currentFilterCount == filterQuestionaire.Count && oneAnswer.next_q_id == 0)
- {
- //后面没有题目了,可以提交
- buttonEvaluationNext.IsEnabled = false;
- bool allQuestionAreSeleceted = true;
- foreach (UserSelection us in evaluationUserSelection)
- {
- if (us.a_id == 0)
- allQuestionAreSeleceted = false;
- }
- //经过检查可以提交
- buttonSubmitEvaluation.IsEnabled = allQuestionAreSeleceted;
- }
- else
- {
- //否则可以做下一题
- buttonEvaluationNext.IsEnabled = true;
- buttonSubmitEvaluation.IsEnabled = false;
- }
-
- }
- /// <summary>
- /// (未实现)评估过程中点击上一题的触发事件
- /// </summary>
- /// <param name="sender">默认</param>
- /// <param name="e">默认</param>
- private void buttonEvaluationPrevious_Click(object sender, RoutedEventArgs e)
- {
- }
- /// <summary>
- /// 点击评估页下一题后触发的事件,主要是判断接下来加载哪一题
- /// </summary>
- /// <param name="sender">默认</param>
- /// <param name="e">默认</param>
- private void buttonEvaluationNext_Click(object sender, RoutedEventArgs e)
- {
- //先看看后面有没有进退阶题目了
- Answer oneAnswer = SQLiteModel.getAnswerById(evaluationUserSelection[currentEvaluationCount - 1].a_id);
- if(oneAnswer.next_q_id!= 0)
- {
- //还有后续题目
- Question aEvaluationQuestion = SQLiteModel.getQuestionById(oneAnswer.next_q_id);
- List<Answer> answersToTheEvaluation = SQLiteModel.getAnswersByQid(aEvaluationQuestion.q_id);
- QuestionAnswerPair qaPairEvaluation = new QuestionAnswerPair(aEvaluationQuestion, answersToTheEvaluation);
- //当前元素后面的题目和选项都清空
- for (int i = evaluationQuestionaire.Count - 1; i > currentEvaluationCount - 1; --i)
- {
- evaluationQuestionaire.RemoveAt(i);
- evaluationUserSelection.RemoveAt(i);
- }
- evaluationQuestionaire.Add(qaPairEvaluation);
- evaluationUserSelection.Add(new UserSelection(aEvaluationQuestion.q_id, 0));
- //再刷新一次
- ++currentEvaluationCount;
- checkStatusEvaluation();
- }
- else
- {
- //否则跳到下一个筛选题上面
- QuestionAnswerPair qaPairEvaluation = filterQuestionaire[currentFilterCount];
- //当前元素后面的题目和选项都清空
- for (int i = evaluationQuestionaire.Count - 1; i > currentEvaluationCount - 1; --i)
- {
- evaluationQuestionaire.RemoveAt(i);
- evaluationUserSelection.RemoveAt(i);
- }
- evaluationQuestionaire.Add(qaPairEvaluation);
- evaluationUserSelection.Add(filterUserSelection[currentFilterCount]);
- //再刷新一次
- ++currentFilterCount;
- ++currentEvaluationCount;
- checkStatusEvaluation();
- }
- }
- /// <summary>
- /// 点击评估页提交后触发的事件
- /// </summary>
- /// <param name="sender">默认</param>
- /// <param name="e">默认</param>
- private void buttonSubmitEvaluation_Click(object sender, RoutedEventArgs e)
- {
- int[] timesLimit = dop.getTimesCount();
- //MessageBox.Show(String.Format("生产环境状态标识:{0}, 授权阈值: {1}, 已使用次数:{2}", Constants.productionEnvironment, timesLimit[0], timesLimit[1]));
- if (Constants.productionEnvironment && (timesLimit[1] >= timesLimit[0]))
- {
- MessageBox.Show("此功能已超过Key授权次数,请使用一个新的Key进行操作。", "提示");
- return;
- }
- int inserted_r_id;
- resultsFilter = JsonMapper.ToJson(filterUserSelection);
- resultsEvaluation = JsonMapper.ToJson(evaluationUserSelection);
- try
- {
- int tempRId;
- if (flagEvaluationWithoutFilter)
- {
- tempRId = SQLiteModel.insertRecord(1, evaluationPatient.p_id, loginDoctor.id, 0, DateTime.Now, 0, resultsFilter);
- SQLiteModel.UpdatePatientDataWithLastDate(evaluationPatient.p_id, "p_last_filter_time", DateTime.Now);
- }
- else
- {
- tempRId = filterReportForEvaluation.r_id;
- }
- inserted_r_id = SQLiteModel.insertRecord(2, evaluationPatient.p_id, loginDoctor.id, tempRId, DateTime.Now, 0, resultsEvaluation);
- SQLiteModel.UpdatePatientDataWithLastDate(evaluationPatient.p_id, "p_last_evaluation_time", DateTime.Now);
- }
- catch (Exception err)
- {
- MessageBox.Show("储存报告错误\r\n调试信息:" + err.Message + "\r\n" + err.StackTrace, "错误");
- return;
- }
- dop.addOneCount();
- loadUSBDogStatus();
- MessageBoxResult dr = MessageBox.Show("保存成功,是否生成报告?", "提示", MessageBoxButton.OKCancel, MessageBoxImage.Question);
- if (dr == MessageBoxResult.OK)
- {
- try
- {
- Record targetRecord = SQLiteModel.getRecordByID(inserted_r_id);
- SQLiteModel.plusOneCountOnRecordByRid(inserted_r_id);
- //ReportGenerater.generateReport(2, evaluationPatient, loginDoctor, targetRecord, cfg.organization_name);
- ReportGenerater.generateReport_constum(targetRecord, evaluationPatient, cfg);
- }
- catch (Exception err)
- {
- MessageBox.Show("报告生成异常,可能是这份报告当前已被打开无法写入,请尝试关闭该报告后重试。\r\n调试信息:" + err.Message + "\r\n" + err.StackTrace, "错误");
- return;
- }
- tabEvaluation.SelectedIndex = 2;
- }
- else
- {
- buttonAbortEvaluation_Click(sender, e);
- }
- return;
- }
- /// <summary>
- /// 点击评估页中止评估后触发的事件
- /// </summary>
- /// <param name="sender">默认</param>
- /// <param name="e">默认</param>
- private void buttonAbortEvaluation_Click(object sender, RoutedEventArgs e)
- {
- //清理相关变量
- filterQuestionaire.Clear();
- filterUserSelection.Clear();
- evaluationQuestionaire.Clear();
- evaluationUserSelection.Clear();
- flagEvaluationWithoutFilter = true;
- filterReportForEvaluation = null;
- evaluationPatient = null;
- resultsFilter = "";
- resultsEvaluation = "";
- currentFilterCount = 0;
- currentEvaluationCount = 0;
- //buttonFilterPrevious.IsEnabled = false;
- buttonEvaluationNext.IsEnabled = false;
- buttonSubmitEvaluation.IsEnabled = false;
- tabEvaluation.SelectedIndex = 0;
- }
- /// <summary>
- /// 返回至选择用户页
- /// </summary>
- /// <param name="sender">默认</param>
- /// <param name="e">默认</param>
- private void buttonEvaluationBackToSelectUser_Click(object sender, RoutedEventArgs e)
- {
- buttonAbortEvaluation_Click(sender, e);
- }
- /// <summary>
- /// 返回至选择首页
- /// </summary>
- /// <param name="sender">默认</param>
- /// <param name="e">默认</param>
- private void buttonEvaluationBackToHome_Click(object sender, RoutedEventArgs e)
- {
- buttonAbortEvaluation_Click(sender, e);
- tabControlGeneral.SelectedIndex = 0;
- }
- #endregion
- #region 历史记录
- /// <summary>
- /// 点击选择病例查看其历史记录后触发的事件
- /// </summary>
- /// <param name="sender">默认</param>
- /// <param name="e">默认</param>
- public void buttonHistorySelectPatient_Click(object sender, RoutedEventArgs e)
- {
- try
- {
- var target = (DataRowView)this.selectUserHistory.dataGrid.SelectedItem;
- historyPatient = SQLiteModel.getPatientById(Convert.ToString(target["p_id"]));
- recordsFromOnePatient = SQLiteModel.getRecordsByPid(Convert.ToInt32(target["p_id"]),true);
- }
- catch (Exception err)
- {
- MessageBox.Show("请选择一个病例进行修改\r\n调试信息:" + err.Message + "\r\n" + err.StackTrace, "警告");
- return;
- }
- if (recordsFromOnePatient == null || historyPatient == null)
- {
- MessageBox.Show("数据库加载异常", "错误");
- return;
- }
- try
- {
- bindingRecords = new BindingList<Record>(recordsFromOnePatient);
- dataGridRecords.ItemsSource = bindingRecords;
- }
- catch(Exception err)
- {
- MessageBox.Show("数据库加载异常\r\n调试信息:\r\n"+err.StackTrace, "错误");
- return;
- }
- tabHistoryRecords.SelectedIndex = 1;
- }
- /// <summary>
- /// 在选择记录页面,点击返回上一级触发的事件
- /// </summary>
- /// <param name="sender">默认</param>
- /// <param name="e">默认</param>
- private void buttonHistoryBackToSelectUser_Click(object sender, RoutedEventArgs e)
- {
- recordsFromOnePatient.Clear();
- tabHistoryRecords.SelectedIndex = 0;
- }
- /// <summary>
- /// 由历史记录相关页面返回至首页的事件
- /// </summary>
- /// <param name="sender">默认</param>
- /// <param name="e">默认</param>
- private void buttonHistoryBackToHome_Click(object sender, RoutedEventArgs e)
- {
- recordsFromOnePatient.Clear();
- tabHistoryRecords.SelectedIndex = 0;
- tabControlGeneral.SelectedIndex = 0;
- }
- /// <summary>
- /// 点击生成报告的页面
- /// </summary>
- /// <param name="sender">默认</param>
- /// <param name="e">默认</param>
- private void buttonRegenerateReport_Click(object sender, RoutedEventArgs e)
- {
- Record targetRecord;
- try
- {
- var target = this.dataGridRecords.SelectedItem as Record;
- targetRecord = SQLiteModel.getRecordByID(Convert.ToInt32(target.r_id));
- }
- catch (Exception err)
- {
- MessageBox.Show("请选择一个记录进行生成\r\n" + err.StackTrace, "提示");
- return;
- }
- if (targetRecord == null)
- {
- MessageBox.Show("数据库加载异常", "错误");
- return;
- }
- try
- {
- //ReportGenerater.generateReport(targetRecord.r_type, historyPatient, loginDoctor, targetRecord, cfg.organization_name);
- ReportGenerater.generateReport_constum(targetRecord, historyPatient, cfg);
- SQLiteModel.plusOneCountOnRecordByRid(targetRecord.r_id);
- }
- catch(Exception err)
- {
- MessageBox.Show("报告生成异常,可能是这份报告当前已被打开无法写入,请尝试关闭该报告后重试。\r\n调试信息:\r\n" + err.StackTrace, "错误");
- return;
- }
- tabHistoryRecords.SelectedIndex = 2;
- }
- /// <summary>
- /// 从报告生成页点击返回上一页的事件
- /// </summary>
- /// <param name="sender">默认</param>
- /// <param name="e">默认</param>
- private void buttonHistoryBackToSelectRecord_Click(object sender, RoutedEventArgs e)
- {
- tabHistoryRecords.SelectedIndex = 1;
- }
- /// <summary>
- /// 双击报告也要生成报告的功能
- /// </summary>
- /// <param name="sender">默认</param>
- /// <param name="e">默认</param>
- private void dataGridRecords_MouseDoubleClick(object sender, MouseButtonEventArgs e)
- {
- buttonRegenerateReport_Click(sender, e);
- }
- #endregion
- #region 系统设置
- //系统设置
- //进入系统设置前主任级别用户的身份验证
- async private void tabControlGeneral_SelectionChanged(object sender, SelectionChangedEventArgs e)
- {
- //System.Console.WriteLine(Convert.ToString(tabControlGeneral.SelectedIndex));
- if (e.Source is TabControl)
- {
- //系统设置页验证
- if (tabitemDoctorSetting.IsSelected)
- {
- DateTime now = DateTime.Now;
- if (lastSettingLogin != null && (now - lastSettingLogin).Minutes <= 10)
- {
- //如果上次有登录而且登录时间在10分钟以内,则免登录
- return;
- }
- bool dialogLoop = true;
- bool wrongPassword = false;
- string description;
- int x = 1;
- while (dialogLoop)
- {
- x++;
- if (wrongPassword)
- {
- description = "用户名或密码不正确,请重新输入账号和密码进入系统设置";
- }
- else
- {
- description = "请输入账号和密码进入系统设置";
- }
- LoginDialogData loginDialogData;
- loginDialogData = await this.ShowLoginAsync
- (
- "输入科室主任级别账号密码以继续..." + Convert.ToString(x),
- description,
- new LoginDialogSettings
- {
- ColorScheme = MetroDialogColorScheme.Accented,
- UsernameWatermark = "用户名",
- PasswordWatermark = "密码",
- NegativeButtonVisibility = Visibility.Visible
- }
- );
- if (loginDialogData == null)
- {
- dialogLoop = false;
- tabControlGeneral.SelectedIndex = 0;
- return;
- //break;
- }
- //调用数据库验证
- string doctorName = loginDialogData.Username;
- string doctorPassword = loginDialogData.Password;
- string doctorPWD = Toolkits.ComputeHash.GetMD5(doctorPassword);
- doctor loginDirector = SQLiteModel.directorLogin(doctorName, doctorPWD);
- if (loginDirector == null)
- {
- //MessageBox.Show("admin");
- wrongPassword = true;
- dialogLoop = true;
- }
- else
- {
- lastSettingLogin = DateTime.Now;
- dialogLoop = false;
- return;
- //break;
- }
- }
- }
- //高级系统设置验证页
- //if (tabitemOEMSetting.IsSelected)
- }
- }
- #region 医师管理
- //系统设置--医师管理
- private void LoadDoctorDataGrid(object sender, RoutedEventArgs e)
- {
- LoadDoctorDataGrid();
- }
- public void LoadDoctorDataGrid()
- {
- //连接字符串
- string Connstr = Toolkits.Constants.Connstr;
- //连接对象
- System.Data.SQLite.SQLiteConnection con = new System.Data.SQLite.SQLiteConnection(Connstr);
- //Sql语句
- string selectCmd = "SELECT * FROM Doctor WHERE delete_flag=0 AND name != '" + Constants.adminUsername + "' LIMIT 100";
- con.Open();
- da = new System.Data.SQLite.SQLiteDataAdapter(selectCmd, con);
- ds = new DataSet();
- da.Fill(ds);
- dataGridDoctor.ItemsSource = ds.Tables[0].DefaultView;
- con.Close();
- }
- //新增医师
- private void buttonAddDoctor_Click(object sender, RoutedEventArgs e)
- {
- AddDoctor a_new_doctor = new AddDoctor(this);
- a_new_doctor.Show();
- }
- //修改医师
- private void buttonChangeDoctor_Click(object sender, RoutedEventArgs e)
- {
- try
- {
- var target = (DataRowView)this.dataGridDoctor.SelectedItem;
- //MessageBox.Show(target["id"].ToString());
- ModifyDoctor modify_one = new ModifyDoctor(this, target["id"].ToString());
- modify_one.Show();
- }
- catch (Exception err)
- {
- this.ShowMessageAsync("警告", "请选择一个医生进行修改\r\n调试信息:" + err.Message + "\r\n" + err.StackTrace);
- }
- }
- //双击表格触发修改医师的方法
- private void dataGridDoctor_MouseDoubleClick(object sender, MouseButtonEventArgs e)
- {
- buttonChangeDoctor_Click(this, e);
- }
- //修改医师密码
- private void buttonChangeDoctorPWD_Click(object sender, RoutedEventArgs e)
- {
- try
- {
- var target = (DataRowView)this.dataGridDoctor.SelectedItem;
- //MessageBox.Show(target["id"].ToString());
- ModifyDoctorPWD modify_one = new ModifyDoctorPWD(this, target["id"].ToString());
- modify_one.Show();
- }
- catch (Exception err)
- {
- this.ShowMessageAsync("警告", "请选择一个医生进行修改\r\n调试信息:" + err.Message + "\r\n" + err.StackTrace);
- }
- }
- //删除医师
- private async void buttonDeleteDoctor_Click(object sender, RoutedEventArgs e)
- {
- try
- {
- var target = (DataRowView)this.dataGridDoctor.SelectedItem;
- if (target == null)
- {
- await this.ShowMessageAsync("提示", "请选择一个医生进行删除");
- return;
- }
- MessageDialogResult clickresult = await this.ShowMessageAsync("提示", "确认删除该医生信息吗?", MessageDialogStyle.AffirmativeAndNegative);
- if (clickresult == MessageDialogResult.Affirmative)//确认
- {
- int status = SQLite.SQLiteModel.DeleteDoctorItem(target["id"].ToString());
- if (status > 0)
- {
- await this.ShowMessageAsync("提示", "删除成功!");
- }
- else
- {
- await this.ShowMessageAsync("警告", "目标已被删除");
- }
- }
- else//取消
- {
- return;
- }
- }
- catch (Exception err)
- {
- await this.ShowMessageAsync("警告", "请选择一个医生进行删除!\r\n调试信息:" + err.Message + "\r\n" + err.StackTrace);
- }
- LoadDoctorDataGrid();
- }
- //筛选医师
- private void buttonFindDoctor_Click(object sender, RoutedEventArgs e)
- {
- try
- {
- //连接字符串
- string Connstr = "Data Source=" + System.Environment.CurrentDirectory + "\\Junde.db3"; ;
- //连接对象
- System.Data.SQLite.SQLiteConnection con = new System.Data.SQLite.SQLiteConnection(Connstr);
- string namelike = textBoxFindDoctor.Text;
- //MessageBox.Show(namelike);
- //Sql语句
- string selectCmd = "SELECT * FROM Doctor WHERE NAME LIKE \'%" + namelike + "%\' AND delete_flag=0 LIMIT 100";
- con.Open();
- System.Data.SQLite.SQLiteDataAdapter da_1 = new System.Data.SQLite.SQLiteDataAdapter(selectCmd, con);
- DataSet ds_1 = new DataSet();
- da_1.Fill(ds_1);
- dataGridDoctor.ItemsSource = ds_1.Tables[0].DefaultView;
- con.Close();
- }
- catch (Exception err)
- {
- MessageBox.Show("数据库错误.\r\n调试信息:" + err.Message, "错误");
- }
- }
- #endregion
- #region 其他设置
- /// <summary>
- /// 更换医疗机构名称
- /// </summary>
- /// <param name="sender">默认</param>
- /// <param name="e">默认</param>
- private void buttonModifyRegisterInfo_Click(object sender, RoutedEventArgs e)
- {
- try
- {
- SQLiteModel.UpdateOrganizationName(Toolkits.FilterDangerousCharacter.filter(textBoxOrganizationName.Text));
- }
- catch (Exception)
- {
- MessageBox.Show("更新失败!", "错误");
- }
- MessageBox.Show("更新成功", "提示");
-
- }
- /// <summary>
- /// buttonOptmizeDatabase_Click:点击优化数据库的方法,把已经被删除的数据进行彻底清除
- /// </summary>
- /// <param name="sender">默认</param>
- /// <param name="e">默认</param>
- private void buttonOptmizeDatabase_Click(object sender, RoutedEventArgs e)
- {
- try
- {
- //获取标记为删除的病人记录
- List<int> ids_to_be_deleted = SQLite.SQLiteModel.getDeletedPatients();
- //确实删除这些病人记录
- SQLite.SQLiteModel.realDeleteRecords();
- //确实删除这些病人所含有的检查记录
- foreach(int each_line in ids_to_be_deleted)
- {
- SQLite.SQLiteModel.deleteRecordByPid(each_line);
- }
- //SQLiteModel.optmizeDatabase();
- MessageBox.Show("操作完成", "信息");
- }
- catch (Exception err)
- {
- MessageBox.Show("数据库异常\r\b"+err.Message+"\r\b"+err.StackTrace, "错误");
- }
- }
- /// <summary>
- /// buttonDeleteAllPdfReport_Click:点击删除某一目录下所有文件的方法
- /// </summary>
- /// <param name="sender">默认</param>
- /// <param name="e">默认</param>
- private void buttonDeleteFiles_Click(object sender, RoutedEventArgs e)
- {
- string target_path = "";
- if (((Button)sender).Equals(buttonDeleteAllPdfReport))
- {
- target_path = Constants.reportPath;
- }
- try
- {
- DirectoryInfo dir = new DirectoryInfo(target_path);
- FileSystemInfo[] fileinfo = dir.GetFileSystemInfos(); //返回目录中所有文件和子目录
- foreach (FileSystemInfo i in fileinfo)
- {
- if (i is DirectoryInfo) //判断是否文件夹
- {
- DirectoryInfo subdir = new DirectoryInfo(i.FullName);
- subdir.Delete(true); //删除子目录和文件
- }
- else
- {
- File.Delete(i.FullName); //删除指定文件
- }
- }
- MessageBox.Show("操作完成", "信息");
- }
- catch (Exception)
- {
- MessageBox.Show("文件系统异常", "错误");
- }
- }
- #endregion
- #endregion
- #region 测试功能
- private void buttonTest1_Click(object sender, RoutedEventArgs e)
- {
- int res_flag = SQLiteModel.loopInsertAnswers();
- if(res_flag == 0)
- {
- MessageBox.Show("操作成功");
- }
- }
- #endregion
- private float treatmentTime_ = 30, treatmentTimeMin = 1, treatmentTimeMax = 100;
- public float treatmentTime
- {
- get => treatmentTime_;
- set
- {
- treatmentTime_ = value > treatmentTimeMax ? treatmentTimeMax : value < treatmentTimeMin ? treatmentTimeMin : value;
- labelTreatmentTime.Content = $"{(int)treatmentTime_}:";
- int sec = (int)((treatmentTime_ - (int)treatmentTime_) * 60);
- if (sec < 10) labelTreatmentTime.Content += "0";
- labelTreatmentTime.Content += sec.ToString();
- }
- }
- private void increaseTreatmentTime(object sender, RoutedEventArgs e)
- {
- treatmentTime += 0.5f;
- }
- private void decreaseTreatmentTime(object sender, RoutedEventArgs e)
- {
- treatmentTime -= 0.5f;
- }
- private Com comAgent => SingleInstance<Com>.getInstance();
- private bool isRunning;
- private void updateUIIsRunning()
- {
- buttonStart.IsEnabled = !isRunning;
- buttonStop.IsEnabled = isRunning;
- }
- private void MetroWindow_Activated(object sender, EventArgs e)
- {
- }
- private void MetroWindow_Closing(object sender, CancelEventArgs e)
- {
- comAgent.shutdown();
- }
- private void buttonStartTreat_Click(object sender, RoutedEventArgs e)
- {
- //if (targetTreatment == null && !checkBoxCustomMode.IsChecked.Value)
- if (targetTreatment == null)
- {
- MessageBox.Show("请选择或添加一个治疗方案", "", MessageBoxButton.OK, MessageBoxImage.Error);
- return;
- }
- //if (checkBoxCustomMode.IsChecked.Value)
- //{
- // TreatmentStep[] steps = new TreatmentStep[treatmentCustomModeList.Count];
- // for (int i = 0; i < steps.Length; i++)
- // {
- // steps[i] = new TreatmentStep((ushort)treatmentCustomModeList[i].tcRate,
- // (byte)treatmentCustomModeList[i].tcActiveTime,
- // (byte)treatmentCustomModeList[i].tcInactiveTime,
- // (ushort)(treatmentCustomModeList[i].tcActiveTime + treatmentCustomModeList[i].tcInactiveTime));
- // }
- // comAgent.enqueueCommand(Com.createStartManualCommand(parseTreatmentTime(treatmentTime), (byte)sliderStrength.Value, steps));
- //}
- //else
- //{
- // //获取当前时间戳并转换为格式化日期 yyyy-MM-dd hh:mm:ss
- // DateTime_TimeStamp dateTimeFormatter = new DateTime_TimeStamp();
- // int timestamp = dateTimeFormatter.GetTimeStamp(DateTime.Now);
- // DateTime now = dateTimeFormatter.GetDateTime(timestamp);
- // //装配诊疗记录对象
- // TreatmentRecord treatmentRecordToInsert = new TreatmentRecord();
- // treatmentRecordToInsert.patient_record_id = filterPatient.p_record_id;
- // treatmentRecordToInsert.patient_id = filterPatient.p_id;
- // treatmentRecordToInsert.strength = Convert.ToInt32(sliderStrength.Value.ToString("0."));
- // treatmentRecordToInsert.duration = treatmentTime;
- // treatmentRecordToInsert.start_time = now;
- // //插入诊疗记录
- // int inserted_row_id = SQLiteModel.insertTreatmentRecord(treatmentRecordToInsert);
- // comAgent.enqueueCommand(Com.createStartDefinedCommand(targetTreatment.id, parseTreatmentTime(treatmentTime), (byte)sliderStrength.Value));
- //}
- //获取当前时间戳并转换为格式化日期 yyyy-MM - dd hh: mm: ss
- DateTime_TimeStamp dateTimeFormatter = new DateTime_TimeStamp();
- int timestamp = dateTimeFormatter.GetTimeStamp(DateTime.Now);
- DateTime now = dateTimeFormatter.GetDateTime(timestamp);
- //装配诊疗记录对象
- TreatmentRecord treatmentRecordToInsert = new TreatmentRecord();
- treatmentRecordToInsert.patient_record_id = filterPatient.p_record_id;
- treatmentRecordToInsert.patient_id = filterPatient.p_id;
- treatmentRecordToInsert.strength = Convert.ToInt32(sliderStrength.Value.ToString("0."));
- treatmentRecordToInsert.duration = treatmentTime;
- treatmentRecordToInsert.start_time = now;
- //插入诊疗记录
- int inserted_row_id = SQLiteModel.insertTreatmentRecord(treatmentRecordToInsert);
- comAgent.enqueueCommand(Com.createStartDefinedCommand(targetTreatment.id, parseTreatmentTime(treatmentTime), (byte)sliderStrength.Value));
- isRunning = true;
- updateUIIsRunning();
- }
-
- private short parseTreatmentTime(float f)
- {
- return (short)(f * 60);
- }
- private void buttonStop_Click(object sender, RoutedEventArgs e)
- {
- //if (checkBoxCustomMode.IsChecked.Value)
- //{
- // comAgent.enqueueCommand(Com.createStopCommand());
- //}
- //else
- //{
- // comAgent.enqueueCommand(Com.createStopCommand(Com.getTCIDByIndex(targetTreatment.id)));
- //}
- comAgent.enqueueCommand(Com.createStopCommand(Com.getTCIDByIndex(targetTreatment.id)));
- isRunning = false;
- updateUIIsRunning();
- }
- }
- /// <summary>
- /// C#时间戳转换为时间格式(互转)
- /// 时间戳定义为从格林威治时间 1970年01月01日00时00分00秒(北京时间1970年01月01日08时00分00秒)起至现在的总秒数。
- /// </summary>
- public class DateTime_TimeStamp
- {
- protected int m_timestamp;
- /// <summary>
- /// 获取时间戳Timestamp
- /// </summary>
- /// <param name="dt"></param>
- /// <returns></returns>
- public int GetTimeStamp(DateTime dt)
- {
- DateTime dateStart = new DateTime(1970, 1, 1, 8, 0, 0);
- int timeStamp = Convert.ToInt32((dt - dateStart).TotalSeconds);
- return timeStamp;
- }
- /// <summary>
- /// 时间戳Timestamp转换成日期
- /// </summary>
- /// <param name="timeStamp"></param>
- /// <returns></returns>
- public DateTime GetDateTime(int timeStamp)
- {
- DateTime dtStart = TimeZone.CurrentTimeZone.ToLocalTime(new DateTime(1970, 1, 1));
- long lTime = ((long)timeStamp * 10000000);
- TimeSpan toNow = new TimeSpan(lTime);
- DateTime targetDt = dtStart.Add(toNow);
- return targetDt;
- }
- }
- }
|