AIMS/DrawGraph/AreaManage/SapManage.cs
leomon 8fa93ff14b 药品拖拽
8间气道压没画
动态配置术前排程显示样式
用药界面增加持续时长
2023-05-15 15:12:35 +08:00

594 lines
25 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

using Newtonsoft.Json;
using AIMSExtension;
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace DrawGraph
{
[Serializable, JsonObject(MemberSerialization.OptOut)]
public class SapManage : AreaManageBase
{
/// <summary>
/// 药品区域
/// </summary>
public RectangleFramePackObj sapPpack;
public LinesPackObj lines;
public LinePackObj H3pack;
public LinePackObj H5pack;
public int RowsCount;
private TipBox aSyncTip = null;
/// <summary>
/// 当前手术对象
/// </summary>
private OperationRecord myOpeRecord = null;
public List<string> DrugsListstr = new List<string>();
#region
public SapManage()
{
init();
}
public SapManage(object _operationRecor, DrawGraph.ZedGraphControl _zedControl, TemplateManage _template, string _name) : base(_operationRecor, _zedControl, _template, _name)
{
init();
}
public void init()
{
//自己要用的手术对象
myOpeRecord = OpeRecord as OperationRecord;
}
/// <summary>
/// 初始画的后置方法
/// </summary>
public override void FollowUpMethod()
{
H3pack = template.GetPackObjectOTag<LinePackObj>("SapManage_LinePackObj_3");
H5pack = template.GetPackObjectOTag<LinePackObj>("SapManage_LinePackObj_5");
sapPpack = template.GetPackObjectOTag<RectangleFramePackObj>("SapManage_RectangleFramePackObj_2");
lines = template.GetPackObjectOTag<LinesPackObj>("SapManage_LinesPackObj_7");
RowsCount = Convert.ToInt32(lines.XPageSpan / lines.XMajorGridStep);
}
#endregion
#region
/// <summary>
/// 鼠标点击画板
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
public override void MouseDown(ZedGraphControl sender, MouseEventArgs e)
{
//if (ConfigSource.sysypyd != null && ConfigSource.sysypyd.Value.ToString() == "1")
//{
//触发可编辑区域的事件
double y = Convert.ToDouble(Convert.ToDouble(e.Y) / Convert.ToDouble(ZedControl.Height));
double x = Convert.ToDouble(Convert.ToDouble(e.X) / Convert.ToDouble(ZedControl.Width));
ZedGraphControl sender1 = sender as ZedGraphControl;
PointF mousePt = new PointF(e.X, e.Y);
GraphPane pane = sender1.MasterPane.FindChartRect(mousePt);
bool isDrugRange = isAddDrugRange(sender, x, y);
if (isDrugRange && e.Button == System.Windows.Forms.MouseButtons.Left)
{
DateTime BeginTime = reDrugsTime(sender as ZedGraphControl, e);
List<FactDrug> record = new List<FactDrug>();
double addDragRowHeight = (lines.RealEndY - lines.RealY) / RowsCount;
foreach (FactDrug dsr in myOpeRecord.FactDrugList)
{
if (dsr.isEqual(y, BeginTime, addDragRowHeight))
{
dsr.IsSelected = true;
break;
}
}
}
}
public override void MouseMove(ZedGraphControl sender, MouseEventArgs e)
{
//if (ConfigSource.sysypyd != null && ConfigSource.sysypyd.Value.ToString() == "1")
//{
double x = Convert.ToDouble(Convert.ToDouble(e.X) / Convert.ToDouble(sender.Width));
double y = Convert.ToDouble(Convert.ToDouble(e.Y) / Convert.ToDouble(sender.Height));
double yP = 18 / Convert.ToDouble(sender.Height);
string viewStr = "";
bool isDrugRange = isAddDrugRange(sender, x, y);
if (isDrugRange)
{
DateTime BeginTime = reDrugsTime(sender as ZedGraphControl, e);
double addDragRowHeight = (lines.RealEndY - lines.RealY) / RowsCount;
foreach (FactDrug dsr in myOpeRecord.FactDrugList)
{
if (dsr.isEqual(y, BeginTime, addDragRowHeight) || dsr.IsSelected)
{
//isDrug = true;
viewStr = dsr.DrugName + ":" + dsr.Dosage + dsr.DosageUnit;
if (dsr.DrugBeginTime != null)
viewStr += "\n开始时间" + dsr.DrugBeginTime.ToString("yyyy-MM-dd HH:mm");
if (dsr.DrugEndTime != null && dsr.DrugEndTime != dsr.DrugBeginTime)
viewStr += "\n结束时间" + dsr.DrugEndTime.ToString("yyyy-MM-dd HH:mm");
aSyncTip.ViewStr = viewStr;
aSyncTip.Show(x, y + yP);
//因为被选中进行托动
if (dsr.IsSelected)
{
aSyncTip.ViewStr = viewStr;
aSyncTip.Show(x, y + yP);
TimeSpan ts = BeginTime - DateTime.Parse(dsr.DrugBeginTime.ToString());
double totalMinutes = ts.TotalMinutes;
if (dsr.DrugEndTime != null)
{
dsr.DrugEndTime = dsr.DrugEndTime.AddMinutes(totalMinutes);
}
dsr.DrugBeginTime = BeginTime;
dsr.ReDraw(sender);
}
ZedControl.Refresh();
break;
}
}
}
//}
}
public override void MouseUp(ZedGraphControl sender, MouseEventArgs e)
{
if (OpeRecord == null) return;
//if (ConfigSource.sysypyd != null && ConfigSource.sysypyd.Value.ToString() == "1")
//{
double y = Convert.ToDouble(Convert.ToDouble(e.Y) / Convert.ToDouble(ZedControl.Height));
double x = Convert.ToDouble(Convert.ToDouble(e.X) / Convert.ToDouble(ZedControl.Width));
bool isDrugRange = isAddDrugRange(sender, x, y);
if (isDrugRange && e.Button == System.Windows.Forms.MouseButtons.Left)
{
//把移动药品强制保存
if (myOpeRecord != null && myOpeRecord.FactDrugList != null)
{
DateTime currentTime = reDrugsTime(sender as ZedGraphControl, e);
foreach (FactDrug dsr in myOpeRecord.FactDrugList)
{
if (dsr.IsSelected)
{
dsr.IsSelected = false;
int reValue = FactDrug.UpdateEntity(dsr);
if (reValue > 0)
{
reDrawDrug();
}
else
{
ZedControl.Refresh();
}
break;
}
}
}
}
//}
}
public override void MouseDoubleClick(ZedGraphControl sender, MouseEventArgs e)
{
if (myOpeRecord != null)
{
if (e.Button != System.Windows.Forms.MouseButtons.Left) return;
//触发可编辑区域的事件
double y = Convert.ToDouble(Convert.ToDouble(e.Y) / Convert.ToDouble(ZedControl.Height));
double x = Convert.ToDouble(Convert.ToDouble(e.X) / Convert.ToDouble(ZedControl.Width));
ZedGraphControl sender1 = sender as ZedGraphControl;
PointF mousePt = new PointF(e.X, e.Y);
GraphPane pane = sender1.MasterPane.FindChartRect(mousePt);
bool isDrugRange = isAddDrugRange(sender, x, y);
if (isDrugRange && e.Button == System.Windows.Forms.MouseButtons.Left)
{
DateTime BeginTime = reDrugsTime(sender as ZedGraphControl, e);
List<FactDrug> record = new List<FactDrug>();
double addDragRowHeight = (lines.RealEndY - lines.RealY) / RowsCount;
foreach (FactDrug dsr in myOpeRecord.FactDrugList)
{
if (dsr.isEqualRow(y, BeginTime, addDragRowHeight))
{
record.Add(dsr);
}
}
if (record.Count > 0)
{
List<FactDrug> records = new List<FactDrug>();
foreach (var fact in record)
{
if (fact.ParentId == 0)
{
records.Add(fact);
foreach (var item in myOpeRecord.FactDrugList)
{
if (item.ParentId == fact.Id)
{
records.Add(item);
}
}
}
else
{
foreach (var item in myOpeRecord.FactDrugList)
{
if (item.Id == fact.ParentId || item.ParentId == fact.ParentId)
{
records.Add(item);
}
}
}
}
if (records.Count > 0)
myOpeRecord.SpeedyDrugsMethod(records);
}
}
}
}
public override void KeyUp(ZedGraphControl sender, KeyEventArgs e)
{
}
#endregion
#region
public override void Bind()
{
aSyncTip = TipBox.CreateInstance("async");
init();
DrawDrug();
}
/// <summary>
/// 画加药
/// </summary>
private void DrawDrug()
{
try
{
foreach (FactDrug temp in myOpeRecord.FactDrugList)
{
if (isSapDrugs(temp))
{
temp.clearAddObj(ZedControl);
}
}
reDrawDrug();
}
catch (Exception exp)
{
PublicMethod.WriteLog(exp);
}
}
/// <summary>
/// 重新画加药文本
/// </summary>
private void reDrawDrug()
{
try
{
//画在第几行
int rowDrugsIndex = 0;
//y的高度//主要高度
double drugsy = 0;
//加药最后位置
double maxDrugsy = sapPpack.RealEndY;
//持续加药当前时间
DateTime curTimeTemp = OperationRecord.getOpeMaxTime(myOpeRecord);
DateTime serverTime = DateTime.Now;
if (curTimeTemp > serverTime) curTimeTemp = serverTime;
//超出的药画备注 镇痛药备注
List<string> SapListstr = new List<string>();
SapListstr.Add("【手术用液】");
myOpeRecord.BeforeDrugs = "";
myOpeRecord.AnalgesiaDrug = "";
//当前时间段加药集合
myOpeRecord.FactDrugList.ForEach(drug =>
{
if (drug.IsContinue == 1 && drug.DrugBeginTime == drug.DrugEndTime) drug.End = curTimeTemp;
else if (drug.DrugEndTime != null) drug.End = drug.DrugEndTime;
});
List<FactDrug> _FactDrugList = myOpeRecord.FactDrugList.Where(s => IfInTimeExist(s.DrugBeginTime, s.End) == true).ToList();
//加药按加药时间排序
_FactDrugList.Sort(new FactDrugComparer());
for (int i = 0; i < _FactDrugList.Count; i++)
{
FactDrug temp = _FactDrugList[i];
if (temp.GiveDrugType == "麻醉前用药" || temp.GiveDrugType == "术后镇痛药" || temp.DrugChannel == "备用" ||temp.DrugChannel == "配药"|| temp.Access == "下") continue;// || temp.GiveDrugType == "麻醉诱导用药"
//子药不画
if (temp.ParentId > 0) continue;
bool isEqual = false;
bool isChildEqual = false;
if (isSapDrugs(temp))
{
//以行号返回具休的位置
drugsy = sapPpack.RealY + getYPositionByListIndex(rowDrugsIndex, sapPpack.RealY, sapPpack.RealEndY, RowsCount);
SetDrug(temp, curTimeTemp, drugsy);
temp.ChildFactDrugList = new List<FactDrug>();
temp.ChildFactDrugList = _FactDrugList.Where(a => a.ParentId == temp.Id).ToList();
//判断是否重复的 主药或组药
for (int j = 0; j < i; j++)
{
FactDrug addDrug1 = _FactDrugList[j];
if (addDrug1.ChildFactDrugList == null) addDrug1.ChildFactDrugList = new List<FactDrug>();
//如果加药品ID相同并且加加药ID不同则认为加了同一种加药
if (addDrug1.Equal(temp) && temp.ParentId == 0 && addDrug1.ParentId == 0 && addDrug1.ChildFactDrugList.Count == 0 && temp.ChildFactDrugList.Count == 0)
{
addDrug1.clearDNAndDT(ZedControl);
//因为相同则取得相同对象的Y,为当前的对象的高度
drugsy = addDrug1.nowY;
isEqual = true;
continue;
}
else if (addDrug1.Equal(temp) && temp.ChildFactDrugList != null && addDrug1.ChildFactDrugList != null && EqualChildDrugs(temp.ChildFactDrugList, addDrug1.ChildFactDrugList))
{
isChildEqual = true;
TimeSpan tsp = temp.DrugBeginTime - addDrug1.DrugBeginTime;
//清除画图对象的名称及总药
addDrug1.clearDNAndDT(ZedControl);
drugsy = addDrug1.nowY;
if (drugsy <= maxDrugsy)
temp.drawText(H3pack.RealX + 0.006f, drugsy);
else
ListAddDrugs(SapListstr, i, temp);
foreach (FactDrug item in temp.ChildFactDrugList)
{
foreach (FactDrug addDrug1item in addDrug1.ChildFactDrugList)
{
//如果加药品ID相同并且加加药ID不同则认为加了同一种加药
if (addDrug1item.Equal(item))
{
SetDrug(item, curTimeTemp, drugsy);
//清除画图对象的名称及总药
addDrug1item.clearDNAndDT(ZedControl);
////因为相同则取得相同对象的Y,为当前的对象的高度
drugsy = addDrug1item.nowY;
if (drugsy <= maxDrugsy)
item.drawText(H3pack.RealX + 0.006f, drugsy);
else
ListAddDrugs(SapListstr, i, item);
continue;
}
}
}
break;
}
}
if (isChildEqual == true) continue;
if (drugsy <= maxDrugsy)
{
temp.drawText(H3pack.RealX + 0.006f, drugsy);
if (isEqual == false)
rowDrugsIndex++;
}
else
ListAddDrugs(SapListstr, i, temp);
if (temp.ChildFactDrugList.Count > 0)
{
foreach (FactDrug sItem in temp.ChildFactDrugList)
{
drugsy = sapPpack.RealY + getYPositionByListIndex(rowDrugsIndex, sapPpack.RealY, sapPpack.RealEndY, RowsCount);
SetDrug(sItem, curTimeTemp, drugsy);
if (drugsy <= maxDrugsy)
{
sItem.drawText(H3pack.RealX + 0.006f, drugsy);
rowDrugsIndex++;
}
else { ListAddDrugs(SapListstr, i, sItem); }
}
if (drugsy <= maxDrugsy)
DrawZuDragsLine(H3pack.RealX + 0.003f, drugsy, temp.nowY, temp);
}
}
}
myOpeRecord.SapsListstr = SapListstr;
}
catch (Exception ex)
{
throw ex;
}
}
public bool EqualChildDrugs(List<FactDrug> childDrugs, List<FactDrug> secondchildDrugs)
{
bool b = false;
foreach (var item in childDrugs)
{
bool istrue = false;
foreach (var secitem in secondchildDrugs)
{
if (secitem.Equal(item))
{
istrue = true;
}
}
if (istrue == true)
{
b = true;
}
else
{
b = false;
break;
}
}
return b;
}
private void DrawZuDragsLine(double x, double y, double zhuy, FactDrug temp)
{
double height = getYPositionByListIndex(1, sapPpack.RealY, sapPpack.RealEndY, RowsCount) / 2;
ZUtil.DrawLine2(x, zhuy + height, x, y + height, ZedControl, "zhuyDrugs" + temp.Id, Color.Red);
ZUtil.DrawLine2(x, zhuy + height, x + 0.0055f, zhuy + height, ZedControl, "zhuyDrugstop" + temp.Id, Color.Red);
ZUtil.DrawLine2(x, y + height, x + 0.0055f, y + height, ZedControl, "zhuyDrugsend" + temp.Id, Color.Red);
}
private void SetDrug(FactDrug temp, DateTime curTimeTemp, double y)
{
if (temp.IsContinue == 1 && temp.DrugBeginTime == temp.DrugEndTime) temp.End = curTimeTemp;
temp.EqualDose = null;
temp.setAnasArr(ZedControl, H5pack.RealX, sapPpack.RealEndX, myOpeRecord.PageBegin, myOpeRecord.PageBegin.AddMinutes(EVERY_PAGE_TIME_SPAN));
temp.nowY = y;
}
private static void ListAddDrugs(List<string> DrugListstr, int i, FactDrug temp)
{
string dose = "";
if (temp.Density != 0)
{
dose += ((double)temp.Density).ToString();
if (temp.DensityUnit != null)
{
dose += temp.DensityUnit;
}
}
if (dose.Trim() != "") dose += " ";
if (temp.Velocity != 0)
{
dose += ((double)temp.Velocity).ToString();
if (temp.VelocityUnit != null)
{
dose += temp.VelocityUnit;
}
}
if (dose.Trim() != "") dose += " ";
if (temp.Dosage != 0)
{
dose += ((double)temp.Dosage).ToString();
if (temp.DosageUnit != null)
{
dose += temp.DosageUnit;
}
}
DrugListstr.Add(string.Format("({0}){1} {2} {3}{4}{5}", i + 1, (temp.DrugBeginTime == temp.DrugEndTime) ? temp.DrugBeginTime.ToShortTimeString() : temp.DrugBeginTime.ToShortTimeString() + "->" + temp.DrugEndTime.ToShortTimeString(), temp.DrugName.Trim(), dose, "", temp.DrugChannel == null ? "" : " " + temp.DrugChannel.ToString()));
//DrugListstr.Append(" ");
}
private bool isSapDrugs(FactDrug record)
{
bool isSap = false;
if (record.DrugChannel != null && record.DrugChannel == "ivgtt")
{
if (record.DosageUnit != null && record.DosageUnit.ToLower() == "ml")
{
if (record.Dosage >= 50)
{
isSap = true;
}
}
if (record.BloodType != null && record.BloodType != "")
{
isSap = true;
}
}
return isSap;
}
/// <summary>
/// 返回是否进入加药范围
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private bool isAddDrugRange(ZedGraphControl sender, double x, double y)
{
bool reValue = false;
if (y > lines.RealY && y < lines.RealEndY)
{
if (x > H3pack.RealX && x < lines.RealEndX)
{
reValue = true;
}
}
return reValue;
}
private DateTime reDrugsTime(ZedGraphControl sender, MouseEventArgs e)
{
try
{
double x, x2;
double[] y;
double[] y2;
//double yTemp = ZedControl.Height * lines.RealEndY + 80;
PointF mousePt = new PointF(e.X, 1000);
ZedGraphControl sender1 = sender as ZedGraphControl;
GraphPane pane = sender1.MasterPane.FindChartRect(mousePt);
if (pane != null)
{
pane.ReverseTransform(mousePt, out x, out x2, out y, out y2);
XDate xd = new XDate(x);
return xd.DateTime;
}
else
{
return DateTime.Now;
}
}
catch (Exception)
{
return DateTime.Now;
}
}
#endregion
#region
private bool IfInTimeExist(DateTime Begin, DateTime End)
{
DateTime lastime = myOpeRecord.lastPageBegin.AddSeconds(59);
bool b = false;
if (End == null)
{
if (Begin > myOpeRecord.PageBegin && Begin < lastime)
{
b = true;
}
}
else
{
if (Begin >= myOpeRecord.PageBegin && Begin <= lastime)
{
b = true;
}
else if (End >= myOpeRecord.PageBegin && End <= lastime)
{
b = true;
}
else if (Begin < myOpeRecord.PageBegin && End > lastime)
{
b = true;
}
}
return b;
}
/// <summary>
/// 根据顶部加药序号确定数值生命体征的纵向位置以1为单位
/// </summary>
/// <param name="index"></param>
/// <returns></returns>
public double getYPositionByListIndex(double index, double yTop, double yBottom, int rowCount)
{
double heightT = ZedControl.Height * (yBottom - yTop);
double setpTemp = heightT / rowCount;
//求一格在实际高度中的百分比
double bfb = (setpTemp / heightT);
//两线之间度*百分比得到一格的百分比高度
double ygBFB = (yBottom - yTop) * bfb;
double y = ygBFB * index;
return y;
}
#endregion
}
}