{*****************************************************************************} { } { llHL7Script.pas - THL7Script and related types & constants } { } { (c)2013-2022 Illuminated Logic, LLC / Ray Marron (see license.txt) } { } {*****************************************************************************} unit llHL7Script; { Typical usage of THL7Script: Instantiate a THL7Script object. Assign the OnLogEntry [and OnOutput] event properties. Assign the DBConnection and/or NamedFieldsFile properties if desired. Open the input file or query and set the InputFilename/PK property. [*] Call LoadFromFile or manually load the script and set the Script and ScriptFilename properties. [**] try For each input message: - Load it into a THL7Message and assign that to the InputHL7 property. OR - Assign InputHL7 once and then LoadFromFile or set MessageStr for each. Call ProcessScript. It returns False when Aborted. Close the input file/query. Free InputHL7 if created per-message. Upon the end of input/interval, If HasPostProcessing is True (and not aborted), call DoPostProcessing. except Call DoErrorProcessing with the captured exception and end the current input/interval. end To run again, repeat from step [*]. If using the same script, the [**] step should be replaced by a call to the ResetScript method. Call DoFinal (Trap errors, call DoErrorProcessing if needed). Free the InputHL7 message if created only once. Free the script object. The EvalBoolExpression, ValidateBoolExpression, and EvalDataExpression functions can be used without loading a script. Just create the object, assign any required properties (HL7Input, etc.), use the desired functions, and Free. } interface uses SysUtils, Classes, Contnrs, Variants, Xml.xmldom, Xml.XMLIntf, Xml.XMLDoc, Data.Db, FireDAC.Comp.Client, FireDAC.Phys.Intf, FireDAC.Stan.Option, FireDAC.Stan.Param, llLike, llSharedVars, llHL7Msg, llHL7Anonymizer; const HL7ScriptVersion = '10.425'; ScriptHelpURL = 'https://www.raymarron.com/hl7/hl7scriptreference.html'; AnyKeyWild = '*'; ConcatChar = '+'; FuncOpen = '['; FuncClose = ']'; ModChar = '@'; QuoteChar = '"'; DefaultMaxLoops = 1000; DefaultCSVNewLine = '\.br\'; DefaultFileEOL = #13#10; InitStart = ''; InitEnd = ''; PreProcStart = '
';
  PreProcEnd = '
'; PostProcStart = ''; PostProcEnd = ''; ErrorStart = ''; ErrorEnd = ''; FinalStart = ''; FinalEnd = ''; type EHL7ScriptException = class(Exception); EHL7ScriptUserException = class(EHL7ScriptException); TOutputEvent = procedure(Sender: TObject; const S: string) of object; // Script Comparison Operators (ordered for searching, most common are last) TScriptOperator = (sopNOOP, sopLE, sopGE, sopLT, sopGT, sopInList, sopLike, sopEndsWith, sopStartsWith, sopSubStr, sopNumLT, sopNumGT, sopNumEQ, sopNE, sopEQ); const ScriptOperatorSymbols: array[TScriptOperator] of string = ( '', '<=', '>=', '<<', '>>', '*=', '~~', '=~', '~=', '$$', '#<', '#>', '#=', '<>', '=='); type THL7Script = class(TObject) private (* 152 lines omitted *) public constructor Create; destructor Destroy; override; property Abort: Boolean read FAbort; property DBConnection: TFDConnection read FFDConnection write SetDbConnection; property Debug: Boolean read FDebug write FDebug; property DebugData: Boolean read FDebugData write FDebugData; property Epsilon: Extended read FEpsilon write FEpsilon; property InputFilename: string read FInFile write FInFile; property InputHL7: THL7Message read FHL7In write SetHL7; property MaxLoops: Integer read FMaxLoops write FMaxLoops; property NamedFieldsDef: string read GetNamedFieldsDef write SetNamedFieldsDef; property NamedFieldsFile: string read FNamedFieldsFile write SetNamedFieldsFile; property OnLogEntry: TOutputEvent read FLogEvent write FLogEvent; property OnOutput: TOutputEvent read FOutputEvent write FOutputEvent; property OutputHL7: THL7Message read FHL7Out; property PK: string read FPK write SetPK; property Script: TStringList read FScript write SetScript; property ScriptFilename: string read FScriptFile write FScriptFile; property SharedVars: TSharedVars read FSharedVars write FSharedVars; property StrictNum: Boolean read FStrictNum write FStrictNum; property ValidationErrors: string read FValidationErrors; property ValidationWarnings: string read FValidationWarnings; procedure DoErrorProcessing(const e: Exception); procedure DoFinal; function DoPostProcessing: Boolean; function EvalBoolExpression(const AExpr: string; const ADepth: Integer = 0): Boolean; function EvalDataExpression(const AExpr: string): string; function HasErrorProcessing: Boolean; function HasPostProcessing: Boolean; procedure LoadFromFile(const AFile: string); function ProcessScript: Boolean; procedure ResetScript; function ValidateBoolExpression(const AExpr: string): Boolean; function ValidateScript(const AScript: TStrings): Boolean; overload; function ValidateScript(const AScriptFile: string): Boolean; overload; end; implementation (* 4784 lines omitted *) end.