⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 patientexplorer.pas

📁 PatientRunner 20 Source
💻 PAS
📖 第 1 页 / 共 4 页
字号:
{ *************************************************************************** }
{                                                                             }
{ 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.           }
{                                                                             }
{ *************************************************************************** }

{
V2.0 - In the patients and note tables, TDate and TTime fields were replaced
with TDateTime.  DictationPending and PleaseReview boolean variables to the
NoteRecord table.  Note editing controls were tweaked including new CheckBox
controls.  The screen updating and ListViewClick procedure were revamped.
Added OpenforEditing boolean in TNoteRecord for internal use.  A bug involving
the PreviousItem note pointer that resulted in sporadic access errors was fixed.
}

{ *************************************************************************** }

unit PatientExplorer;

interface

uses
  SysUtils, Classes, Controls, Forms,
  Dialogs, StdCtrls, ComCtrls, ExtCtrls, Menus, FMTBcd, DB, SqlExpr,
  ImgList, ToolWin, Graphics, ad3RichEdit, ad3SpellBase, ad3Spell, Main;

type
  PNoteRecord = ^TNoteRecord;
  TNoteRecord = record
    NoteID: integer;
    PatientID: integer;
    Description: string;
    NoteDateTime: TDateTime;
    NoteStringStream: TStringStream;
    DictationPending:  boolean;
    PleaseReview: boolean;
    Author: string;
    //The following variables are for internal use and not part of the DB
    //There are 3 possible states for notes:
    //1.  Note is brand new and would require a SQL insert (NewNote)
    //2.  Note already exists and has been changed (Modded) and is open for
    //    editing.  A SQL update would be needed.
    //3.  Note already exists, is open for editing but is unchanged.  Leave
    //    the note open but no SQL update needed.
    NewNote: boolean;
    Modded: boolean; //used instead of 'modified' to prevent confusion
    OpenforEditing: boolean; //it is possible for a note to be "open" but not modified
  end;

  PScaleRecord = ^TScaleRecord;
  TScaleRecord = record
    ScaleID: integer;
    PatientID: integer;
    Description: string;
    Result: string;
    ScaleDate: TDateTime;
    Author: string;
  end;

  PDiagnosisRecord = ^TDiagnosisRecord;
  TDiagnosisRecord = record
    DiagnosisID: integer;
    PatientID: integer;
    Diagnosis: string;
    StartDate: TDateTime;
    EndDate: TDateTime;
    Resolved: boolean;
    Author: string;
  end;

  PMedicationRecord = ^TMedicationRecord;
  TMedicationRecord = record
    MedicationID: integer;
    PatientID: integer;
    Prescription: string;
    StartDate: TDateTime;
    EndDate: TDateTime;
    Discontinued: boolean;
    Author: string;
  end;

  //The richedit control does not publish the OnDblClick event but it is there,
  //only protected.  Use an interposer class as below to make it public.
  //This commented out after addition of TAddictRichEdit for spelling
  //TRichedit = class( ComCtrls.Trichedit )
  //public
  //  property OnDblClick;
  //end;

  TPatientExplorerForm = class(TForm)
    BottomPanel: TPanel;
    StatusBar: TStatusBar;
    LeftSplitter: TSplitter;
    RightPanel: TPanel;
    RightSplitter: TSplitter;
    UpDownSplitter: TSplitter;
    NoteGroupBox: TGroupBox;
    NotesPopupMenu: TPopupMenu;
    NewNoteMenuItem: TMenuItem;
    EditNoteMenuItem: TMenuItem;
    DeleteNoteMenuItem: TMenuItem;
    N2: TMenuItem;
    Refresh: TMenuItem;
    DiagnosesPopupMenu: TPopupMenu;
    NewDiagnosisMenuItem: TMenuItem;
    EditDiagnosisMenuItem: TMenuItem;
    DeleteDiagnosisMenuItem: TMenuItem;
    MenuItem5: TMenuItem;
    MenuItem6: TMenuItem;
    MedsPopupMenu: TPopupMenu;
    NewMedMenuItem: TMenuItem;
    EditMedMenuItem: TMenuItem;
    DeleteMedMenuItem: TMenuItem;
    MenuItem11: TMenuItem;
    MenuItem12: TMenuItem;
    MainMenu: TMainMenu;
    Notes1: TMenuItem;
    Diagnoses1: TMenuItem;
    Medications2: TMenuItem;
    NewNote: TMenuItem;
    EditNote: TMenuItem;
    DeleteNote: TMenuItem;
    N1: TMenuItem;
    Refresh1: TMenuItem;
    NewDiagnosis: TMenuItem;
    EditDiagnosis: TMenuItem;
    DeleteDiagnosis: TMenuItem;
    N3: TMenuItem;
    Refresh2: TMenuItem;
    NewMedication: TMenuItem;
    EditMedication: TMenuItem;
    DeleteMedication: TMenuItem;
    N4: TMenuItem;
    RefreshMedsDB: TMenuItem;
    SQLQuery: TSQLQuery;
    NewfromTemplate1: TMenuItem;
    NewNotefromTemplate: TMenuItem;
    PrintDialog: TPrintDialog;
    PrinterSetupDialog: TPrinterSetupDialog;
    Print1: TMenuItem;
    PrintSetup: TMenuItem;
    PrintPreview: TMenuItem;
    Print: TMenuItem;
    PrintSetup2: TMenuItem;
    PrintPreview2: TMenuItem;
    Print2: TMenuItem;
    N5: TMenuItem;
    DisableHeaderandFooter2: TMenuItem;
    DisableHeaderandFooter: TMenuItem;
    Edit1: TMenuItem;
    Undo1: TMenuItem;
    N6: TMenuItem;
    Cut1: TMenuItem;
    Copy1: TMenuItem;
    Paste1: TMenuItem;
    N7: TMenuItem;
    Font1: TMenuItem;
    Save1: TMenuItem;
    Revert1: TMenuItem;
    N8: TMenuItem;
    PasteDiagnosesList1: TMenuItem;
    PasteMedicationsList1: TMenuItem;
    CoolBar1: TCoolBar;
    StandardToolBar: TToolBar;
    CutButton: TToolButton;
    CopyButton: TToolButton;
    PasteButton: TToolButton;
    UndoButton: TToolButton;
    ToolButton10: TToolButton;
    FontName: TComboBox;
    ToolButton11: TToolButton;
    FontSize: TEdit;
    UpDown1: TUpDown;
    ToolButton2: TToolButton;
    BoldButton: TToolButton;
    ItalicButton: TToolButton;
    UnderlineButton: TToolButton;
    ToolButton16: TToolButton;
    LeftAlign: TToolButton;
    CenterAlign: TToolButton;
    RightAlign: TToolButton;
    ToolButton20: TToolButton;
    BulletsButton: TToolButton;
    ToolBar1: TToolBar;
    Label7: TLabel;
    DescriptionEdit: TEdit;
    ToolBar2: TToolBar;
    ToolbarImages: TImageList;
    Undo2: TMenuItem;
    N9: TMenuItem;
    Cut2: TMenuItem;
    Copy2: TMenuItem;
    Paste2: TMenuItem;
    N10: TMenuItem;
    Font2: TMenuItem;
    N11: TMenuItem;
    N12: TMenuItem;
    Save2: TMenuItem;
    Revert2: TMenuItem;
    PatientInfoPanel: TPanel;
    Label1: TLabel;
    Label2: TLabel;
    Label3: TLabel;
    Label4: TLabel;
    Label5: TLabel;
    Label6: TLabel;
    N13: TMenuItem;
    PasteDiagnosesList2: TMenuItem;
    PasteMedicationsList2: TMenuItem;
    N14: TMenuItem;
    FontDialog: TFontDialog;
    Panel1: TPanel;
    NotesListView: TListView;
    Splitter1: TSplitter;
    ScalesListView: TListView;
    ScalesPopupMenu: TPopupMenu;
    NewScaleMenuItem: TMenuItem;
    EditScaleMenuItem: TMenuItem;
    DeleteScaleMenuItem: TMenuItem;
    MenuItem4: TMenuItem;
    MenuItem7: TMenuItem;
    RatingScales1: TMenuItem;
    NewScale: TMenuItem;
    EditScale: TMenuItem;
    DeleteScale: TMenuItem;
    N15: TMenuItem;
    Refresh3: TMenuItem;
    NoteRichEdit: TAddictRichEdit;
    AddictSpell31: TAddictSpell3;
    ools1: TMenuItem;
    Spelling1: TMenuItem;
    Spellcheckoptions1: TMenuItem;
    ToolButton1: TToolButton;
    SpellingButton: TToolButton;
    N16: TMenuItem;
    Spelling2: TMenuItem;
    DictationPendingCheckBox: TCheckBox;
    PleaseReviewCheckBox: TCheckBox;
    DiagnosesListView: TListView;
    MedicationsListView: TListView;
    procedure NotesListViewClick(Sender: TObject);
    procedure NewNoteClick(Sender: TObject);
    procedure EditNoteClick(Sender: TObject);
    procedure DeleteNoteClick(Sender: TObject);
    procedure RefreshNotesDBClick(Sender: TObject);
    procedure NewNotefromTemplateClick(Sender: TObject);

    procedure ScalesListViewClick(Sender: TObject);
    procedure NewScaleClick(Sender: TObject);
    procedure EditScaleClick(Sender: TObject);
    procedure DeleteScaleClick(Sender: TObject);
    procedure RefreshScalesDBClick(Sender: TObject);

    procedure DiagnosesListViewClick(Sender: TObject);
    procedure NewDiagnosisClick(Sender: TObject);
    procedure EditDiagnosisClick(Sender: TObject);
    procedure DeleteDiagnosisClick(Sender: TObject);
    procedure RefreshDiagnosesDBClick(Sender: TObject);

    procedure MedicationsListViewClick(Sender: TObject);
    procedure NewMedicationClick(Sender: TObject);
    procedure EditMedicationClick(Sender: TObject);
    procedure DeleteMedicationClick(Sender: TObject);
    procedure RefreshMedsDBClick(Sender: TObject);

    procedure FormShow(Sender: TObject);
    procedure PrintSetupClick(Sender: TObject);
    procedure PrintPreviewClick(Sender: TObject);
    procedure PrintClick(Sender: TObject);
    procedure FormCreate(Sender: TObject);
    procedure DisableHeaderandFooter2Click(Sender: TObject);
    procedure DisableHeaderandFooterClick(Sender: TObject);
    procedure FormClose(Sender: TObject; var Action: TCloseAction);
    procedure SaveNoteClick(Sender: TObject);
    procedure RevertNoteClick(Sender: TObject);
    procedure UndoClick(Sender: TObject);
    procedure CutClick(Sender: TObject);
    procedure CopyClick(Sender: TObject);
    procedure PasteClick(Sender: TObject);
    procedure SelectionChange(Sender: TObject);
    procedure FontClick(Sender: TObject);
    procedure FontNameChange(Sender: TObject);
    procedure FontSizeChange(Sender: TObject);
    procedure BoldButtonClick(Sender: TObject);
    procedure ItalicButtonClick(Sender: TObject);
    procedure UnderlineButtonClick(Sender: TObject);
    procedure BulletsButtonClick(Sender: TObject);
    procedure AlignButtonClick(Sender: TObject);
    procedure PasteDiagnosesListClick(Sender: TObject);
    procedure PasteMedicationsListClick(Sender: TObject);
    procedure NotesListViewCustomDrawItem(Sender: TCustomListView;
      Item: TListItem; State: TCustomDrawState; var DefaultDraw: Boolean);
    procedure Spelling1Click(Sender: TObject);
    procedure Spellcheckoptions1Click(Sender: TObject);
    procedure MedicationsListViewCustomDrawItem(Sender: TCustomListView;
      Item: TListItem; State: TCustomDrawState; var DefaultDraw: Boolean);
    procedure DiagnosesListViewCustomDrawItem(Sender: TCustomListView;
      Item: TListItem; State: TCustomDrawState; var DefaultDraw: Boolean);
  private
    PreviousItem: TListItem;
    FUpdating: boolean;
    procedure GetFontNames;
    function CurrText: TTextAttributes;
    procedure EnableNoteEditingControls;
    procedure DisableNoteEditingControls;
    procedure CleanUpNotesListView;
    procedure CleanUpScalesListView;
    procedure CleanUpDiagnosesListView;
    procedure CleanUpMedicationsListView;
  public
  end;

var
  PatientExplorerForm: TPatientExplorerForm;

implementation

uses TemplateManager, ScaleEditor, DiagnosisEditor, MedicationEditor,
     QuickReport, Windows, Messages;

{$R *.dfm}

procedure TPatientExplorerForm.EnableNoteEditingControls;
begin
  with DescriptionEdit do
  begin
    Color:=clWindow;
    ReadOnly:=False;
  end;
  DictationPendingCheckBox.Enabled:=True;
  PleaseReviewCheckBox.Enabled:=True;
  with NoteRichEdit do
  begin
    Color:=clWindow;
    ReadOnly:=False;
  end;
end;

procedure TPatientExplorerForm.DisableNoteEditingControls;
begin
  with DescriptionEdit do
  begin
    Color:=clBtnFace;
    ReadOnly:=True;
  end;
  DictationPendingCheckBox.Enabled:=False;
  PleaseReviewCheckBox.Enabled:=False;
  with NoteRichEdit do
  begin
    Color:=clBtnFace;
    ReadOnly:=True;
  end;
end;

procedure TPatientExplorerForm.CleanUpNotesListView;
var i: integer;
begin
  //Destroy old list
  try
    for i:=NotesListView.Items.Count-1 downto 0 do
    begin
      if Assigned(NotesListView.Items[i].Data) then
      begin
        PNoteRecord(NotesListView.Items[i].Data)^.NoteStringStream.Free;
        Dispose(PNoteRecord(NotesListView.Items[i].Data));
      end;
      NotesListView.Items.Delete(i);
    end;
  finally
    NotesListView.Clear;
  end;

  //Any time we delete notes, we need to reset the PreviousItem note pointer.
  //If the redraw procedure tries to access a pointer that pointed to one of
  //the deleted items, a nasty access error will trip.

  PreviousItem:=nil;
end;

procedure TPatientExplorerForm.NotesListViewCustomDrawItem(
  Sender: TCustomListView; Item: TListItem; State: TCustomDrawState;
  var DefaultDraw: Boolean);
begin
  //This procedure is called when the note description is drawn in the
  //list box control.  If it is modden, the color of the font is red to alert
  //the user of unsaved changes.

  if PNoteRecord(Item.Data)^.Modded then
  begin
    Sender.Canvas.Font.Style:=[fsBold];
    Sender.Canvas.Font.Color:=clRed;
  end
  else
  begin
    Sender.Canvas.Font.Style:=[];
    Sender.Canvas.Font.Color:=clBlack;
  end;
end;

procedure TPatientExplorerForm.NotesListViewClick(Sender: TObject);
var NotesListViewnotEmpty: boolean;
begin
  //For debugging
  //StatusBar.Panels[0].Text:='Description Modified: '+BooltoStr(DescriptionEdit.Modified)+' RichEdit Modified: '+BooltoStr(NoteRichEdit.Modified);

  NotesListViewnotEmpty:=Boolean(NotesListView.Items.Count>0);

  //First we need to update (enable/disable) the menu items on the edit menu
  EditNote.Enabled:=NotesListViewnotEmpty;
  EditNoteMenuItem.Enabled:=NotesListViewnotEmpty;
  DeleteNote.Enabled:=NotesListViewnotEmpty;
  DeleteNoteMenuItem.Enabled:=NotesListViewnotEmpty;

  //If no items exist, then reset all controls to default setting and exit
  if not NotesListViewnotEmpty then
  begin
    DescriptionEdit.Text:='';
    DictationPendingCheckBox.Checked:=False;
    PleaseReviewCheckBox.Checked:=False;
    NoteGroupBox.Caption:='Note Text';
    NoteRichEdit.Clear;
    DisableNoteEditingControls;
    Exit;
  end;

  //At this point, the list is populated with at least one item.  Now we check
  //and see if something is selected.  If not, we select the top item by default.
  if NotesListView.ItemFocused=nil then
  begin
    NotesListView.Selected:=NotesListView.TopItem;
    NotesListView.ItemFocused:=NotesListView.TopItem;
  end;

  //Check to make sure there is a pointer associated with the itme, if not exit

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -