270 lines
13 KiB
C#
270 lines
13 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using Datalib.DatabaseSpecific;
|
|
using System.Windows.Forms;
|
|
using Datalib.Linq;
|
|
using Datalib.EntityClasses;
|
|
using Datalib.FactoryClasses;
|
|
using Datalib.HelperClasses;
|
|
using PatientMan.Classes;
|
|
|
|
namespace PatientMan.Classes
|
|
{
|
|
class clsFullPrint
|
|
{
|
|
public DataAccessAdapter adapter = new DataAccessAdapter(SettingInfo.Constr);
|
|
public void PrintOut(List<string> PatientLists)
|
|
{
|
|
SaveFileDialog saveDlg = new SaveFileDialog();
|
|
saveDlg.Filter = "Excel File|*.xlsx";
|
|
if (saveDlg.ShowDialog() != DialogResult.OK) return;
|
|
|
|
LinqMetaData meta = new LinqMetaData(adapter);
|
|
EntityCollection<TblPatientEntity> Patients = new EntityCollection<TblPatientEntity>();
|
|
EntityCollection<TblExaminationInfoEntity> Exams = new EntityCollection<TblExaminationInfoEntity>();
|
|
EntityCollection<TblPreClinicsInfoEntity> Tests= new EntityCollection<TblPreClinicsInfoEntity>();
|
|
EntityCollection<TblTreatmentInfoEntity> TreatmentInfo = new EntityCollection<TblTreatmentInfoEntity>();
|
|
EntityCollection<TblPreClinicsInfoEntity> CD4 = new EntityCollection<TblPreClinicsInfoEntity>();
|
|
EntityCollection<TblPreClinicsInfoEntity> INH = new EntityCollection<TblPreClinicsInfoEntity>();
|
|
EntityCollection<TblPreClinicsInfoEntity> CTX = new EntityCollection<TblPreClinicsInfoEntity>();
|
|
adapter.FetchEntityCollection(Patients, null);
|
|
adapter.FetchEntityCollection(Exams, null);
|
|
adapter.FetchEntityCollection(Tests, null);
|
|
adapter.FetchEntityCollection(TreatmentInfo, null);
|
|
var PrintPatients = Patients.Where(m => PatientLists.Contains(m.PatientId)).ToList();
|
|
var LastExams = Exams.GroupBy(m => m.PatientId).Select(g => g.OrderBy(m => m.ExamDate).Last()).Select(g => new { g.PatientId, g.ExamDate, g.EndExamDate, g.ReasonEnd, g.ReExamDate,g.OutPatientTreatment, Delays =g.ReExamDate==null?(double?)null:Math.Round( (DateTime.Now-g.ReExamDate.Value).TotalDays) }).ToList();
|
|
var LastCD4 = Tests.Where(p=>p.Testid=="01").GroupBy(m=>m.PatientId).Select(g=>g.OrderBy(m=>m.TestDate).Last()).Select(g=>new{g.PatientId,CD4=g.QuantityResult, CD4Delays = (DateTime.Now- g.TestDate.Value).TotalDays}).ToList();
|
|
var LastARV = TreatmentInfo.Where(p => p.TreatmentId == "01").GroupBy(m => m.PatientId).Select(g => g.OrderBy(m => m.TreatmentSdate).Last()).Select(g => new { g.PatientId, ARVsDate =g.TreatmentSdate, ARVeDate= g.TreatmentEdate, g.Regimenid}).ToList();
|
|
var LastINH = TreatmentInfo.Where(p => p.TreatmentId == "03").GroupBy(m => m.PatientId).Select(g => g.OrderBy(m => m.TreatmentSdate).Last()).Select(g => new { g.PatientId, INHsDate = g.TreatmentSdate, INHeDate = g.TreatmentEdate, }).ToList();
|
|
var LastCTX = TreatmentInfo.Where(p => p.TreatmentId == "04").GroupBy(m => m.PatientId).Select(g => g.OrderBy(m => m.TreatmentSdate).Last()).Select(g => new { g.PatientId, CTXsDate = g.TreatmentSdate, CTXeDate = g.TreatmentEdate, }).ToList();
|
|
|
|
var LastExamRec = (from p in PrintPatients
|
|
join q in LastExams on p.PatientId equals q.PatientId
|
|
select new
|
|
|
|
{
|
|
p.PatientId,
|
|
p.PatientName,
|
|
p.Sex,
|
|
p.BirthYear,
|
|
p.TelephoneNo,
|
|
p.SupporterInfo,
|
|
sms=(bool)p.Sms?"X":"",
|
|
p.Address,
|
|
p.DateofArv,
|
|
p.DateofRegistration,
|
|
p.HivConfirmedDate,
|
|
q.ReasonEnd,
|
|
q.ExamDate,
|
|
q.ReExamDate,
|
|
q.EndExamDate,
|
|
p.ProvinceId,
|
|
p.DistrictId,
|
|
p.CommuneId,
|
|
p.ReferralId,
|
|
q.OutPatientTreatment,
|
|
q.Delays
|
|
|
|
|
|
}
|
|
|
|
|
|
).ToList();
|
|
|
|
var LastCD4record = (from p in LastExamRec
|
|
join q in LastCD4 on p.PatientId equals q.PatientId into g
|
|
from q in g.DefaultIfEmpty()
|
|
select
|
|
new
|
|
{
|
|
p.PatientId,
|
|
p.PatientName,
|
|
p.Sex,
|
|
p.BirthYear,
|
|
p.TelephoneNo,
|
|
p.SupporterInfo,
|
|
p.sms,
|
|
p.Address,
|
|
p.DateofArv,
|
|
p.DateofRegistration,
|
|
p.HivConfirmedDate,
|
|
p.ReasonEnd,
|
|
p.ExamDate,
|
|
p.ReExamDate,
|
|
p.EndExamDate,
|
|
p.ProvinceId,
|
|
p.DistrictId,
|
|
p.CommuneId,
|
|
p.ReferralId,
|
|
p.OutPatientTreatment,
|
|
p.Delays,
|
|
CD4=q!=null?q.CD4.ToString():"N/A",
|
|
CD4Delays = q != null ? Math.Round(q.CD4Delays).ToString() : "N/A"
|
|
|
|
}
|
|
|
|
).ToList();
|
|
|
|
var LastARVrecord = (from p in LastCD4record
|
|
join q in LastARV on p.PatientId equals q.PatientId into g
|
|
from q in g.DefaultIfEmpty()
|
|
select
|
|
new
|
|
{
|
|
p.PatientId,
|
|
p.PatientName,
|
|
p.Sex,
|
|
p.BirthYear,
|
|
p.TelephoneNo,
|
|
p.SupporterInfo,
|
|
p.sms,
|
|
p.Address,
|
|
p.DateofArv,
|
|
p.DateofRegistration,
|
|
p.HivConfirmedDate,
|
|
p.ReasonEnd,
|
|
p.ExamDate,
|
|
p.ReExamDate,
|
|
p.ProvinceId,
|
|
p.DistrictId,
|
|
p.EndExamDate,
|
|
p.CommuneId,
|
|
p.ReferralId,
|
|
p.OutPatientTreatment,
|
|
p.Delays,
|
|
p.CD4,
|
|
p.CD4Delays,
|
|
ARVsDate=q!=null?q.ARVsDate:null,
|
|
ARVeDate = q != null ? q.ARVeDate : null,
|
|
Regimenid= q!=null? q.Regimenid: string.Empty,
|
|
}
|
|
).ToList();
|
|
|
|
|
|
|
|
var LastCTXrecord = (from p in LastARVrecord
|
|
join q in LastCTX on p.PatientId equals q.PatientId into g
|
|
from q in g.DefaultIfEmpty()
|
|
select
|
|
new
|
|
{
|
|
p.PatientId,
|
|
p.PatientName,
|
|
p.Sex,
|
|
p.BirthYear,
|
|
p.TelephoneNo,
|
|
p.SupporterInfo,
|
|
p.sms,
|
|
p.Address,
|
|
p.DateofArv,
|
|
p.DateofRegistration,
|
|
p.HivConfirmedDate,
|
|
p.ReasonEnd,
|
|
p.ExamDate,
|
|
p.ReExamDate,
|
|
p.EndExamDate,
|
|
p.ProvinceId,
|
|
p.DistrictId,
|
|
p.CommuneId,
|
|
p.ReferralId,
|
|
p.OutPatientTreatment,
|
|
p.Delays,
|
|
p.CD4,
|
|
p.CD4Delays,
|
|
p.ARVsDate,
|
|
p.ARVeDate,
|
|
p.Regimenid,
|
|
CTXsDate=q!=null?q.CTXsDate:null,
|
|
CTXeDate = q != null ? q.CTXeDate : null
|
|
}
|
|
).ToList();
|
|
int i =1;
|
|
var LastINHrecord = (from p in LastCTXrecord
|
|
join q in LastINH on p.PatientId equals q.PatientId into g
|
|
from q in g.DefaultIfEmpty()
|
|
select
|
|
new
|
|
{
|
|
p.PatientId,
|
|
p.PatientName,
|
|
p.Sex,
|
|
p.BirthYear,
|
|
p.TelephoneNo,
|
|
p.SupporterInfo,
|
|
p.sms,
|
|
p.Address,
|
|
p.DateofArv,
|
|
p.DateofRegistration,
|
|
p.HivConfirmedDate,
|
|
p.ReasonEnd,
|
|
p.ExamDate,
|
|
p.ReExamDate,
|
|
p.EndExamDate,
|
|
p.ProvinceId,
|
|
p.DistrictId,
|
|
p.CommuneId,
|
|
p.ReferralId,
|
|
p.OutPatientTreatment,
|
|
p.Delays,
|
|
p.CD4,
|
|
p.CD4Delays,
|
|
p.ARVsDate,
|
|
p.ARVeDate,
|
|
p.Regimenid,
|
|
p.CTXsDate,
|
|
p.CTXeDate,
|
|
INHsDate = q != null ? q.INHsDate : null,
|
|
INHeDate = q != null ? q.INHeDate : null
|
|
|
|
}
|
|
).Select(p => new clsPatientInfo
|
|
{
|
|
No= i++,
|
|
PatientID=p.PatientId,
|
|
PatientName=p.PatientName,
|
|
Sex=(int)p.Sex==1?"Nam":"Nữ",
|
|
BirthYear= (int)p.BirthYear,
|
|
TelephoneNo= p.TelephoneNo,
|
|
SupporterInfo=p.SupporterInfo,
|
|
sms=p.sms,
|
|
Address= p.Address,
|
|
DateofArv=p.DateofArv,
|
|
IsArv =p.DateofArv!=null?"X":"",
|
|
DateofRegistration= p.DateofRegistration,
|
|
HIVConfirmDate = p.HivConfirmedDate,
|
|
ReasonEnd=p.ReasonEnd,
|
|
LastExamDate= p.ExamDate,
|
|
ReExamDate= p.ReExamDate,
|
|
EndExamDate = p.EndExamDate,
|
|
ProvinceId= p.ProvinceId,
|
|
DistrictId=p.DistrictId,
|
|
CommuneId=p.CommuneId,
|
|
Referral= p.ReferralId!="01"?"X":"",
|
|
OutPatientTreatment=(short)p.OutPatientTreatment ==1?"X":"",
|
|
Delays = p.EndExamDate !=null?p.Delays.ToString():"",
|
|
CD4=p.CD4,
|
|
CD4Delays= p.EndExamDate !=null?p.CD4Delays:"",
|
|
ARVsDate=p.ARVsDate,
|
|
ARVeDate = p.ARVeDate,
|
|
Regimenid=p.Regimenid,
|
|
CTXsDate=p.CTXsDate,
|
|
CTXeDate=p.CTXeDate,
|
|
INHsDate =p.INHsDate,
|
|
INHeDate = p.INHeDate
|
|
|
|
}).ToList();
|
|
|
|
PatientMan.Forms.frmExp frm = new PatientMan.Forms.frmExp();
|
|
frm.LoadData();
|
|
frm.grdExport.DataSource = LastINHrecord;
|
|
frm.grdExport.ExportToXlsx(saveDlg.FileName);
|
|
|
|
MessageBox.Show("Dữ liệu đã được kết xuất ra tệp " + saveDlg.FileName);
|
|
frm.Dispose();
|
|
|
|
|
|
}
|
|
}
|
|
}
|