//kt -- Modified with SourceScanner on 8/15/2007
unit uTIU;

interface

uses SysUtils, Classes, ORNet, ORFn, rCore, uCore, uConst, ORCtrls, ComCtrls, Controls;

type

  TEditNoteRec = record
    DocType: Integer;
    IsNewNote: boolean;
    Title: Integer;
    TitleName: string;
    DateTime: TFMDateTime;
    Author: Int64;
    AuthorName: string;
    Cosigner: Int64;
    CosignerName: string;
    Subject: string;
    Location: Integer;
    LocationName: string;
    VisitDate: TFMDateTime;
    PkgRef: string;      // 'IEN;GMR(123,' or 'IEN;SRF('
    PkgIEN: integer;     // file IEN
    PkgPtr: string;      // 'GMR(123,' or 'SRF(' 
    NeedCPT: Boolean;
    Addend: Integer;
    LastCosigner: Int64;
    LastCosignerName: string;
    IDParent: integer;
    ClinProcSummCode: integer;
    ClinProcDateTime: TFMDateTime;
    Lines: TStrings;
    PRF_IEN: integer;
    ActionIEN: string;
  end;

  TNoteRec = TEditNoteRec;

  TActionRec = record
    Success: Boolean;
    Reason: string;
  end;

  TCreatedDoc = record
    IEN: Integer;
    ErrorText: string;
  end;

  TTIUContext = record
    Changed: Boolean;
    BeginDate: string;
    EndDate: string;
    FMBeginDate: TFMDateTime;
    FMEndDate: TFMDateTime;
    Status: string;
    Author: int64;
    MaxDocs: integer;
    ShowSubject: Boolean;
    SortBy: string;
    ListAscending: Boolean;
    GroupBy: string;
    TreeAscending: Boolean;
    SearchField: string;
    KeyWord: string;
    Filtered: Boolean;
    SearchString: String;  // Text Search CQ: HDS00002856
  end ;

  TNoteTitles = class
    DfltTitle: Integer;
    DfltTitleName: string;
    ShortList: TStringList;
    //TX_SAVE_ERROR1 : string;  //kt
    //TX_SAVE_ERROR2 : string;  //kt
    //TC_SAVE_ERROR : string;  //kt
    constructor Create;
    destructor Destroy; override;
  end;

  TTIUPrefs = class
    DfltLoc: Integer;
    DfltLocName: string;
    SortAscending: Boolean;
    SortBy: string;    // D,R,S,A
    AskNoteSubject: Boolean;
    AskCosigner: Boolean;
    DfltCosigner: Int64;
    DfltCosignerName: string;
    MaxNotes: Integer;
  end;

//  notes tab specific procedures
function MakeNoteDisplayText(RawText: string): string;
function MakeConsultDisplayText(RawText:string): string;
function SetLinesTo74ForSave(AStrings: TStrings; AParent: TWinControl): TStrings;

//const
//TX_SAVE_ERROR1 = 'An error was encountered while trying to save the note you are editing.' + CRLF + CRLF + '    Error:  ';  <-- original line.  //kt 8/15/2007
//TX_SAVE_ERROR2 = CRLF + CRLF + 'Please try again now using CTRL-SHIFT-S, or ''Save without signature''.' + CRLF +  <-- original line.  //kt 8/15/2007
//                 'These actions will improve the likelihood that no text will be lost.' + CRLF + CRLF +  <-- original line.  //kt 8/15/2007
//                 'If problems continue, or network connectivity is lost, please copy all of your text to' + CRLF +  <-- original line.  //kt 8/15/2007
//                 'the clipboard and paste it into Microsoft Word before continuing or before closing CPRS.';  <-- original line.  //kt 8/15/2007
//TC_SAVE_ERROR =  'Error saving note text';  <-- original line.  //kt 8/15/2007

function TX_SAVE_ERROR1 : string;  //kt
function TX_SAVE_ERROR2 : string;  //kt
function TC_SAVE_ERROR : string;   //kt

implementation

uses
  DKLang; //kt

function TX_SAVE_ERROR1 : string;
begin Result := DKLangConstW('uTIU_An_error_was_encountered_while_trying_to_save_the_note_you_are_editingx') + CRLF + CRLF + DKLangConstW('uTIU_Errorx');
end;

function TX_SAVE_ERROR2 : string;
begin Result := CRLF + CRLF + DKLangConstW('uTIU_Please_try_again_now_using_CTRLxSHIFTxSx_or_xxSave_without_signaturexxx') + CRLF +
                    DKLangConstW('uTIU_These_actions_will_improve_the_likelihood_that_no_text_will_be_lostx') + CRLF + CRLF +
                    DKLangConstW('uTIU_If_problems_continuex_or_network_connectivity_is_lostx_please_copy_all_of_your_text_to') + CRLF +
                    DKLangConstW('uTIU_the_clipboard_and_paste_it_into_Microsoft_Word_before_continuing_or_before_closing_CPRSx');
end;

function TC_SAVE_ERROR : string;
begin Result :=  DKLangConstW('uTIU_Error_saving_note_text');
end;


function MakeConsultDisplayText(RawText:string): string;
var
 x: string;
begin
   x := RawText;
   Result := Piece(x, U, 2) + ',' + Piece(x, U, 3) + ',' +
             Piece(x, U, 4) + ', '+ Piece(x, U, 5);

end;

function MakeNoteDisplayText(RawText: string): string;
var
  x: string;
begin
  x := RawText;
  if Piece(x, U, 1) = '' then
    Result := FormatFMDateTime('mmm dd,yy', MakeFMDateTime(Piece(x, U, 3))) + '  ' +
        Piece(x, U, 2) + ', ' + Piece(x, U, 6) + ', ' + Piece(Piece(x, U, 5), ';', 2)
  else if Piece(x, U, 1)[1] in ['A', 'N', 'E'] then
    Result := Piece(x, U, 2)
  else
    Result := FormatFMDateTime('mmm dd,yy', MakeFMDateTime(Piece(x, U, 3))) + '  ' +
              Piece(x, U, 2) + ', ' + Piece(x, U, 6) + ', ' + Piece(Piece(x, U, 5), ';', 2);
end;


{ Progress Note Titles  -------------------------------------------------------------------- }
constructor TNoteTitles.Create;
{ creates an object to store progress note titles so only obtained from server once }
begin
  inherited Create;
  ShortList := TStringList.Create;
end;

destructor TNoteTitles.Destroy;
{ frees the lists that were used to store the progress note titles }
begin
  ShortList.Free;
  inherited Destroy;
end;

function SetLinesTo74ForSave(AStrings: TStrings; AParent: TWinControl): TStrings;
var
  ARichEdit74: TRichEdit;
begin
  Result := AStrings;
  ARichEdit74 := TRichEdit.Create(AParent);
  try
    with ARichEdit74 do
      begin
        Parent := AParent;
        Lines.Text := AStrings.Text;
        Width := 525;
        Result.Assign(Lines);
      end;
  finally
    ARichEdit74.Free;
  end;
end;

end.
