Ignore:
Timestamp:
Jul 7, 2010, 4:51:54 PM (14 years ago)
Author:
Kevin Toppenberg
Message:

Upgrading to version 27

File:
1 edited

Legend:

Unmodified
Added
Removed
  • cprs/trunk/CPRS-Chart/fMHTest.pas

    r456 r830  
    55uses
    66  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
    7   StdCtrls, ExtCtrls, ORCtrls, ORFn, uConst;
     7  StdCtrls, ExtCtrls, ORCtrls, ORFn, uConst, fBase508Form, uDlgComponents,
     8  VA508AccessibilityManager, uCore, orNet, TRPCB, StrUtils, rCore, VAUtils;
    89
    910type
    10   TfrmMHTest = class(TForm)
     11TShowProc = procedure(Broker: TRPCBroker;
     12  InstrumentName,
     13  PatientDFN,
     14  OrderedBy,
     15  OrderedByDUZ,
     16  AdministeredBy,
     17  AdministeredByDUZ,
     18  Location,
     19  LocationIEN: string;
     20  Required: boolean;
     21  var ProgressNote: string); stdcall;
     22
     23TSaveProc = procedure(Broker: TRPCBroker;
     24  InstrumentName,
     25  PatientDFN,
     26  OrderedByDUZ,
     27  AdministeredByDUZ,
     28  AdminDate,
     29  LocationIEN: string;
     30  var Status: string); stdcall;
     31
     32TRemoveTempFile = procedure(
     33  InstrumentName,
     34  PatientDFN: string); stdcall;
     35
     36TCloseProc = procedure;
     37
     38TUsedMHDll = record
     39  Checked: boolean;
     40  Display: boolean;
     41end;
     42
     43type
     44  TfrmMHTest = class(TfrmBase508Form)
    1145    sbMain: TScrollBox;
    1246    pnlBottom: TPanel;
     
    2761    FObjs: TList;
    2862    FInfoText: string;
    29     FInfoLabel: TMemo;
     63    FInfoLabel: TMentalHealthMemo;
    3064    FBuilt: boolean;
    3165    FMaxLines: integer;
     
    4074  MHTestComp: string;
    4175  MHA3: boolean;
    42   end;
    43 
    44 function PerformMHTest(InitialAnswers, TestName: string; QText: TStringList): string;
    45 
     76  function CallMHDLL(TestName: string; Required: boolean): String;
     77  end;
     78
     79function PerformMHTest(InitialAnswers, TestName: string; QText: TStringList; Required: boolean): string;
     80function SaveMHTest(TestName, Date, Loc: string): boolean;
     81procedure RemoveMHTest(TestName: string);
     82function CheckforMHDll: boolean;
     83procedure CloseMHDLL;
     84
     85var
     86  MHDLLHandle: THandle = 0;
     87 
    4688implementation
    4789
    48 uses rReminders;
     90uses fFrame,rReminders, VA508AccessibilityRouter;
    4991
    5092{$R *.DFM}
     
    63105  Gap = 2;
    64106
     107  ShowProc                    : TShowProc = nil;
     108  SaveProc                    : TSaveProc = nil;
     109  RemoveTempFile              : TRemoveTempFile = nil;
     110  CloseProc                  : TCloseProc = nil;
     111  SHARE_DIR = '\VISTA\Common Files\';
    65112var
    66113  frmMHTest: TfrmMHTest;
    67114  FFirstCtrl: TList;
    68115  FYPos: TList;
     116  UsedMHDll: TUsedMHDll;
     117  //DLLForceClose: boolean = false;
    69118
    70119type
     
    117166end;
    118167
    119 function PerformMHTest(InitialAnswers, TestName: string; QText: TStringList): string;
     168function PerformMHTest(InitialAnswers, TestName: string; QText: TStringList; Required: boolean): string;
     169var
     170str,scores, tempStr: string;
    120171begin
    121172  Result := InitialAnswers;
     173  str := frmMHTest.CallMHDLL(testName, Required);
     174  if str <> '' then
     175    begin
     176      if Piece(str,U,1) = 'COMPLETE' then
     177        begin
     178         Scores := Piece(str, U, 4);
     179         if QText <> nil then
     180           begin
     181             tempStr := Piece(Str, U, 5);
     182             if Pos('GAF Score', tempStr) = 0 then tempStr := Copy(tempStr, 2, Length(tempStr));
     183             tempStr := AnsiReplaceStr(tempStr,'1156','Response not required due to responses to other questions.');
     184             tempStr := AnsiReplaceStr(tempStr,'*','~~');
     185             PiecesToList(tempStr,'~',QText);
     186           end;
     187         Result := 'New MH dll^COMPLETE^'+ Scores;
     188        end
     189      else if Piece(str,U,1) = 'INCOMPLETE' then
     190        begin
     191          Result := 'New MH dll^INCOMPLETE^';
     192        end
     193      else if (Piece(str,U,1) = 'CANCELLED') or (Piece(str, U, 1) = 'NOT STARTED') then
     194        begin
     195          Result := 'New MH dll^CANCELLED^';
     196        end;
     197      frmMHTest.Free;
     198      exit;
     199    end;
    122200  frmMHTest := TfrmMHTest.Create(Application);
    123201  try
     
    142220    frmMHTest.Free;
    143221  end;
     222end;
     223
     224function SaveMHTest(TestName, date, Loc: string): boolean;
     225var
     226  MHPath, save: string;
     227 
     228begin
     229  MHPath := GetProgramFilesPath + SHARE_DIR + 'YS_MHA';
     230  if MHDLLHandle = 0 then
     231    MHDLLHandle := LoadLibrary(PChar(MHPath));
     232  Result := true;
     233  if MHDLLHandle = 0 then
     234    begin
     235      InfoBox('YS_MHA.DLL not available', 'Error', MB_OK);
     236      Exit;
     237    end
     238  else
     239    begin
     240      try
     241        @SaveProc := GetProcAddress(MHDLLHandle, 'SaveInstrument');
     242
     243        if @SaveProc = nil then
     244          begin
     245          // function not found.. misspelled?
     246            infoBox('Save Instrument Function not found within YS_MHA.DLL.', 'Error', MB_OK);
     247            Exit;
     248          end;
     249
     250        if Assigned(SaveProc) then
     251         begin
     252//          fFrame.frmFrame.DLLActive := True;
     253          try
     254            SaveProc(RPCBrokerV,
     255            UpperCase(TestName), //InstrumentName
     256            Patient.DFN, //PatientDFN
     257            InttoStr(User.duz), //OrderedByDUZ
     258            InttoStr(User.duz), //AdministeredByDUZ
     259            date,
     260            Loc, //LocationIEN
     261            save);
     262          finally
     263//            fFrame.frmFrame.DLLActive := false;
     264            if RPCBrokerV.CurrentContext <> 'OR CPRS GUI CHART' then
     265               begin
     266                 if RPCBrokerV.CreateContext('OR CPRS GUI CHART') = false then
     267                    infoBox('Error switching broker context','Error', MB_OK);
     268               end;
     269          end;  {inner try..finally}
     270         end;
     271      finally
     272        if MHDLLHandle <> 0 then
     273        begin
     274          FreeLibrary(MHDLLHandle);
     275          MHDLLHandle := 0;
     276        end;
     277      end; {try..finally}
     278  end;
     279end;
     280
     281procedure RemoveMHTest(TestName: string);
     282var
     283  MHPath: string;
     284begin
     285  MHPath := GetProgramFilesPath + SHARE_DIR + 'YS_MHA';
     286  if MHDLLHandle = 0 then
     287    MHDLLHandle := LoadLibrary(PChar(MHPath));
     288  if MHDLLHandle = 0 then
     289    begin
     290      InfoBox('YS_MHA.DLL not available', 'Error', MB_OK);
     291      Exit;
     292    end
     293  else
     294    begin
     295      try
     296        @RemoveTempFile := GetProcAddress(MHDLLHandle, 'RemoveTempFile');
     297
     298        if @RemoveTempFile = nil then
     299          begin
     300          // function not found.. misspelled?
     301            InfoBox('Remove Temp File function not found within YS_MHA.DLL.', 'Error', MB_OK);
     302            Exit;
     303          end;
     304
     305        if Assigned(RemoveTempFile) then
     306         begin
     307//          fFrame.frmFrame.DLLActive := True;
     308          try
     309            RemoveTempFile(UpperCase(TestName), //InstrumentName
     310            Patient.DFN);
     311          finally
     312//            fFrame.frmFrame.DLLActive := False;
     313            if RPCBrokerV.CurrentContext <> 'OR CPRS GUI CHART' then
     314               begin
     315                 if RPCBrokerV.CreateContext('OR CPRS GUI CHART') = false then
     316                    infoBox('Error switching broker context','Error', MB_OK);
     317               end;
     318          end;  {inner try..finally}
     319         end;
     320      finally
     321        if MHDLLHandle <> 0 then
     322        begin
     323          FreeLibrary(MHDLLHandle);
     324          MHDLLHandle := 0;
     325        end;
     326      end; {try..finally}
     327  end;
     328end;
     329
     330function CheckforMHDll: boolean;
     331var
     332  MHPath: string;
     333begin
     334  Result := True;
     335    if (UsedMHDll.Checked = True) and (UsedMHDll.Display = False) then Exit
     336  else if UsedMHDll.Checked = false then
     337    begin
     338      UsedMHDll.Display := UsedMHDllRPC;
     339      UsedMHDll.Checked := True;
     340      if UsedMHDll.Display = false then
     341        begin
     342          Result := False;
     343          exit;
     344        end;
     345    end;
     346  if MHDLLHandle = 0 then // if not 0 the DLL already loaded - result = true
     347  begin
     348    MHPath := GetProgramFilesPath + SHARE_DIR + 'YS_MHA';
     349    MHDLLHandle := LoadLibrary(PChar(MHPath));
     350    if MHDLLHandle = 0 then
     351      Result := false
     352    else
     353    begin
     354      FreeLibrary(MHDLLHandle);
     355      MHDLLHandle := 0;
     356    end;
     357  end;
     358end;
     359
     360procedure CloseMHDLL;
     361begin
     362  if MHDLLHandle = 0 then Exit;
     363  try
     364    @CloseProc := GetProcAddress(MHDLLHandle, 'CloseDLL');
     365    if Assigned(CloseProc) then
     366    begin
     367      CloseProc;
     368    end;
     369  finally
     370    if MHDLLHandle <> 0 then
     371    begin
     372      FreeLibrary(MHDLLHandle);
     373      MHDLLHandle := 0;
     374    end;
     375  end; {try..finally}
    144376end;
    145377
     
    250482  TstData := TStringList.Create;
    251483  try
    252     TstData.Assign(LoadMentalHealthTest(TestName));
     484    FastAssign(LoadMentalHealthTest(TestName), TstData);
    253485    if TstData.Strings[0] = '1' then MHA3 := True
    254486    else MHA3 := False;
     
    360592  end;
    361593  if(not Result) then
    362     ShowMessage('Error encountered loading ' + TestName)
     594    InfoBox('Error encountered loading ' + TestName, 'Error', MB_OK)
    363595  else
    364596  begin
     
    407639     if(not assigned(FInfoLabel)) then
    408640      begin
    409         FInfoLabel := TMemo.Create(Self);
     641        FInfoLabel := TMentalHealthMemo.Create(Self);
    410642        FInfoLabel.Color := clBtnFace;
    411643        FInfoLabel.BorderStyle := bsNone;
    412644        FInfoLabel.ReadOnly := TRUE;
    413         FInfoLabel.TabStop := FALSE;
     645        FInfoLabel.TabStop := ScreenReaderSystemActive;
    414646        FInfoLabel.Parent := sbMain;
    415647        FInfoLabel.WordWrap := TRUE;
    416648        FInfoLabel.Text := FInfoText;
    417649        FInfoLabel.Left := Gap;
     650        UpdateColorsFor508Compliance(FInfoLabel);
    418651      end;
    419652      BoundsRect := FInfoLabel.BoundsRect;
     
    439672    end;
    440673  end;
     674  amgrMain.RefreshComponents;
    441675end;
    442676
     
    455689  for i := 0 to FObjs.Count-1 do
    456690    QText.Add(copy(IntToStr(i+1) + '.      ', 1, lx) + TMHQuestion(FObjs[i]).Question);
     691end;
     692
     693function TfrmMHTest.CallMHDLL(TestName: string; Required: boolean): String;
     694var                               
     695//  dllHandle                   : THandle;
     696  ProgressNote, MHPath                : string;
     697begin
     698  ProgressNote := '';
     699  if (UsedMHDll.Checked = True) and (UsedMHDll.Display = False) then Exit
     700  else if UsedMHDll.Checked = false then
     701    begin
     702      UsedMHDll.Display := UsedMHDllRPC;
     703      UsedMHDll.Checked := True;
     704      if UsedMHDll.Display = false then exit;
     705    end;
     706  MHPath := GetProgramFilesPath + SHARE_DIR + 'YS_MHA';
     707  if MHDLLHandle = 0 then
     708    MHDLLHandle := LoadLibrary(PChar(MHPath));
     709  Result := '';
     710  if MHDLLHandle = 0 then
     711    begin
     712      InfoBox('YS_MHA.dll not available.' + CRLF + 'CPRS will continue processing the MH test using the previous format.' +
     713                  CRLF + CRLF + 'Contact IRM to install the YS_MHA.dll file on this machine.', 'Warning', MB_OK);
     714      Exit;
     715    end
     716  else
     717    begin
     718      try
     719        @ShowProc := GetProcAddress(MHDLLHandle, 'ShowInstrument');
     720
     721        if @ShowProc = nil then
     722          begin
     723          // function not found.. misspelled?
     724            InfoBox('Function ShowInstrument not found within YS_MHA.DLL not available', 'Error', MB_OK);
     725            Exit;
     726          end;
     727
     728        if Assigned(ShowProc) then
     729           begin
     730//             MHDLLHandle := dllHandle;
     731             Result := '';
     732//             fFrame.frmFrame.DLLActive := True;
     733             try
     734               ShowProc(RPCBrokerV,
     735               UpperCase(TestName), //InstrumentName
     736               Patient.DFN, //PatientDFN
     737               '', //OrderedByName
     738               InttoStr(User.duz), //OrderedByDUZ
     739               User.Name, //AdministeredByName
     740               InttoStr(User.duz), //AdministeredByDUZ
     741               Encounter.LocationName, //Location
     742               InttoStr(Encounter.Location), //LocationIEN
     743               Required,
     744               ProgressNote);
     745               Result := ProgressNote;
     746           finally
     747//             MHDllHandle := 0;
     748//             fFrame.frmFrame.DLLActive := false;
     749             if RPCBrokerV.CurrentContext <> 'OR CPRS GUI CHART' then
     750               begin
     751                 if RPCBrokerV.CreateContext('OR CPRS GUI CHART') = false then
     752                    infoBox('Error switching broker context','Error', MB_OK);
     753                end;
     754               end; {inner try ..finally}
     755            end;
     756      finally
     757        if MHDLLHandle <> 0 then
     758        begin
     759          FreeLibrary(MHDLLHandle);
     760          MHDllHandle := 0;
     761        end;
     762      end; {try..finally}
     763      //Result := ProgressNote;
     764  end;
    457765end;
    458766
     
    502810  Shift: TShiftState);
    503811begin
     812  inherited;
    504813  if Key = VK_PRIOR then
    505814  begin
     
    520829var
    521830  RCombo: TComboBox;
    522   LNLbl, RLbl: TMemo;
     831  LNLbl, RLbl: TMentalHealthMemo;
    523832  Bvl: TBevel;
    524833  cb: TORCheckBox;
     
    556865    if(FText <> '') then
    557866    begin
    558       RLbl := TMemo(GetCtrl(QuestionLabelTag));
     867      RLbl := TMentalHealthMemo(GetCtrl(QuestionLabelTag));
    559868      if(not assigned(RLbl)) then
    560869      begin
    561         RLbl := TMemo.Create(frmMHTest);
     870        RLbl := TMentalHealthMemo.Create(frmMHTest);
    562871        RLbl.Color := clBtnFace;
    563872        RLbl.BorderStyle := bsNone;
    564873        RLbl.ReadOnly := TRUE;
    565         RLbl.TabStop := FALSE;
     874        RLbl.TabStop := ScreenReaderSystemActive;
    566875        RLbl.Parent := frmMHTest.sbMain;
    567876        RLbl.Tag := FID + QuestionLabelTag;
     
    569878        RLbl.Text := FText;
    570879        FObjects.Add(RLbl);
     880        UpdateColorsFor508Compliance(RLbl);
    571881      end;
    572882      BoundsRect.Top := Y;
     
    596906  if(frmMHTest.FObjs.Count >= NumberThreshhold) then
    597907  begin
    598     LNLbl := TMemo(GetCtrl(LineNumberTag));
     908    LNLbl := TMentalHealthMemo(GetCtrl(LineNumberTag));
    599909    if(not assigned(LNLbl)) then
    600910    begin
    601       LNLbl := TMemo.Create(frmMHTest);
     911      LNLbl := TMentalHealthMemo.Create(frmMHTest);
    602912      LNLbl.Color := clBtnFace;
    603913      LNLbl.BorderStyle := bsNone;
    604914      LNLbl.ReadOnly := TRUE;
    605       LNLbl.TabStop := FALSE;
     915      LNLbl.TabStop := ScreenReaderSystemActive;
    606916      LNLbl.Parent := frmMHTest.sbMain;
    607917      LNLbl.Tag := FID + LineNumberTag;
    608918      LNLbl.Text := IntToStr(QNum+1) + '.';
     919      if ScreenReaderSystemActive then
     920        frmMHTest.amgrMain.AccessText[LNLbl] := 'Question';     
    609921      LNLbl.Width := TextWidthByFont(LNLbl.Font.Handle, LNLbl.Text);
    610922      LNLbl.Height := TextHeightByFont(LNLbl.Font.Handle, LNLbl.Text);
    611923      FObjects.Add(LNLbl);
     924      UpdateColorsFor508Compliance(LNLbl);
    612925    end;
    613926    LNLbl.Top := Y;
     
    625938    Bvl.Shape := bsFrame;
    626939    FObjects.Add(Bvl);
     940    UpdateColorsFor508Compliance(Bvl);
    627941  end;
    628942  Bvl.Top := Y;
     
    660974        cb.Caption := Piece(frmMHTest.FAnswers[FAnswerIndex + idx], U, 2);
    661975        FObjects.Add(cb);
     976        UpdateColorsFor508Compliance(cb);
    662977      end;
    663978      cb.Top := Y;
     
    6921007      RCombo.Width := MaxDX + 24;
    6931008      RCombo.OnChange := OnChange;
     1009      UpdateColorsFor508Compliance(RCombo);
    6941010    end;
    6951011    RCombo.Top := Y;
Note: See TracChangeset for help on using the changeset viewer.