{*****************************************************************************} { } { llHL7NamedFields.pas - THL7NamedFields and related classes } { } { (c)2013-2022 Illuminated Logic, LLC / Ray Marron (see license.txt) } { } {*****************************************************************************} unit llHL7NamedFields; interface uses SysUtils, Classes, Contnrs, Windows, llHL7Utils; const NFVersion = 2; NFComment = ';'; NFConvertOK = 'Success'; DefaultDataType = 'ST'; DTError = 'ERROR '; DTSep = ':'; ValidOptionality = 'RENOCXBW'; TypeSection = 'DataTypes'; FieldSection = 'NamedFields'; TypeSectionLine = '[' + TypeSection + ']'; FieldSectionLine = '[' + FieldSection + ']'; TableCaseSensitive = 'CaseSensitive'; type THL7DataDef = class(TObject) private (* 22 lines omitted *) public constructor Create; constructor CreateStr(const S: string); // Name:DT:Min:Max:Opt:Rep:Table:ID destructor Destroy; override; property Key: string read FKey write SetKey; // Fields only property Name: string read FName write SetName; property DataType: string read FDataType write SetDataType; property Min: Integer read FMin write FMin; // 0=no limit property Max: Integer read FMax write FMax; // 0=no limit property Optionality: string read FOpt write SetOpt; property Repetition: string read FRepeat write SetRepeat; // Fields only property Table: string read FTable write FTable; property ID: string read FID write FID; property SubCount: Integer read GetSubCount; property Subs[const Index: Integer]: THL7DataDef read GetSubByIndex; default; property MaxReps: Integer read GetMaxReps; property NullOK: Boolean read GetNullOK; // True if Optionality contains "N" property Required: Boolean read GetRequired; // True if Optionality contains "R" property ErrorStr: string read GetErrorStr; property DefStr: string read GetDefStr; function AddSub(const AName: string; const ADataType: string = DefaultDataType; const AMin: Integer = 0; const AMax: Integer = 0; const AOpt: string = ''; const ARepeat: string = ''; const ATable: string = ''; const AID: string = ''): THL7DataDef; function AddSubStr(const S: string): THL7DataDef; function GetIndexByName(const ACom, ASub: string; out c, s: Integer): Boolean; function GetNameByIndex(const AComIndex: Integer; const ASubIndex: Integer = -1; const ACompact: Boolean = True): string; function GetComNameByIndex(const AComIndex: Integer): string; function GetSubNameByIndex(const AComIndex, ASubIndex: Integer): string; function GetSub(const AComIndex, ASubIndex: Integer): THL7DataDef; function HasLengthLimits: Boolean; function ValidLength(const ALength: Integer): Boolean; function GetDataTypeByIndex(const c, s: Integer): string; end; THL7NamedFields = class(TObject) private (* 15 lines omitted *) public constructor Create; destructor Destroy; override; property Definition: string read FDefinition write SetDefinition; property ValidationError: string read FErrorStr; property CargoStr: string read FCargoStr write FCargoStr; property CargoObj: TObject read FCargoObj write FCargoObj; property FileName: string read FFileName; // Set by successful LoadFromFile property TableCount: Integer read GetTableCount; property Tables[const ATableID: string]: TStringList read GetTableByID; procedure Clear; function LoadFromFile(const AFile: string): Boolean; function LoadFromStrings(const AStrings: TStrings): Boolean; function Validate: Boolean; function GetDataType(const S: string): THL7DataDef; function GetFieldDef(const SID: string; const f: Integer): THL7DataDef; function GetFieldData(const SID: string; const f: Integer; var ADataType: THL7DataDef): string; // GetFieldDef + returns field name function MakeNamedKey(const SID: string; const q, f, c, s, r: Integer; const ALevel: THL7KeyLevel = klCompact): string; function ParseNamedKey(const AKey: string; out SID: string; out q, f, c, s, r: Integer): Boolean; function AddTable(const ATableID: string; const AValues: TStrings): Boolean; function TableValueIsValid(const ATableID, AValue: string): Boolean; end; function GetNFVersion(const AFile: string): Integer; function NFConvert1to2(const AInFile, AOutFile: string): string; implementation (* 1158 lines omitted *) end.