737 lines
35 KiB
C#
737 lines
35 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.ComponentModel;
|
|
using System.Data;
|
|
using System.Drawing;
|
|
using System.Text;
|
|
using System.Windows.Forms;
|
|
using Datalib.EntityClasses;
|
|
using Datalib.HelperClasses;
|
|
using System.Linq;
|
|
using System.Linq.Expressions;
|
|
using Datalib.Linq;
|
|
using DevExpress.XtraEditors;
|
|
using DevExpress.Spreadsheet;
|
|
using SD.LLBLGen.Pro.ORMSupportClasses;
|
|
using PatientMan.Classes;
|
|
namespace PatientMan.Forms
|
|
{
|
|
public partial class frmLogBooks : PatientMan.BasicForms.frmCommon
|
|
|
|
{
|
|
EntityCollection<TblPatientEntity> Patients = new EntityCollection<TblPatientEntity>();
|
|
EntityCollection<TblExaminationInfoEntity> exams = new EntityCollection<TblExaminationInfoEntity>();
|
|
EntityCollection<TblPreClinicsInfoEntity> preclinics = new EntityCollection<TblPreClinicsInfoEntity>();
|
|
EntityCollection<TblClinicInfoEntity> clinics = new EntityCollection<TblClinicInfoEntity>();
|
|
EntityCollection<TblTreatmentInfoEntity> treatments = new EntityCollection<TblTreatmentInfoEntity>();
|
|
List<TblPatientEntity> PatientLists {get;set;}
|
|
int startYear { set; get; }
|
|
const int PreArvPageNum = 15;
|
|
const int ArvPageNum = 10;
|
|
int PageNum = 0;
|
|
int SelectedReportIndex;
|
|
public frmLogBooks()
|
|
{
|
|
InitializeComponent();
|
|
}
|
|
|
|
private void frmLogBooks_Load(object sender, EventArgs e)
|
|
{
|
|
var path = Application.StartupPath;
|
|
var templatefile = path + @"\templates\logbook2.xls";
|
|
//this.barGen.Enabled = SettingInfo.Registered ;
|
|
object val = this.LogTypes.Items[0];
|
|
this.BarLogType.EditValue = val;
|
|
LinqMetaData meta = new LinqMetaData(adapter);
|
|
PatientLists = meta.TblPatient.Where(g => g.Dateofreferral == null).ToList<TblPatientEntity>();
|
|
PageNum = PatientLists.Count;
|
|
genPages(PageNum, PreArvPageNum);
|
|
this.spreadsheetControl.LoadDocument(templatefile);
|
|
adapter.FetchEntityCollection(Patients, null);
|
|
adapter.FetchEntityCollection(exams, null);
|
|
adapter.FetchEntityCollection(preclinics, null);
|
|
// adapter.FetchEntityCollection(clinics, null);
|
|
adapter.FetchEntityCollection(treatments, null);
|
|
var cohortlist = (from p in Patients where (p.DateofArv != null) orderby p.DateofArv select new { x = p.DateofArv.Value.Month.ToString().Length == 1 ? "0" + p.DateofArv.Value.Month.ToString() + "-" + p.DateofArv.Value.Year.ToString():p.DateofArv.Value.Month.ToString() + "-" + p.DateofArv.Value.Year.ToString() }).GroupBy(x => x.x).Select(x => x.First()).ToArray();
|
|
foreach (var s in cohortlist)
|
|
{
|
|
Cohorts.Items.Add(s.x);
|
|
}
|
|
GenYearList();
|
|
}
|
|
|
|
public override void LoadData()
|
|
{
|
|
base.LoadData();
|
|
}
|
|
private void LogTypes_EditValueChanged(object sender, EventArgs e)
|
|
{
|
|
string templateFile = "";
|
|
string path = Application.StartupPath;
|
|
SelectedReportIndex = ((ComboBoxEdit)sender).SelectedIndex;
|
|
|
|
switch (SelectedReportIndex)
|
|
{
|
|
case 0:
|
|
templateFile = path + @"\templates\logbook2.xls";
|
|
this.barCohort.Enabled = false;
|
|
this.barYear.Enabled = true;
|
|
LinqMetaData meta = new LinqMetaData(adapter);
|
|
if (barYear.EditValue==null)
|
|
{
|
|
PatientLists = meta.TblPatient.Where(g => g.Dateofreferral == null).ToList<TblPatientEntity>();
|
|
}else
|
|
{
|
|
|
|
char[] separator = new char[] { ',' };
|
|
|
|
string yeartmp = this.repYearList.GetCheckedItems().ToString();
|
|
|
|
yeartmp = yeartmp.Replace(" ", "");
|
|
string[] yearSelected = yeartmp.Split(separator);
|
|
PatientLists = meta.TblPatient.Where(g => g.Dateofreferral == null).Where(g=>yearSelected.Contains(g.DateofRegistration.Value.Year.ToString())).ToList<TblPatientEntity>();
|
|
|
|
this.spreadsheetControl.LoadDocument(templateFile);
|
|
}
|
|
//PageNum = PatientLists.Count;
|
|
|
|
//genPages(PageNum, PreArvPageNum);
|
|
break;
|
|
case 1:
|
|
templateFile = path + @"\templates\logbook4.xls";
|
|
this.barCohort.Enabled = true;
|
|
this.barYear.Enabled = false;
|
|
var cohorts = this.barCohort.EditValue;
|
|
if (cohorts != null)
|
|
{
|
|
int bookMonth = Convert.ToInt32(cohorts.ToString().Substring(0, 2));
|
|
int bookYear = Convert.ToInt32(cohorts.ToString().Substring(3, 4));
|
|
PatientLists = (from q in Patients where (q.DateofArv != null && q.DateofArv.Value.Month == bookMonth && q.DateofArv.Value.Year == bookYear) select q).ToList<TblPatientEntity>();
|
|
PageNum = PatientLists.Count;
|
|
}else
|
|
{
|
|
PageNum = 0;
|
|
}
|
|
genPages(PageNum, ArvPageNum);
|
|
this.spreadsheetControl.LoadDocument(templateFile);
|
|
break;
|
|
case 2:
|
|
templateFile = path + @"\templates\pmtct.xls";
|
|
this.barCohort.Enabled = false;
|
|
this.barYear.Enabled = false;
|
|
this.spreadsheetControl.LoadDocument(templateFile);
|
|
break;
|
|
}
|
|
|
|
}
|
|
|
|
private void barGen_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
|
|
{
|
|
if (Page.EditValue == null && SelectedReportIndex==3) return;
|
|
int pageNo = Convert.ToInt32(Page.EditValue);
|
|
|
|
switch (SelectedReportIndex)
|
|
{
|
|
case 0:
|
|
fillPreArvCohorts(pageNo);
|
|
break;
|
|
case 1:
|
|
FillArvCohorts( pageNo);
|
|
break;
|
|
case 2:
|
|
clsPMTCT pmtct = new clsPMTCT();
|
|
pmtct.spreed = this.spreadsheetControl;
|
|
pmtct.Calculate();
|
|
break;
|
|
}
|
|
}
|
|
|
|
private void FillArvCohorts(int PageNo)
|
|
{
|
|
this.spreadsheetControl.Visible = false;
|
|
this.progressPanel.Visible = true;
|
|
int StartNum = ArvPageNum*(PageNo-1);
|
|
int EndNum = Math.Min(ArvPageNum*PageNo-1,PageNum-1);
|
|
string path = Application.StartupPath;
|
|
string templateFile = path + @"\templates\logbook4.xls";
|
|
this.spreadsheetControl.LoadDocument(templateFile);
|
|
int rows =8;
|
|
|
|
for (int i= StartNum; i<=EndNum;i++)
|
|
{
|
|
FillArvPatientInfo(rows, PatientLists[i], i+1);
|
|
rows =rows+2;
|
|
}
|
|
this.spreadsheetControl.Visible = true;
|
|
this.progressPanel.Visible = false;
|
|
}
|
|
|
|
private void FillArvPatientInfo(int rows,TblPatientEntity p, int pos)
|
|
{
|
|
var _arvTreatment = treatments.Where(m => m.PatientId == p.PatientId).Where(m=>m.TreatmentId=="01").OrderBy(m=>m.TreatmentSdate).ToList();
|
|
var _otherTreatment = treatments.Where(m => m.PatientId == p.PatientId).Where(m => m.TreatmentId != "01").Where(m=>m.TreatmentSdate >= p.DateofArv).OrderBy(m=>m.TreatmentSdate).ToList();
|
|
var _clinics = exams.Where(m => m.PatientId == p.PatientId).Where(g => g.IsClinic == 1).Where(g=>g.ExamDate >=p.DateofArv).ToList();
|
|
var _exams = exams.Where(m => m.PatientId == p.PatientId).Where(g=>g.ExamDate >=p.DateofArv).OrderBy(m=>m.ExamDate).ToList();
|
|
var _preclinics = preclinics.Where(m => m.PatientId == p.PatientId).Where(m => m.Testid == "01").ToList();
|
|
string FirstCd4 = _preclinics.Where(m => m.TestDate <= p.DateofArv).OrderBy(m => m.TestDate).Count() > 0 ? _preclinics.Where(m => m.TestDate <= p.DateofArv).OrderBy(m => m.TestDate).Last().QuantityResult.ToString() : "N/A";
|
|
LinqMetaData meta = new LinqMetaData(adapter);
|
|
#region "Điền thông in ban đầu"
|
|
try
|
|
{
|
|
this.spreadsheetControl.Document.Worksheets["ARV"].Cells[rows, 0].Value = pos.ToString();
|
|
this.spreadsheetControl.Document.Worksheets["ARV"].Cells[rows, 1].Value = p.PatientId; ;
|
|
this.spreadsheetControl.Document.Worksheets["ARV"].Cells[rows, 2].Value = p.PatientName;
|
|
this.spreadsheetControl.Document.Worksheets["ARV"].Cells[rows, 3].Value = p.Sex == 1 ? p.BirthYear.ToString() : null;
|
|
this.spreadsheetControl.Document.Worksheets["ARV"].Cells[rows, 4].Value = p.Sex == 2 ? p.BirthYear.ToString() : null;
|
|
this.spreadsheetControl.Document.Worksheets["ARV"].Cells[rows, 5].Value = p.DateofArv;
|
|
|
|
this.spreadsheetControl.Document.Worksheets["ARV"].Cells[rows, 6].Value = p.Regimenid != string.Empty ? meta.TblRegimen.Where(q => q.Regimenid == p.Regimenid).First().Sign : "N/A";
|
|
|
|
this.spreadsheetControl.Document.Worksheets["ARV"].Cells[rows, 7].Value = _clinics.Count() > 0 ? _clinics.First().ClinicStage.ToString() : "N/A";
|
|
|
|
this.spreadsheetControl.Document.Worksheets["ARV"].Cells[rows, 8].Value = FirstCd4;
|
|
this.spreadsheetControl.Document.Worksheets["ARV"].Cells[rows, 9].Value = _clinics.Count() > 0 ?_clinics.First().Weight.ToString() : "N/A";
|
|
this.spreadsheetControl.Document.Worksheets["ARV"].Cells[rows + 1, 9].Value = exams.Where(m => m.PatientId == p.PatientId).Where(g => g.IsClinic == 1).Count() > 0 ? exams.Where(m => m.PatientId == p.PatientId).Where(g => g.IsClinic == 1).First().Height.ToString() : "N/A";
|
|
}
|
|
catch(Exception er)
|
|
{
|
|
MessageBox.Show(er.Message + " " + p.PatientId);
|
|
}
|
|
|
|
//Điền phác đồ cuối cùng ở ô thay đổi phác đồ
|
|
if (_arvTreatment.Count > 1)
|
|
{
|
|
int LastRec = _arvTreatment.Count - 1;
|
|
this.spreadsheetControl.Document.Worksheets["ARV"].Cells[rows, 10].Value = _arvTreatment[LastRec].TreatmentSdate;
|
|
this.spreadsheetControl.Document.Worksheets["ARV"].Cells[rows, 11].Value = _arvTreatment[LastRec-1].ReasonId;
|
|
|
|
this.spreadsheetControl.Document.Worksheets["ARV"].Cells[rows, 12].Value = meta.TblRegimen.Where(m => m.Regimenid == _arvTreatment[LastRec].Regimenid).First().Sign;
|
|
|
|
}
|
|
//Phác đồ tháng đầu tiên
|
|
try
|
|
{
|
|
this.spreadsheetControl.Document.Worksheets["ARV"].Cells[rows, 13].Value = _arvTreatment.Count() > 0 ? meta.TblRegimen.Where(m => m.Regimenid == _arvTreatment[0].Regimenid).Single().Sign : "N/A";
|
|
}catch (Exception er)
|
|
{
|
|
MessageBox.Show(er.Message+ " " + p.PatientId);
|
|
}
|
|
//Tính ngày cuối cùng cho Logs-Book - Nếu bệnh nhân đã kết thúc điều trị ngày cuối cùng trong LogBooks là ngày kết thúc. Nếu không ngày cuối cùng là ngày hiện thời
|
|
|
|
var EndExamDate = (_exams.Count ==0)?p.DateofArv:(_exams.Last().EndExamDate==null? DateTime.Today :_exams.Last().EndExamDate);
|
|
#endregion
|
|
#region "Khởi tạo danh sách sự kiện"
|
|
List<ArvStatus> Statuses = new List<ArvStatus>();
|
|
// Tính số tháng cần điền
|
|
var printmonths = 0;
|
|
int monthCounts = common.MonthDiff(p.DateofArv.Value, EndExamDate.Value);
|
|
try
|
|
{
|
|
printmonths = p.HaveArvBefore == 1 ? common.MonthDiff(p.DateofArv.Value, p.DateofRegistration.Value) : 0;
|
|
}
|
|
catch (Exception er)
|
|
{
|
|
MessageBox.Show("Thiếu ngày đăng ký " + p.PatientId);
|
|
|
|
}
|
|
|
|
|
|
for (int i = 0; i <= monthCounts; i++)
|
|
{
|
|
|
|
var s = new ArvStatus();
|
|
s.month = i;
|
|
s.PatientId = p.PatientId;
|
|
if (i >= printmonths)
|
|
{
|
|
s.ExamDes = "KK";
|
|
s.remonth = i + 1;
|
|
s.Regimenid = "";
|
|
s.OtherStatus = "";
|
|
s.CD4 = (i == 0) ? FirstCd4 : "N/A";
|
|
}
|
|
|
|
Statuses.Add(s);
|
|
|
|
}
|
|
|
|
if (p.HaveArvBefore == 1)
|
|
{
|
|
try
|
|
{
|
|
Statuses[printmonths].ExamDes = "CT";
|
|
Statuses[printmonths].Regimenid =
|
|
meta.TblRegimen.Where(m => m.Regimenid == p.Regimenid).First().Sign;
|
|
}
|
|
catch (Exception err)
|
|
{
|
|
|
|
MessageBox.Show(err + " " + p.PatientId);
|
|
}
|
|
|
|
|
|
}
|
|
|
|
for (int j = 0; j < _exams.Count; j++)
|
|
{
|
|
try
|
|
{
|
|
var ex = _exams[j];
|
|
int mondiff = common.MonthDiff(p.DateofArv.Value, ex.ExamDate.Value);
|
|
var currNode = Statuses.Where(q => q.month == mondiff).First();
|
|
|
|
if (ex.ReTreatment==1)
|
|
{
|
|
currNode.ExamDes = "DTL";
|
|
}
|
|
else
|
|
{ if (currNode.ExamDes =="KK") currNode.ExamDes = "CK";
|
|
}
|
|
|
|
if (ex.EndExamDate !=null )
|
|
{
|
|
int monthEnd = 0;
|
|
|
|
monthEnd = common.MonthDiff(p.DateofArv.Value, ex.EndExamDate.Value);
|
|
var enndCurrNode = Statuses.Where(q => q.month == monthEnd).First();
|
|
|
|
try {
|
|
|
|
enndCurrNode.EndReason = ex.ReasonEnd.Length == 0 ? "00" : meta.TblRegimenStopReason.Where(q => q.ReasonId == ex.ReasonEnd).First().Sign;
|
|
enndCurrNode.ExamDes = ex.ReasonEnd.Length == 0 ? "00" : meta.TblRegimenStopReason.Where(q => q.ReasonId == ex.ReasonEnd).First().Sign;
|
|
|
|
}
|
|
catch(Exception err)
|
|
{
|
|
MessageBox.Show(err.Message + " " + p.PatientId + " " + monthEnd.ToString() + " " + ex.ReasonEnd + " Lý do kết thúc điều trị");
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
// if (p.HaveArvBefore == 1 && mondiff == printmonths) currNode.ExamDes = "CT";
|
|
currNode.ArvDes = currNode.ExamDes;
|
|
currNode.remonth = ex.ReExamDate != null? common.MonthDiff(p.DateofArv.Value, ex.ReExamDate.Value):currNode.month;
|
|
|
|
}catch(Exception err)
|
|
{
|
|
MessageBox.Show(err.Message + " Step 1");
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
#endregion
|
|
#region "điền CD4"
|
|
var _interPreClinics = _preclinics.Where(m => m.TestDate >= p.DateofArv).ToList();
|
|
for (int i = 1; i < _interPreClinics.Count; i++)
|
|
{
|
|
var ex = _interPreClinics[i];
|
|
int mondiff = common.MonthDiff(p.DateofArv.Value, ex.TestDate.Value);
|
|
var currNode = Statuses.Where(q => q.month == mondiff).First();
|
|
currNode.CD4 = ex.QuantityResult.ToString();
|
|
}
|
|
#endregion
|
|
#region "Điền phác đồ"
|
|
for (int i = 0; i < _arvTreatment.Count; i++)
|
|
{
|
|
var ex = _arvTreatment[i];
|
|
try
|
|
{
|
|
int mondiff = common.MonthDiff(p.DateofArv.Value, ex.TreatmentSdate.Value);
|
|
var currNode = Statuses.Where(q => q.month == mondiff).First();
|
|
currNode.Regimenid = meta.TblRegimen.Where(m => m.Regimenid == ex.Regimenid).Single().Sign;
|
|
}
|
|
catch(Exception err)
|
|
{
|
|
MessageBox.Show(err.Message + " " + p.PatientId + " In phác đồ ARV");
|
|
}
|
|
}
|
|
|
|
#endregion
|
|
#region "Điền các thông tin điều trị khác"
|
|
for (int i = 0; i <_otherTreatment.Count; i++)
|
|
{
|
|
var ex = _otherTreatment[i];
|
|
int mondiff = common.MonthDiff(p.DateofArv.Value, ex.TreatmentSdate.Value) ;
|
|
var currNode = Statuses.Where(q => q.month == mondiff).First();
|
|
try
|
|
{
|
|
currNode.OtherStatus = currNode.OtherStatus.Trim().Length == 0 ? meta.TblTreatment.Where(m => m.TreatmentId == ex.TreatmentId).First().Sign : currNode.OtherStatus ;
|
|
// currNode.OtherStatus = currNode.OtherStatus + meta.TblTreatment.Where(m => m.TreatmentId == ex.TreatmentId).First().Sign;
|
|
}
|
|
catch (Exception er)
|
|
{
|
|
|
|
MessageBox.Show(er.Message + " ," + p.PatientId + ex.TreatmentId);
|
|
}
|
|
}
|
|
|
|
#endregion
|
|
#region "Finalizing"
|
|
for(int i=printmonths+1; i< Statuses.Count; i++)
|
|
{
|
|
if( Statuses[i].CD4 == "N/A") Statuses[i].CD4 = Statuses[i-1].CD4;
|
|
if (Statuses[i].Regimenid == "N/A" && Statuses[i].ExamDes == "CK") Statuses[i].Regimenid = Statuses[i - 1].Regimenid;
|
|
if (Statuses[i].ExamDes == "KK")
|
|
{
|
|
Statuses[i].remonth = Statuses[i - 1].remonth;
|
|
Statuses[i].Regimenid = Statuses[i - 1].Regimenid;
|
|
}
|
|
|
|
if (Statuses[i].month < Statuses[i - 1].remonth ) Statuses[i].ExamDes = "CK";
|
|
if (Statuses[i].ExamDes == "CK" && Statuses[i].Regimenid == "") Statuses[i].Regimenid = Statuses[i - 1].Regimenid;
|
|
if (Statuses[i].ExamDes == "KK" && (Statuses[i - 1].ExamDes == "B" || Statuses[i - 1].ExamDes =="")) Statuses[i].ExamDes = "";
|
|
if (Statuses[i].ExamDes == "KK" && (Statuses[i - 1].ExamDes == "B" || Statuses[i - 1].ExamDes =="")) Statuses[i].Regimenid = "";
|
|
|
|
}
|
|
|
|
#endregion
|
|
|
|
|
|
#region "Fill Spreed Sheet"
|
|
|
|
for(int i =0; i< Statuses.Count; i++)
|
|
{
|
|
|
|
var g = Statuses[i];
|
|
// if (i==0 && p.HaveArvBefore==0) g.Regimenid= _ArvTreatment.Count() > 0 ? meta.TblRegimen.Where(m => m.Regimenid == _ArvTreatment[0].Regimenid).Single().Sign : "";
|
|
g.ArvDes = g.ExamDes;
|
|
if (g.ExamDes == "DTL" || g.ExamDes == "CT") g.ArvDes = g.Regimenid + "\n" + g.ExamDes;
|
|
if (g.ExamDes == "CK") g.ArvDes = g.Regimenid + "\n" + " ";
|
|
int col = g.getCol();
|
|
if (col != 0)
|
|
{
|
|
this.spreadsheetControl.Document.Worksheets["ARV"].Cells[rows, col].Value = g.ArvDes;
|
|
this.spreadsheetControl.Document.Worksheets["ARV"].Cells[7, col].Value = p.DateofArv.Value.AddMonths(i).ToString("MM")+ "/" + p.DateofArv.Value.AddMonths(i).ToString("yy");
|
|
this.spreadsheetControl.Document.Worksheets["ARV"].Cells[rows+1, col].Value = g.OtherStatus;
|
|
}
|
|
|
|
if ( g.month%6==0 && g.month!=0)
|
|
{
|
|
|
|
this.spreadsheetControl.Document.Worksheets["ARV"].Cells[rows, col+1].Value = g.CD4;
|
|
|
|
}
|
|
}
|
|
#endregion
|
|
|
|
|
|
}
|
|
|
|
private void fillPreArvCohorts(int PageNo)
|
|
{
|
|
|
|
this.spreadsheetControl.Visible = false;
|
|
this.progressPanel.Visible = true;
|
|
string path = Application.StartupPath;
|
|
string templateFile = path + @"\templates\logbook2.xls";
|
|
this.spreadsheetControl.LoadDocument(templateFile);
|
|
|
|
int minYear = PatientLists.Where(m=>m.DateofRegistration!=null).Select(m => new { year = m.DateofRegistration.Value.Year }).OrderBy(m => m.year).First().year;
|
|
|
|
this.startYear = minYear;
|
|
for (int i=1;i<28;i+=4)
|
|
{
|
|
this.spreadsheetControl.Document.Worksheets["Pre-ARV"].Cells[6, 12 + i].Value = minYear++;
|
|
|
|
}
|
|
int StartNum = PreArvPageNum * (PageNo - 1);
|
|
int EndNum = Math.Min(PreArvPageNum * PageNo - 1, PageNum - 1);
|
|
int rows = 9;
|
|
|
|
for (int i= StartNum; i<=EndNum;i++)
|
|
{
|
|
|
|
fillPreArvPatientInfo(rows, PatientLists[i], i+1);
|
|
rows = rows + 2;
|
|
}
|
|
this.spreadsheetControl.Visible = true;
|
|
this.progressPanel.Visible = false;
|
|
}
|
|
|
|
private void fillPreArvPatientInfo(int thisrow, TblPatientEntity p, int pos)
|
|
|
|
{
|
|
|
|
var _exams = p.DateofArv != null ? exams.Where(m => m.PatientId == p.PatientId).Where(m => m.ExamDate <= p.DateofArv).ToList() : exams.Where(m => m.PatientId == p.PatientId).ToList();
|
|
var _treatment = p.DateofArv != null ?treatments.Where(m => m.PatientId == p.PatientId).Where(m => m.TreatmentSdate <= p.DateofArv).ToList():treatments.Where(m => m.PatientId == p.PatientId).ToList();
|
|
var _clinics = p.DateofArv != null ? exams.Where(m => m.PatientId == p.PatientId).Where(g => g.IsClinic == 1).Where(m => m.ExamDate <= p.DateofArv).ToList() : exams.Where(m => m.PatientId == p.PatientId).Where(g => g.IsClinic == 1).ToList();
|
|
var _preclinics = p.DateofArv != null ? preclinics.Where(m => m.PatientId == p.PatientId).Where(m => m.TestDate <= p.DateofArv).Where(m=>m.Testid =="01").ToList() : preclinics.Where(m => m.PatientId == p.PatientId).Where(m=>m.Testid =="01").ToList();
|
|
|
|
|
|
|
|
|
|
try
|
|
{
|
|
|
|
this.spreadsheetControl.Document.Worksheets["Pre-ARV"].Cells[thisrow, 0].Value = pos.ToString();
|
|
this.spreadsheetControl.Document.Worksheets["Pre-ARV"].Cells[thisrow, 2].Value = p.PatientName;
|
|
this.spreadsheetControl.Document.Worksheets["Pre-ARV"].Cells[thisrow, 1].Value = p.DateofRegistration != null ? p.DateofRegistration.Value.ToShortDateString() : "N/A";
|
|
this.spreadsheetControl.Document.Worksheets["Pre-ARV"].Cells[thisrow, 3].Value = p.PatientId;
|
|
this.spreadsheetControl.Document.Worksheets["Pre-ARV"].Cells[thisrow, 4].Value = (p.Sex == 1 ? p.BirthYear.ToString() : null);
|
|
this.spreadsheetControl.Document.Worksheets["Pre-ARV"].Cells[thisrow, 5].Value = (p.Sex == 2 ? p.BirthYear.ToString() : null);
|
|
this.spreadsheetControl.Document.Worksheets["Pre-ARV"].Cells[thisrow, 6].Value = p.Address;
|
|
|
|
this.spreadsheetControl.Document.Worksheets["Pre-ARV"].Cells[thisrow, 8].Value = _clinics.Count==0 ? "N/A" : _clinics.First().ClinicStage.ToString();
|
|
this.spreadsheetControl.Document.Worksheets["Pre-ARV"].Cells[thisrow, 9].Value = _preclinics.Where(m => m.Testid == "01").Count() > 0 ? _preclinics.Where(m => m.Testid == "01").First().QuantityResult.ToString() : "N/A";
|
|
this.spreadsheetControl.Document.Worksheets["Pre-ARV"].Cells[thisrow, 10].Value = _clinics.Count == 0 ? "N/A" : _clinics.First().Weight.ToString();
|
|
this.spreadsheetControl.Document.Worksheets["Pre-ARV"].Cells[thisrow + 1, 10].Value = _clinics.Count == 0 ? "N/A" : _clinics.First().Height.ToString();
|
|
this.spreadsheetControl.Document.Worksheets["Pre-ARV"].Cells[thisrow, 11].Value = this.ArvDate(p.PatientId);
|
|
this.spreadsheetControl.Document.Worksheets["Pre-ARV"].Cells[thisrow, 12].Value = p.DateofArv != null ? p.DateofArv.Value.ToShortDateString() : "N/A";
|
|
}
|
|
catch (Exception err)
|
|
{
|
|
MessageBox.Show(err.Message);
|
|
}
|
|
if (_exams.Count() == 0) return;
|
|
List<prevArvStatus> Statuses = new List<prevArvStatus>();
|
|
var EndExamDate = _exams.Last().EndExamDate == null ? (p.DateofArv == null ? DateTime.Today : p.DateofArv) : _exams.Last().EndExamDate;
|
|
int quarterCount = (EndExamDate.Value.Year - this.startYear) * 4 + common.GetQuarter(EndExamDate.Value);
|
|
int startQuarter = (_exams.First().ExamDate.Value.Year - this.startYear) * 4 + common.GetQuarter(_exams.First().ExamDate.Value);
|
|
|
|
|
|
for (int i = startQuarter; i <= quarterCount; i++)
|
|
{
|
|
var s = new prevArvStatus();
|
|
s.quarter = i ;
|
|
s.PreArvDes = "";
|
|
s.OtherStatus = "";
|
|
Statuses.Add(s);
|
|
s.col = s.quarter + 13;
|
|
}
|
|
|
|
for (int i = 0; i < _preclinics.Count; i++)
|
|
{
|
|
var ex = _preclinics[i];
|
|
int quarters = (ex.TestDate.Value.Year-this.startYear ) * 4 + common.GetQuarter(ex.TestDate.Value);
|
|
try
|
|
{
|
|
var currNode = Statuses.Where(q => q.quarter == quarters).First();
|
|
currNode.PreArvDes = ex.QuantityResult.ToString();
|
|
}
|
|
catch(Exception err)
|
|
{
|
|
MessageBox.Show(err.Message + " " + p.PatientId + " " + quarters);
|
|
}
|
|
}
|
|
|
|
|
|
for (int i = 0; i < _exams.Count; i++)
|
|
{
|
|
var ex = _exams[i];
|
|
int quarters = (ex.ExamDate.Value.Year - this.startYear) * 4 + common.GetQuarter(ex.ExamDate.Value);
|
|
|
|
if (ex.EndExamDate != null)
|
|
{
|
|
int Equarters = (ex.EndExamDate.Value.Year - this.startYear) * 4 + common.GetQuarter(ex.EndExamDate.Value);
|
|
Statuses.Where(q => q.quarter == Equarters).First().PreArvDes = ex.ReasonEnd + "\n" + ex.EndExamDate.Value.ToShortDateString() ;
|
|
}
|
|
}
|
|
|
|
|
|
for (int i = 1; i < Statuses.Count; i++)
|
|
{
|
|
|
|
// if (Statuses[i].CD4 == "N/A") Statuses[i].CD4 = Statuses[i - 1].CD4;
|
|
// if (Statuses[i].PreArvDes == "KK") Statuses[i].PreArvDes = Statuses[i - 1].PreArvDes;
|
|
}
|
|
|
|
//Fill Spreed Sheet
|
|
for (int i = 0; i < Statuses.Count; i++)
|
|
{
|
|
var g = Statuses[i];
|
|
int col = g.col;
|
|
try
|
|
{
|
|
this.spreadsheetControl.Document.Worksheets["Pre-ARV"].Cells[thisrow, col - 1].Value = g.PreArvDes; ;
|
|
} catch (Exception err)
|
|
{
|
|
MessageBox.Show(err.Message + " " + Statuses.Count().ToString());
|
|
}
|
|
}
|
|
}
|
|
|
|
private void spreadsheetControl_DoubleClick(object sender, EventArgs e)
|
|
{
|
|
string PatientID = "0";
|
|
switch( SelectedReportIndex)
|
|
{
|
|
case 0:
|
|
PatientID= this.spreadsheetControl.ActiveWorksheet.Cells[spreadsheetControl.ActiveCell.RowIndex, 3].Value.ToString();
|
|
break;
|
|
case 1:
|
|
PatientID = this.spreadsheetControl.ActiveWorksheet.Cells[spreadsheetControl.ActiveCell.RowIndex, 1].Value.ToString();
|
|
break;
|
|
}
|
|
if(PatientID.Length>3)
|
|
{
|
|
var frm = new frmPatientInfo();
|
|
frm.PatientsCollection = new EntityCollection<TblPatientEntity>();
|
|
var PatientInfo = new TblPatientEntity(PatientID);
|
|
adapter.FetchEntity(PatientInfo);
|
|
frm.PatientsCollection.Add(PatientInfo);
|
|
frm.PatientInfo = PatientInfo;
|
|
frm.LoadData();
|
|
frm.ShowDialog();
|
|
}
|
|
}
|
|
|
|
private void genPages(int Records,int RecordperPage)
|
|
{
|
|
this.PageList.Items.Clear();
|
|
int m = Records % RecordperPage > 0 ? Records / RecordperPage + 1 : Records / RecordperPage;
|
|
for (int i =1;i<=m;i++)
|
|
{
|
|
this.PageList.Items.Add(i);
|
|
}
|
|
}
|
|
|
|
private void barCohort_EditValueChanged(object sender, EventArgs e)
|
|
{
|
|
var cohorts = this.barCohort.EditValue;
|
|
string path = Application.StartupPath;
|
|
string templateFile = path + @"\templates\logbook4.xls";
|
|
if (cohorts != null)
|
|
{
|
|
int bookMonth = Convert.ToInt32(cohorts.ToString().Substring(0, 2));
|
|
int bookYear = Convert.ToInt32(cohorts.ToString().Substring(3, 4));
|
|
PatientLists = (from q in Patients where (q.DateofArv != null && q.DateofArv.Value.Month == bookMonth && q.DateofArv.Value.Year == bookYear) select q).ToList<TblPatientEntity>();
|
|
PageNum = PatientLists.Count;
|
|
}
|
|
else
|
|
{
|
|
PageNum = 0;
|
|
}
|
|
genPages(PageNum, ArvPageNum);
|
|
this.spreadsheetControl.LoadDocument(templateFile);
|
|
}
|
|
private void GenYearList()
|
|
{
|
|
LinqMetaData meta = new LinqMetaData(adapter);
|
|
var years = meta.TblPatient.Where(m=>m.DateofRegistration!=null).Where(m=>m.HaveArvBefore==0).Select(m => new { year=m.DateofRegistration.Value.Year }).Distinct().ToList();
|
|
this.repYearList.DataSource = years;
|
|
this.repYearList.DisplayMember = "year";
|
|
this.repYearList.ValueMember = "year";
|
|
}
|
|
|
|
private void barYear_EditValueChanged(object sender, EventArgs e)
|
|
{
|
|
char[] separator = new char[] { ',' };
|
|
LinqMetaData meta = new LinqMetaData(adapter);
|
|
string Yeartmp = this.barYear.EditValue.ToString();
|
|
Yeartmp = Yeartmp.Replace(" ", "");
|
|
|
|
PatientLists.Clear();
|
|
string[] YearSelected = Yeartmp.Split(separator);
|
|
|
|
List<TblPatientEntity> tempPatient = meta.TblPatient.Where(g => g.DateofRegistration != null).ToList<TblPatientEntity>();
|
|
PatientLists = (from q in tempPatient where YearSelected.Contains(q.DateofRegistration.Value.Year.ToString()) orderby q.DateofRegistration select q).ToList<TblPatientEntity>();
|
|
|
|
PageNum = PatientLists.Count;
|
|
MessageBox.Show(PageNum.ToString());
|
|
genPages(PageNum, PreArvPageNum);
|
|
|
|
|
|
}
|
|
|
|
private void spreadsheetControl_Click(object sender, EventArgs e)
|
|
{
|
|
|
|
}
|
|
private string ArvDate(string PatientId)
|
|
{
|
|
|
|
try {
|
|
var exams = new EntityCollection<TblExaminationInfoEntity>();
|
|
var tests = new EntityCollection<TblPreClinicsInfoEntity>();
|
|
|
|
adapter.FetchEntityCollection(exams, null);
|
|
adapter.FetchEntityCollection(tests, null);
|
|
|
|
DateTime CD4CriteridaDate = tests.Where(m => m.PatientId == PatientId).Where(p => p.Testid == "01").Where(p => p.QuantityResult < 350).OrderBy(p => p.TestDate).First().TestDate.Value;
|
|
DateTime ClinicStateDate = exams.Where(p => p.ClinicStage >= 3).Where(m => m.PatientId == PatientId).OrderBy(m => m.ExamDate).First().ExamDate.Value;
|
|
return common.MinDate(CD4CriteridaDate, CD4CriteridaDate).ToShortDateString();
|
|
}
|
|
catch
|
|
{
|
|
return "N/A";
|
|
}
|
|
}
|
|
|
|
private void barExcel_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
|
|
{
|
|
this.SaveFileDialog.FileName = "arvlogbook" + DateTime.Today.ToString("dd") + DateTime.Today.ToString("MM") + DateTime.Today.ToString("yy") + ".xls";
|
|
this.SaveFileDialog.Filter = "Excel File|*.xls";
|
|
if (this.SaveFileDialog.ShowDialog() == DialogResult.OK)
|
|
{
|
|
this.spreadsheetControl.SaveDocument(SaveFileDialog.FileName, DocumentFormat.Xls);
|
|
MessageBox.Show("Quá trình kết xuất file đã hoàn tất", "kết xuất", MessageBoxButtons.OK, MessageBoxIcon.Information);
|
|
}
|
|
|
|
}
|
|
|
|
private void barpdf_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
|
|
{
|
|
this.SaveFileDialog.FileName = "arvlogbook" + DateTime.Today.ToString("dd") + DateTime.Today.ToString("MM") + DateTime.Today.ToString("yy") + ".pdf";
|
|
this.SaveFileDialog.Filter = "Pdf File|*.pdf";
|
|
if (this.SaveFileDialog.ShowDialog() == DialogResult.OK)
|
|
{
|
|
|
|
|
|
this.spreadsheetControl.ExportToPdf(SaveFileDialog.FileName);
|
|
MessageBox.Show("Quá trình kết xuất file đã hoàn tất", "kết xuất", MessageBoxButtons.OK, MessageBoxIcon.Information);
|
|
}
|
|
}
|
|
|
|
private void barReload_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
|
|
{
|
|
LinqMetaData meta = new LinqMetaData(adapter);
|
|
|
|
var patientids = meta.TblPatient.Select(m => m.PatientId).ToList();
|
|
foreach (string id in patientids)
|
|
{
|
|
fixdata(id);
|
|
|
|
}
|
|
|
|
MessageBox.Show("Quá trình hiệu chỉnh dữ liệu đã kết thúc. Đề khởi động lại logbook để tác vụ có hiệu lực", "Hiệu chỉnh", MessageBoxButtons.OK, MessageBoxIcon.Information);
|
|
}
|
|
|
|
|
|
private void fixdata(string patientid)
|
|
{
|
|
TblPatientEntity PatientInfor = new TblPatientEntity(patientid);
|
|
adapter.FetchEntity(PatientInfor);
|
|
EntityCollection<TblExaminationInfoEntity>ExamInfos = new EntityCollection<TblExaminationInfoEntity>();
|
|
|
|
ExamInfos = PatientInfor.TblExaminationInfos;
|
|
|
|
ISortExpression sorter = new SortExpression(TblExaminationInfoFields.ExamDate | SortOperator.Ascending);
|
|
adapter.FetchEntityCollection(ExamInfos, PatientInfor.GetRelationInfoTblExaminationInfos(), 0, sorter);
|
|
|
|
for (int j = 0; j <= ExamInfos.Count - 1; j++)
|
|
{
|
|
|
|
|
|
ExamInfos[j].DayDiff = (j == 0) ? (short)0 : (short)
|
|
(System.Convert.ToDateTime(ExamInfos[j].ExamDate) -
|
|
System.Convert.ToDateTime(ExamInfos[j - 1].ReExamDate)).TotalDays;
|
|
|
|
ExamInfos[j].Status = (ExamInfos[j].DayDiff == 0) ? (short)1 : ((ExamInfos[j].DayDiff < 0) ? (short)2 : (short)3);
|
|
if (j > 0) ExamInfos[j].ReTreatment = (ExamInfos[j - 1].ReasonEnd =="10") ? (short)1 : (short)0;
|
|
|
|
|
|
}
|
|
adapter.SaveEntityCollection(ExamInfos);
|
|
|
|
|
|
}
|
|
|
|
}
|
|
}
|