📄 patienteditor.pas
字号:
{ *************************************************************************** }
{ }
{ PatientRunner }
{ }
{ Copyright (c) 2002-2005 IgD Software, LLC }
{ }
{ This file may be distributed and/or modified under the terms of the GNU }
{ General Public License (GPL) version 2 as published by the Free Software }
{ Foundation and appearing at http://www.gnu.org/licenses/gpl.html. }
{ }
{ *************************************************************************** }
unit PatientEditor;
interface
uses
SysUtils, Classes, Controls, Forms,
Dialogs, StdCtrls, ComCtrls, DB, FMTBcd, SqlExpr;
type
TPatientEditorForm = class(TForm)
OKButton: TButton;
CancelButton: TButton;
Label1: TLabel;
Label2: TLabel;
Label3: TLabel;
Label4: TLabel;
Label6: TLabel;
Label5: TLabel;
Label7: TLabel;
Label8: TLabel;
Label9: TLabel;
LastnameEdit: TEdit;
FirstnameEdit: TEdit;
SSNEdit: TEdit;
MaleCheckBox: TCheckBox;
BirthdatePicker: TDateTimePicker;
RateEdit: TEdit;
ServiceComboBox: TComboBox;
PayDatePicker: TDateTimePicker;
CommandEdit: TEdit;
POCEdit: TEdit;
StatusComboBox: TComboBox;
Label10: TLabel;
Label11: TLabel;
AllergiesEdit: TEdit;
InactiveCheckBox: TCheckBox;
SQLQuery: TSQLQuery;
RankEdit: TEdit;
Label12: TLabel;
procedure CancelButtonClick(Sender: TObject);
procedure OKButtonClick(Sender: TObject);
procedure NumberEditKeyPress(Sender: TObject; var Key: Char);
procedure SSNEditKeyPress(Sender: TObject; var Key: Char);
procedure PayDatePickerChange(Sender: TObject);
procedure BirthdatePickerChange(Sender: TObject);
procedure FormShow(Sender: TObject);
private
FNewRecord: boolean;
procedure SetNewRecord(const Value: boolean);
{ Private declarations }
public
//If NewRecord is true then perform INSERT SQL query
//if not then perform REPLACE SQL query
property NewRecord: boolean read FNewRecord write SetNewRecord;
end;
var
PatientEditorForm: TPatientEditorForm;
implementation
uses Main;
{$R *.dfm}
procedure TPatientEditorForm.CancelButtonClick(Sender: TObject);
begin
if MessageDlg('Exit without saving changes?', mtConfirmation, [mbYes, mbNo], 0) = mrYes then
Close;
end;
procedure TPatientEditorForm.OKButtonClick(Sender: TObject);
//var PatientRecordPtr: PPatientRecord;
begin
LastnameEdit.Text:=TrimRight(LastnameEdit.Text);
FirstnameEdit.Text:=TrimRight(FirstnameEdit.Text);
SSNEdit.Text:=TrimRight(SSNEdit.Text);
if (LastnameEdit.Text='') or (FirstnameEdit.Text='') or (SSNEdit.Text='') then
begin
MessageDlg('You must enter a valid Lastname, Firstname and SSN to save this record!', mtError,
[mbOk], 0);
Exit;
end;
DateSeparator := '/';
ShortDateFormat := 'yyyy/mm/dd';
LongTimeFormat:='hh:nn:ss';
with SQLQuery do
begin
SQL.Clear;
Params.Clear;
if FNewRecord then
begin
//new(PatientRecordPtr);
//with PatientRecordPtr^ do
//begin
// Lastname:=LastnameEdit.Text;
// Firstname:=FirstnameEdit.Text;
// SSN:=SSNEdit.Text;
// Birthday:=BirthDatePicker.Date;
// Status:=StatusComboBox.Text;
// IsMale:=MaleCheckBox.Checked;
// Rate:=RateEdit.Text;
// Rank:=RankEdit.Text;
// Service:=ServiceComboBox.Text;
// PayDate:=PayDatePicker.Date;
// Command:=CommandEdit.Text;
// POC:=POCEdit.Text;
// Allergies:=AllergiesEdit.Text;
// Inactive:=InactiveCheckBox.Checked;
// Author:=MainForm.SQLConnection.Params.Values['User_Name'];
// LastSeenDateTime:=Now;}
SQL.Text:='insert into patients (lastname, firstname, ssn, birthday, status, sex, rate, rank, service, paydate, command, poc, allergies, inactive, author, lastseendatetime)'
+' values (:lastname, :firstname, :ssn, :birthday, :status, :sex, :rate, :rank, :service, :paydate, :command, :poc, :allergies, :inactive, :author, :lastseendatetime)';
Params[0].AsString:=LastnameEdit.Text;
Params[1].AsString:=FirstnameEdit.Text;
Params[2].AsString:=SSNEdit.Text;
Params[3].AsString:=DatetoStr(BirthDatePicker.Date);
Params[4].AsString:=StatusComboBox.Text;
Params[5].AsString:=InttoStr(Integer(MaleCheckBox.Checked) );
Params[6].AsString:=RateEdit.Text;
Params[7].AsString:=RankEdit.Text;
Params[8].AsString:=ServiceComboBox.Text;
Params[9].AsString:=DatetoStr(PayDatePicker.Date);
Params[10].AsString:=CommandEdit.Text;
Params[11].AsString:=POCEdit.Text;
Params[12].AsString:=AllergiesEdit.Text;
Params[13].AsString:=IntToStr(Integer(InactiveCheckBox.Checked) );
Params[14].AsString:=MainForm.SQLConnection.Params.Values['User_Name'];
Params[15].AsString:=DateTimetoStr(Now);
ExecSql;
//whether or not record is new insert or update we need to redraw the screen
MainForm.RefreshPatientsDBClick(Sender);
//We just inserted a new note at the top of the list, now we must select
//it before screen is redrawn
MainForm.PatientListView.Selected:=MainForm.PatientListView.TopItem;
MainForm.PatientListView.ItemFocused:=MainForm.PatientListView.TopItem;
//Note ideally you would add item to list after MySQL insert
//Then you would use select last_insert_id() to get auto_increment variable PatientID
//problem is select last_insert_id() always returns 0
//suspect this has to do with per connection basis of select command
//work-around is to refresh entire patient DB
//Below is some code that could theoretically return the last_insert_id()
//SQL.Clear;
//SQL.Text:='select last_insert_id() from patients'; //from patients limit 1
//Open;
//First;
//PatientID:=Fields[0].AsInteger;
//showmessage(inttostr(PatientId));
//Here is the code that could be used to add to the patient list on
//the main form including the data pointer
//with MainForm.PatientListBox.Items.Insert(0) do
//begin
// Caption:=Lastname+', '+Firstname+' '+SSN;
// SubItems.Add(FormatDateTime('dd mmm yy', LastSeenDate) );
// SubItems.Add(Author);
// Data:=TObject(PatientRecordPtr);
//end;
//end; //with PatientRecordPtr
end
else
begin //update item
with PPatientRecord(MainForm.PatientListView.ItemFocused.Data)^ do
begin
Lastname:=LastnameEdit.Text;
Firstname:=FirstnameEdit.Text;
SSN:=SSNEdit.Text;
Birthday:=BirthDatePicker.Date;
Status:=StatusComboBox.Text;
IsMale:=MaleCheckBox.Checked;
Rate:=RateEdit.Text;
Rank:=RankEdit.Text;
Service:=ServiceComboBox.Text;
PayDate:=PayDatePicker.Date;
Command:=CommandEdit.Text;
POC:=POCEdit.Text;
Allergies:=AllergiesEdit.Text;
Inactive:=InactiveCheckBox.Checked;
end;
SQL.Text:='update patients set lastname=:lastname, firstname=:firstname, ssn=:ssn, birthday=:birthday, status=:status, sex=:sex, '
+'rate=:rate, rank=:rank, service=:service, paydate=:paydate, command=:command, poc=:poc, allergies=:allergies, '
+'inactive=:inactive where patientid=:patientid';
Params[0].AsString:=LastnameEdit.Text;
Params[1].AsString:=FirstnameEdit.Text;
Params[2].AsString:=SSNEdit.Text;
Params[3].AsString:=DatetoStr(BirthdatePicker.Date);
Params[4].AsString:=StatusComboBox.Text;
Params[5].AsString:=InttoStr(Integer(MaleCheckBox.Checked));
Params[6].AsString:=RateEdit.Text;
Params[7].AsString:=RankEdit.Text;
Params[8].AsString:=ServiceComboBox.Text;
Params[9].AsString:=DatetoStr(PayDatePicker.Date);
Params[10].AsString:=CommandEdit.Text;
Params[11].AsString:=POCEdit.Text;
Params[12].AsString:=AllergiesEdit.Text;
Params[13].AsString:=IntToStr(Integer(InactiveCheckBox.Checked));
Params[14].AsString:=InttoStr(PPatientRecord(MainForm.PatientListView.ItemFocused.Data)^.PatientID);
//Author will not change
//LastSeen will not change
ExecSql;
//whether or not record is new insert or update we need to redraw the screen
MainForm.RefreshPatientsDBClick(Sender);
end;
end;
Close; //Close form
end;
procedure TPatientEditorForm.SetNewRecord(const Value: boolean);
begin
FNewRecord := Value;
end;
procedure TPatientEditorForm.NumberEditKeyPress(Sender: TObject;
var Key: Char);
begin
if Key In ['0'..'9', #8] Then // #8 = backspace
inherited
Else
Key := #0;
end;
procedure TPatientEditorForm.SSNEditKeyPress(Sender: TObject;
var Key: Char);
begin
if Key In ['0'..'9', '-', '/', #8] Then // #8 = backspace
inherited
else
Key := #0;
end;
procedure TPatientEditorForm.PayDatePickerChange(Sender: TObject);
begin
Label7.Caption:='Pay Entry Base Date ('+AgetoStr(PayDatePicker.Date, Now() )+')';
end;
procedure TPatientEditorForm.BirthdatePickerChange(Sender: TObject);
begin
Label4.Caption:='Birthday ('+AgetoStr(BirthdatePicker.Date, Now() )+')';
end;
procedure TPatientEditorForm.FormShow(Sender: TObject);
begin
ActiveControl:=LastnameEdit;
end;
end.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -