unit rLex;

interface

uses SysUtils, Classes, ORNet, ORFn;

const
  LX_ICD = 12;
  LX_CPT = 13;
  LX_SCT = 14;

  LX_Threshold = 15;

{ Lexicon Lookup Calls }
function GetFreqOfText(SearchStr: String): integer;
function  LexiconToCode(IEN, LexApp: Integer; ADate: TFMDateTime = 0): string;
procedure ListLexicon(Dest: TStrings; const x: string; LexApp: Integer; ADate: TFMDateTime = 0; AExtend: Boolean = False; AI10Active: Boolean = False);

implementation

function GetFreqOfText(SearchStr: String): integer;
begin
  Result := 0;
  CallVistA('ORWLEX GETFREQ', [SearchStr], Result);
end;

{ Lexicon Lookup Calls }

function LexiconToCode(IEN, LexApp: Integer; ADate: TFMDateTime = 0): string;
var
  CodeSys: string;
  tmp: string;
begin
  case LexApp of
  LX_ICD: CodeSys := 'ICD';
  LX_CPT: CodeSys := 'CHP';
  LX_SCT: CodeSys := 'GMPX';
  end;
  CallVistA('ORWPCE LEXCODE', [IEN, CodeSys, ADate], tmp);
  Result := Piece(tmp, U, 1);
end;

procedure ListLexicon(Dest: TStrings; const x: string; LexApp: Integer; ADate: TFMDateTime = 0; AExtend: Boolean = False; AI10Active: Boolean = False);
var
  CodeSys: string;
  ExtInt: integer;
begin
  case LexApp of
    LX_ICD: CodeSys := 'ICD';
    LX_CPT: CodeSys := 'CHP';
    LX_SCT: CodeSys := 'GMPX';
  end;
  if AExtend then
    ExtInt := 1
  else
    ExtInt := 0;
  if (LexApp = LX_ICD) and AExtend and AI10Active then
    CallVistA('ORWLEX GETI10DX', [x, ADate], Dest)
  else
    CallVistA('ORWPCE4 LEX', [x, CodeSys, ADate, ExtInt, True], Dest);
end;

end.
