

I am posting the code Below for all
I hope OD finds it useful
Thanks all
Code: Select all
using System;
using System.Drawing;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.Windows.Forms;
using OpenDental.UI;
using OpenDentBusiness;
namespace OpenDental
{
///<summary></summary>
public class FormRxSelect : ODForm
{
private OpenDental.UI.Button butCancel;
private OpenDental.UI.Button butOK;
private System.Windows.Forms.Label labelInstructions;
private OpenDental.UI.Button butBlank;
private System.ComponentModel.Container components = null;// Required designer variable.
private Patient PatCur;
private OpenDental.UI.ODGrid gridMain;
private RxDef[] RxDefList;
private TextBox textSearch;
private Label label1;
private TextBox textBox1;
/// <summary>This is set for any medical orders that are selected.</summary>
public long _medOrderNum;
///<summary></summary>
public FormRxSelect(Patient patCur)
{
InitializeComponent();// Required for Windows Form Designer support
PatCur = patCur;
Lan.F(this);
}
///<summary></summary>
protected override void Dispose(bool disposing)
{
if (disposing)
{
if (components != null)
{
components.Dispose();
}
}
base.Dispose(disposing);
}
#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(FormRxSelect));
this.butCancel = new OpenDental.UI.Button();
this.butOK = new OpenDental.UI.Button();
this.labelInstructions = new System.Windows.Forms.Label();
this.butBlank = new OpenDental.UI.Button();
this.gridMain = new OpenDental.UI.ODGrid();
this.textSearch = new System.Windows.Forms.TextBox();
this.label1 = new System.Windows.Forms.Label();
this.textBox1 = new System.Windows.Forms.TextBox();
this.SuspendLayout();
//
// butCancel
//
this.butCancel.AdjustImageLocation = new System.Drawing.Point(0, 0);
this.butCancel.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
this.butCancel.Autosize = true;
this.butCancel.BtnShape = OpenDental.UI.enumType.BtnShape.Rectangle;
this.butCancel.BtnStyle = OpenDental.UI.enumType.XPStyle.Silver;
this.butCancel.CornerRadius = 4F;
this.butCancel.DialogResult = System.Windows.Forms.DialogResult.Cancel;
this.butCancel.Location = new System.Drawing.Point(1009, 630);
this.butCancel.Name = "butCancel";
this.butCancel.Size = new System.Drawing.Size(90, 30);
this.butCancel.TabIndex = 3;
this.butCancel.Text = "&Cancel";
this.butCancel.Click += new System.EventHandler(this.butCancel_Click);
//
// butOK
//
this.butOK.AdjustImageLocation = new System.Drawing.Point(0, 0);
this.butOK.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
this.butOK.Autosize = true;
this.butOK.BtnShape = OpenDental.UI.enumType.BtnShape.Rectangle;
this.butOK.BtnStyle = OpenDental.UI.enumType.XPStyle.Silver;
this.butOK.CornerRadius = 4F;
this.butOK.Location = new System.Drawing.Point(898, 630);
this.butOK.Name = "butOK";
this.butOK.Size = new System.Drawing.Size(90, 30);
this.butOK.TabIndex = 2;
this.butOK.Text = "&OK";
this.butOK.Click += new System.EventHandler(this.butOK_Click);
//
// labelInstructions
//
this.labelInstructions.Location = new System.Drawing.Point(10, 9);
this.labelInstructions.Name = "labelInstructions";
this.labelInstructions.Size = new System.Drawing.Size(564, 19);
this.labelInstructions.TabIndex = 15;
this.labelInstructions.Text = "Please select a Prescription from the list or click Blank to start with a blank p" +
"rescription.";
//
// butBlank
//
this.butBlank.AdjustImageLocation = new System.Drawing.Point(0, 0);
this.butBlank.Autosize = true;
this.butBlank.BtnShape = OpenDental.UI.enumType.BtnShape.Rectangle;
this.butBlank.BtnStyle = OpenDental.UI.enumType.XPStyle.Silver;
this.butBlank.CornerRadius = 4F;
this.butBlank.Location = new System.Drawing.Point(437, 4);
this.butBlank.Name = "butBlank";
this.butBlank.Size = new System.Drawing.Size(90, 30);
this.butBlank.TabIndex = 0;
this.butBlank.Text = "&Blank";
this.butBlank.Click += new System.EventHandler(this.butBlank_Click);
//
// gridMain
//
this.gridMain.HasAddButton = false;
this.gridMain.HasMultilineHeaders = false;
this.gridMain.HeaderHeight = 15;
this.gridMain.HScrollVisible = false;
this.gridMain.Location = new System.Drawing.Point(14, 43);
this.gridMain.Name = "gridMain";
this.gridMain.ScrollValue = 0;
this.gridMain.Size = new System.Drawing.Size(1094, 676);
this.gridMain.TabIndex = 16;
this.gridMain.Title = "Prescriptions";
this.gridMain.TitleHeight = 18;
this.gridMain.TranslationName = "TableRxSetup";
this.gridMain.CellDoubleClick += new OpenDental.UI.ODGridClickEventHandler(this.gridMain_CellDoubleClick);
//
// textSearch
//
this.textSearch.Location = new System.Drawing.Point(590, 10);
this.textSearch.Name = "textSearch";
this.textSearch.Size = new System.Drawing.Size(212, 20);
this.textSearch.TabIndex = 17;
this.textSearch.TextChanged += new System.EventHandler(this.textSearch_TextChanged);
//
// label1
//
this.label1.AutoSize = true;
this.label1.Location = new System.Drawing.Point(543, 15);
this.label1.Name = "label1";
this.label1.Size = new System.Drawing.Size(41, 13);
this.label1.TabIndex = 18;
this.label1.Text = "Search";
//
// textBox1
//
this.textBox1.Location = new System.Drawing.Point(824, 10);
this.textBox1.Name = "textBox1";
this.textBox1.Size = new System.Drawing.Size(212, 20);
this.textBox1.TabIndex = 19;
this.textBox1.TextChanged += new System.EventHandler(this.textBox1_TextChanged);
//
// FormRxSelect
//
this.CancelButton = this.butCancel;
this.ClientSize = new System.Drawing.Size(1121, 674);
this.Controls.Add(this.textBox1);
this.Controls.Add(this.label1);
this.Controls.Add(this.textSearch);
this.Controls.Add(this.gridMain);
this.Controls.Add(this.butBlank);
this.Controls.Add(this.labelInstructions);
this.Controls.Add(this.butCancel);
this.Controls.Add(this.butOK);
this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon")));
this.MaximizeBox = false;
this.MinimizeBox = false;
this.MinimumSize = new System.Drawing.Size(120, 115);
this.Name = "FormRxSelect";
this.ShowInTaskbar = false;
this.Text = "Select Prescription";
this.Load += new System.EventHandler(this.FormRxSelect_Load);
this.ResumeLayout(false);
this.PerformLayout();
}
#endregion
private void FormRxSelect_Load(object sender, System.EventArgs e)
{
FillGrid();
if (PrefC.GetBool(PrefName.ShowFeatureEhr))
{
//We cannot allow blank prescription when using EHR, because each prescription created in this window must have an RxCui.
//If we allowed blank, we would not know where to pull the RxCui from.
butBlank.Visible = false;
labelInstructions.Text = "Please select a Prescription from the list.";
}
}
private void FillGrid()
{
if (textSearch.Text.Trim().Length > 0)
{
string searchText = textSearch.Text.Trim().ToUpper();
List<RxDef> tempList = new List<RxDef>();
foreach (RxDef rx in RxDefs.Refresh())
{
if (rx.Drug.ToUpper().Contains(searchText) || rx.Disp.ToUpper().Contains(searchText) || rx.Notes.ToUpper().Contains(searchText)
|| rx.Refills.ToUpper().Contains(searchText) || rx.Sig.ToUpper().Contains(searchText))
tempList.Add(rx);
}
RxDefList = tempList.ToArray();
}
else
RxDefList = RxDefs.Refresh();
gridMain.BeginUpdate();
gridMain.Columns.Clear();
ODGridColumn col = new ODGridColumn(Lan.g("TableRxSetup", "Drug"), 140);
gridMain.Columns.Add(col);
col = new ODGridColumn(Lan.g("TableRxSetup", "Controlled"), 70, HorizontalAlignment.Center);
gridMain.Columns.Add(col);
col = new ODGridColumn(Lan.g("TableRxSetup", "Sig"), 250);
gridMain.Columns.Add(col);
col = new ODGridColumn(Lan.g("TableRxSetup", "Disp"), 70);
gridMain.Columns.Add(col);
col = new ODGridColumn(Lan.g("TableRxSetup", "Refills"), 70);
gridMain.Columns.Add(col);
col = new ODGridColumn(Lan.g("TableRxSetup", "Notes"), 300);
gridMain.Columns.Add(col);
gridMain.Rows.Clear();
ODGridRow row;
for (int i = 0; i < RxDefList.Length; i++)
{
row = new ODGridRow();
row.Cells.Add(RxDefList[i].Drug);
if (RxDefList[i].IsControlled)
{
row.Cells.Add("X");
}
else
{
row.Cells.Add("");
}
row.Cells.Add(RxDefList[i].Sig);
row.Cells.Add(RxDefList[i].Disp);
row.Cells.Add(RxDefList[i].Refills);
row.Cells.Add(RxDefList[i].Notes);
gridMain.Rows.Add(row);
}
gridMain.EndUpdate();
}
private void gridMain_CellDoubleClick(object sender, OpenDental.UI.ODGridClickEventArgs e)
{
RxSelected();
}
private void RxSelected()
{
if (gridMain.GetSelectedIndex() == -1)
{
//this should never happen
return;
}
RxDef RxDefCur = RxDefList[gridMain.GetSelectedIndex()];
if (PrefC.GetBool(PrefName.ShowFeatureEhr) && RxDefCur.RxCui == 0)
{
string strMsgText = Lan.g(this, "The selected prescription is missing an RxNorm") + ".\r\n"
+ Lan.g(this, "Prescriptions without RxNorms cannot be exported in EHR documents") + ".\r\n"
+ Lan.g(this, "Edit RxNorm in Rx Template?");
if (MsgBox.Show(this, true, strMsgText))
{
FormRxDefEdit form = new FormRxDefEdit(RxDefCur);
form.ShowDialog();
RxDefCur = RxDefs.GetOne(RxDefCur.RxDefNum);//FormRxDefEdit does not modify the RxDefCur object, so we must get the updated RxCui from the db.
}
}
//Alert
if (!RxAlertL.DisplayAlerts(PatCur.PatNum, RxDefCur.RxDefNum))
{
return;
}
//User OK with alert
RxPat RxPatCur = new RxPat();
RxPatCur.RxDate = DateTime.Today;
RxPatCur.PatNum = PatCur.PatNum;
RxPatCur.Drug = RxDefCur.Drug;
RxPatCur.IsControlled = RxDefCur.IsControlled;
RxPatCur.Sig = RxDefCur.Sig;
RxPatCur.Disp = RxDefCur.Disp;
RxPatCur.Refills = RxDefCur.Refills;
if (PrefC.GetBool(PrefName.RxSendNewToQueue))
{
RxPatCur.SendStatus = RxSendStatus.InElectQueue;
}
else
{
RxPatCur.SendStatus = RxSendStatus.Unsent;
}
//Notes not copied: we don't want these kinds of notes cluttering things
FormRxEdit FormE = new FormRxEdit(PatCur, RxPatCur);
FormE.IsNew = true;
FormE.ShowDialog();
if (FormE.DialogResult != DialogResult.OK)
{
return;
}
bool isProvOrder = false;
if (Security.CurUser.ProvNum != 0)
{//The user who is currently logged in is a provider.
isProvOrder = true;
}
_medOrderNum = MedicationPats.InsertOrUpdateMedOrderForRx(RxPatCur, RxDefCur.RxCui, isProvOrder);//RxDefCur.RxCui can be 0.
EhrMeasureEvent newMeasureEvent = new EhrMeasureEvent();
newMeasureEvent.DateTEvent = DateTime.Now;
newMeasureEvent.EventType = EhrMeasureEventType.CPOE_MedOrdered;
newMeasureEvent.PatNum = PatCur.PatNum;
newMeasureEvent.MoreInfo = "";
newMeasureEvent.FKey = _medOrderNum;
EhrMeasureEvents.Insert(newMeasureEvent);
DialogResult = DialogResult.OK;
}
private void butBlank_Click(object sender, System.EventArgs e)
{
RxPat RxPatCur = new RxPat();
RxPatCur.RxDate = DateTime.Today;
RxPatCur.PatNum = PatCur.PatNum;
if (PrefC.GetBool(PrefName.RxSendNewToQueue))
{
RxPatCur.SendStatus = RxSendStatus.InElectQueue;
}
else
{
RxPatCur.SendStatus = RxSendStatus.Unsent;
}
FormRxEdit FormE = new FormRxEdit(PatCur, RxPatCur);
FormE.IsNew = true;
FormE.ShowDialog();
if (FormE.DialogResult != DialogResult.OK)
{
return;
}
//We do not need to make a medical order here, because butBlank is not visible in EHR mode.
DialogResult = DialogResult.OK;
}
private void butCancel_Click(object sender, System.EventArgs e)
{
DialogResult = DialogResult.Cancel;
}
private void butOK_Click(object sender, System.EventArgs e)
{
if (gridMain.GetSelectedIndex() == -1)
{
if (PrefC.GetBool(PrefName.ShowFeatureEhr))
{
MsgBox.Show(this, "Please select Rx first.");
}
else
{
MsgBox.Show(this, "Please select Rx first or click Blank");
}
return;
}
RxSelected();
}
private void textSearch_TextChanged(object sender, EventArgs e)
{
FillGrid();
}
private void textBox1_TextChanged(object sender, EventArgs e)
{
bool isScrollSet = false;
for (int i = 0; i < gridMain.Rows.Count; i++)
{
gridMain.Rows[i].ColorBackG = Color.White;//set all rows back to white.
if (textBox1.Text == "")
{
continue;
}
for (int j = 0; j < gridMain.Columns.Count; j++)
{
if (gridMain.Rows[i].Cells[j].Text.ToUpper().Contains(textBox1.Text.ToUpper()))
{
gridMain.Rows[i].ColorBackG = Color.FromArgb(255, 255, 128);
if (!isScrollSet)
{//scroll to the first match in the list.
gridMain.ScrollToIndex(i);
isScrollSet = true;
}
break;//next row
}
}//end i
}//end i
gridMain.Invalidate();
}
}
}