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

📄 patientexplorer.pas

📁 PatientRunner 20 Source
💻 PAS
📖 第 1 页 / 共 4 页
字号:
begin
  try
    for i:=ScalesListView.Items.Count-1 downto 0 do
    begin
      if Assigned(ScalesListView.Items[i].Data) then Dispose(PScaleRecord(ScalesListView.Items[i].Data));
      ScalesListView.Items.Delete(i);
    end;
  finally
    ScalesListView.Clear;
  end;
end;

procedure TPatientExplorerForm.ScalesListViewClick(Sender: TObject);
var ScalesListViewnotEmpty: boolean;
begin
  ScalesListViewnotEmpty:=Boolean(ScalesListView.Items.Count>0);

  EditScale.Enabled:=ScalesListViewnotEmpty;
  EditScaleMenuItem.Enabled:=ScalesListViewnotEmpty;
  DeleteScale.Enabled:=ScalesListViewnotEmpty;
  DeleteScaleMenuItem.Enabled:=ScalesListViewnotEmpty;

  if not ScalesListViewnotEmpty then Exit;

  if ScalesListView.ItemFocused=nil then
  begin
    ScalesListView.Selected:=ScalesListView.TopItem;
    ScalesListView.ItemFocused:=ScalesListView.TopItem;
  end;

  if not Assigned(ScalesListView.ItemFocused.Data) then Exit;

  with PScaleRecord(ScalesListView.ItemFocused.Data)^ do
  begin
    ScalesListView.ItemFocused.Caption:=FormatDateTime('dd mmm yy', ScaleDate);
    ScalesListView.ItemFocused.SubItems[0]:=Description;
    ScalesListView.ItemFocused.SubItems[1]:=Result;
  end;
end;

procedure TPatientExplorerForm.NewScaleClick(Sender: TObject);
begin
  with ScaleEditorForm do
  begin
    NewRecord:=True;
    DescriptionEdit.Text:='';
    ResultEdit.Text:='';
    DatePicker.Date:=Now;
    ShowModal;
  end;
end;

procedure TPatientExplorerForm.EditScaleClick(Sender: TObject);
begin
  if ScalesListView.Items.Count<=0 then Exit;
  if ScalesListView.ItemFocused=nil then Exit;
  if not Assigned(ScalesListView.ItemFocused.Data) then Exit;

  with PScaleRecord(ScalesListView.ItemFocused.Data)^ do
  begin
    with ScaleEditorForm do
    begin
      NewRecord:=False;
      DescriptionEdit.Text:=Description;
      ResultEdit.Text:=Result;
      DatePicker.Date:=Date;
      ShowModal;
    end;
  end; //with PScaleRecord
end;

procedure TPatientExplorerForm.DeleteScaleClick(Sender: TObject);
begin
  if ScalesListView.Items.Count<=0 then Exit;
  if ScalesListView.ItemFocused=nil then Exit;
  if not Assigned(ScalesListView.ItemFocused.Data) then Exit;

  if PScaleRecord(ScalesListView.ItemFocused.Data)^.Author<>
    MainForm.SQLConnection.Params.Values['User_Name'] then
  begin
    MessageDlg('Unable to delete - You are not the author of this scale', mtError, [mbOk], 0);
    Exit;
  end;

  if MessageDlg('Are you sure you want to delete the selected scale?',
                mtConfirmation, [mbYes, mbNo], 0) <> mrYes then Exit;

  //This will first dispose record from item then delete item from list
  //Efficient - No db refresh necessary since item is removed from list

  with SQLQuery do
  begin
    SQL.Clear;
    SQL.Add('delete from scales where scaleid='+
            inttostr(PScaleRecord(ScalesListView.ItemFocused.Data)^.ScaleID) );
    ExecSQL;
  end;

  Dispose(PScaleRecord(ScalesListView.ItemFocused.Data));
  ScalesListView.ItemFocused.Delete;

  ScalesListViewClick(Sender);
end;

procedure TPatientExplorerForm.RefreshScalesDBClick(Sender: TObject);
var ScaleRecordPtr: PScaleRecord;
    SelectedScaleIDHolder, i: integer;
    Save_Cursor: TCursor;
begin
  Save_Cursor:=Screen.Cursor;
  Screen.Cursor:=crSQLWait;

  SelectedScaleIDHolder:=-1;
  if ScalesListView.ItemFocused<>nil then
  begin
    if Assigned(ScalesListView.ItemFocused.Data) then
      SelectedScaleIDHolder:=PScaleRecord(ScalesListView.ItemFocused.Data)^.ScaleID;
  end;

  //Destroy old list
  ScalesListView.Items.BeginUpdate;

  CleanUpScalesListView;

  with SQLQuery do
  begin
    SQL.Clear;

    SQL.Add('select * from scales where patientid='+InttoStr(PPatientRecord(MainForm.PatientListView.ItemFocused.Data)^.PatientID) );

    Open;
    First;
    while (not EOF) do
    begin
      new(ScaleRecordPtr);
      with ScaleRecordPtr^ do
      begin
        ScaleID:=FieldByName('scaleid').AsInteger;
        PatientID:=FieldByName('patientid').AsInteger;
        Description:=FieldByName('description').AsString;
        Result:=FieldByName('result').AsString;
        ScaleDate:=StrtoDateTime(FieldByName('scaledate').AsString);
        Author:=FieldByName('author').AsString;
        with ScalesListView.Items.Add do
        begin
          Caption:=FormatDateTime('dd mmm yy', Date);
          SubItems.Add(Description);
          SubItems.Add(Result);
          Data:=TObject(ScaleRecordPtr);
        end;
      end;
      Next;
    end;
    Close;
  end;
  ScalesListView.Items.EndUpdate;
  Screen.Cursor := Save_Cursor;

  if (SelectedScaleIDHolder=-1) or (ScalesListView.Items.Count<=0) then
  begin
    ScalesListViewClick(Sender);
    Exit;
  end;

  for i:=0 to ScalesListView.Items.Count-1 do
  begin
    if PScaleRecord(ScalesListView.Items[i].Data)^.ScaleID = SelectedScaleIDHolder then
    begin
      ScalesListView.Selected := ScalesListView.Items[i];
      ScalesListView.ItemFocused := ScalesListView.Items[i];
      Break;
    end;
  end;

  ScalesListViewClick(Sender);
end;

{-----------------------------------------------------
Diagnoses DB
------------------------------------------------------}

procedure TPatientExplorerForm.CleanUpDiagnosesListView;
var i: integer;
begin
  try
    for i:=DiagnosesListView.Items.Count-1 downto 0 do
    begin
      if Assigned(DiagnosesListView.Items[i].Data) then Dispose(PDiagnosisRecord(DiagnosesListView.Items[i].Data));
      DiagnosesListView.Items.Delete(i);
    end;
  finally
    DiagnosesListView.Clear;
  end;
end;

procedure TPatientExplorerForm.DiagnosesListViewCustomDrawItem(
  Sender: TCustomListView; Item: TListItem; State: TCustomDrawState;
  var DefaultDraw: Boolean);
begin
  //This procedure is called when a diagnosis is drawn to the listview box.
  //If the diagnosis has been resolved, a strike through line is present
  //to alert the clinician of old diagnoses.

  if PDiagnosisRecord(Item.Data)^.Resolved then
    Sender.Canvas.Font.Style:=[fsStrikeOut]
  else
    Sender.Canvas.Font.Style:=[];
end;

procedure TPatientExplorerForm.DiagnosesListViewClick(Sender: TObject);
var DiagnosesListViewnotEmpty: Boolean;
begin
  DiagnosesListViewnotEmpty:=Boolean(DiagnosesListView.Items.Count>0);

  EditDiagnosis.Enabled:=DiagnosesListViewnotEmpty;
  EditDiagnosisMenuItem.Enabled:=DiagnosesListViewnotEmpty;
  DeleteDiagnosis.Enabled:=DiagnosesListViewnotEmpty;
  DeleteDiagnosisMenuItem.Enabled:=DiagnosesListViewnotEmpty;

  if not DiagnosesListViewnotEmpty then Exit;

  if DiagnosesListView.ItemFocused=nil then
  begin
    DiagnosesListView.Selected:=DiagnosesListView.TopItem;
    DiagnosesListView.ItemFocused:=DiagnosesListView.TopItem;
  end;

  if not Assigned(DiagnosesListView.ItemFocused.Data) then Exit;

  with PDiagnosisRecord(DiagnosesListView.ItemFocused.Data)^ do
  begin
    DiagnosesListView.ItemFocused.Caption:=Diagnosis;
  end;
end;

procedure TPatientExplorerForm.NewDiagnosisClick(Sender: TObject);
begin
  with DiagnosisEditorForm do
  begin
    NewRecord:=True;
    DiagnosisEdit.Text:='';
    StartDatePicker.Date:=Now;
    EndDatePicker.Date:=Now;
    ResolvedCheckBox.Checked:=False;
    ShowModal;
  end;
end;

procedure TPatientExplorerForm.EditDiagnosisClick(Sender: TObject);
begin
  if DiagnosesListView.Items.Count<=0 then Exit;
  if DiagnosesListView.ItemFocused=nil then Exit;
  if not Assigned(DiagnosesListView.ItemFocused.Data) then Exit;

  with PDiagnosisRecord(DiagnosesListView.ItemFocused.Data)^ do
  begin
    with DiagnosisEditorForm do
    begin
      NewRecord:=False;
      DiagnosisEdit.Text:=Diagnosis;
      StartDatePicker.Date:=StartDate;
      EndDatePicker.Date:=EndDate;
      ResolvedCheckBox.Checked:=Resolved;
      ShowModal;
    end;
  end;
end;

procedure TPatientExplorerForm.DeleteDiagnosisClick(Sender: TObject);
begin
  if DiagnosesListView.Items.Count<=0 then Exit;
  if DiagnosesListView.ItemFocused=nil then Exit;
  if not Assigned(DiagnosesListView.ItemFocused.Data) then Exit;

  if PDiagnosisRecord(DiagnosesListView.ItemFocused.Data)^.Author<>
    MainForm.SQLConnection.Params.Values['User_Name'] then
  begin
    MessageDlg('Unable to delete - You are not the author of this diagnosis', mtError, [mbOk], 0);
    Exit;
  end;

  if MessageDlg('Are you sure you want to delete the selected diagnosis?',
                mtConfirmation, [mbYes, mbNo], 0) <> mrYes then Exit;

  with SQLQuery do
  begin
    SQL.Clear;
    SQL.Add('delete from diagnoses where diagnosisid='+
            inttostr(PDiagnosisRecord(DiagnosesListView.ItemFocused.Data)^.DiagnosisID) );
    ExecSQL;
  end;

  Dispose(PDiagnosisRecord(DiagnosesListView.ItemFocused.Data));
  DiagnosesListView.ItemFocused.Delete;

  DiagnosesListViewClick(Sender);
end;

procedure TPatientExplorerForm.RefreshDiagnosesDBClick(Sender: TObject);
var DiagnosisRecordPtr: PDiagnosisRecord;
    SelectedDiagnosisIDHolder, i: integer;
    Save_Cursor: TCursor;
begin
  Save_Cursor:=Screen.Cursor;
  Screen.Cursor:=crSQLWait;

  SelectedDiagnosisIDHolder:=-1;
  if DiagnosesListView.ItemFocused<>nil then
  begin
    if Assigned(DiagnosesListView.ItemFocused.Data) then
      SelectedDiagnosisIDHolder:=PDiagnosisRecord(DiagnosesListView.ItemFocused.Data)^.DiagnosisID;
  end;

  DiagnosesListView.Items.BeginUpdate;

  CleanUpDiagnosesListView;

  with SQLQuery do
  begin
    SQL.Clear;

    SQL.Add('select * from diagnoses where patientid='+InttoStr(PPatientRecord(MainForm.PatientListView.ItemFocused.Data)^.PatientID)+' order by resolved, startdate');

    Open;
    First;
    while (not EOF) do
    begin
      new(DiagnosisRecordPtr);
      with DiagnosisRecordPtr^ do
      begin
        DiagnosisID:=FieldByName('diagnosisid').AsInteger;
        PatientID:=FieldByName('patientid').AsInteger;
        Diagnosis:=FieldByName('diagnosis').AsString;
        StartDate:=StrtoDateTime(FieldByName('startdate').AsString);
        EndDate:=StrtoDateTime(FieldByName('enddate').AsString);
        Resolved:=Boolean(FieldByName('resolved').AsInteger);
        Author:=FieldByName('author').AsString;
        with DiagnosesListView.Items.Add do
        begin
          Caption:=Diagnosis;
          Data:=TObject(DiagnosisRecordPtr);
        end;
      end;
      Next;
    end;
    Close;
  end;
  DiagnosesListView.Items.EndUpdate;
  Screen.Cursor := Save_Cursor;

  if (SelectedDiagnosisIDHolder=-1) or (DiagnosesListView.Items.Count<=0) then
  begin
    DiagnosesListViewClick(Sender);
    Exit;
  end;

  for i:=0 to DiagnosesListView.Items.Count-1 do
  begin
    if PDiagnosisRecord(DiagnosesListView.Items[i].Data)^.DiagnosisID = SelectedDiagnosisIDHolder then
    begin
      DiagnosesListView.Selected := DiagnosesListView.Items[i];
      DiagnosesListView.ItemFocused := DiagnosesListView.Items[i];
      Break;
    end;
  end;

  DiagnosesListViewClick(Sender);
end;

{-----------------------------------------------------
Medications DB
------------------------------------------------------}

procedure TPatientExplorerForm.CleanUpMedicationsListView;
var i: integer;
begin
  try
    for i:=MedicationsListView.Items.Count-1 downto 0 do
    begin
      if Assigned(MedicationsListView.Items[i].Data) then Dispose(PMedicationRecord(MedicationsListView.Items[i].Data));
      MedicationsListView.Items.Delete(i);
    end;
  finally
    MedicationsListView.Clear;
  end;
end;

procedure TPatientExplorerForm.MedicationsListViewCustomDrawItem(
  Sender: TCustomListView; Item: TListItem; State: TCustomDrawState;
  var DefaultDraw: Boolean);
begin
  //This procedure is called when a medication is drawn to the listview box.
  //If the medication has been discontinued, a strike through line is present
  //to alert the clinician of meds that have been tried in the past.

  if PMedicationRecord(Item.Data)^.Discontinued then
    Sender.Canvas.Font.Style:=[fsStrikeOut]
  else
    Sender.Canvas.Font.Style:=[];
end;

procedure TPatientExplorerForm.MedicationsListViewClick;
var MedicationsListViewnotEmpty: boolean;
begin
  MedicationsListViewnotEmpty:=Boolean(MedicationsListView.Items.Count>0);

  EditMedication.Enabled:=MedicationsListViewnotEmpty;
  EditMedMenuItem.Enabled:=MedicationsListViewnotEmpty;
  DeleteMedication.Enabled:=MedicationsListViewnotEmpty;
  DeleteMedMenuItem.Enabled:=MedicationsListViewnotEmpty;

  if not MedicationsListViewnotEmpty then Exit;

  if MedicationsListView.ItemFocused=nil then
  begin
    MedicationsListView.Selected:=MedicationsListView.TopItem;
    MedicationsListView.ItemFocused:=MedicationsListView.TopItem;
  end;

  if not Assigned(MedicationsListView.ItemFocused.Data) then Exit;

  with PMedicationRecord(MedicationsListView.ItemFocused.Data)^ do
  begin
    if Discontinued then
      MedicationsListView.ItemFocused.Caption:=Prescription+' '+AgetoStr(StartDate, EndDate)
    else
      MedicationsListView.ItemFocused.Caption:=Prescription+' '+AgetoStr(StartDate, Now() );
  end;
end;

procedure TPatientExplorerForm.NewMedicationClick(Sender: TObject);
begin
  with MedicationEditorForm do
  begin
    NewRecord:=True;
    PrescriptionEdit.Text:='';
    StartDatePicker.Date:=Now;
    EndDatePicker.Date:=Now;
    DiscontinuedCheckBox.Checked:=False;
    ShowModal;

⌨️ 快捷键说明

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