{*****************************************************************************} { } { llHL7Anonymizer.pas - THL7Anonymizer and related classes } { } { (c)2013-2022 Illuminated Logic, LLC / Ray Marron (see license.txt) } { } {*****************************************************************************} unit llHL7Anonymizer; { NOTE: You must define HL7SCRIPT in your project if including the llHL7Script unit and you want to support advanced conditionals. } interface uses Windows, SysUtils, Classes, Contnrs, Math, Data.Db, FireDAC.Comp.Client, FireDAC.Phys.Intf, FireDAC.Stan.Option, FireDAC.Stan.Param, llStrings, llHL7Msg, llHL7NamedFields; type TAnonValueType = (avtST, avtNM, avtDT); const AnonValueTypes: array[TAnonValueType] of string = ('ST', 'NM', 'DT'); ValueNameParam = 'ValueName'; ValueIncParam = 'ValueInc'; ValueMinParam = 'ValueMin'; DataKeyParam = 'FieldKey'; DataOrigParam = 'OrigData'; DataAnonParam = 'AnonData'; type THL7Anonymizer = class; // Forward declaration TAnonValueDef = class(TObject) private (* 45 lines omitted *) public constructor Create(const AOwner: THL7Anonymizer); constructor CreateDef(const AOwner: THL7Anonymizer; const ADef: string); property Owner: THL7Anonymizer read FOwner; property Definition: string read GetDef write SetDef; property ValueName: string read FName write FName; property ValueType: TAnonValueType read FType write FType; property Min: Int64 read FMin write SetMin; property Max: Int64 read FMax write SetMax; property IsDigits: Boolean read FIsDigits write SetIsDigits; property Decimals: Cardinal read FDecimals write FDecimals; property Increment: Int64 read FIncrement write SetIncrement; property Alphabet: string read GetAlphabet write FAlphabet; property Constant: string read GetConstant write SetConstant; property SameAge: Boolean read FSameAge write FSameAge; property Mask: string read FMask write SetMask; property MaskEsc: Char read FMaskEsc write FMaskEsc; property PadChar: Char read FPadChar write FPadChar; property PadLeft: Integer read FPadL write SetPadL; property PadRight: Integer read FPadR write SetPadR; property Left: Integer read FLeft write SetLeft; property Right: Integer read FRight write SetRight; property Prefix: string read FPrefix write SetPrefix; property Suffix: string read FSuffix write SetSuffix; property Ignore: string read FIgnore write SetIgnore; property LastIncrement: Int64 read FLastInc write FLastInc; property IsConstant: Boolean read GetIsConstant; function IsIgnored(const AInput: string): Boolean; function GetValue(const AInput: string): string; end; TAnonFieldDef = class(TObject) private (* 13 lines omitted *) public constructor Create(const AOwner: THL7Anonymizer); destructor Destroy; override; property Owner: THL7Anonymizer read FOwner; property Definition: string read GetDef; property Key: string read FKey write FKey; property Conditional: string read FConditional write FConditional; property ValueDef: TAnonValueDef read FValueDef write FValueDef; property CopyKey: string read FCopyKey write FCopyKey; property Persist: Boolean read FPersist write FPersist; property Ignore: string read FIgnore write SetIgnore; property Data: TStringList read FData; function IsIgnored(const AInput: string): Boolean; procedure ResetData; procedure UpdateMsg(const AMsg: THL7Message); function ParseConditional: Boolean; procedure ApplyConditional(const AIndex, ASeq, ARep: Integer); end; THL7Anonymizer = class(TObject) private (* 36 lines omitted *) public constructor Create; destructor Destroy; override; property Alphabet: string read FAlphabet write FAlphabet; property Database: string read FDatabase write FDatabase; property DataStore: string read FDataStore write FDataStore; property DataReadSQL: string read FDataReadSQL write FDataReadSQL; // Params: FieldKey, OldData property DataSaveSQL: string read FDataSaveSQL write FDataSaveSQL; // Params: FieldKey, OldData, NewData property Definition: string read GetDefinitionStr write SetDefinitionStr; property DefinitionError: string read FError; property Filename: string read FFilename; property FieldCount: Integer read GetFieldCount; property FieldDefs[Index: Integer]: TAnonFieldDef read GetFieldDefByIndex; default; property IncrementSQL: string read FIncrementSQL write FIncrementSQL; // Params: ValueName, Increment, Minimum property NamedFields: THL7NamedFields read FNamedFields write FNamedFields; property NamedFieldsSQL: string read FNamedFieldsSQL write FNamedFieldsSQL; property Persist: Boolean read FPersist write FPersist; property SaveIncrements: Boolean read FSaveInc write FSaveInc; property ValueCount: Integer read GetValueCount; property ValueDefs[Index: Integer]: TAnonValueDef read GetValueDefByIndex; procedure GetDefinition(const AStrings: TStrings); function GetFieldDefByKey(const AKey: string): TAnonFieldDef; function GetValueDefByName(const AName: string): TAnonValueDef; function LoadDefinition(const AFile: string): Boolean; function LoadStrings(const AStrings: TStrings): Boolean; procedure ResetData; procedure UpdateMsg(const AMsg: THL7Message); // Events: procedure FDConnectionError(ASender, AInitiator: TObject; var AException: Exception); procedure FDConnectionLost(Sender: TObject); procedure FDConnectionRestored(Sender: TObject); procedure FDConnectionRecover(ASender, AInitiator: TObject; AException: Exception; var AAction: TFDPhysConnectionRecoverAction); end; implementation (* 1657 lines omitted *) end.