Files
csharpcode/patientman/PatientMan/Classes/Actions/clsPMTCT.cs
2025-08-02 05:20:17 +07:00

97 lines
4.1 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 clsPMTCT
{
public DevExpress.XtraSpreadsheet.SpreadsheetControl spreed;
private DevExpress.Spreadsheet.Worksheet _Rep;
public DataAccessAdapter adapter = new DataAccessAdapter(SettingInfo.Constr);
public LinqMetaData meta = new LinqMetaData(new DataAccessAdapter(SettingInfo.Constr));
private int row = 9;
private int Num=0;
public void Calculate()
{
_Rep = spreed.Document.Worksheets["Rep"];
var children = meta.TblChild.Join(meta.TblPregnanceInfo, p => p.PreganceId, q => q.UniqueKey, (p, q) => new { p.ChildId, q.PatientId, q.EstimatedDelivery }).OrderBy(q => q.ChildId).ThenBy(q => q.EstimatedDelivery).Select(q => q.ChildId).ToList();
foreach (var child in children)
{
Num++;
clsChildInfo Chidlinfo = FillChild(child);
_Rep.Cells[row, 0].Value = Num;
_Rep.Cells[row, 1].Value = Chidlinfo.ChildName;
_Rep.Cells[row, 2].Value = Chidlinfo.Sex == "Nam" ? Chidlinfo.ChildBod :null;
_Rep.Cells[row, 3].Value = Chidlinfo.Sex == "Nữ" ? Chidlinfo.ChildBod: null;
_Rep.Cells[row, 4].Value = Chidlinfo.ChildName;
_Rep.Cells[row+1, 4].Value = Chidlinfo.ChildId;
_Rep.Cells[row, 5].Value = Chidlinfo.MotherName;
_Rep.Cells[row+1, 5].Value = Chidlinfo.MotherId;
_Rep.Cells[row, 8].Value = Chidlinfo.FeedingType;
_Rep.Cells[row, 9].Value = Chidlinfo.CTXDate;
_Rep.Cells[row+1, 9].Value = Chidlinfo.EmbrioAge;
_Rep.Cells[row, 10].Value = Chidlinfo.PCRDate1;
_Rep.Cells[row + 1, 10].Value = Chidlinfo.PCRResult1;
_Rep.Cells[row, 11].Value = Chidlinfo.PCRDate2;
_Rep.Cells[row + 1, 11].Value = Chidlinfo.PCRResult2;
_Rep.Cells[row , 12].Value = Chidlinfo.HIV18Result;
row = row + 2;
}
}
private clsChildInfo FillChild(string ChildId)
{
clsChildInfo ChildInfo = new clsChildInfo();
var currChild = meta.TblChild.Where(q => q.ChildId == ChildId).FirstOrDefault();
ChildInfo.ChildId = currChild.ChildId;
ChildInfo.ChildName = currChild.ChildName;
ChildInfo.ChildBod = meta.TblPregnanceInfo.Where(q => q.UniqueKey == currChild.PreganceId).FirstOrDefault().EstimatedDelivery.Value;
ChildInfo.Sex = currChild.Sex == 1 ? "Nam" : "Nữ";
ChildInfo.MotherId = meta.TblPregnanceInfo.Where(q => q.UniqueKey == currChild.PreganceId).FirstOrDefault().PatientId;
DateTime PreganceDate = meta.TblPregnanceInfo.Where(q => q.UniqueKey == currChild.PreganceId).FirstOrDefault().PregnanceDate.Value;
ChildInfo.MotherName = meta.TblPatient.Where(p => p.PatientId == ChildInfo.MotherId).FirstOrDefault().PatientName;
ChildInfo.FeedingType = currChild.FeedingType == 1 ? "Sữa mẹ":"Nuôi bộ";
ChildInfo.CTXDate = currChild.Ctxdate.Value;
ChildInfo.EmbrioAge = Math.Round(((TimeSpan)(PreganceDate - currChild.Ctxdate)).TotalDays / 7,0);
ChildInfo.PCRDate1 = currChild.Pcrcdate1.Value;
ChildInfo.PCRResult1 = currChild.Pcrresult1==1?"Âm tính":"Dương tính";
ChildInfo.PCRDate2 = currChild.Pcrcdate1.Value;
ChildInfo.PCRResult2 = currChild.Pcrresult2 == 1 ? "Âm tính" : "Dương tính";
ChildInfo.HIV18Date = (DateTime)currChild.Hiv18Date;
ChildInfo.HIV18Result = currChild.Hiv18Result == 1 ? "Âmtính" : "Dương tính";
return ChildInfo;
}
public void Dispose()
{
adapter.Dispose();
}
}
}