Module

uPCE

Path

C:\CPRS\CPRS30\Encounter\uPCE.pas

Last Modified

7/15/2014 3:26:36 PM

Initialization Code

initialization

Finalization Code

finalization
  KillObj(@PCESetsOfCodes);
  KillObj(@HistLocations);

end.

Units Used in Interface

Name Comments
UBAGlobals -
uConst -

Units Used in Implementation

Name Comments
fEncounterFrame -
fFrame -
fPCEProvider -
rCore -
rPCE -
rTIU -
rVitals -
uCore -
uReminders -
uVitals -

Classes

Name Comments
TPCEData
Modified: 6/9/99
By: Robert Bott
Location: ISL
Purpose: Changed to allow capture of multiple providers.
TPCEDiag -
TPCEExams -
TPCEHealth -
TPCEImm -
TPCEItem -
TPCEPat -
TPCEProc -
TPCEProviderList -
TPCESkin -

Procedures

Name Owner Declaration Scope Comments
Add - procedure Add(Txt: string); Local -
Add - procedure Add(Typ: tRequiredPCEDataType; txt: string); Local -
AddList - procedure AddList(List: TList); Local -
AddStrData TPCEData procedure AddStrData(List: TStrings); Public -
AddTxt - procedure AddTxt(txt: string); Local Returns as a string the type of encounter (according to CPT) & related contitions treated
AddVitalData TPCEData procedure AddVitalData(Data, List: TStrings); Public -
Assign TPCEDiag procedure Assign(Src: TPCEItem); override; Public TPCEDiag methods -------------------------------------------------------------------------
Assign TPCEExams procedure Assign(Src: TPCEItem); override; Public TPCEExams methods -------------------------------------------------------------------------
Assign TPCEHealth procedure Assign(Src: TPCEItem); override; Public TPCEHealth methods -------------------------------------------------------------------------
Assign TPCEImm procedure Assign(Src: TPCEItem); override; Public TPCEImm methods -------------------------------------------------------------------------
Assign TPCEItem procedure Assign(Src: TPCEItem); virtual; Public -
Assign TPCEPat procedure Assign(Src: TPCEItem); override; Public TPCEPat methods -------------------------------------------------------------------------
Assign TPCEProc procedure Assign(Src: TPCEItem); override; Public TPCEProc methods -------------------------------------------------------------------------
Assign TPCEProviderList procedure Assign(Source: TPersistent); override; Public -
Assign TPCESkin procedure Assign(Src: TPCEItem); override; Public TPCESkin methods -------------------------------------------------------------------------
Clear TPCEData procedure Clear; Public -
Clear TPCEDiag procedure Clear; override; Public
Procedure TPCEDiag.Clear;
modified: 6/17/98
By: Robert Bott
Location: ISL
Purpose: Clear a diagnosis object.

clear fields(properties) of class
Clear TPCEExams procedure Clear; override; Public Clear fields(properties) of class
Clear TPCEHealth procedure Clear; override; Public Clear fields(properties) of class
Clear TPCEImm procedure Clear; override; Public Clear fields(properties) of class
Clear TPCEItem procedure Clear; virtual; Public
Procedure TPCEItem.Clear;
modified: 6/17/98
By: Robert Bott
Location: ISL
Purpose: Add Comments to PCE Items.

clear fields(properties) of class
Clear TPCEPat procedure Clear; override; Public Clear fields(properties) of class
Clear TPCEProc procedure Clear; override; Public Clear fields(properties) of class
Clear TPCEProviderList procedure Clear; override; Public -
Clear TPCESkin procedure Clear; override; Public Clear fields(properties) of class
ClearList - procedure ClearList(AList: TList); Local -
CopyDiagnoses TPCEData procedure CopyDiagnoses(Dest: TStrings); Public ICDcode^P|S^Category^Narrative^P|S Text
CopyExams TPCEData procedure CopyExams(Dest: TStrings); Public -
CopyHealthFactors TPCEData procedure CopyHealthFactors(Dest: TStrings); Public -
CopyImmunizations TPCEData procedure CopyImmunizations(Dest: TStrings); Public -
CopyPatientEds TPCEData procedure CopyPatientEds(Dest: TStrings); Public -
CopyPCEData TPCEData procedure CopyPCEData(Dest: TPCEData); Public -
CopyPCEItems TPCEData procedure CopyPCEItems(Src: TList; Dest: TObject; ItemClass: TPCEItemClass); Private -
CopyProc TPCEProc procedure CopyProc(Dest: TPCEProc); Public -
CopyProcedures TPCEData procedure CopyProcedures(Dest: TStrings); Public CPTcode^Qty^Category^Narrative^Qty Text
CopySkinTests TPCEData procedure CopySkinTests(Dest: TStrings); Public -
Delete TPCEProviderList procedure Delete(Index: Integer); override; Public -
GetComboBoxMinMax - procedure GetComboBoxMinMax(dest: TORComboBox; var Min, Max: integer); Interfaced -
GetHasCPTList TPCEData procedure GetHasCPTList(AList: TStrings); Private -
GetPCECodes - procedure GetPCECodes(List: TStrings; CodeType: integer); Interfaced -
GetVitalsFromDate - procedure GetVitalsFromDate(VitalStr: TStrings; PCEObj: TPCEData); Interfaced -
GetVitalsFromNote - procedure GetVitalsFromNote(VitalStr: TStrings; PCEObj: TPCEData; ANoteIEN: Int64); Interfaced -
MarkDeletions TPCEData procedure MarkDeletions(PreList: TList; PostList: TStrings); Private Mark items that need deleted
Merge TPCEProviderList procedure Merge(AList: TPCEProviderList); Public -
PCEForNote TPCEData procedure PCEForNote(NoteIEN: Integer; EditObj: TPCEData);(* overload; Public
Overload;
    procedure PCEForNote(NoteIEN: Integer; EditObj: TPCEData; DCSummAdmitString: string); overload;
const
  NULL_STR = '';
begin
  PCEForNote(NoteIEN, EditObj, NULL_STR);
end;

procedure TPCEData.PCEForNote(NoteIEN: Integer; EditObj: TPCEData; DCSummAdmitString: string);






  AProvider:     TPCEProvider;  {6/9/99}
PCELoadORCombo - procedure PCELoadORCombo(dest: TORComboBox; var Min, Max: integer); overload; Interfaced -
PCELoadORCombo - procedure PCELoadORCombo(dest: TORComboBox); overload; Interfaced -
PCELoadORComboData - procedure PCELoadORComboData(dest: TORComboBox; GetMinMax: boolean; var Min, Max: integer); Global -
Save TPCEData procedure Save; Public
Procedure TPCEData.Save;
modified: 6/17/98
By: Robert Bott
Location: ISL
Purpose: Add Comments to PCE Items.

 pass the changes to the encounter to DATA2PCE,
  Pieces: Subscript^Code^Qualifier^Category^Narrative^Delete 

 into two strings, the second being for the comment.
Send TPCEDiag procedure Send; Public Marks diagnosis to be sent;
SetAORelated TPCEData procedure SetAORelated(Value: Integer); Private -
SetComment TPCEItem procedure SetComment(const Value: String); Protected -
SetCVRelated TPCEData procedure SetCVRelated(Value: Integer); Private -
SetDefaultProvider - procedure SetDefaultProvider(ProviderList: TPCEProviderList; APCEData: TPCEData); Interfaced -
SetDiagnoses TPCEData procedure SetDiagnoses(Src: TStrings; FromForm: boolean = TRUE); Public
ICDcode^P|S^Category^Narrative^P|S Text
load diagnoses for this encounter into TPCEDiag records, assumes all diagnoses for the
  encounter will be listed in Src and marks those that are not in Src for deletion
SetECRelated TPCEData procedure SetECRelated(Value: Integer); Private -
SetEncUseCurr TPCEData procedure SetEncUseCurr(Value: Boolean); Private -
SetExams TPCEData procedure SetExams(Src: TStrings; FromForm: boolean = TRUE); Public -
SetFromString TPCEDiag procedure SetFromString(const x: string); override; Public
Procedure TPCEDiag.SetFromString(const x: string);
modified: 6/17/98
By: Robert Bott
Location: ISL
Purpose: Sets fields to pieces passed from server.

 sets fields to pieces passed from server:  TYP ^ Code ^ Category ^ Narrative ^ Primary ^ ^ ^ Comment
SetFromString TPCEExams procedure SetFromString(const x: string); override; Public Sets fields to pieces passed from server: TYP ^ Code ^ Category ^ Narrative ^ Qty ^ Prov
SetFromString TPCEHealth procedure SetFromString(const x: string); override; Public Sets fields to pieces passed from server: TYP ^ Code ^ Category ^ Narrative ^ Qty ^ Prov
SetFromString TPCEImm procedure SetFromString(const x: string); override; Public Sets fields to pieces passed from server: TYP ^ Code ^ Category ^ Narrative ^ Qty ^ Prov
SetFromString TPCEItem procedure SetFromString(const x: string); virtual; Public
Procedure TPCEItem.SetFromString(const x: string);
modified: 6/17/98
By: Robert Bott
Location: ISL
Purpose: Add Comments to PCE Items.

 sets fields to pieces passed from server:  TYP ^ Code ^ Category ^ Narrative
SetFromString TPCEPat procedure SetFromString(const x: string); override; Public Sets fields to pieces passed from server: TYP ^ Code ^ Category ^ Narrative ^ Qty ^ Prov
SetFromString TPCEProc procedure SetFromString(const x: string); override; Public Sets fields to pieces passed from server: TYP ^ Code ^ Category ^ Narrative ^ Qty ^ Prov
SetFromString TPCESkin procedure SetFromString(const x: string); override; Public Sets fields to pieces passed from server: TYP ^ Code ^ Category ^ Narrative ^ Qty ^ Prov
SetHealthFactors TPCEData Procedure SetHealthFactors(Src: TStrings; FromForm: boolean = TRUE); Public -
SetHNCRelated TPCEData procedure SetHNCRelated(Value: Integer); Private -
SetImmunizations TPCEData procedure SetImmunizations(Src: TStrings; FromForm: boolean = TRUE); Public
IMMcode^
load Immunizations for this encounter into TPCEImm records, assumes all Immunizations for the
  encounter will be listed in Src and marks those that are not in Src for deletion
SetIRRelated TPCEData procedure SetIRRelated(Value: Integer); Private -
SetMSTRelated TPCEData procedure SetMSTRelated(Value: Integer); Private -
SetPatientEds TPCEData Procedure SetPatientEds(Src: TStrings; FromForm: boolean = TRUE); Public -
SetPrimary TPCEProviderList procedure SetPrimary(index: integer; Primary: boolean); Private -
SetPrimaryIdx TPCEProviderList procedure SetPrimaryIdx(const Value: integer); Private -
SetProcedures TPCEData procedure SetProcedures(Src: TStrings; FromForm: boolean = TRUE); Public
CPTcode^Qty^Category^Narrative^Qty Text
load Procedures for this encounter into TPCEProc records, assumes all Procedures for the
  encounter will be listed in Src and marks those that are not in Src for deletion
SetProviderData TPCEProviderList procedure SetProviderData(Index: integer; const Value: TPCEProviderRec); Private -
SetSCRelated TPCEData procedure SetSCRelated(Value: Integer); Private -
SetSHADRelated TPCEData procedure SetSHADRelated(Value: Integer); Private -
SetSkinTests TPCEData procedure SetSkinTests(Src: TStrings; FromForm: boolean = TRUE); Public
Load SkinTests for this encounter into TPCESkin records, assumes all SkinTests for the
  encounter will be listed in Src and marks those that are not in Src for deletion
SetVisitType TPCEData procedure SetVisitType(Value: TPCEProc); Public CPTcode^1^Category^Narrative

Functions

Name Owner Declaration Scope Comments
Add TPCEProviderList function Add(const S: string): Integer; override; Public TPCEProviderList
AddProvider TPCEProviderList function AddProvider(AIEN, AName: string; APrimary: boolean): integer; Public -
AppendComment - function AppendComment(x: string): String; Local -
CanEditPCE - function CanEditPCE(APCEData: TPCEData): boolean; Interfaced -
Check - function Check(AIEN: Int64): Int64; Local -
CodeSetIndex - function CodeSetIndex(CodeType: integer): integer; Global -
DelimitedStr TPCEDiag function DelimitedStr: string; override; Public
Function TPCEDiag.DelimitedStr: string;
modified: 6/17/98
By: Robert Bott
Location: ISL
Purpose: Create delimited string to pass to Broker.

created delimited string to pass to broker
DelimitedStr TPCEExams function DelimitedStr: string; override; Public
Function TPCEExams.DelimitedStr: string;
modified: 6/17/98
By: Robert Bott
Location: ISL
Purpose: Add Comments to PCE Items.

created delimited string to pass to broker
DelimitedStr TPCEHealth function DelimitedStr: string; override; Public
Function TPCEHealth.DelimitedStr: string;
modified: 6/17/98
By: Robert Bott
Location: ISL
Purpose: Add Comments to PCE Items.

created delimited string to pass to broker
DelimitedStr TPCEImm function DelimitedStr: string; override; Public
Function TPCEImm.DelimitedStr: string;
modified: 6/17/98
By: Robert Bott
Location: ISL
Purpose: Add Comments to PCE Items.

created delimited string to pass to broker
DelimitedStr TPCEItem function DelimitedStr: string; virtual; Public
Function TPCEItem.DelimitedStr: string;
modified: 6/17/98
By: Robert Bott
Location: ISL
Purpose: Add Comments to PCE Items.

created delimited string to pass to broker
DelimitedStr TPCEPat function DelimitedStr: string; override; Public
Function TPCEPat.DelimitedStr: string;
modified: 6/17/98
By: Robert Bott
Location: ISL
Purpose: Add Comments to PCE Items.

created delimited string to pass to broker
DelimitedStr TPCEProc function DelimitedStr: string; override; Public
Function TPCEProc.DelimitedStr: string;
modified: 6/17/98
By: Robert Bott
Location: ISL
Purpose: Add Comments to PCE Items.

created delimited string to pass to broker
DelimitedStr TPCESkin function DelimitedStr: string; override; Public
Function TPCESkin.DelimitedStr: string;
modified: 6/17/98
By: Robert Bott
Location: ISL
Purpose: Add Comments to PCE Items.

created delimited string to pass to broker
DelimitedStr2 TPCEDiag function DelimitedStr2: string; override; Public -
DelimitedStr2 TPCEItem function DelimitedStr2: string; virtual; Public
Function TPCEItem.DelimitedStr2: string;
added: 6/17/98
By: Robert Bott
Location: ISL
Purpose: Return comment string to be passed in RPC call.

created delimited string to pass to broker
Empty TPCEData function Empty: boolean; Public -
Empty TPCEProc function Empty: boolean; Public
Function TPCEProc.delimitedStrC: string;
begin
  Result := inherited DelimitedStr;
  Result := 'CPT' + Result + U + IntToStr(Quantity) + U + IntToStr(Provider) +
  U + U + U + U + comment;
end;
FutureEncounter - function FutureEncounter(APCEData: TPCEData): boolean; Interfaced -
GetCPTRequired TPCEData function GetCPTRequired: Boolean; Private -
getDocCount TPCEData function getDocCount: Integer; Private -
GetHasData TPCEData function GetHasData: Boolean; Private -
GetPCECodeString - function GetPCECodeString(CodeType: integer; ID: string): string; Global -
GetPCEDataText - function GetPCEDataText(Cat: TPCEDataCat; Code, Category, Narrative: string; PrimaryDiag: boolean = FALSE; Qty: integer = 0): string; Interfaced -
GetPCEDisplayText - function GetPCEDisplayText(ID: string; Tag: integer): string; Interfaced -
GetPrimaryIdx TPCEProviderList function GetPrimaryIdx: integer; Private -
GetProviderData TPCEProviderList function GetProviderData(Index: integer): TPCEProviderRec; Private -
GetVisitString TPCEData function GetVisitString: string; Private -
HasCPTStr TPCEExams function HasCPTStr: string; override; Public
Function TPCEExams.delimitedStrC: string;
begin
  Result := inherited DelimitedStr;
  Result := 'XAM' + Result + U + Results + U + IntToStr(Provider) +U + U + U +
   U + comment;
end;
HasCPTStr TPCEHealth function HasCPTStr: string; override; Public
Function TPCEHealth.delimitedStrC: string;
begin
  Result := inherited DelimitedStr;
  Result := 'HF' + Result + U + Level + U + IntToStr(Provider) + U + U + U +
   U + comment;
end;
HasCPTStr TPCEImm function HasCPTStr: string; override; Public
Function TPCEImm.delimitedStrC: string;
begin
  Result := inherited DelimitedStr;
  Result := 'IMM' + Result + U + Series + U + IntToStr(Provider) + U + Reaction;
  if Contraindicated then Result := Result + U + '1'
  else Result := Result + U + '0';
  Result := Result + U + U + comment;
    {the following two lines are not yet implemented in PCE side}
  //if Refused then Result := Result + U + '1'
  //else Result := Result + U + '0';
end;
HasCPTStr TPCEItem function HasCPTStr: string; virtual; Public -
HasCPTStr TPCEPat function HasCPTStr: string; override; Public
Function TPCEPat.delimitedStrC: string;
begin
  Result := inherited DelimitedStr;
  Result := 'PED' + Result + U + Level + U + IntToStr(Provider) + U + U + U +
   U + comment;
end;
HasCPTStr TPCESkin function HasCPTStr: string; override; Public
Function TPCESkin.delimitedStrC: string;
begin
  Result := inherited DelimitedStr;
  Result := 'SK' + Result + U + results + U + IntToStr(Provider) + U +
   IntToStr(Reading) + U + U + U + comment;
end;
IndexOfProvider TPCEProviderList function IndexOfProvider(AIEN: string): integer; Public -
InvalidPCEProviderTxt - function InvalidPCEProviderTxt(AIEN: Int64; ADate: TFMDateTime): string; Interfaced -
IsOK2Sign - function IsOK2Sign(const PCEData: TPCEData; const IEN: integer) :boolean; Interfaced -
IsSecondaryVisit TPCEData function IsSecondaryVisit: boolean; Public -
ItemStr TPCEDiag function ItemStr: string; override; Public
Function delimitedStrC: string;
function TPCEDiag.DelimitedStrC: string;
{created delimited string for internal use - keep comment in same string.}
begin
  Result := inherited DelimitedStr;
  Result := 'POV' + Result + U + BOOLCHAR[Primary] + U + IntToStr(Provider)+
  U + BOOLCHAR[AddProb] + U + U + U + comment;
end;


returns string to be assigned to Tlist in PCEData object
ItemStr TPCEExams function ItemStr: string; override; Public
Function delimitedStrC: string;
returns string to be assigned to Tlist in PCEData object
ItemStr TPCEHealth function ItemStr: string; override; Public
Function delimitedStrC: string;
returns string to be assigned to Tlist in PCEData object
ItemStr TPCEImm function ItemStr: string; override; Public
Function delimitedStrC: string;
returns string to be assigned to Tlist in PCEData object
ItemStr TPCEItem function ItemStr: string; virtual; Public Returns string to be assigned to Tlist in PCEData object
ItemStr TPCEPat function ItemStr: string; override; Public
Function delimitedStrC: string;
returns string to be assigned to Tlist in PCEData object
ItemStr TPCEProc function ItemStr: string; override; Public Returns string to be assigned to Tlist in PCEData object
ItemStr TPCESkin function ItemStr: string; override; Public
Function delimitedStrC: string;
returns string to be assigned to Tlist in PCEData object
Match TPCEItem function Match(AnItem: TPCEItem): Boolean; Public Checks for match of Code, Category. and Item
MatchItem TPCEData function MatchItem(AList: TList; AnItem: TPCEItem): Integer; Private Return index in AList of matching item
MatchProvider TPCEItem function MatchProvider(AnItem: TPCEItem):Boolean; Public
Function MatchProvider(AnItem: TPCEItem):Boolean;
function TPCEItem.MatchProvider(AnItem: TPCEItem): Boolean;
begin
  Result := False;
  if (Provider = AnItem.Provider) then Result := True;
end;
MissingProviderInfo - function MissingProviderInfo(PCEEdit: TPCEData; PCEType: TPCEType = ptEncounter): boolean; Interfaced -
ModText TPCEProc function ModText: string; Public
Function DelimitedStrC: string;
    function Match(AnItem: TPCEProc): Boolean;
function TPCEProc.Match(AnItem: TPCEProc): Boolean;        {NEW CODE - v20 testing only - RV}
begin
  Result := inherited Match(AnItem) and (Modifiers = AnItem.Modifiers);
end;
NeededPCEData TPCEData function NeededPCEData: tRequiredPCEDataTypes; Public -
NeedProviderInfo TPCEData function NeedProviderInfo: boolean; Public -
OK2SignNote TPCEData function OK2SignNote: boolean; Public -
PCEProvider TPCEProviderList function PCEProvider: Int64; Public -
PCEProviderName TPCEProviderList function PCEProviderName: string; Public -
PendingIEN TPCEProviderList function PendingIEN(ADefault: boolean): Int64; Public -
PendingName TPCEProviderList function PendingName(ADefault: boolean): string; Public -
PersonClassDate TPCEData function PersonClassDate: TFMDateTime; Public -
PrimaryIEN TPCEProviderList function PrimaryIEN: int64; Public -
PrimaryName TPCEProviderList function PrimaryName: string; Public -
SCCValue - function SCCValue(x: string): Integer; Local AProvider: TPCEProvider; {6/9/99}
StandAlone TPCEData function StandAlone: boolean; Public -
StrDiagnoses TPCEData function StrDiagnoses: string; Public
Diagnoses: ...
returns the list of diagnoses for this encounter as a single comma delimited string
StrExams TPCEData function StrExams: string; Public -
StrHealthFactors TPCEData function StrHealthFactors: string; Public -
StrImmunizations TPCEData function StrImmunizations: string; Public
Immunizzations: ...
returns the list of Immunizations for this encounter as a single comma delimited string
StrPatientEds TPCEData function StrPatientEds: string; Public -
StrProcedures TPCEData function StrProcedures: string; Public
Procedures: ...
returns the list of procedures for this encounter as a single comma delimited string
StrSkinTests TPCEData function StrSkinTests: string; Public Returns the list of Immunizations for this encounter as a single comma delimited string
StrVisitType TPCEData function StrVisitType: string; overload; Public Returns as a string the type of encounter (according to CPT) & related contitions treated
StrVisitType TPCEData function StrVisitType(const ASCRelated, AAORelated, AIRRelated, AECRelated, AMSTRelated, AHNCRelated, ACVRelated, ASHADRelated: Integer): string; overload; Public Returns as a string the type of encounter (according to CPT) & related contitions treated
ValidateGAFDate - function ValidateGAFDate(var GafDate: TFMDateTime): string; Interfaced -
VisitDateTime TPCEData function VisitDateTime: TFMDateTime; Public -

Global Variables

Name Type Declaration Comments
HistLocations TORStringList HistLocations: TORStringList = nil; -
PCESetsOfCodes TStringList PCESetsOfCodes: TStringList = nil; -
UNxtCommSeqNum Integer UNxtCommSeqNum: integer; -
WHMammResult TORStringList WHMammResult: TORStringList = nil; -
WHNotPurpose TORStringList WHNotPurpose: TORStringList = nil; -
WHPapResult TORStringList WHPapResult: TORStringList = nil; -
WHUltraResult TORStringList WHUltraResult: TORStringList = nil; -

Constants

Name Declaration Scope Comments
FN_NEW_PERSON 200 Global -
ListMinMax array[1..7, TListMinMax] of integer = Global -
mmFont TListMinMax Global -
mmMax TListMinMax Global -
mmMin TListMinMax Global -
ndDiag tRequiredPCEDataType Interfaced
TPCEData = class;

jm 9/9/99
ndProc tRequiredPCEDataType Interfaced
TPCEData = class;

jm 9/9/99
ndSC tRequiredPCEDataType Interfaced
TPCEData = class;

jm 9/9/99
NoPCEValue '@' Interfaced -
PCEDataCatText array[TPCEDataCat] of string = Interfaced -
PCETypeText array[TPCEType] of string = ('encounter', 'reminder', 'template') Interfaced -
pdcDiag TPCEDataCat Interfaced -
pdcExam TPCEDataCat Interfaced -
pdcHF TPCEDataCat Interfaced -
pdcHNC TPCEDataCat Interfaced -
pdcImm TPCEDataCat Interfaced -
pdcMH TPCEDataCat Interfaced -
pdcMST TPCEDataCat Interfaced -
pdcOrder TPCEDataCat Interfaced -
pdcPED TPCEDataCat Interfaced -
pdcProc TPCEDataCat Interfaced -
pdcSkin TPCEDataCat Interfaced -
pdcVisit TPCEDataCat Interfaced -
pdcVital TPCEDataCat Interfaced -
pdcWH TPCEDataCat Interfaced -
pdcWHR TPCEDataCat Interfaced -
pnumCategory 3 Interfaced -
pnumCode 2 Interfaced These piece numbers are used by both the PCE objects and reminders
pnumComment 10 Interfaced -
pnumCPTMods 9 Interfaced -
pnumDiagAdd2PL 7 Interfaced -
pnumDiagPrimary 5 Interfaced -
pnumExamResults 5 Interfaced -
pnumHFLevel 5 Interfaced -
pnumImmContra 8 Interfaced -
pnumImmReaction 7 Interfaced -
pnumImmRefused 9 Interfaced -
pnumImmSeries 5 Interfaced -
pnumNarrative 4 Interfaced -
pnumPEDLevel 5 Interfaced -
pnumProcQty 5 Interfaced -
pnumProvider 6 Interfaced -
pnumPrvdrIEN 2 Interfaced -
pnumPrvdrName 5 Interfaced -
pnumPrvdrPrimary 6 Interfaced -
pnumSkinDTGiven 9 Interfaced -
pnumSkinDTRead 8 Interfaced -
pnumSkinReading 7 Interfaced -
pnumSkinResults 5 Interfaced -
pnumWHNotPurp 12 Interfaced -
pnumWHPapResult 11 Interfaced -
ptEncounter TPCEType Interfaced -
ptReminder TPCEType Interfaced -
ptTemplate TPCEType Interfaced -
SetOfCodesHeader '{^~Codes~^}' Global -
SOCHeaderLen length(SetOfCodesHeader) Global -
TAB_STOP_CHARS 7 Interfaced -
TAG_HFLEVEL 50 Interfaced -
TAG_HISTLOC 70 Interfaced -
TAG_IMMREACTION 20 Interfaced -
TAG_IMMSERIES 10 Interfaced -
TAG_PEDLEVEL 40 Interfaced -
TAG_SKRESULTS 30 Interfaced -
TAG_XAMRESULTS 60 Interfaced -
TC_COS 'Select Cosigner' Interfaced -
TC_REQ 'Required Fields' Interfaced -
TX_ADDEND_AD 'Cannot make an addendum to an addendum' + CRLF + Interfaced -
TX_ADDEND_MK 'Unable to Make Addendum' Interfaced -
TX_BAD_PROV 'Invalid Provider' Interfaced -
TX_COS_AUTH ' is not authorized to cosign this document.' Interfaced -
TX_COS_REQ 'A cosigner is required for this document.' Interfaced -
TX_COS_SELF 'You cannot make yourself a cosigner.' Interfaced -
TX_DEL_CNF 'Confirm Deletion' Interfaced -
TX_IN_AUTH 'Insufficient Authorization' Interfaced -
TX_MISSING 'Required Information Missing' Interfaced -
TX_NEED_DIAG ' A diagnosis.' Interfaced -
TX_NEED_PROC ' A visit type or procedure.' Interfaced -
TX_NEED_PROV1 'The provider responsible for this encounter must be entered before ' Interfaced -
TX_NEED_PROV2 ' information may be entered.' Interfaced -
TX_NEED_SC ' One or more service connected questions.' Interfaced -
TX_NEED_T 'Missing Encounter Information' Interfaced -
TX_NEED1 'This note title is marked to prompt for the following missing' + CRLF + Interfaced -
TX_NEED2 'Would you like to enter encounter information now?' Interfaced -
TX_NEED3 'You must enter the encounter information before you can sign the note.' Interfaced -
TX_NEEDABORT 'Document not signed.' Interfaced -
TX_NO_PROV 'Missing Provider' Interfaced TX_NEED_PROV3 = 'you can sign the note.';
TX_NO_VISIT 'Insufficient Visit Information' Interfaced -
TX_NOPCE '<No encounter information entered>' Interfaced -
TX_NOT_ACTIVE ' does not have an active person class.' Interfaced -
TX_NOT_PROV ' is not a known Provider.' Interfaced -
TX_REQ1 'The following required fields have not been entered:' + CRLF Interfaced -
USE_CURRENT_VISITSTR -2 Interfaced -


Module Source

1     unit uPCE;
2     
3     interface
4     
5     uses Windows, SysUtils, Classes, ORFn, uConst, ORCtrls, ORClasses,UBAGlobals;
6     
7     type
8       TPCEProviderRec = record
9         IEN: int64;
10        Name: string;
11        Primary: boolean;
12        Delete: boolean;
13      end;
14    
15      TPCEProviderList = class(TORStringList)
16      private
17        FNoUpdate: boolean;
18        FOnPrimaryChanged: TNotifyEvent;
19        FPendingDefault: string;
20        FPendingUser: string;
21        FPCEProviderIEN: Int64;
22        FPCEProviderName: string;
23        function GetProviderData(Index: integer): TPCEProviderRec;
24        procedure SetProviderData(Index: integer; const Value: TPCEProviderRec);
25        function GetPrimaryIdx: integer;
26        procedure SetPrimaryIdx(const Value: integer);
27        procedure SetPrimary(index: integer; Primary: boolean);
28      public
29        function Add(const S: string): Integer; override;
30        function AddProvider(AIEN, AName: string; APrimary: boolean): integer;
31        procedure Assign(Source: TPersistent); override;
32        function PCEProvider: Int64;
33        function PCEProviderName: string;
34        function IndexOfProvider(AIEN: string): integer;
35        procedure Merge(AList: TPCEProviderList);
36        procedure Clear; override;
37        procedure Delete(Index: Integer); override;
38        function PrimaryIEN: int64;
39        function PrimaryName: string;
40        function PendingIEN(ADefault: boolean): Int64;
41        function PendingName(ADefault: boolean): string;
42        property ProviderData[Index: integer]: TPCEProviderRec read GetProviderData
43                                                              write SetProviderData; default;
44        property PrimaryIdx: integer read GetPrimaryIdx write SetPrimaryIdx;
45        property OnPrimaryChanged: TNotifyEvent read FOnPrimaryChanged
46                                               write FOnPrimaryChanged;
47      end;
48    
49      TPCEItem = class(TObject)
50      {base class for PCE items}
51      private
52        FDelete:   Boolean;                          //flag for deletion
53        FSend:     Boolean;                          //flag to send to broker
54        FComment:  String;
55      protected
56        procedure SetComment(const Value: String);
57      public
58    //    Provider:  Int64;
59        Provider:  Int64;
60        Code:      string;
61        Category:  string;
62        Narrative: string;
63        FGecRem: string;
64        procedure Assign(Src: TPCEItem); virtual;
65        procedure Clear; virtual;
66        function DelimitedStr: string; virtual;
67        function DelimitedStr2: string; virtual;
68        function ItemStr: string; virtual;
69        function Match(AnItem: TPCEItem): Boolean;
70    //    function MatchProvider(AnItem: TPCEItem):Boolean;
71        function MatchProvider(AnItem: TPCEItem):Boolean;
72        procedure SetFromString(const x: string); virtual;
73        function HasCPTStr: string; virtual;
74        property Comment: String read FComment write SetComment;
75        property GecRem: string read FGecRem write FGecRem;
76      end;
77    
78      TPCEItemClass = class of TPCEItem;
79    
80      TPCEProc = class(TPCEItem)
81      {class for procedures}
82      public
83        FIsOldProcedure: boolean;
84        Quantity:  Integer;
85        Modifiers: string; // Format Modifier1IEN;Modifier2IEN;Modifier3IEN; Trailing ; needed
86    //    Provider: Int64; {jm 9/8/99}
87        Provider: Int64; {jm 9/8/99}
88        procedure Assign(Src: TPCEItem); override;
89        procedure Clear; override;
90        function DelimitedStr: string; override;
91    //    function DelimitedStrC: string;
92    //    function Match(AnItem: TPCEProc): Boolean;
93        function ModText: string;
94        function ItemStr: string; override;
95        procedure SetFromString(const x: string); override;
96        procedure CopyProc(Dest: TPCEProc);
97        function Empty: boolean;
98      end;
99    
100     TPCEDiag = class(TPCEItem)
101     {class for diagnosis}
102     public
103       fProvider: Int64; 
104       Primary:   Boolean;
105       AddProb:   Boolean;
106       OldComment: string;
107       SaveComment: boolean;
108       procedure Assign(Src: TPCEItem); override;
109       procedure Clear; override;
110       function DelimitedStr: string; override;
111       function DelimitedStr2: string; override;
112   //    function delimitedStrC: string;        
113       function ItemStr: string; override;
114       procedure SetFromString(const x: string); override;
115       procedure Send;
116     end;
117   
118     TPCEExams = class(TPCEItem)
119     {class for Examinations}
120     public
121   //    Provider: Int64;
122       Results:   String;
123       procedure Assign(Src: TPCEItem); override;
124       procedure Clear; override;
125       function DelimitedStr: string; override;
126   //    function delimitedStrC: string;
127       function ItemStr: string; override;
128       procedure SetFromString(const x: string); override;
129       function HasCPTStr: string; override;
130     end;
131   
132   
133     TPCEHealth = class(TPCEItem)
134     {class for Health Factors}
135     public
136   //    Provider: Int64; {jm 9/8/99}
137       Level:   string;
138       procedure Assign(Src: TPCEItem); override;
139       procedure Clear; override;
140       function DelimitedStr: string; override;
141   //    function delimitedStrC: string;        
142       function ItemStr: string; override;
143       procedure SetFromString(const x: string); override;
144       function HasCPTStr: string; override;
145     end;
146   
147     TPCEImm = class(TPCEItem)  
148     {class for immunizations}
149     public
150   //    Provider:        Int64; {jm 9/8/99}
151       Series:          String;
152       Reaction:        String;
153       Refused:         Boolean; //not currently used
154       Contraindicated: Boolean;
155       procedure Assign(Src: TPCEItem); override;
156       procedure Clear; override;
157       function DelimitedStr: string; override;
158   //    function delimitedStrC: string;        
159       function ItemStr: string; override;
160       procedure SetFromString(const x: string); override;
161       function HasCPTStr: string; override;
162     end;
163   
164     TPCEPat = class(TPCEItem)
165     {class for patient Education}
166     public
167   //    Provider: Int64; {jm 9/8/99}
168       Level:   String;
169       procedure Assign(Src: TPCEItem); override;
170       procedure Clear; override;
171       function DelimitedStr: string; override;
172   //    function delimitedStrC: string;        
173       function ItemStr: string; override;
174       procedure SetFromString(const x: string); override;
175       function HasCPTStr: string; override;
176     end;
177   
178     TPCESkin = class(TPCEItem)  
179     {class for skin tests}
180     public
181   //    Provider:  Int64; {jm 9/8/99}
182       Results:   String;                   //Do not confuse for reserved word "result"
183       Reading:   Integer;
184       DTRead:    TFMDateTime;
185       DTGiven:   TFMDateTime;
186       procedure Assign(Src: TPCEItem); override;
187       procedure Clear; override;
188       function DelimitedStr: string; override;
189   //    function delimitedStrC: string;
190       function ItemStr: string; override;
191       procedure SetFromString(const x: string); override;
192       function HasCPTStr: string; override;
193     end;
194   
195   //  TPCEData = class;
196   
197     tRequiredPCEDataType = (ndDiag, ndProc, ndSC); {jm 9/9/99}
198     tRequiredPCEDataTypes = set of tRequiredPCEDataType;
199   
200     //modified: 6/9/99
201     //By: Robert Bott
202     //Location: ISL
203     //Purpose: Changed to allow capture of multiple providers.
204     TPCEData = class
205     {class for data to be passed to and from broker}
206     private
207       FUpdated:      boolean;
208       FEncDateTime:  TFMDateTime;                    //encounter date & time
209       FNoteDateTime: TFMDateTime;                    //Note date & time
210       FEncLocation:  Integer;                        //encounter location
211       FEncSvcCat:    Char;                           //
212       FEncInpatient: Boolean;                        //Inpatient flag
213       FEncUseCurr:   Boolean;                        //
214       FSCChanged:    Boolean;                        //
215       FSCRelated:    Integer;                        //service con. related?
216       FAORelated:    Integer;                        //
217       FIRRelated:    Integer;                        //
218       FECRelated:    Integer;                        //
219       FMSTRelated:   Integer;                        //
220       FHNCRelated:   Integer;                        //
221       FCVRelated:    Integer;                        //
222       FSHADRelated:   Integer;                        //
223       fVisitType:    TPCEProc;                       //
224       FProviders:    TPCEProviderList;
225       fDiagnoses:    TList;                          //pointer list for diagnosis
226       FProcedures:   TList;                          //pointer list for Procedures
227       FImmunizations: TList;                         //pointer list for Immunizations
228       FSkinTests:     TList;                         //pointer list for skin tests
229       FPatientEds:    TList;
230       FHealthFactors: TList;
231       fExams:         TList;
232       FNoteTitle:    Integer;
233       FNoteIEN:      Integer;
234       FParent:       string;                         // Parent Visit for secondary encounters
235       FHistoricalLocation: string;                   // Institution IEN^Name (if IEN=0 Piece 4 = outside location)
236       FStandAlone: boolean;
237       FStandAloneLoaded: boolean;
238       FProblemAdded: Boolean;                         // Flag set when one or more Dx are added to PL
239   
240       function GetVisitString: string;
241       function GetCPTRequired: Boolean;
242       function getDocCount: Integer;
243       function MatchItem(AList: TList; AnItem: TPCEItem): Integer;
244       procedure MarkDeletions(PreList: TList; PostList: TStrings);
245       procedure SetSCRelated(Value: Integer);
246       procedure SetAORelated(Value: Integer);
247       procedure SetIRRelated(Value: Integer);
248       procedure SetECRelated(Value: Integer);
249       procedure SetMSTRelated(Value: Integer);
250       procedure SetHNCRelated(Value: Integer);
251       procedure SetCVRelated(Value: Integer);
252       procedure SetSHADRelated(Value: Integer);
253       procedure SetEncUseCurr(Value: Boolean);
254       function GetHasData: Boolean;
255       procedure GetHasCPTList(AList: TStrings);
256       procedure CopyPCEItems(Src: TList; Dest: TObject; ItemClass: TPCEItemClass);
257     public
258       constructor Create;
259       destructor Destroy; override;
260       procedure Clear;
261       procedure CopyPCEData(Dest: TPCEData);
262       function Empty: boolean;
263       procedure PCEForNote(NoteIEN: Integer; EditObj: TPCEData);(* overload;
264       procedure PCEForNote(NoteIEN: Integer; EditObj: TPCEData; DCSummAdmitString: string); overload;*)
265       procedure Save;
266       procedure CopyDiagnoses(Dest: TStrings);     // ICDcode^P|S^Category^Narrative^P|S Text
267       procedure CopyProcedures(Dest: TStrings);    // CPTcode^Qty^Category^Narrative^Qty Text
268       procedure CopyImmunizations(Dest: TStrings); //
269       procedure CopySkinTests(Dest: TStrings);     //
270       procedure CopyPatientEds(Dest: TStrings);
271       procedure CopyHealthFactors(Dest: TStrings);
272       procedure CopyExams(Dest: TStrings);
273   
274       procedure SetDiagnoses(Src: TStrings; FromForm: boolean = TRUE);       // ICDcode^P|S^Category^Narrative^P|S Text
275       procedure SetExams(Src: TStrings; FromForm: boolean = TRUE);
276       Procedure SetHealthFactors(Src: TStrings; FromForm: boolean = TRUE);
277       procedure SetImmunizations(Src: TStrings; FromForm: boolean = TRUE);   // IMMcode^
278       Procedure SetPatientEds(Src: TStrings; FromForm: boolean = TRUE);
279       procedure SetSkinTests(Src: TStrings; FromForm: boolean = TRUE);        //
280       procedure SetProcedures(Src: TStrings; FromForm: boolean = TRUE);      // CPTcode^Qty^Category^Narrative^Qty Text
281   
282       procedure SetVisitType(Value: TPCEProc);     // CPTcode^1^Category^Narrative
283       function StrDiagnoses: string;               // Diagnoses: ...
284       function StrImmunizations: string;           // Immunizzations: ...
285       function StrProcedures: string;              // Procedures: ...
286       function StrSkinTests: string;
287       function StrPatientEds: string;
288       function StrHealthFactors: string;
289       function StrExams: string;
290       function StrVisitType(const ASCRelated, AAORelated, AIRRelated, AECRelated,
291                                   AMSTRelated, AHNCRelated, ACVRelated, ASHADRelated: Integer): string; overload;
292       function StrVisitType: string; overload;
293       function StandAlone: boolean;
294       procedure AddStrData(List: TStrings);
295       procedure AddVitalData(Data, List: TStrings);
296   
297       function NeededPCEData: tRequiredPCEDataTypes;
298       function OK2SignNote: boolean;
299   
300       function PersonClassDate: TFMDateTime;
301       function VisitDateTime: TFMDateTime;
302       function IsSecondaryVisit: boolean;
303       function NeedProviderInfo: boolean;
304   
305       property HasData:      Boolean  read GetHasData;
306       property CPTRequired:  Boolean  read GetCPTRequired;
307       property ProblemAdded: Boolean  read FProblemAdded;
308       property Inpatient:    Boolean  read FEncInpatient;
309       property UseEncounter: Boolean  read FEncUseCurr  write SetEncUseCurr;
310       property SCRelated:    Integer  read FSCRelated   write SetSCRelated;
311       property AORelated:    Integer  read FAORelated   write SetAORelated;
312       property IRRelated:    Integer  read FIRRelated   write SetIRRelated;
313       property ECRelated:    Integer  read FECRelated   write SetECRelated;
314       property MSTRelated:   Integer  read FMSTRelated  write SetMSTRelated;
315       property HNCRelated:   Integer  read FHNCRelated  write SetHNCRelated;
316       property CVRelated:    Integer  read FCVRelated  write SetCVRelated;
317       property SHADRelated:   Integer  read FSHADRelated write SetSHADRelated;
318       property VisitType:    TPCEProc read fVisitType   write SetVisitType;
319       property VisitString:  string   read GetVisitString;
320       property VisitCategory:char     read FEncSvcCat   write FEncSvcCat;
321       property DateTime:     TFMDateTime read FEncDateTime write FEncDateTime;
322       property NoteDateTime: TFMDateTime read FNoteDateTime write FNoteDateTime;
323       property Location:     Integer  Read FencLocation;
324       property NoteTitle:    Integer read FNoteTitle write FNoteTitle;
325       property NoteIEN:      Integer read FNoteIEN write FNoteIEN;
326       property DocCOunt:     Integer read getDocCount;
327       property Providers:    TPCEProviderList read FProviders;
328       property Parent:       string read FParent write FParent;
329       property HistoricalLocation: string read FHistoricalLocation write FHistoricalLocation;
330       property Updated: boolean read FUpdated write FUpdated;
331     end;
332   
333   type
334     TPCEType = (ptEncounter, ptReminder, ptTemplate);
335   
336   const
337     PCETypeText: array[TPCEType] of string = ('encounter', 'reminder', 'template');
338   
339   function InvalidPCEProviderTxt(AIEN: Int64; ADate: TFMDateTime): string;
340   function MissingProviderInfo(PCEEdit: TPCEData; PCEType: TPCEType = ptEncounter): boolean;
341   function IsOK2Sign(const PCEData: TPCEData; const IEN: integer) :boolean;
342   function FutureEncounter(APCEData: TPCEData): boolean;
343   function CanEditPCE(APCEData: TPCEData): boolean;
344   procedure GetPCECodes(List: TStrings; CodeType: integer);
345   procedure GetComboBoxMinMax(dest: TORComboBox; var Min, Max: integer);
346   procedure PCELoadORCombo(dest: TORComboBox); overload;
347   procedure PCELoadORCombo(dest: TORComboBox; var Min, Max: integer); overload;
348   function GetPCEDisplayText(ID: string; Tag: integer): string;
349   procedure SetDefaultProvider(ProviderList: TPCEProviderList; APCEData: TPCEData);
350   function ValidateGAFDate(var GafDate: TFMDateTime): string;
351   procedure GetVitalsFromDate(VitalStr: TStrings; PCEObj: TPCEData);
352   procedure GetVitalsFromNote(VitalStr: TStrings; PCEObj: TPCEData; ANoteIEN: Int64);
353   
354   type
355     TPCEDataCat = (pdcVisit, pdcDiag, pdcProc, pdcImm, pdcSkin, pdcPED, pdcHF,
356                    pdcExam, pdcVital, pdcOrder, pdcMH, pdcMST, pdcHNC, pdcWHR, pdcWH);
357   
358   function GetPCEDataText(Cat: TPCEDataCat; Code, Category, Narrative: string;
359                          PrimaryDiag: boolean = FALSE; Qty: integer = 0): string;
360   
361   const
362     PCEDataCatText: array[TPCEDataCat] of string =
363                           { dcVisit } ('',
364                           { dcDiag  }  'Diagnoses: ',
365                           { dcProc  }  'Procedures: ',
366                           { dcImm   }  'Immunizations: ',
367                           { dcSkin  }  'Skin Tests: ',
368                           { dcPED   }  'Patient Educations: ',
369                           { dcHF    }  'Health Factors: ',
370                           { dcExam  }  'Examinations: ',
371                           { dcVital }  '',
372                           { dcOrder }  'Orders: ',
373                           { dcMH    }  'Mental Health: ',
374                           { dcMST   }  'MST History: ',
375                           { dcHNC   }  'Head and/or Neck Cancer: ',
376                           { dcWHR   }  'Women''s Health Procedure: ',
377                           { dcWH    }  'WH Notification: ');
378   
379     NoPCEValue = '@';
380     TAB_STOP_CHARS = 7;
381     TX_NO_VISIT   = 'Insufficient Visit Information';
382     TX_NEED_PROV1  = 'The provider responsible for this encounter must be entered before ';
383     TX_NEED_PROV2  = ' information may be entered.';
384   //  TX_NEED_PROV3  = 'you can sign the note.';
385     TX_NO_PROV    = 'Missing Provider';
386     TX_BAD_PROV   = 'Invalid Provider';
387     TX_NOT_ACTIVE = ' does not have an active person class.';
388     TX_NOT_PROV   = ' is not a known Provider.';
389     TX_MISSING    = 'Required Information Missing';
390     TX_REQ1       = 'The following required fields have not been entered:' + CRLF;
391     TC_REQ        = 'Required Fields';
392     TX_ADDEND_AD  = 'Cannot make an addendum to an addendum' + CRLF +
393                     'Please select the parent note or document, and try again.';
394     TX_ADDEND_MK  = 'Unable to Make Addendum';
395     TX_DEL_CNF    = 'Confirm Deletion';
396     TX_IN_AUTH    = 'Insufficient Authorization';
397     TX_NOPCE      = '<No encounter information entered>';
398     TX_NEED_T     = 'Missing Encounter Information';
399     TX_NEED1      = 'This note title is marked to prompt for the following missing' + CRLF +
400                     'encounter information:' + CRLF;
401     TX_NEED_DIAG  = '  A diagnosis.';
402     TX_NEED_PROC  = '  A visit type or procedure.';
403     TX_NEED_SC    = '  One or more service connected questions.';
404     TX_NEED2      = 'Would you like to enter encounter information now?';
405     TX_NEED3      = 'You must enter the encounter information before you can sign the note.';
406     TX_NEEDABORT  = 'Document not signed.';
407     TX_COS_REQ    = 'A cosigner is required for this document.';
408     TX_COS_SELF   = 'You cannot make yourself a cosigner.';
409     TX_COS_AUTH   = ' is not authorized to cosign this document.';
410     TC_COS        = 'Select Cosigner';
411   
412     TAG_IMMSERIES  = 10;
413     TAG_IMMREACTION= 20;
414     TAG_SKRESULTS  = 30;
415     TAG_PEDLEVEL   = 40;
416     TAG_HFLEVEL    = 50;
417     TAG_XAMRESULTS = 60;
418     TAG_HISTLOC    = 70;
419   
420   { These piece numbers are used by both the PCE objects and reminders }
421     pnumCode           = 2;
422     pnumPrvdrIEN       = 2;
423     pnumCategory       = 3;
424     pnumNarrative      = 4;
425     pnumExamResults    = 5;
426     pnumSkinResults    = 5;
427     pnumHFLevel        = 5;
428     pnumImmSeries      = 5;
429     pnumProcQty        = 5;
430     pnumPEDLevel       = 5;
431     pnumDiagPrimary    = 5;
432     pnumPrvdrName      = 5;
433     pnumProvider       = 6;
434     pnumPrvdrPrimary   = 6;
435     pnumSkinReading    = 7;
436     pnumImmReaction    = 7;
437     pnumDiagAdd2PL     = 7;
438     pnumSkinDTRead     = 8;
439     pnumImmContra      = 8;
440     pnumSkinDTGiven    = 9;
441     pnumImmRefused     = 9;
442     pnumCPTMods        = 9;
443     pnumComment        = 10;
444     pnumWHPapResult    =11;
445     pnumWHNotPurp      =12;
446   
447     USE_CURRENT_VISITSTR = -2;
448   
449   implementation
450   
451   uses uCore, rPCE, rCore, rTIU, fEncounterFrame, uVitals, fFrame,
452        fPCEProvider, rVitals, uReminders;
453   
454   const
455     FN_NEW_PERSON = 200;
456   
457   function InvalidPCEProviderTxt(AIEN: Int64; ADate: TFMDateTime): string;
458   begin
459     Result := '';
460     if(not CheckActivePerson(IntToStr(AIEN), ADate)) then
461       Result := TX_NOT_ACTIVE
462     else
463     if(not IsUserAProvider(AIEN, ADate)) then
464       Result := TX_NOT_PROV;
465   end;
466   
467   function MissingProviderInfo(PCEEdit: TPCEData; PCEType: TPCEType = ptEncounter): boolean;
468   begin
469     if(PCEEdit.Empty and (PCEEdit.Location <> Encounter.Location) and (not Encounter.NeedVisit)) then
470       PCEEdit.UseEncounter := TRUE;
471     Result := NoPrimaryPCEProvider(PCEEdit.Providers, PCEEdit);
472     if(Result) then
473       InfoBox(TX_NEED_PROV1 + PCETypeText[PCEType] + TX_NEED_PROV2,
474               TX_NO_PROV, MB_OK or MB_ICONWARNING);
475   end;
476   
477   var
478     UNxtCommSeqNum: integer;                             
479   
480   function IsOK2Sign(const PCEData: TPCEData; const IEN: integer) :boolean;
481   var
482     TmpPCEData: TPCEData;
483   
484   begin
485     if(assigned(PCEData)) then
486       PCEData.FUpdated := FALSE;
487     if(assigned(PCEData) and (PCEData.VisitString <> '') and
488        (VisitStrForNote(IEN) = PCEData.VisitString)) then
489     begin
490       if(PCEData.FNoteIEN <= 0) then
491         PCEData.FNoteIEN := IEN;
492       Result := PCEData.OK2SignNote
493     end
494     else
495     begin
496       TmpPCEData := TPCEData.Create;
497       try
498         TmpPCEData.PCEForNote(IEN, nil);
499         Result := TmpPCEData.OK2SignNote;
500       finally
501         TmpPCEData.Free;
502       end;
503     end;
504   end;
505   
506   function FutureEncounter(APCEData: TPCEData): boolean;
507   begin
508     Result := (Int(APCEData.FEncDateTime + 0.0000001) > Int(FMToday + 0.0000001));
509   end;
510   
511   function CanEditPCE(APCEData: TPCEData): boolean;
512   begin
513     if(GetAskPCE(APCEData.FEncLocation) = apDisable) then
514       Result := FALSE
515     else
516       Result := (not FutureEncounter(APCEData));
517   end;
518   
519   procedure GetComboBoxMinMax(dest: TORComboBox; var Min, Max: integer);
520   var
521     DC: HDC;
522     SaveFont: HFont;
523     TextSize: TSize;
524     TLen, i: integer;
525     x: string;
526   
527   begin
528     Min := MaxInt;
529     Max := 0;
530     DC := GetDC(0);
531     try
532       SaveFont := SelectObject(DC, dest.Font.Handle);
533       try
534         for i := 0 to dest.Items.Count-1 do
535         begin
536           x := dest.DisplayText[i];
537           GetTextExtentPoint32(DC, PChar(x), Length(x), TextSize);
538           TLen := TextSize.cx;
539           if(TLen > 0) and (Min > TLen) then
540             Min := TLen;
541           if(Max < TLen) then
542             Max := TLen;
543         end;
544       finally
545         SelectObject(DC, SaveFont);
546       end;
547     finally
548       ReleaseDC(0, DC);
549     end;
550     if(Min > Max) then Min := Max;
551   
552     inc(Min, ScrollBarWidth + 8);
553     inc(Max, ScrollBarWidth + 8);
554   end;
555   
556   type
557     TListMinMax = (mmMin, mmMax, mmFont);
558   
559   var
560     PCESetsOfCodes: TStringList = nil;
561     HistLocations: TORStringList = nil;
562     WHNotPurpose: TORStringList = nil;
563     WHPapResult: TORStringList = nil;
564     WHMammResult: TORStringList = nil;
565     WHUltraResult: TORStringList = nil;
566   const
567     SetOfCodesHeader = '{^~Codes~^}';
568     SOCHeaderLen = length(SetOfCodesHeader);
569     ListMinMax: array[1..7, TListMinMax] of integer =
570                             ((0,0,-1),  // TAG_IMMSERIES
571                              (0,0,-1),  // TAG_IMMREACTION
572                              (0,0,-1),  // TAG_SKRESULTS
573                              (0,0,-1),  // TAG_PEDLEVEL
574                              (0,0,-1),  // TAG_HFLEVEL
575                              (0,0,-1),  // TAG_XAMRESULTS
576                              (0,0,-1));  // TAG_HISTLOC
577                              
578   function CodeSetIndex(CodeType: integer): integer;
579   var
580     TempSL: TStringList;
581     Hdr: string;
582   
583   begin
584     Hdr := SetOfCodesHeader + IntToStr(CodeType);
585     Result := PCESetsOfCodes.IndexOf(Hdr);
586     if(Result < 0) then
587     begin
588       TempSL := TStringList.Create;
589       try
590         case CodeType of
591           TAG_IMMSERIES:   LoadImmSeriesItems(TempSL);
592           TAG_IMMREACTION: LoadImmReactionItems(TempSL);
593           TAG_SKRESULTS:   LoadSkResultsItems(TempSL);
594           TAG_PEDLEVEL:    LoadPEDLevelItems(TempSL);
595           TAG_HFLEVEL:     LoadHFLevelItems(TempSL);
596           TAG_XAMRESULTS:  LoadXAMResultsItems(TempSL);
597           else
598             KillObj(@TempSL);
599         end;
600         if(assigned(TempSL)) then
601         begin
602           Result := PCESetsOfCodes.Add(Hdr);
603           FastAddStrings(TempSL, PCESetsOfCodes);
604         end;
605       finally
606         KillObj(@TempSL);
607       end;
608     end;
609   end;
610   
611   procedure GetPCECodes(List: TStrings; CodeType: integer);
612   var
613     idx: integer;
614   
615     begin
616     if(CodeType = TAG_HISTLOC) then
617     begin
618       if(not assigned(HistLocations)) then
619       begin
620         HistLocations := TORStringList.Create;
621         LoadHistLocations(HistLocations);
622         HistLocations.SortByPiece(2);
623         HistLocations.Insert(0,'0');
624       end;
625       FastAddStrings(HistLocations, List);
626     end
627     else
628     begin
629       if(not assigned(PCESetsOfCodes)) then
630         PCESetsOfCodes := TStringList.Create;
631       idx := CodeSetIndex(CodeType);
632       if(idx >= 0) then
633       begin
634         inc(idx);
635         while((idx < PCESetsOfCodes.Count) and
636               (copy(PCESetsOfCodes[idx],1,SOCHeaderLen) <> SetOfCodesHeader)) do
637         begin
638           List.Add(PCESetsOfCodes[idx]);
639           inc(idx);
640         end;
641       end;
642     end;
643   end;
644   
645   function GetPCECodeString(CodeType: integer; ID: string): string;
646   var
647     idx: integer;
648   
649   begin
650     Result := '';
651     if(CodeType <> TAG_HISTLOC) then
652     begin
653       if(not assigned(PCESetsOfCodes)) then
654         PCESetsOfCodes := TStringList.Create;
655       idx := CodeSetIndex(CodeType);
656       if(idx >= 0) then
657       begin
658         inc(idx);
659         while((idx < PCESetsOfCodes.Count) and
660               (copy(PCESetsOfCodes[idx],1,SOCHeaderLen) <> SetOfCodesHeader)) do
661         begin
662           if(Piece(PCESetsOfCodes[idx], U, 1) = ID) then
663           begin
664             Result := Piece(PCESetsOfCodes[idx], U, 2);
665             break;
666           end;
667           inc(idx);
668         end;
669       end;
670     end;
671   end;
672   
673   procedure PCELoadORComboData(dest: TORComboBox; GetMinMax: boolean; var Min, Max: integer);
674   var
675     idx: integer;
676   
677   begin
678     if(dest.items.count < 1) then
679     begin
680       dest.Clear;
681       GetPCECodes(dest.Items, dest.Tag);
682       dest.itemindex := 0;
683       if(GetMinMax) and (dest.Items.Count > 0) then
684       begin
685         idx := dest.Tag div 10;
686         if(idx > 0) and (idx < 8) then
687         begin
688           if(ListMinMax[idx, mmFont] <> integer(dest.Font.Handle)) then
689           begin
690             GetComboBoxMinMax(dest, Min, Max);
691             ListMinMax[idx, mmMin] := Min;
692             ListMinMax[idx, mmMax] := Max;
693           end
694           else
695           begin
696             Min := ListMinMax[idx, mmMin];
697             Max := ListMinMax[idx, mmMax];
698           end;
699         end;
700       end;
701     end;
702   end;
703   
704   procedure PCELoadORCombo(dest: TORComboBox);
705   var
706     tmp: integer;
707   
708   begin
709     PCELoadORComboData(dest, FALSE, tmp, tmp);
710   end;
711   
712   procedure PCELoadORCombo(dest: TORComboBox; var Min, Max: integer);
713   begin
714     PCELoadORComboData(dest, TRUE, Min, Max);
715   end;
716   
717   function GetPCEDisplayText(ID: string; Tag: integer): string;
718   var
719     Hdr: string;
720     idx: integer;
721     TempSL: TStringList;
722   
723   begin
724     Result := '';
725     if(Tag = TAG_HISTLOC) then
726     begin
727       if(not assigned(HistLocations)) then
728       begin
729         HistLocations := TORStringList.Create;
730         LoadHistLocations(HistLocations);
731         HistLocations.SortByPiece(2);
732         HistLocations.Insert(0,'0');
733       end;
734       idx := HistLocations.IndexOfPiece(ID);
735       if(idx >= 0) then
736         Result := Piece(HistLocations[idx], U, 2);
737     end
738     else
739     begin
740       if(not assigned(PCESetsOfCodes)) then
741         PCESetsOfCodes := TStringList.Create;
742       Hdr := SetOfCodesHeader + IntToStr(Tag);
743       idx := PCESetsOfCodes.IndexOf(Hdr);
744       if(idx < 0) then
745       begin
746         TempSL := TStringList.Create;
747         try
748           case Tag of
749             TAG_IMMSERIES:   LoadImmSeriesItems(TempSL);
750             TAG_IMMREACTION: LoadImmReactionItems(TempSL);
751             TAG_SKRESULTS:   LoadSkResultsItems(TempSL);
752             TAG_PEDLEVEL:    LoadPEDLevelItems(TempSL);
753             TAG_HFLEVEL:     LoadHFLevelItems(TempSL);
754             TAG_XAMRESULTS:  LoadXAMResultsItems(TempSL);
755             else
756               KillObj(@TempSL);
757           end;
758           if(assigned(TempSL)) then
759           begin
760             idx := PCESetsOfCodes.Add(Hdr);
761             FastAddStrings(TempSL, PCESetsOfCodes);
762           end;
763         finally
764           KillObj(@TempSL);
765         end;
766       end;
767       if(idx >= 0) then
768       begin
769         inc(idx);
770         while((idx < PCESetsOfCodes.Count) and
771               (copy(PCESetsOfCodes[idx],1,SOCHeaderLen) <> SetOfCodesHeader)) do
772         begin
773           if(Piece(PCESetsOfCodes[idx], U, 1) = ID) then
774           begin
775             Result := Piece(PCESetsOfCodes[idx], U, 2);
776             break;
777           end;
778           inc(idx);
779         end;
780       end;
781     end;
782   end;
783   
784   function GetPCEDataText(Cat: TPCEDataCat; Code, Category, Narrative: string;
785                          PrimaryDiag: boolean = FALSE; Qty: integer = 0): string;
786   begin
787     Result := '';
788     case Cat of
789       pdcVisit: if Code <> '' then Result := Category + ' ' + Narrative;
790       pdcDiag:  begin
791                  Result := GetDiagnosisText(Narrative, Code);
792                  if PrimaryDiag then Result := Result + ' (Primary)';
793                end;
794       pdcProc: begin
795                 Result := Narrative;
796                 if Qty > 1 then Result := Result + ' (' + IntToStr(Qty) + ' times)';
797               end;
798       else Result := Narrative;
799     end;
800   end;
801   
802   procedure SetDefaultProvider(ProviderList: TPCEProviderList; APCEData: TPCEData);
803   var
804     SIEN, tmp: string;
805     DefUser, AUser: Int64;
806     UserName: string;
807   
808   begin
809     DefUser := Encounter.Provider;
810     if(DefUser <> 0) and (InvalidPCEProviderTxt(DefUser, APCEData.PersonClassDate) <> '') then
811       DefUser := 0;
812     if(DefUser <> 0) then
813     begin
814       AUser := DefUser;
815       UserName := Encounter.ProviderName;
816     end
817     else
818     if(InvalidPCEProviderTxt(User.DUZ, APCEData.PersonClassDate) = '') then
819     begin
820       AUser := User.DUZ;
821       UserName := User.Name;
822     end
823     else
824     begin
825       AUser := 0;
826       UserName := '';
827     end;
828     if(AUser = 0) then
829       ProviderList.FPendingUser := ''
830     else
831       ProviderList.FPendingUser := IntToStr(AUser) + U + UserName;
832     ProviderList.FPendingDefault := '';
833     tmp := DefaultProvider(APCEData.Location, DefUser, APCEData.PersonClassDate, APCEData.NoteIEN);
834     SIEN := IntToStr(StrToIntDef(Piece(tmp,U,1),0));
835     if(SIEN <> '0') then
836     begin
837       if(CheckActivePerson(SIEN, APCEData.PersonClassDate)) then
838       begin
839         if(piece(TIUSiteParams, U, 8) = '1') and // Check to see if DEFAULT PRIMARY PROVIDER is by Location 
840           (SIEN = IntToStr(User.DUZ)) then
841           ProviderList.AddProvider(SIEN, Piece(tmp,U,2) ,TRUE)
842         else
843           ProviderList.FPendingDefault := tmp;
844       end;
845     end;
846   end;
847   
848   function ValidateGAFDate(var GafDate: TFMDateTime): string;
849   var
850     DateMsg: string;
851     OKDate: TFMDateTime;
852   
853   begin
854     Result := '';
855     if(Patient.DateDied > 0) and (FMToday > Patient.DateDied) then
856     begin
857       DateMsg := 'Date of Death';
858       OKDate := Patient.DateDied;
859     end
860     else
861     begin
862       DateMsg := 'Today';
863       OKDate := FMToday;
864     end;
865     if(GafDate <= 0) then
866     begin
867       Result := 'A date is required to enter a GAF score.  Date Determined changed to ' + DateMsg + '.';
868       GafDate := OKDate;
869     end
870     else
871     if(Patient.DateDied > 0) and (GafDate > Patient.DateDied) then
872     begin
873       Result := 'This patient died ' + FormatFMDateTime('mmm dd, yyyy hh:nn', Patient.DateDied) +
874              '.  Date GAF determined can not ' + CRLF +
875              'be later than the date of death, and has been changed to ' + DateMsg + '.';
876       GafDate := OKDate;
877     end;
878   end;
879   
880   procedure GetVitalsFromDate(VitalStr: TStrings; PCEObj: TPCEData);
881   var
882     dte: TFMDateTime;
883     
884   begin
885     if(PCEObj.IsSecondaryVisit) then
886       dte := PCEObj.NoteDateTime
887     else
888       dte := PCEObj.DateTime;
889     GetVitalsFromEncDateTime(VitalStr, Patient.DFN, dte);
890   end;
891   
892   procedure GetVitalsFromNote(VitalStr: TStrings; PCEObj: TPCEData; ANoteIEN: Int64);
893   begin
894     if(PCEObj.IsSecondaryVisit) then
895       GetVitalsFromEncDateTime(VitalStr, Patient.DFN, PCEObj.NoteDateTime)
896     else
897       GetVitalFromNoteIEN(VitalStr, Patient.DFN, ANoteIEN);
898   end;
899   
900   { TPCEItem methods ------------------------------------------------------------------------- }
901   
902   //function TPCEItem.DelimitedStr2: string;
903   //added: 6/17/98
904   //By: Robert Bott
905   //Location: ISL
906   //Purpose: Return comment string to be passed in RPC call.
907   function TPCEItem.DelimitedStr2: string;
908   {created delimited string to pass to broker}
909   begin
910     If Comment = '' then
911     begin
912       result := 'COM' + U +  IntToStr(UNxtCommSeqNum) + U + NoPCEValue;
913     end
914     else
915     begin
916       Result := 'COM' + U +  IntToStr(UNxtCommSeqNum) + U + Comment;
917     end;
918   
919     Inc(UNxtCommSeqNum); //set up for next comment
920   end;
921   
922   procedure TPCEItem.Assign(Src: TPCEItem);
923   begin
924     FDelete   := Src.FDelete;
925     FSend     := Src.FSend;
926     Code      := Src.Code;
927     Category  := Src.Category;
928     Narrative := Src.Narrative;
929     Provider  := Src.Provider;
930     Comment   := Src.Comment;                            
931   end;
932   
933   procedure TPCEItem.SetComment(const Value: String);
934   begin
935     FComment := Value;
936     while (length(FComment) > 0) and (FComment[1] = '?') do
937       delete(FComment,1,1);
938   end;
939   
940   
941   //procedure TPCEItem.Clear;
942   //modified: 6/17/98
943   //By: Robert Bott
944   //Location: ISL
945   //Purpose: Add Comments to PCE Items.
946   procedure TPCEItem.Clear;
947   {clear fields(properties) of class}
948   begin
949     FDelete   := False;
950     FSend     := False;
951     Code      := '';
952     Category  := '';
953     Narrative := '';
954     Provider  := 0;
955     Comment   := '';                                     
956   end;
957   
958   //function TPCEItem.DelimitedStr: string;
959   //modified: 6/17/98
960   //By: Robert Bott
961   //Location: ISL
962   //Purpose: Add Comments to PCE Items.
963   function TPCEItem.DelimitedStr: string;
964   {created delimited string to pass to broker}
965   var
966     DelFlag: Char;
967   begin
968     if FDelete then DelFlag := '-' else DelFlag := '+';
969     Result := DelFlag + U + Code + U + Category + U + Narrative;
970   end;
971   
972   function TPCEItem.ItemStr: string;
973   {returns string to be assigned to Tlist in PCEData object}
974   begin
975     Result := Narrative;
976   end;
977   
978   function TPCEItem.Match(AnItem: TPCEItem): Boolean;
979   {checks for match of Code, Category. and Item}
980   begin
981     Result := False;
982     if (Code = AnItem.Code) and (Category = AnItem.Category) and (Narrative = AnItem.Narrative)
983       then Result := True;
984   end;
985   
986   function TPCEItem.HasCPTStr: string;
987   begin
988     Result := '';
989   end;
990   
991   //procedure TPCEItem.SetFromString(const x: string);
992   //modified: 6/17/98
993   //By: Robert Bott
994   //Location: ISL
995   //Purpose: Add Comments to PCE Items.
996   procedure TPCEItem.SetFromString(const x: string);
997   { sets fields to pieces passed from server:  TYP ^ Code ^ Category ^ Narrative }
998   begin
999     Code      := Piece(x, U, pnumCode);
1000    Category  := Piece(x, U, pnumCategory);
1001    Narrative := Piece(x, U, pnumNarrative);
1002    Provider  := StrToInt64Def(Piece(x, U, pnumProvider), 0);
1003    Comment   := Piece(x, U, pnumComment);
1004  end;
1005  
1006  
1007  { TPCEExams methods ------------------------------------------------------------------------- }
1008  
1009  procedure TPCEExams.Assign(Src: TPCEItem);
1010  begin
1011    inherited Assign(Src);
1012    Results := TPCEExams(Src).Results;
1013    if Results = '' then Results := NoPCEValue;
1014  end;
1015  
1016  procedure TPCEExams.Clear;
1017  {clear fields(properties) of class}
1018  begin
1019    inherited Clear;
1020  //  Provider := 0;
1021    Results  := NoPCEValue;
1022  end;
1023  
1024  //function TPCEExams.DelimitedStr: string;
1025  //modified: 6/17/98
1026  //By: Robert Bott
1027  //Location: ISL
1028  //Purpose: Add Comments to PCE Items.
1029  function TPCEExams.DelimitedStr: string;
1030  {created delimited string to pass to broker}
1031  begin
1032    Result := inherited DelimitedStr;
1033    //Result := 'XAM' + Result + U + Results + U + IntToStr(Provider) +U + U + U +
1034    Result := 'XAM' + Result + U + Results + U +U + U + U +
1035     U + IntToStr(UNxtCommSeqNum);
1036  end;
1037  
1038  (*function TPCEExams.delimitedStrC: string;
1039  begin
1040    Result := inherited DelimitedStr;
1041    Result := 'XAM' + Result + U + Results + U + IntToStr(Provider) +U + U + U +
1042     U + comment;
1043  end;
1044  *)
1045  function TPCEExams.HasCPTStr: string;
1046  begin
1047    Result := Code + ';AUTTEXAM(';
1048  end;
1049  
1050  function TPCEExams.ItemStr: string;
1051  {returns string to be assigned to Tlist in PCEData object}
1052  begin
1053    if(Results <> NoPCEValue) then
1054      Result := GetPCECodeString(TAG_XAMRESULTS, Results)
1055    else
1056      Result := '';
1057    Result := Result + U + inherited ItemStr;
1058  end;
1059  
1060  procedure TPCEExams.SetFromString(const x: string);
1061  { sets fields to pieces passed from server:  TYP ^ Code ^ Category ^ Narrative ^ Qty ^ Prov }
1062  begin
1063    inherited SetFromString(x);
1064  //  Provider := StrToInt64Def(Piece(x, U, pnumProvider), 0);
1065    Results  := Piece(x, U, pnumExamResults);
1066    If results = '' then results := NoPCEValue;
1067  end;
1068  
1069  
1070  { TPCESkin methods ------------------------------------------------------------------------- }
1071  
1072  procedure TPCESkin.Assign(Src: TPCEItem);
1073  var
1074    SKSrc: TPCESkin;
1075  
1076  begin
1077    inherited Assign(Src);
1078    SKSrc := TPCESkin(Src);
1079    Results := SKSrc.Results;
1080    Reading := SKSrc.Reading;
1081    DTRead  := SKSrc.DTRead;
1082    DTGiven := SKSrc.DTGiven;
1083    if Results = '' then Results := NoPCEValue;
1084  end;
1085  
1086  procedure TPCESkin.Clear;
1087  {clear fields(properties) of class}
1088  begin
1089    inherited Clear;
1090  //  Provider := 0;
1091    Results := NoPCEValue;
1092    Reading   := 0;
1093    DTRead    := 0.0;        //What should dates be ititialized to?
1094    DTGiven   := 0.0;
1095  end;
1096  
1097  //function TPCESkin.DelimitedStr: string;
1098  //modified: 6/17/98
1099  //By: Robert Bott
1100  //Location: ISL
1101  //Purpose: Add Comments to PCE Items.
1102  function TPCESkin.DelimitedStr: string;
1103  {created delimited string to pass to broker}
1104  begin
1105    Result := inherited DelimitedStr;
1106    //Result := 'SK' + Result + U + results + U + IntToStr(Provider) + U +
1107    Result := 'SK' + Result + U + results + U + U +
1108     IntToStr(Reading) + U + U + U + IntToStr(UNxtCommSeqNum); 
1109      //+ FloatToStr(DTRead) + U + FloatToStr(DTGiven);
1110  end;
1111  
1112  (*function TPCESkin.delimitedStrC: string;
1113  begin
1114    Result := inherited DelimitedStr;
1115    Result := 'SK' + Result + U + results + U + IntToStr(Provider) + U +
1116     IntToStr(Reading) + U + U + U + comment;
1117  end;
1118  *)
1119  function TPCESkin.HasCPTStr: string;
1120  begin
1121    Result := Code + ';AUTTSK(';
1122  end;
1123  
1124  function TPCESkin.ItemStr: string;
1125  {returns string to be assigned to Tlist in PCEData object}
1126  begin
1127    if(Results <> NoPCEValue) then
1128      Result := GetPCECodeString(TAG_SKRESULTS, Results)
1129    else
1130      Result := '';
1131    Result := Result + U;
1132    if(Reading <> 0) then
1133      Result := Result + IntToStr(Reading);
1134    Result := Result + U + inherited ItemStr;
1135  end;
1136  
1137  procedure TPCESkin.SetFromString(const x: string);
1138  { sets fields to pieces passed from server:  TYP ^ Code ^ Category ^ Narrative ^ Qty ^ Prov }
1139  var
1140    sRead, sDTRead, sDTGiven: String;
1141  begin
1142    inherited SetFromString(x);
1143  //  Provider := StrToInt64Def(Piece(x, U, pnumProvider), 0);
1144    Results  := Piece(x, U, pnumSkinResults);
1145    sRead    := Piece(x, U, pnumSkinReading);
1146    sDTRead  := Piece(x, U, pnumSkinDTRead);
1147    sDtGiven := Piece(x, U, pnumSkinDTGiven);
1148    If results = '' then results := NoPCEValue;
1149  
1150    if sRead <> '' then
1151      Reading  := StrToInt(sRead);
1152    if sDTRead <> '' then
1153      DTRead   := StrToFMDateTime(sDTRead);
1154    if sDTGiven <> '' then
1155      DTGiven  := StrToFMDateTime(sDTGiven);
1156  
1157  end;
1158  
1159  
1160  { TPCEHealth methods ------------------------------------------------------------------------- }
1161  
1162  procedure TPCEHealth.Assign(Src: TPCEItem);
1163  begin
1164    inherited Assign(Src);
1165    Level := TPCEHealth(Src).Level;
1166    if Level = '' then Level := NoPCEValue;
1167  end;
1168  
1169  procedure TPCEHealth.Clear;
1170  {clear fields(properties) of class}
1171  begin
1172    inherited Clear;
1173  //  Provider := 0;
1174    Level    := NoPCEValue;
1175  end;
1176  
1177  //function TPCEHealth.DelimitedStr: string;
1178  //modified: 6/17/98
1179  //By: Robert Bott
1180  //Location: ISL
1181  //Purpose: Add Comments to PCE Items.
1182  function TPCEHealth.DelimitedStr: string;
1183  {created delimited string to pass to broker}
1184  begin
1185    Result := inherited DelimitedStr;
1186  //  Result := 'HF' + Result + U + Level + U + IntToStr(Provider) + U + U + U +
1187    Result := 'HF' + Result + U + Level + U + U + U + U +
1188     U + IntToStr(UNxtCommSeqNum)+ U + GecRem; 
1189  end;
1190  
1191  (*function TPCEHealth.delimitedStrC: string;
1192  begin
1193    Result := inherited DelimitedStr;
1194    Result := 'HF' + Result + U + Level + U + IntToStr(Provider) + U + U + U +
1195     U + comment;
1196  end;
1197  *)
1198  function TPCEHealth.HasCPTStr: string;
1199  begin
1200    Result := Code + ';AUTTHF(';
1201  end;
1202  
1203  function TPCEHealth.ItemStr: string;
1204  {returns string to be assigned to Tlist in PCEData object}
1205  begin
1206    if(Level <> NoPCEValue) then
1207      Result := GetPCECodeString(TAG_HFLEVEL, Level)
1208    else
1209      Result := '';
1210    Result := Result + U + inherited ItemStr;
1211  end;
1212  
1213  procedure TPCEHealth.SetFromString(const x: string);
1214  { sets fields to pieces passed from server:  TYP ^ Code ^ Category ^ Narrative ^ Qty ^ Prov }
1215  begin
1216    inherited SetFromString(x);
1217  //  Provider := StrToInt64Def(Piece(x, U, pnumProvider), 0);
1218    Level    := Piece(x, U, pnumHFLevel);
1219    if level = '' then level := NoPCEValue;
1220  end;
1221  
1222  
1223  { TPCEImm methods ------------------------------------------------------------------------- }
1224  
1225  procedure TPCEImm.Assign(Src: TPCEItem);
1226  var
1227    IMMSrc: TPCEImm;
1228    
1229  begin
1230    inherited Assign(Src);
1231    IMMSrc := TPCEImm(Src);
1232    Series          := IMMSrc.Series;
1233    Reaction        := IMMSrc.Reaction;
1234    Refused         := IMMSrc.Refused;
1235    Contraindicated := IMMSrc.Contraindicated;
1236    if Series = '' then Series := NoPCEValue;
1237    if Reaction ='' then Reaction := NoPCEValue;
1238  end;
1239  
1240  procedure TPCEImm.Clear;
1241  {clear fields(properties) of class}
1242  begin
1243    inherited Clear;
1244  //  Provider := 0;
1245    Series   := NoPCEValue;
1246    Reaction := NoPCEValue;
1247    Refused  := False; //not currently used
1248    Contraindicated := false;
1249  end;
1250  
1251  //function TPCEImm.DelimitedStr: string;
1252  //modified: 6/17/98
1253  //By: Robert Bott
1254  //Location: ISL
1255  //Purpose: Add Comments to PCE Items.
1256  function TPCEImm.DelimitedStr: string;
1257  {created delimited string to pass to broker}
1258  begin
1259    Result := inherited DelimitedStr;
1260    //Result := 'IMM' + Result + U + Series + U + IntToStr(Provider) + U + Reaction;
1261    Result := 'IMM' + Result + U + Series + U + U + Reaction;
1262    if Contraindicated then Result := Result + U + '1'
1263    else Result := Result + U + '0';
1264    Result := Result + U + U + IntToStr(UNxtCommSeqNum); 
1265    {the following two lines are not yet implemented in PCE side}
1266    //if Refused then Result := Result + U + '1'
1267    //else Result := Result + U + '0';
1268  end;
1269  
1270  (*function TPCEImm.delimitedStrC: string;
1271  begin
1272    Result := inherited DelimitedStr;
1273    Result := 'IMM' + Result + U + Series + U + IntToStr(Provider) + U + Reaction;
1274    if Contraindicated then Result := Result + U + '1'
1275    else Result := Result + U + '0';
1276    Result := Result + U + U + comment;
1277      {the following two lines are not yet implemented in PCE side}
1278    //if Refused then Result := Result + U + '1'
1279    //else Result := Result + U + '0';
1280  end;
1281  *)
1282  function TPCEImm.HasCPTStr: string;
1283  begin
1284    Result := Code + ';AUTTIMM(';
1285  end;
1286  
1287  function TPCEImm.ItemStr: string;
1288  {returns string to be assigned to Tlist in PCEData object}
1289  begin
1290    if(Series <> NoPCEValue) then
1291      Result := GetPCECodeString(TAG_IMMSERIES, Series)
1292    else
1293      Result := '';
1294    Result := Result + U;
1295    if(Reaction <> NoPCEValue) then
1296      Result := Result + GetPCECodeString(TAG_IMMREACTION, Reaction);
1297    Result := Result + U;
1298    if(Contraindicated) then
1299      Result := Result + 'X';
1300    Result := Result + U + inherited ItemStr;
1301  end;
1302  
1303  procedure TPCEImm.SetFromString(const x: string);
1304  { sets fields to pieces passed from server:  TYP ^ Code ^ Category ^ Narrative ^ Qty ^ Prov }
1305  var
1306    temp: String;
1307  begin
1308    inherited SetFromString(x);
1309  //  Provider := StrToInt64Def(Piece(x, U, pnumProvider), 0);
1310    Series   := Piece(x, U, pnumImmSeries);
1311    Reaction := Piece(x, U, pnumImmReaction);
1312    temp     := Piece(x, U, pnumImmRefused);
1313    if temp = '1' then refused  := true else refused := false;
1314    temp     := Piece(x, U, pnumImmContra);
1315    if temp = '1' then Contraindicated := true else Contraindicated := false;
1316    if Series = '' then series := NoPCEValue;
1317    if Reaction ='' then reaction := NoPCEValue;
1318  end;
1319  
1320  
1321  
1322  { TPCEProc methods ------------------------------------------------------------------------- }
1323  
1324  procedure TPCEProc.Assign(Src: TPCEItem);
1325  begin
1326    inherited Assign(Src);
1327    Quantity := TPCEProc(Src).Quantity;
1328    Modifiers := TPCEProc(Src).Modifiers;
1329    Provider := TPCEProc(Src).Provider;
1330  end;
1331  
1332  procedure TPCEProc.Clear;
1333  {clear fields(properties) of class}
1334  begin
1335    inherited Clear;
1336    Quantity := 0;
1337    Modifiers := '';
1338  //  Provider := 0;
1339    Provider := 0;
1340  end;
1341  
1342  procedure TPCEProc.CopyProc(Dest: TPCEProc);
1343  begin
1344    Dest.FDelete    :=  FDelete;
1345    Dest.FSend      :=  Fsend;                          //flag to send to broker
1346  //  Dest.Provider   := Provider;
1347    Dest.Provider   := Provider;
1348    Dest.Code       := Code;
1349    Dest.Category   := Category;
1350    Dest.Narrative  := Narrative;
1351    Dest.Comment    := Comment;
1352    Dest.Modifiers  := Modifiers;
1353  end;
1354  
1355  //function TPCEProc.DelimitedStr: string;
1356  //modified: 6/17/98
1357  //By: Robert Bott
1358  //Location: ISL
1359  //Purpose: Add Comments to PCE Items.
1360  function TPCEProc.DelimitedStr: string;
1361  var
1362    i, cnt: integer;
1363    Mods, ModIEN, tmpProv: string;
1364  
1365  {created delimited string to pass to broker}
1366  begin
1367    i := 1;
1368    cnt := 0;
1369    Mods := '';
1370    repeat
1371      ModIEN := piece(Modifiers, ';', i);
1372      if(ModIEN <> '') then
1373      begin
1374        inc(cnt);
1375        Mods := Mods + ';' + ModifierCode(ModIEN) + '/' + ModIEN;
1376        inc(i);
1377      end;
1378    until (ModIEN = '');
1379  
1380    Result := inherited DelimitedStr;
1381    if Provider > 0 then tmpProv := IntToStr(Provider) else tmpProv := '';
1382    Result := 'CPT' + Result + U + IntToStr(Quantity) + U + tmpProv
1383               + U + U + U + IntToStr(cnt) + Mods + U + IntToStr(UNxtCommSeqNum) + U;
1384    if Length(Result) > 250 then SetPiece(Result, U, 4, '');
1385  end;
1386  
1387  (*function TPCEProc.delimitedStrC: string;
1388  begin
1389    Result := inherited DelimitedStr;
1390    Result := 'CPT' + Result + U + IntToStr(Quantity) + U + IntToStr(Provider) +
1391    U + U + U + U + comment;
1392  end;
1393  *)
1394  
1395  function TPCEProc.Empty: boolean;
1396  begin
1397    Result := (Code = '') and (Category = '') and (Narrative = '') and
1398              (Comment = '') and (Quantity = 0) and (Provider = 0) and (Modifiers = '');
1399  end;
1400  
1401  (*function TPCEProc.Match(AnItem: TPCEProc): Boolean;        {NEW CODE - v20 testing only - RV}
1402  begin
1403    Result := inherited Match(AnItem) and (Modifiers = AnItem.Modifiers);
1404  end;*)
1405  
1406  function TPCEProc.ModText: string;
1407  var
1408    i: integer;
1409    tmp: string;
1410  
1411  begin
1412    Result := '';
1413    if(Modifiers <> '') then
1414    begin
1415      i := 1;
1416      repeat
1417        tmp := Piece(Modifiers,';',i);
1418        if(tmp <> '') then
1419        begin
1420          tmp := ModifierName(tmp);
1421          Result := Result + ' - ' + tmp;
1422        end;
1423        inc(i);
1424      until (tmp = '');
1425    end;
1426  end;
1427  
1428  function TPCEProc.ItemStr: string;
1429  {returns string to be assigned to Tlist in PCEData object}
1430  begin
1431    if(Quantity > 1) then
1432      Result := IntToStr(Quantity) + ' times'
1433    else
1434      Result := '';
1435    Result := Result + U + inherited ItemStr + ModText;
1436  end;
1437  
1438  procedure TPCEProc.SetFromString(const x: string);
1439  var
1440    i, cnt: integer;
1441    Mods: string;
1442  { sets fields to pieces passed from server:  TYP ^ Code ^ Category ^ Narrative ^ Qty ^ Prov }
1443  begin
1444    inherited SetFromString(x);
1445    Quantity := StrToIntDef(Piece(x, U, pnumProcQty), 1);
1446  //  Provider := StrToInt64Def(Piece(x, U, pnumProvider), 0);
1447    Provider := StrToInt64Def(Piece(x, U, pnumProvider), 0);
1448    Modifiers := '';
1449    Mods := Piece(x, U, pnumCPTMods);
1450    cnt := StrToIntDef(Piece(Mods, ';', 1), 0);
1451    if(cnt > 0) then
1452     for i := 1 to cnt do
1453       Modifiers := Modifiers + Piece(Piece(Mods, ';' , i+1), '/', 2) + ';';
1454  end;
1455  
1456  
1457  { TPCEPat methods ------------------------------------------------------------------------- }
1458  
1459  procedure TPCEPat.Assign(Src: TPCEItem);
1460  begin
1461    inherited Assign(Src);
1462    Level := TPCEPat(Src).Level;
1463    if Level = '' then Level := NoPCEValue;
1464  end;
1465  
1466  procedure TPCEPat.Clear;
1467  {clear fields(properties) of class}
1468  begin
1469    inherited Clear;
1470  //  Provider := 0;
1471    Level    := NoPCEValue;
1472  end;
1473  
1474  //function TPCEPat.DelimitedStr: string;
1475  //modified: 6/17/98
1476  //By: Robert Bott
1477  //Location: ISL
1478  //Purpose: Add Comments to PCE Items.
1479  function TPCEPat.DelimitedStr: string;
1480  {created delimited string to pass to broker}
1481  begin
1482    Result := inherited DelimitedStr;
1483    //Result := 'PED' + Result + U + Level + U + IntToStr(Provider) + U + U + U +
1484    Result := 'PED' + Result + U + Level + U+ U + U + U +
1485     U + IntToStr(UNxtCommSeqNum); 
1486  end;
1487  
1488  (*function TPCEPat.delimitedStrC: string;
1489  begin
1490    Result := inherited DelimitedStr;
1491    Result := 'PED' + Result + U + Level + U + IntToStr(Provider) + U + U + U +
1492     U + comment;
1493  end;
1494  *)
1495  function TPCEPat.HasCPTStr: string;
1496  begin
1497    Result := Code + ';AUTTEDT(';
1498  end;
1499  
1500  function TPCEPat.ItemStr: string;
1501  {returns string to be assigned to Tlist in PCEData object}
1502  begin
1503    if(Level <> NoPCEValue) then
1504      Result := GetPCECodeString(TAG_PEDLEVEL, Level)
1505    else
1506      Result := '';
1507    Result := Result + U + inherited ItemStr;
1508  end;
1509  
1510  procedure TPCEPat.SetFromString(const x: string);
1511  { sets fields to pieces passed from server:  TYP ^ Code ^ Category ^ Narrative ^ Qty ^ Prov }
1512  begin
1513    inherited SetFromString(x);
1514  //  Provider := StrToInt64Def(Piece(x, U, pnumProvider), 0);
1515    Level    := Piece(x, U, pnumPEDLevel);
1516    if level = '' then level := NoPCEValue;
1517  end;
1518  
1519  { TPCEDiag methods ------------------------------------------------------------------------- }
1520  
1521  procedure TPCEDiag.Assign(Src: TPCEItem);
1522  begin
1523    inherited Assign(Src);
1524    Primary    := TPCEDiag(Src).Primary;
1525    AddProb    := TPCEDiag(Src).AddProb;
1526  end;
1527  
1528  //procedure TPCEDiag.Clear;
1529  //modified: 6/17/98
1530  //By: Robert Bott
1531  //Location: ISL
1532  //Purpose: Clear a diagnosis object.
1533  procedure TPCEDiag.Clear;
1534  {clear fields(properties) of class}
1535  begin
1536    inherited Clear;
1537    Primary := False;
1538    //Provider := 0;
1539    AddProb  := False;
1540  end;
1541  
1542  //function TPCEDiag.DelimitedStr: string;
1543  //modified: 6/17/98
1544  //By: Robert Bott
1545  //Location: ISL
1546  //Purpose: Create delimited string to pass to Broker.
1547  function TPCEDiag.DelimitedStr: string;
1548  {created delimited string to pass to broker}
1549  var
1550    ProviderStr: string; {jm 9/8/99}
1551  begin
1552    Result := inherited DelimitedStr;
1553    if(AddProb) then
1554      ProviderStr := IntToStr(fProvider)
1555    else
1556      ProviderStr := '';
1557    Result := 'POV' + Result + U + BOOLCHAR[Primary] + U + ProviderStr + U +
1558      BOOLCHAR[AddProb] + U + U + U;
1559    if(SaveComment) then Result := Result + IntToStr(UNxtCommSeqNum);
1560    if Length(Result) > 250 then SetPiece(Result, U, 4, '');
1561  end;
1562  
1563  function TPCEDiag.DelimitedStr2: string;
1564  begin
1565    If Comment = '' then
1566    begin
1567      SaveComment := (OldComment <> '') or (not AddProb);
1568      if(SaveComment) then
1569        result := 'COM' + U +  IntToStr(UNxtCommSeqNum) + U + NoPCEValue
1570      else
1571        result := '';
1572    end
1573    else
1574    begin
1575      Result := 'COM' + U +  IntToStr(UNxtCommSeqNum) + U + Comment;
1576      SaveComment := TRUE;
1577    end;
1578    Inc(UNxtCommSeqNum);
1579  end;
1580  
1581  (*function TPCEDiag.DelimitedStrC: string;
1582  {created delimited string for internal use - keep comment in same string.}
1583  begin
1584    Result := inherited DelimitedStr;
1585    Result := 'POV' + Result + U + BOOLCHAR[Primary] + U + IntToStr(Provider)+
1586    U + BOOLCHAR[AddProb] + U + U + U + comment;
1587  end;
1588  *)
1589  function TPCEDiag.ItemStr: string;
1590  {returns string to be assigned to Tlist in PCEData object}
1591  begin
1592    if Primary then
1593      Result := 'Primary'
1594    else
1595      Result := 'Secondary';
1596  // This may change in the future if we add a check box to the grid    
1597    if(AddProb) then
1598      Result := 'Add' + U + Result
1599    else
1600      Result := U + Result;
1601  
1602    Result := Result + U + GetDiagnosisText((inherited ItemStr), Code);
1603  end;
1604  
1605  procedure TPCEDiag.Send;
1606  //marks diagnosis to be sent;
1607  begin
1608    Fsend := True;
1609  end;
1610  
1611  //procedure TPCEDiag.SetFromString(const x: string);
1612  //modified: 6/17/98
1613  //By: Robert Bott
1614  //Location: ISL
1615  //Purpose: Sets fields to pieces passed from server.
1616  procedure TPCEDiag.SetFromString(const x: string);
1617  { sets fields to pieces passed from server:  TYP ^ Code ^ Category ^ Narrative ^ Primary ^ ^ ^ Comment }
1618  begin
1619    inherited SetFromString(x);
1620    OldComment := Comment;
1621    Primary := (Piece(x, U, pnumDiagPrimary) = '1');
1622    //Provider := StrToInt64Def(Piece(x, U, pnumProvider),0);
1623    AddProb := (Piece(x, U, pnumDiagAdd2PL) = '1');
1624  end;
1625  
1626  { TPCEData methods ------------------------------------------------------------------------- }
1627  
1628  constructor TPCEData.Create;
1629  begin
1630    fDiagnoses   := TList.Create;
1631    FProcedures  := TList.Create;
1632    FImmunizations := TList.Create;
1633    FSkinTests   := TList.Create;
1634    fVisitType   := TPCEProc.Create;
1635    FPatientEds  := TList.Create;
1636    FHealthFactors := TList.Create;
1637    fExams       := TList.Create;
1638    FProviders := TPCEProviderList.Create;
1639    FSCRelated   := SCC_NA;
1640    FAORelated   := SCC_NA;
1641    FIRRelated   := SCC_NA;
1642    FECRelated   := SCC_NA;
1643    FMSTRelated  := SCC_NA;
1644    FHNCRelated  := SCC_NA;
1645    FCVRelated   := SCC_NA;
1646    FSHADRelated := SCC_NA;
1647    FSCChanged   := False;
1648  end;
1649  
1650  destructor TPCEData.Destroy;
1651  var
1652    i: Integer;
1653  begin
1654    with fDiagnoses  do for i := 0 to Count - 1 do TPCEDiag(Items[i]).Free;
1655    with FProcedures do for i := 0 to Count - 1 do TPCEProc(Items[i]).Free;
1656    with FImmunizations do for i := 0 to Count - 1 do TPCEImm(Items[i]).Free;
1657    with FSkinTests do for i := 0 to Count - 1 do TPCESkin(Items[i]).Free;
1658    with FPatientEds do for i := 0 to Count - 1 do TPCEPat(Items[i]).Free;
1659    with FHealthFactors do for i := 0 to Count - 1 do TPCEHealth(Items[i]).Free;
1660    with FExams do for i := 0 to Count - 1 do TPCEExams(Items[i]).Free;
1661    fVisitType.Free;
1662    fDiagnoses.Free;
1663    FProcedures.Free;
1664    FImmunizations.Free;  
1665    FSkinTests.free;      
1666    FPatientEds.Free;
1667    FHealthFactors.Free;
1668    FExams.Free;
1669    FProviders.Free;
1670    inherited Destroy;
1671  end;
1672  
1673  procedure TPCEData.Clear;
1674  
1675    procedure ClearList(AList: TList);
1676    var
1677      i: Integer;
1678  
1679    begin
1680      for i := 0 to AList.Count - 1 do
1681        TObject(AList[i]).Free;
1682      AList.Clear;
1683    end;
1684  
1685  begin
1686    FEncDateTime := 0;
1687    FNoteDateTime := 0;
1688    FEncLocation := 0;
1689    FEncSvcCat   := 'A';
1690    FEncInpatient := FALSE;
1691    FProblemAdded := False;
1692    FEncUseCurr   := FALSE;
1693    FStandAlone := FALSE;
1694    FStandAloneLoaded := FALSE;
1695    FParent       := '';
1696    FHistoricalLocation := '';
1697    FSCRelated  := SCC_NA;
1698    FAORelated  := SCC_NA;
1699    FIRRelated  := SCC_NA;
1700    FECRelated  := SCC_NA;
1701    FMSTRelated := SCC_NA;
1702    FHNCRelated := SCC_NA;
1703    FCVRelated  := SCC_NA;
1704    FSHADRelated := SCC_NA;
1705  
1706    ClearList(fDiagnoses);
1707    ClearList(FProcedures);
1708    ClearList(FImmunizations);
1709    ClearList(FSkinTests);
1710    ClearList(FPatientEds);
1711    ClearList(FHealthFactors);
1712    ClearList(FExams);
1713  
1714    fVisitType.Clear;
1715    FProviders.Clear;
1716    FSCChanged   := False;
1717    FNoteIEN := 0;
1718    FNoteTitle := 0;
1719  end;
1720  
1721  procedure TPCEData.CopyDiagnoses(Dest: TStrings);
1722  begin
1723    CopyPCEItems(fDiagnoses, Dest, TPCEDiag);
1724  end;
1725  
1726  procedure TPCEData.CopyProcedures(Dest: TStrings);
1727  begin
1728    CopyPCEItems(FProcedures, Dest, TPCEProc);
1729  end;
1730  
1731  procedure TPCEData.CopyImmunizations(Dest: TStrings);
1732  begin
1733    CopyPCEItems(FImmunizations, Dest, TPCEImm);
1734  end;
1735  
1736  procedure TPCEData.CopySkinTests(Dest: TStrings);
1737  begin
1738    CopyPCEItems(FSkinTests, Dest, TPCESkin);
1739  end;
1740  
1741  procedure TPCEData.CopyPatientEds(Dest: TStrings);
1742  begin
1743    CopyPCEItems(FPatientEds, Dest, TPCEPat);
1744  end;
1745  
1746  procedure TPCEData.CopyHealthFactors(Dest: TStrings);
1747  begin
1748    CopyPCEItems(FHealthFactors, Dest, TPCEHealth);
1749  end;
1750  
1751  procedure TPCEData.CopyExams(Dest: TStrings);
1752  begin
1753    CopyPCEItems(FExams, Dest, TPCEExams);
1754  end;
1755  
1756  function TPCEData.GetVisitString: string;
1757  begin
1758    Result :=  IntToStr(FEncLocation) + ';' + FloatToStr(VisitDateTime) + ';' + FEncSvcCat;
1759  end;
1760  
1761  function TPCEData.GetCPTRequired: Boolean;
1762  begin
1763    Result := (([ndDiag, ndProc] * NeededPCEData) <> []);
1764  end;
1765  
1766  procedure TPCEData.PCEForNote(NoteIEN: Integer; EditObj: TPCEData);
1767  (*const
1768    NULL_STR = '';
1769  begin
1770    PCEForNote(NoteIEN, EditObj, NULL_STR);
1771  end;
1772  
1773  procedure TPCEData.PCEForNote(NoteIEN: Integer; EditObj: TPCEData; DCSummAdmitString: string);*)
1774  var
1775    i, j: Integer;
1776    TmpCat, TmpVStr: string;
1777    x: string;
1778    DoCopy, IsVisit: Boolean;
1779    PCEList, VisitTypeList: TStringList;
1780    ADiagnosis:    TPCEDiag;
1781    AProcedure:    TPCEProc;
1782    AImmunization: TPCEImm;
1783    ASkinTest:     TPCESkin;
1784    APatientEd:    TPCEPat;
1785    AHealthFactor: TPCEHealth;
1786    AExam:         TPCEExams;
1787    FileVStr: string;
1788    FileIEN: integer;
1789    GetCat, DoRestore: boolean;
1790    FRestDate: TFMDateTime;
1791  //  AProvider:     TPCEProvider;  {6/9/99}
1792  
1793    function SCCValue(x: string): Integer;
1794    begin
1795      Result := SCC_NA;
1796      if Piece(x, U, 3) = '1' then Result := SCC_YES;
1797      if Piece(x, U, 3) = '0' then Result := SCC_NO;
1798    end;
1799  
1800    function AppendComment(x: string): String;
1801    begin
1802      //check for comment append string if a comment exists   
1803      If (((i+1) <= (PCEList.Count - 1)) and (Copy(PCEList[(i+1)], 1, 3) = 'COM')) then
1804      begin
1805        //remove last piece (comment sequence number) from x.
1806        While x[length(x)] <> U do
1807          x := Copy(X,0,(length(x)-1));
1808        //add last piece of comment to x
1809        x := X + Piece (PCEList[(i+1)],U,3);
1810      end;
1811      result := x;
1812    end;
1813  
1814  begin
1815  (*  if DCSummAdmitString <> '' then
1816      TmpVStr := DCSummAdmitString
1817    else*) if(NoteIEN < 1) then
1818      TmpVStr := Encounter.VisitStr
1819    else
1820    begin
1821      TmpVStr := VisitStrForNote(NoteIEN);
1822      if(FEncSvcCat = #0) then
1823        GetCat :=TRUE
1824      else
1825      if(GetVisitString = '0;0;A') then
1826      begin
1827        FEncLocation := StrToIntDef(Piece(TmpVStr, ';', 1), 0);
1828        FEncDateTime := StrToFloatDef(Piece(TmpVStr, ';', 2),0);
1829        GetCat :=TRUE
1830      end
1831      else
1832        GetCat := FALSE;
1833      if(GetCat) then
1834      begin
1835        TmpCat := Piece(TmpVStr, ';', 3);
1836        if(TmpCat <> '') then
1837          FEncSvcCat := TmpCat[1];
1838      end;
1839    end;
1840  
1841    if(assigned(EditObj)) then
1842    begin
1843      if(copy(TmpVStr,1,2) <> '0;') and   // has location
1844        (pos(';0;',TmpVStr) = 0) and     // has time
1845        (EditObj.GetVisitString = TmpVStr) then
1846      begin
1847        if(FEncSvcCat = 'H') and (FEncInpatient) then
1848          DoCopy := (FNoteDateTime = EditObj.FNoteDateTime)
1849        else
1850          DoCopy := TRUE;
1851        if(DoCopy) then
1852        begin
1853          if(EditObj <> Self) then
1854          begin
1855            EditObj.CopyPCEData(Self);
1856            FNoteTitle := 0;
1857            FNoteIEN := 0;
1858          end;
1859          exit;
1860        end;
1861      end;
1862    end;
1863  
1864    TmpCat := Piece(TmpVStr, ';', 3);
1865    if(TmpCat <> '') then
1866      FEncSvcCat := TmpCat[1]
1867    else
1868      FEncSvcCat := #0;
1869    FEncLocation := StrToIntDef(Piece(TmpVStr,';',1),0);
1870    FEncDateTime := StrToFloatDef(Piece(TmpVStr, ';', 2),0);
1871  
1872    if(IsSecondaryVisit and (FEncLocation > 0)) then
1873    begin
1874      FileIEN := USE_CURRENT_VISITSTR;
1875      FileVStr := IntToStr(FEncLocation) + ';' + FloatToStr(FNoteDateTime) + ';' +
1876                                                 GetLocSecondaryVisitCode(FEncLocation);
1877      DoRestore := TRUE;
1878      FRestDate := FEncDateTime;
1879    end
1880    else
1881    begin
1882      DoRestore := FALSE;
1883      FRestDate := 0; 
1884      FileIEN := NoteIEN;
1885  (*    if DCSummAdmitString <> '' then
1886        FileVStr := DCSummAdmitString
1887      else*) if(FileIEN < 0) then
1888        FileVStr := Encounter.VisitStr
1889      else
1890        FileVStr := '';
1891    end;
1892  
1893    Clear;
1894    PCEList       := TStringList.Create;
1895    VisitTypeList := TStringList.Create;
1896    try
1897      LoadPCEDataForNote(PCEList, FileIEN, FileVStr);        // calls broker RPC to load data
1898      FNoteIEN := NoteIEN;
1899      for i := 0 to PCEList.Count - 1 do
1900      begin
1901        x := PCEList[i];
1902        if Copy(x, 1, 4) = 'HDR^' then             // HDR ^ Inpatient ^ ProcReq ^ VStr ^ Provider
1903        {header information-------------------------------------------------------------}
1904        begin
1905          FEncInpatient := Piece(x, U, 2) = '1';
1906          //FCPTRequired  := Piece(x, U, 3) = '1';  
1907          //FNoteHasCPT   := Piece(x, U, 6) = '1';    //4/21/99 error! PIECE 3 = cptRequired, not HasCPT!
1908          FEncLocation  := StrToIntDef(Piece(Piece(x, U, 4), ';', 1), 0);
1909          if DoRestore then
1910          begin
1911            FEncSvcCat := 'H';
1912            FEncDateTime := FRestDate;
1913            FNoteDateTime := MakeFMDateTime(Piece(Piece(x, U, 4), ';', 2));
1914          end
1915          else
1916          begin
1917            FEncDateTime  := MakeFMDateTime(Piece(Piece(x, U, 4), ';', 2));
1918            FEncSvcCat    := CharAt(Piece(Piece(x, U, 4), ';', 3), 1);
1919          end;
1920          //FEncProvider  := StrToInt64Def(Piece(x, U, 5), 0);
1921          ListVisitTypeByLoc(VisitTypeList, FEncLocation, FEncDateTime);
1922          //set the values needed fot the RPCs
1923          SetRPCEncLocation(FEncLocation);
1924  //        SetRPCEncDateTime(FEncDateTime);
1925        end;
1926        {visit information--------------------------------------------------------------}
1927        if Copy(x, 1, 7) = 'VST^DT^' then
1928        begin
1929          if DoRestore then
1930          begin
1931            FEncDateTime := FRestDate;
1932            FNoteDateTime := MakeFMDateTime(Piece(x, U, 3));
1933          end
1934          else
1935            FEncDateTime := MakeFMDateTime(Piece(x, U, 3));
1936        end;
1937        if Copy(x, 1, 7) = 'VST^HL^' then FEncLocation := StrToIntDef(Piece(x, U, 3), 0);
1938        if Copy(x, 1, 7) = 'VST^VC^' then
1939        begin
1940          if DoRestore then
1941            FEncSvcCat := 'H'
1942          else
1943            FEncSvcCat := CharAt(x, 8);
1944        end;
1945        if Copy(x, 1, 7) = 'VST^PS^' then FEncInpatient := CharAt(x, 8) = '1';
1946        {6/10/99}//if Copy(x, 1, 4) = 'PRV^'    then FEncProvider := StrToInt64Def(Piece(x, U, 2), 0);
1947        if Copy(x, 1, 7) = 'VST^SC^'  then FSCRelated := SCCValue(x);
1948        if Copy(x, 1, 7) = 'VST^AO^'  then FAORelated := SCCValue(x);
1949        if Copy(x, 1, 7) = 'VST^IR^'  then FIRRelated := SCCValue(x);
1950        if Copy(x, 1, 7) = 'VST^EC^'  then FECRelated := SCCValue(x);
1951        if Copy(x, 1, 8) = 'VST^MST^' then FMSTRelated := SCCValue(x);
1952  //      if HNCOK and (Copy(x, 1, 8) = 'VST^HNC^') then
1953        if Copy(x, 1, 8) = 'VST^HNC^' then FHNCRelated := SCCValue(x);
1954        if Copy(x, 1, 7) = 'VST^CV^' then FCVRelated := SCCValue(x);
1955        if (Copy(x, 1, 3) = 'PRV') and (CharAt(x, 4) <> '-') then
1956        {Providers---------------------------------------------------------------------}
1957        begin
1958          FProviders.Add(x);
1959        end;
1960  
1961        if (Copy(x, 1, 3) = 'POV') and (CharAt(x, 4) <> '-') then
1962        {'POV'=Diagnosis--------------------------------------------------------------}
1963        begin
1964          //check for comment append string if a comment exists   
1965          x := AppendComment(x);                         
1966          ADiagnosis := TPCEDiag.Create;
1967          ADiagnosis.SetFromString(x);
1968          fDiagnoses.Add(ADiagnosis);
1969        end;
1970        if (Copy(x, 1, 3) = 'CPT') and (CharAt(x, 4) <> '-') then
1971        {CPT (procedure) information--------------------------------------------------}
1972        begin
1973          x := AppendComment(x);                         
1974  
1975          IsVisit := False;
1976          with VisitTypeList do for j := 0 to Count - 1 do
1977            if Pieces(x, U, 2, 4) = Strings[j] then IsVisit := True;
1978          if IsVisit and (fVisitType.Code = '') then fVisitType.SetFromString(x) else
1979          begin
1980            AProcedure := TPCEProc.Create;
1981            AProcedure.SetFromString(x);
1982            AProcedure.fIsOldProcedure := TRUE;
1983            FProcedures.Add(AProcedure);
1984          end; {if IsVisit}
1985        end; {if Copy}
1986        if (Copy(x, 1, 3) = 'IMM') and (CharAt(x, 4) <> '-') then
1987        {Immunizations ---------------------------------------------------------------}
1988        begin
1989          x := AppendComment(x);                         
1990          AImmunization := TPCEImm.Create;
1991          AImmunization.SetFromString(x);
1992          FImmunizations.Add(AImmunization);
1993        end;
1994        if (Copy(x, 1, 2) = 'SK') and (CharAt(x, 3) <> '-') then
1995        {Skin Tests-------------------------------------------------------------------}
1996        begin
1997          x := AppendComment(x);                         
1998          ASkinTest := TPCESkin.Create;
1999          ASkinTest.SetFromString(x);
2000          FSkinTests.Add(ASkinTest);
2001        end;
2002        if (Copy(x, 1, 3) = 'PED') and (CharAt(x, 3) <> '-') then
2003        {Patient Educations------------------------------------------------------------}
2004        begin
2005          x := AppendComment(x);                         
2006          APatientEd := TPCEPat.Create;
2007          APatientEd.SetFromString(x);
2008          FpatientEds.Add(APatientEd);
2009        end;
2010        if (Copy(x, 1, 2) = 'HF') and (CharAt(x, 3) <> '-') then
2011        {Health Factors----------------------------------------------------------------}
2012        begin
2013          x := AppendComment(x);                         
2014          AHealthFactor := TPCEHealth.Create;
2015          AHealthFactor.SetFromString(x);
2016          FHealthFactors.Add(AHealthFactor);
2017        end;
2018        if (Copy(x, 1, 3) = 'XAM') and (CharAt(x, 3) <> '-') then
2019        {Exams ------------------------------------------------------------------------}
2020        begin
2021          x := AppendComment(x);
2022          AExam := TPCEExams.Create;
2023          AExam.SetFromString(x);
2024          FExams.Add(AExam);
2025        end;
2026  
2027      end;
2028    finally
2029      PCEList.Free;
2030      VisitTypeList.Free;
2031    end;
2032  end;
2033  
2034  //procedure TPCEData.Save;
2035  //modified: 6/17/98
2036  //By: Robert Bott
2037  //Location: ISL
2038  //Purpose: Add Comments to PCE Items.
2039  procedure TPCEData.Save;
2040  { pass the changes to the encounter to DATA2PCE,
2041    Pieces: Subscript^Code^Qualifier^Category^Narrative^Delete }
2042  var
2043    i: Integer;
2044    x, AVisitStr, EncName, Temp2: string;
2045    PCEList: TStringList;
2046    FileCat: char;
2047    FileDate: TFMDateTime;
2048    FileNoteIEN: integer;
2049    dstring1,dstring2: pchar; //used to separate former DelimitedStr variable
2050                               // into two strings, the second being for the comment.
2051  
2052  begin
2053    PCEList := TStringList.Create;
2054    UNxtCommSeqNum := 1;                                 
2055    try
2056      with PCEList do
2057      begin
2058        if(IsSecondaryVisit) then
2059        begin
2060          FileCat := GetLocSecondaryVisitCode(FEncLocation);
2061          FileDate := FNoteDateTime;
2062          FileNoteIEN := NoteIEN;
2063          if((NoteIEN > 0) and ((FParent = '') or (FParent = '0'))) then
2064            FParent := GetVisitIEN(NoteIEN);
2065        end
2066        else
2067        begin
2068          FileCat := FEncSvcCat;
2069          FileDate := FEncDateTime;
2070          FileNoteIEN := 0;
2071        end;
2072        AVisitStr :=  IntToStr(FEncLocation) + ';' + FloatToStr(FileDate) + ';' + FileCat;
2073        Add('HDR^' + BOOLCHAR[FEncInpatient] + U + U + AVisitStr);
2074  //      Add('HDR^' + BOOLCHAR[FEncInpatient] + U + BOOLCHAR[FNoteHasCPT] + U + AVisitStr);
2075        // set up list that can be passed via broker to set up array for DATA2PCE
2076        Add('VST^DT^' + FloatToStr(FileDate));  // Encounter Date/Time
2077        Add('VST^PT^' + Patient.DFN);               // Encounter Patient    //*DFN*
2078        if(FEncLocation > 0) then
2079          Add('VST^HL^' + IntToStr(FEncLocation));    // Encounter Location
2080        Add('VST^VC^' + FileCat);                // Encounter Service Category
2081        if(StrToIntDef(FParent,0) > 0) then
2082          Add('VST^PR^' + FParent);                 // Parent for secondary visit
2083        if(FileCat = 'E') and (FHistoricalLocation <> '') then
2084          Add('VST^OL^' + FHistoricalLocation);     // Outside Location
2085        FastAddStrings(FProviders, PCEList);
2086  
2087        if FSCChanged then
2088        begin
2089          if FSCRelated  <> SCC_NA then  Add('VST^SC^'  + IntToStr(FSCRelated));
2090          if FAORelated  <> SCC_NA then  Add('VST^AO^'  + IntToStr(FAORelated));
2091          if FIRRelated  <> SCC_NA then  Add('VST^IR^'  + IntToStr(FIRRelated));
2092          if FECRelated  <> SCC_NA then  Add('VST^EC^'  + IntToStr(FECRelated));
2093          if FMSTRelated <> SCC_NA then  Add('VST^MST^' + IntToStr(FMSTRelated));
2094          if FHNCRelated  <> SCC_NA then Add('VST^HNC^'+ IntToStr(FHNCRelated));
2095          if FCVRelated   <> SCC_NA then Add('VST^CV^' + IntToStr(FCVRelated));
2096          if FSHADRelated <> SCC_NA then Add('VST^SHD^'+ IntToStr(FSHADRelated));
2097        end;
2098       with fDiagnoses  do for i := 0 to Count - 1 do with TPCEDiag(Items[i]) do
2099          if FSend then
2100          begin
2101            Temp2 := DelimitedStr2; // Call first to make sure SaveComment is set.
2102            if(SaveComment) then
2103              dec(UNxtCommSeqNum);
2104            fProvider := FProviders.PCEProvider;
2105            // Provides user with list of dx when signing orders - Billing Aware
2106            PCEList.Add(DelimitedStr);
2107            if(SaveComment) then
2108            begin
2109              inc(UNxtCommSeqNum);
2110              if(Temp2 <> '') then
2111                PCEList.Add(Temp2);
2112            end;
2113        end;
2114        with FProcedures do for i := 0 to Count - 1 do with TPCEProc(Items[i]) do
2115          if FSend then
2116          begin
2117            PCEList.Add(DelimitedStr);
2118            PCEList.Add(DelimitedStr2);
2119          end;
2120        with FImmunizations do for i := 0 to Count - 1 do with TPCEImm(Items[i]) do
2121          if FSend then
2122          begin
2123            PCEList.Add(DelimitedStr);
2124            PCEList.Add(DelimitedStr2);
2125          end;
2126        with FSkinTests do for i := 0 to Count - 1 do with TPCESkin(Items[i]) do
2127          if FSend then
2128          begin
2129            PCEList.Add(DelimitedStr);
2130            PCEList.Add(DelimitedStr2);
2131          end;
2132        with FPatientEds do for i := 0 to Count - 1 do with TPCEPat(Items[i]) do
2133          if FSend then
2134          begin
2135            PCEList.Add(DelimitedStr);
2136            PCEList.Add(DelimitedStr2);
2137          end;
2138        with FHealthFactors do for i := 0 to Count - 1 do with TPCEHealth(Items[i]) do
2139          if FSend then
2140          begin
2141            PCEList.Add(DelimitedStr);
2142            PCEList.Add(DelimitedStr2);
2143          end;
2144        with FExams do for i := 0 to Count - 1 do with TPCEExams(Items[i]) do
2145          if FSend then
2146          begin
2147            PCEList.Add(DelimitedStr);
2148            PCEList.Add(DelimitedStr2);
2149          end;
2150  
2151        with fVisitType  do
2152        begin
2153          if Code = '' then Fsend := false;
2154          if FSend then
2155          begin
2156            PCEList.Add(DelimitedStr);
2157            PCEList.Add(DelimitedStr2);
2158          end;
2159        end;
2160        // call DATA2PCE (in background)
2161        SavePCEData(PCEList, FileNoteIEN, FEncLocation);
2162  
2163        // turn off 'Send' flags and remove items that were deleted
2164        with fDiagnoses  do for i := Count - 1 downto 0 do with TPCEDiag(Items[i]) do
2165        begin
2166          FSend := False;
2167          // for diags, toggle off AddProb flag as well
2168          AddProb := False;
2169          if FDelete then
2170          begin
2171            TPCEDiag(Items[i]).Free;
2172            Delete(i);
2173          end;
2174        end;
2175        with FProcedures do for i := Count - 1 downto 0 do with TPCEProc(Items[i]) do
2176        begin
2177          FSend := False;
2178          if FDelete then
2179          begin
2180            TPCEProc(Items[i]).Free;
2181            Delete(i);
2182          end;
2183        end;
2184        with FImmunizations do for i := Count - 1 downto 0 do with TPCEImm(Items[i]) do
2185        begin
2186          FSend := False;
2187          if FDelete then
2188          begin
2189            TPCEImm(Items[i]).Free;
2190            Delete(i);
2191          end;
2192        end;
2193        with FSkinTests do for i := Count - 1 downto 0 do with TPCESkin(Items[i]) do
2194        begin
2195          FSend := False;
2196          if FDelete then
2197          begin
2198            TPCESkin(Items[i]).Free;
2199            Delete(i);
2200          end;
2201        end;
2202        with FPatientEds do for i := Count - 1 downto 0 do with TPCEPat(Items[i]) do
2203        begin
2204          FSend := False;
2205          if FDelete then
2206          begin
2207            TPCEPat(Items[i]).Free;
2208            Delete(i);
2209          end;
2210        end;
2211        with FHealthFactors do for i := Count - 1 downto 0 do with TPCEHealth(Items[i]) do
2212        begin
2213          FSend := False;
2214          if FDelete then
2215          begin
2216            TPCEHealth(Items[i]).Free;
2217            Delete(i);
2218          end;
2219        end;
2220        with FExams do for i := Count - 1 downto 0 do with TPCEExams(Items[i]) do
2221        begin
2222          FSend := False;
2223          if FDelete then
2224          begin
2225            TPCEExams(Items[i]).Free;
2226            Delete(i);
2227          end;
2228        end;
2229        
2230        for i := FProviders.Count - 1 downto 0 do
2231        begin
2232          if(FProviders.ProviderData[i].Delete) then
2233            FProviders.Delete(i);
2234        end;
2235  
2236        if fVisitType.FDelete then fVisitType.Clear else fVisitType.FSend := False;
2237      end; {with PCEList}
2238      //if (FProcedures.Count > 0) or (FVisitType.Code <> '') then FCPTRequired := False;  
2239  
2240      // update the Changes object
2241      EncName := FormatFMDateTime('mmm dd,yy hh:nn', FileDate);
2242      x := StrVisitType;
2243      if Length(x) > 0 then Changes.Add(CH_PCE, 'V' + AVisitStr, x, EncName, CH_SIGN_NA);
2244      x := StrProcedures;
2245      if Length(x) > 0 then Changes.Add(CH_PCE, 'P' + AVisitStr, x, EncName, CH_SIGN_NA);
2246      x := StrDiagnoses;
2247      if Length(x) > 0 then Changes.Add(CH_PCE, 'D' + AVisitStr, x, EncName, CH_SIGN_NA,
2248         Parent, User.DUZ, '', False, False, ProblemAdded);
2249      x := StrImmunizations;
2250      if Length(x) > 0 then Changes.Add(CH_PCE, 'I' + AVisitStr, x, EncName, CH_SIGN_NA);
2251      x := StrSkinTests;
2252      if Length(x) > 0 then Changes.Add(CH_PCE, 'S' + AVisitStr, x, EncName, CH_SIGN_NA);
2253      x := StrPatientEds;
2254      if Length(x) > 0 then Changes.Add(CH_PCE, 'A' + AVisitStr, x, EncName, CH_SIGN_NA);
2255      x := StrHealthFactors;
2256      if Length(x) > 0 then Changes.Add(CH_PCE, 'H' + AVisitStr, x, EncName, CH_SIGN_NA);
2257      x := StrExams;
2258      if Length(x) > 0 then Changes.Add(CH_PCE, 'E' + AVisitStr, x, EncName, CH_SIGN_NA);
2259  
2260  
2261    finally
2262      PCEList.Free;
2263    end;
2264  end;
2265  
2266  function TPCEData.MatchItem(AList: TList; AnItem: TPCEItem): Integer;
2267  { return index in AList of matching item }
2268  var
2269    i: Integer;
2270  begin
2271    Result := -1;
2272    with AList do for i := 0 to Count - 1 do with TPCEItem(Items[i]) do if Match(AnItem) and MatchProvider(AnItem)then
2273    begin
2274      Result := i;
2275      break;
2276    end;
2277  end;
2278  
2279  procedure TPCEData.MarkDeletions(PreList: TList; PostList: TStrings);
2280  {mark items that need deleted}
2281  var
2282    i, j: Integer;
2283    MatchFound: Boolean;
2284    PreItem, PostItem: TPCEItem;
2285  begin
2286    with PreList do for i := 0 to Count - 1 do
2287    begin
2288      PreItem := TPCEItem(Items[i]);
2289      MatchFound := False;
2290      with PostList do for j := 0 to Count - 1 do
2291      begin
2292        PostItem := TPCEItem(Objects[j]);
2293        if (PreItem.Match(PostItem) and (PreItem.MatchProvider(PostItem))) then MatchFound := True;
2294      end;
2295      if not MatchFound then
2296      begin
2297        PreItem.FDelete := True;
2298        PreItem.FSend   := True;
2299      end;
2300    end;
2301  end;
2302  
2303  procedure TPCEData.SetDiagnoses(Src: TStrings; FromForm: boolean = TRUE);
2304  { load diagnoses for this encounter into TPCEDiag records, assumes all diagnoses for the
2305    encounter will be listed in Src and marks those that are not in Src for deletion }
2306  var
2307    i, MatchIndex: Integer;
2308    SrcDiagnosis, CurDiagnosis, PrimaryDiag: TPCEDiag;
2309  begin
2310    if FromForm then MarkDeletions(fDiagnoses, Src);
2311    PrimaryDiag := nil;
2312    for i := 0 to Src.Count - 1 do
2313    begin
2314      SrcDiagnosis := TPCEDiag(Src.Objects[i]);
2315      MatchIndex := MatchItem(fDiagnoses, SrcDiagnosis);
2316      if MatchIndex > -1 then    //found in fdiagnoses
2317      begin
2318        CurDiagnosis := TPCEDiag(fDiagnoses.Items[MatchIndex]);
2319        if ((SrcDiagnosis.Primary <> CurDiagnosis.Primary) or
2320         (SrcDiagnosis.Comment <> CurDiagnosis.Comment) or
2321         (SrcDiagnosis.AddProb <> CurDiagnosis.Addprob)) then
2322        begin
2323          CurDiagnosis.Primary    := SrcDiagnosis.Primary;
2324          CurDiagnosis.Comment    := SrcDiagnosis.Comment;
2325          CurDiagnosis.AddProb    := SrcDiagnosis.AddProb;
2326          CurDiagnosis.FSend := True;
2327        end;
2328      end
2329      else
2330      begin
2331        CurDiagnosis := TPCEDiag.Create;
2332        CurDiagnosis.Assign(SrcDiagnosis);
2333        CurDiagnosis.FSend := True;
2334        fDiagnoses.Add(CurDiagnosis);
2335      end; {if MatchIndex}
2336      if(CurDiagnosis.Primary and (not assigned(PrimaryDiag))) then
2337        PrimaryDiag := CurDiagnosis;
2338      if (CurDiagnosis.AddProb) then
2339        FProblemAdded := True;
2340    end; {for}
2341    if(assigned(PrimaryDiag)) then
2342    begin
2343      for i := 0 to fDiagnoses.Count - 1 do
2344      begin
2345        CurDiagnosis := TPCEDiag(fDiagnoses[i]);
2346        if(CurDiagnosis.Primary) and (CurDiagnosis <> PrimaryDiag) then
2347        begin
2348          CurDiagnosis.Primary := FALSE;
2349          CurDiagnosis.FSend := True;
2350        end;
2351      end;
2352    end;
2353  end;
2354  
2355  procedure TPCEData.SetProcedures(Src: TStrings; FromForm: boolean = TRUE);
2356  { load Procedures for this encounter into TPCEProc records, assumes all Procedures for the
2357    encounter will be listed in Src and marks those that are not in Src for deletion }
2358  var
2359    i, MatchIndex: Integer;
2360    SrcProcedure, CurProcedure, OldProcedure: TPCEProc;
2361  begin
2362    if FromForm then MarkDeletions(FProcedures, Src);
2363    for i := 0 to Src.Count - 1 do
2364    begin
2365      SrcProcedure := TPCEProc(Src.Objects[i]);
2366      MatchIndex := MatchItem(FProcedures, SrcProcedure);
2367      if MatchIndex > -1 then
2368      begin
2369        CurProcedure := TPCEProc(FProcedures.Items[MatchIndex]);
2370  (*      if (SrcProcedure.Provider <> CurProcedure.Provider) then
2371        begin
2372          OldProcedure := TPCEProc.Create;
2373          OldProcedure.Assign(CurProcedure);
2374          OldProcedure.FDelete := TRUE;
2375          OldProcedure.FSend := TRUE;
2376          FProcedures.Add(OldProcedure);
2377        end;*)
2378        if (SrcProcedure.Quantity <> CurProcedure.Quantity) or
2379           (SrcProcedure.Provider <> CurProcedure.Provider) or
2380           (Curprocedure.Comment <> SrcProcedure.Comment) or
2381           (Curprocedure.Modifiers <> SrcProcedure.Modifiers)then
2382        begin
2383          OldProcedure := TPCEProc.Create;
2384          OldProcedure.Assign(CurProcedure);
2385          OldProcedure.FDelete := TRUE;
2386          OldProcedure.FSend := TRUE;
2387          FProcedures.Add(OldProcedure);
2388          CurProcedure.Quantity := SrcProcedure.Quantity;
2389          CurProcedure.Provider := SrcProcedure.Provider;
2390          CurProcedure.Comment := SrcProcedure.Comment;
2391          CurProcedure.Modifiers := SrcProcedure.Modifiers;
2392          CurProcedure.FSend := True;
2393        end;
2394      end else
2395      begin
2396        CurProcedure := TPCEProc.Create;
2397        CurProcedure.Assign(SrcProcedure);
2398        CurProcedure.FSend := True;
2399        FProcedures.Add(CurProcedure);
2400      end; {if MatchIndex}
2401    end; {for}
2402  end;
2403  
2404  
2405  
2406  procedure TPCEData.SetImmunizations(Src: TStrings; FromForm: boolean = TRUE);
2407  { load Immunizations for this encounter into TPCEImm records, assumes all Immunizations for the
2408    encounter will be listed in Src and marks those that are not in Src for deletion }
2409  var
2410    i, MatchIndex: Integer;
2411    SrcImmunization, CurImmunization: TPCEImm;
2412  begin
2413    if FromForm then MarkDeletions(FImmunizations, Src);
2414    for i := 0 to Src.Count - 1 do
2415    begin
2416      SrcImmunization := TPCEImm(Src.Objects[i]);
2417      MatchIndex := MatchItem(FImmunizations, SrcImmunization);
2418      if MatchIndex > -1 then
2419      begin
2420        CurImmunization := TPCEImm(FImmunizations.Items[MatchIndex]);
2421  
2422        //set null strings to NoPCEValue
2423        if SrcImmunization.Series = '' then SrcImmunization.Series := NoPCEValue;
2424        if SrcImmunization.Reaction = '' then SrcImmunization.Reaction := NoPCEValue;
2425        if CurImmunization.Series = '' then CurImmunization.Series := NoPCEValue;
2426        if CurImmunization.Reaction = '' then CurImmunization.Reaction := NoPCEValue;
2427  
2428        if(SrcImmunization.Series <> CurImmunization.Series) or
2429          (SrcImmunization.Reaction <> CurImmunization.Reaction) or
2430          (SrcImmunization.Refused <> CurImmunization.Refused) or
2431          (SrcImmunization.Contraindicated <> CurImmunization.Contraindicated) or
2432          (CurImmunization.Comment <> SrcImmunization.Comment)then  
2433        begin
2434          CurImmunization.Series          := SrcImmunization.Series;
2435          CurImmunization.Reaction        := SrcImmunization.Reaction;
2436          CurImmunization.Refused         := SrcImmunization.Refused;
2437          CurImmunization.Contraindicated := SrcImmunization.Contraindicated;
2438          CurImmunization.Comment         := SrcImmunization.Comment;  
2439          CurImmunization.FSend := True;
2440        end;
2441      end else
2442      begin
2443        CurImmunization := TPCEImm.Create;
2444        CurImmunization.Assign(SrcImmunization);
2445        CurImmunization.FSend := True;
2446        FImmunizations.Add(CurImmunization);
2447      end; {if MatchIndex}
2448    end; {for}
2449  end;
2450  
2451  procedure TPCEData.SetSkinTests(Src: TStrings; FromForm: boolean = TRUE);
2452  { load SkinTests for this encounter into TPCESkin records, assumes all SkinTests for the
2453    encounter will be listed in Src and marks those that are not in Src for deletion }
2454  var
2455    i, MatchIndex: Integer;
2456    SrcSkinTest, CurSkinTest: TPCESkin;
2457  begin
2458    if FromForm then MarkDeletions(FSKinTests, Src);
2459    for i := 0 to Src.Count - 1 do
2460    begin
2461      SrcSkinTest := TPCESkin(Src.Objects[i]);
2462      MatchIndex := MatchItem(FSKinTests, SrcSkinTest);
2463      if MatchIndex > -1 then
2464      begin
2465        CurSkinTest := TPCESkin(FSkinTests.Items[MatchIndex]);
2466        if CurSkinTest.Results = '' then CurSkinTest.Results := NoPCEValue;
2467        if SrcSkinTest.Results = '' then SrcSkinTest.Results := NoPCEValue;
2468  
2469        if(SrcSkinTest.Results <> CurSkinTest.Results) or
2470          (SrcSkinTest.Reading <> CurSkinTest.Reading) or
2471          (CurSkinTest.Comment <> SrcSkinTest.Comment) then
2472        begin
2473  
2474          CurSkinTest.Results := SrcSkinTest.Results;
2475          CurSkinTest.Reading := SrcSkinTest.Reading;
2476          CurSkinTest.Comment := SrcSkinTest.Comment;
2477          CurSkinTest.FSend := True;
2478        end;
2479      end else
2480      begin
2481        CurSKinTest := TPCESkin.Create;
2482        CurSkinTest.Assign(SrcSkinTest);
2483        CurSkinTest.FSend := True;
2484        FSkinTests.Add(CurSkinTest);
2485      end; {if MatchIndex}
2486    end; {for}
2487  end;
2488  
2489  procedure TPCEData.SetPatientEds(Src: TStrings; FromForm: boolean = TRUE);
2490  var
2491    i, MatchIndex: Integer;
2492    SrcPatientEd, CurPatientEd: TPCEPat;
2493  begin
2494    if FromForm then MarkDeletions(FPatientEds, Src);
2495    for i := 0 to Src.Count - 1 do
2496    begin
2497      SrcPatientEd := TPCEPat(Src.Objects[i]);
2498      MatchIndex := MatchItem(FPatientEds, SrcPatientEd);
2499      if MatchIndex > -1 then
2500      begin
2501        CurPatientEd := TPCEPat(FPatientEds.Items[MatchIndex]);
2502  
2503        if CurPatientEd.level = '' then CurPatientEd.level := NoPCEValue;
2504        if SrcPatientEd.level = '' then SrcPatientEd.level := NoPCEValue;
2505        if(SrcPatientEd.Level <> CurPatientEd.Level) or
2506          (CurPatientEd.Comment <> SrcPatientEd.Comment) then
2507        begin
2508          CurPatientEd.Level  := SrcPatientEd.Level;
2509          CurPatientEd.Comment := SrcPatientEd.Comment;  
2510          CurPatientEd.FSend := True;
2511        end;
2512      end else
2513      begin
2514        CurPatientEd := TPCEPat.Create;
2515        CurPatientEd.Assign(SrcPatientEd);
2516        CurPatientEd.FSend := True;
2517        FPatientEds.Add(CurPatientEd);
2518      end; {if MatchIndex}
2519    end; {for}
2520  end;
2521  
2522  
2523  procedure TPCEData.SetHealthFactors(Src: TStrings; FromForm: boolean = TRUE);
2524  
2525  var
2526    i, MatchIndex: Integer;
2527    SrcHealthFactor, CurHealthFactor: TPCEHealth;
2528  begin
2529    if FromForm then MarkDeletions(FHealthFactors, Src);
2530    for i := 0 to Src.Count - 1 do
2531    begin
2532      SrcHealthFactor := TPCEHealth(Src.Objects[i]);
2533      MatchIndex := MatchItem(FHealthFactors, SrcHealthFactor);
2534      if MatchIndex > -1 then
2535      begin
2536        CurHealthFactor := TPCEHealth(FHealthFactors.Items[MatchIndex]);
2537  
2538        if CurHealthFactor.level = '' then CurHealthFactor.level := NoPCEValue;
2539        if SrcHealthFactor.level = '' then SrcHealthFactor.level := NoPCEValue;
2540        if(SrcHealthFactor.Level <> CurHealthFactor.Level) or
2541          (CurHealthFactor.Comment <> SrcHealthFactor.Comment) then  
2542        begin
2543          CurHealthFactor.Level  := SrcHealthFactor.Level;
2544          CurHealthFactor.Comment := SrcHealthFactor.Comment;  
2545          CurHealthFactor.FSend := True;
2546        end;
2547         if(SrcHealthFactor.GecRem <> CurHealthFactor.GecRem) then
2548            CurHealthFactor.GecRem := SrcHealthFactor.GecRem;
2549      end else
2550      begin
2551        CurHealthFactor := TPCEHealth.Create;
2552        CurHealthFactor.Assign(SrcHealthFactor);
2553        CurHealthFactor.FSend := True;
2554        CurHealthFactor.GecRem := SrcHealthFactor.GecRem;
2555        FHealthFactors.Add(CurHealthFactor);
2556      end; {if MatchIndex}
2557    end; {for}
2558  end;
2559  
2560  
2561  procedure TPCEData.SetExams(Src: TStrings; FromForm: boolean = TRUE);
2562  
2563  var
2564    i, MatchIndex: Integer;
2565    SrcExam, CurExam: TPCEExams;
2566  begin
2567    if FromForm then MarkDeletions(FExams, Src);
2568    for i := 0 to Src.Count - 1 do
2569    begin
2570      SrcExam := TPCEExams(Src.Objects[i]);
2571      MatchIndex := MatchItem(FExams, SrcExam);
2572      if MatchIndex > -1 then
2573      begin
2574        CurExam := TPCEExams(FExams.Items[MatchIndex]);
2575        if CurExam.Results = '' then CurExam.Results := NoPCEValue;
2576        if SrcExam.Results = '' then SrcExam.Results := NoPCEValue;
2577        if(SrcExam.Results <> CurExam.Results) or
2578          (CurExam.Comment <> SrcExam.Comment) then  
2579        begin
2580          CurExam.Results  := SrcExam.Results;
2581          CurExam.Comment := SrcExam.Comment;  
2582          CurExam.Fsend := True;
2583        end;
2584      end else
2585      begin
2586        CurExam := TPCEExams.Create;
2587        CurExam.Assign(SrcExam);
2588        CurExam.FSend := True;
2589        FExams.Add(CurExam);
2590      end; {if MatchIndex}
2591    end; {for}
2592  end;
2593  
2594  
2595  procedure TPCEData.SetVisitType(Value: TPCEProc);
2596  var
2597    VisitDelete: TPCEProc;
2598  begin
2599    if (not fVisitType.Match(Value)) or
2600    (fVisitType.Modifiers <> Value.Modifiers) then  {causes CPT delete/re-add}
2601    begin
2602      if fVisitType.Code <> '' then                // add old visit to procedures for deletion
2603      begin
2604        VisitDelete := TPCEProc.Create;
2605        VisitDelete.Assign(fVisitType);
2606        VisitDelete.FDelete := True;
2607        VisitDelete.FSend   := True;
2608        FProcedures.Add(VisitDelete);
2609      end;
2610      fVisitType.Assign(Value);
2611      fVisitType.Quantity := 1;
2612      fVisitType.FSend := True;
2613    end;
2614  end;
2615  
2616  procedure TPCEData.SetSCRelated(Value: Integer);
2617  begin
2618    if Value <> FSCRelated then
2619    begin
2620      FSCRelated := Value;
2621      FSCChanged := True;
2622    end;
2623  end;
2624  
2625  procedure TPCEData.SetAORelated(Value: Integer);
2626  begin
2627    if Value <> FAORelated then
2628    begin
2629      FAORelated := Value;
2630      FSCChanged := True;
2631    end;
2632  end;
2633  
2634  procedure TPCEData.SetIRRelated(Value: Integer);
2635  begin
2636    if Value <> FIRRelated then
2637    begin
2638      FIRRelated := Value;
2639      FSCChanged := True;
2640    end;
2641  end;
2642  
2643  procedure TPCEData.SetECRelated(Value: Integer);
2644  begin
2645    if Value <> FECRelated then
2646    begin
2647      FECRelated := Value;
2648      FSCChanged := True;
2649    end;
2650  end;
2651  
2652  procedure TPCEData.SetMSTRelated(Value: Integer);
2653  begin
2654    if Value <> FMSTRelated then
2655    begin
2656      FMSTRelated := Value;
2657      FSCChanged := True;
2658    end;
2659  end;
2660  
2661  procedure TPCEData.SetHNCRelated(Value: Integer);
2662  begin
2663  //  if HNCOK and (Value <> FHNCRelated) then
2664    if Value <> FHNCRelated then
2665    begin
2666      FHNCRelated := Value;
2667      FSCChanged := True;
2668    end;
2669  end;
2670  
2671  procedure TPCEData.SetCVRelated(Value: Integer);
2672  begin
2673    if (Value <> FCVRelated) then
2674    begin
2675      FCVRelated := Value;
2676      FSCChanged := True;
2677    end;
2678  end;
2679  
2680  procedure TPCEData.SetSHADRelated(Value: Integer);
2681  begin
2682    if (Value <> FSHADRelated) then
2683    begin
2684      FSHADRelated := Value;
2685      FSCChanged   := True;
2686    end;
2687  end;
2688  
2689  procedure TPCEData.SetEncUseCurr(Value: Boolean);
2690  begin
2691    FEncUseCurr := Value;
2692    if FEncUseCurr then
2693    begin
2694      FEncDateTime  := Encounter.DateTime;
2695      FEncLocation  := Encounter.Location;
2696      //need to add to full list of providers
2697      FEncSvcCat    := Encounter.VisitCategory;
2698      FStandAlone   := Encounter.StandAlone;
2699      FStandAloneLoaded := TRUE;
2700      FEncInpatient := Encounter.Inpatient;
2701  
2702    end else
2703    begin
2704      FEncDateTime  := 0;
2705      FEncLocation  := 0;
2706      FStandAlone := FALSE;
2707      FStandAloneLoaded := FALSE;
2708      FProviders.PrimaryIdx := -1;
2709      FEncSvcCat    := 'A';
2710      FEncInpatient := False;
2711    end;
2712    //
2713    SetRPCEncLocation(FEncLocation);
2714  end;
2715  
2716  function TPCEData.StrDiagnoses: string;
2717  { returns the list of diagnoses for this encounter as a single comma delimited string }
2718  var
2719    i: Integer;
2720  begin
2721    Result := '';
2722    with fDiagnoses do for i := 0 to Count - 1 do with TPCEDiag(Items[i]) do
2723      if not FDelete then
2724        Result := Result + GetPCEDataText(pdcDiag, Code, Category, Narrative, Primary) + CRLF;
2725    if Length(Result) > 0 then Result := PCEDataCatText[pdcDiag] + CRLF + Copy(Result, 1, Length(Result) - 2) + CRLF;
2726  end;
2727  
2728  function TPCEData.StrProcedures: string;
2729  { returns the list of procedures for this encounter as a single comma delimited string }
2730  var
2731    i: Integer;
2732  begin
2733    Result := '';
2734    with FProcedures do for i := 0 to Count - 1 do with TPCEProc(Items[i]) do
2735      if not FDelete then
2736        Result := Result + GetPCEDataText(pdcProc, Code, Category, Narrative, FALSE, Quantity) +
2737                           ModText + CRLF;
2738    if Length(Result) > 0 then Result := PCEDataCatText[pdcProc] + CRLF + Copy(Result, 1, Length(Result) - 2) + CRLF;
2739  end;
2740  
2741  function TPCEData.StrImmunizations: string;
2742  { returns the list of Immunizations for this encounter as a single comma delimited string }
2743  var
2744    i: Integer;
2745  begin
2746    Result := '';
2747    with FImmunizations do for i := 0 to Count - 1 do with TPCEImm(Items[i]) do
2748      if not FDelete then
2749        Result := Result + GetPCEDataText(pdcImm, Code, Category, Narrative) + CRLF;
2750    if Length(Result) > 0 then Result := PCEDataCatText[pdcImm] + CRLF + Copy(Result, 1, Length(Result) - 2) + CRLF;
2751  end;
2752  
2753  
2754  function TPCEData.StrSkinTests: string;
2755  { returns the list of Immunizations for this encounter as a single comma delimited string }
2756  var
2757    i: Integer;
2758  begin
2759    Result := '';
2760    with FSkinTests do for i := 0 to Count - 1 do with TPCESkin(Items[i]) do
2761      if not FDelete then
2762        Result := Result + GetPCEDataText(pdcSkin, Code, Category, Narrative) + CRLF;
2763    if Length(Result) > 0 then Result := PCEDataCatText[pdcSkin] + CRLF + Copy(Result, 1, Length(Result) - 2) + CRLF;
2764  end;
2765  
2766  function TPCEData.StrPatientEds: string;
2767  var
2768    i: Integer;
2769  begin
2770    Result := '';
2771    with FPatientEds do for i := 0 to Count - 1 do with TPCEPat(Items[i]) do
2772      if not FDelete then
2773        Result := Result + GetPCEDataText(pdcPED, Code, Category, Narrative) + CRLF;
2774    if Length(Result) > 0 then Result := PCEDataCatText[pdcPED] + CRLF + Copy(Result, 1, Length(Result) - 2) + CRLF;
2775  end;
2776  
2777  function TPCEData.StrHealthFactors: string;
2778  var
2779    i: Integer;
2780  begin
2781    Result := '';
2782    with FHealthFactors do for i := 0 to Count - 1 do with TPCEHealth(Items[i]) do
2783      if not FDelete then
2784        Result := Result + GetPCEDataText(pdcHF, Code, Category, Narrative) + CRLF;
2785    if Length(Result) > 0 then Result := PCEDataCatText[pdcHF] + CRLF + Copy(Result, 1, Length(Result) - 2) + CRLF;
2786  end;
2787  
2788  function TPCEData.StrExams: string;
2789  var
2790    i: Integer;
2791  begin
2792    Result := '';
2793    with FExams do for i := 0 to Count - 1 do with TPCEExams(Items[i]) do
2794      if not FDelete then
2795        Result := Result + GetPCEDataText(pdcExam, Code, Category, Narrative) + CRLF;
2796    if Length(Result) > 0 then Result := PCEDataCatText[pdcExam] + CRLF + Copy(Result, 1, Length(Result) - 2) + CRLF;
2797  end;
2798  
2799  function TPCEData.StrVisitType(const ASCRelated, AAORelated, AIRRelated,
2800    AECRelated, AMSTRelated, AHNCRelated, ACVRelated, ASHADRelated: Integer): string;
2801  { returns as a string the type of encounter (according to CPT) & related contitions treated }
2802  
2803    procedure AddTxt(txt: string);
2804    begin
2805      if(Result <> '') then
2806        Result := Result + ',';
2807      Result := Result + ' ' + txt;
2808    end;
2809  
2810  begin
2811    Result := '';
2812    if ASCRelated = SCC_YES  then AddTxt('Service Connected Condition');
2813    if AAORelated = SCC_YES  then AddTxt('Agent Orange Exposure');
2814    if AIRRelated = SCC_YES  then AddTxt('Ionizing Radiation Exposure');
2815    if AECRelated = SCC_YES  then AddTxt('Environmental Contaminants');
2816    if AMSTRelated = SCC_YES then AddTxt('MST');//'Military Sexual Trauma';
2817  //  if HNCOK and (AHNCRelated = SCC_YES) then AddTxt('Head and/or Neck Cancer');
2818    if AHNCRelated = SCC_YES then AddTxt('Head and/or Neck Cancer');
2819    if ACVRelated = SCC_YES  then AddTxt('Combat Veteran Related');
2820    if Length(Result) > 0 then Result := ' related to: ' + Result;
2821  //  Result := Trim(Result);
2822  end;
2823  
2824  function TPCEData.StrVisitType: string;
2825  { returns as a string the type of encounter (according to CPT) & related contitions treated }
2826  begin
2827    Result := '';
2828    with fVisitType do
2829      begin
2830        Result := GetPCEDataText(pdcVisit, Code, Category, Narrative);
2831        if Length(ModText) > 0 then Result := Result + ModText + ', ';
2832      end;
2833    Result := Trim(Result + StrVisitType(FSCRelated, FAORelated, FIRRelated,
2834                                         FECRelated, FMSTRelated, FHNCRelated, FCVRelated, FSHADRelated));
2835  end;
2836  
2837  function TPCEData.StandAlone: boolean;
2838  var
2839    Sts: integer;
2840  
2841  begin
2842    if(not FStandAloneLoaded) and ((FNoteIEN > 0) or ((FEncLocation > 0) and (FEncDateTime > 0))) then
2843    begin
2844      Sts := HasVisit(FNoteIEN, FEncLocation, FEncDateTime);
2845      FStandAlone := (Sts <> 1);
2846      if(Sts >= 0) then
2847        FStandAloneLoaded := TRUE;
2848    end;
2849    Result := FStandAlone;
2850  end;
2851  
2852  function TPCEData.getDocCount: Integer;
2853  begin
2854    rESULT := 1;
2855  //  result := DocCount(vISIT);
2856  end;
2857  
2858  {function TPCEItem.MatchProvider(AnItem: TPCEItem): Boolean;
2859  begin
2860    Result := False;
2861    if (Provider = AnItem.Provider) then Result := True;
2862  end;
2863  }
2864  function TPCEItem.MatchProvider(AnItem: TPCEItem): Boolean;
2865  begin
2866    Result := False;
2867    if (Provider = AnItem.Provider) then Result := True;
2868  end;
2869  
2870  function TPCEData.GetHasData: Boolean;
2871  begin
2872    result := True;
2873    if ((fDiagnoses.count = 0)
2874       and (FProcedures.count = 0)
2875       and (FImmunizations.count = 0)
2876       and (FSkinTests.count = 0)
2877       and (FPatientEds.count = 0)
2878       and (FHealthFactors.count = 0)
2879       and (fExams.count = 0) and
2880       (fVisitType.Quantity = 0))then
2881        result := False;
2882  end;
2883  
2884  procedure TPCEData.CopyPCEData(Dest: TPCEData);
2885  begin
2886    Dest.Clear;
2887    Dest.FEncDateTime  := FEncDateTime;
2888    Dest.FNoteDateTime := FNoteDateTime;
2889    Dest.FEncLocation  := FEncLocation;
2890    Dest.FEncSvcCat    := FEncSvcCat;
2891    Dest.FEncInpatient := FEncInpatient;
2892    Dest.FStandAlone   := FStandAlone;
2893    Dest.FStandAloneLoaded := FStandAloneLoaded;
2894    Dest.FEncUseCurr   := FEncUseCurr;
2895    Dest.FSCChanged    := FSCChanged;
2896    Dest.FSCRelated    := FSCRelated;
2897    Dest.FAORelated    := FAORelated;
2898    Dest.FIRRelated    := FIRRelated;
2899    Dest.FECRelated    := FECRelated;
2900    Dest.FMSTRelated   := FMSTRelated;
2901    Dest.FHNCRelated   := FHNCRelated;
2902    Dest.FCVRelated    := FCVRelated;
2903    Dest.FSHADRelated  := FSHADRelated;
2904    fVisitType.CopyProc(Dest.VisitType);
2905    Dest.FProviders.Assign(FProviders);
2906  
2907    CopyPCEItems(fDiagnoses,     Dest.fDiagnoses,     TPCEDiag);
2908    CopyPCEItems(FProcedures,    Dest.FProcedures,    TPCEProc);
2909    CopyPCEItems(FImmunizations, Dest.FImmunizations, TPCEImm);
2910    CopyPCEItems(FSkinTests,     Dest.FSkinTests,     TPCESkin);
2911    CopyPCEItems(FPatientEds,    Dest.FPatientEds,    TPCEPat);
2912    CopyPCEItems(FHealthFactors, Dest.FHealthFactors, TPCEHealth);
2913    CopyPCEItems(FExams,         Dest.FExams,         TPCEExams);
2914  
2915    Dest.FNoteTitle := FNoteTitle;
2916    Dest.FNoteIEN := FNoteIEN;
2917    Dest.FParent := FParent;
2918    Dest.FHistoricalLocation := FHistoricalLocation;
2919  end;
2920  
2921  function TPCEData.NeededPCEData: tRequiredPCEDataTypes;
2922  var
2923    EC: TSCConditions;
2924    NeedSC: boolean;
2925    TmpLst: TStringList;
2926  
2927  begin
2928    Result := [];
2929    if(not FutureEncounter(Self)) then
2930    begin
2931      if(PromptForWorkload(FNoteIEN, FNoteTitle, FEncSvcCat, StandAlone)) then
2932      begin
2933        if(fDiagnoses.count <= 0) then
2934          Include(Result, ndDiag);
2935        if((fprocedures.count <= 0) and (fVisitType.Code = '')) then
2936        begin
2937          TmpLst := TStringList.Create;
2938          try
2939            GetHasCPTList(TmpLst);
2940            if(not DataHasCPTCodes(TmpLst)) then
2941              Include(Result, ndProc);
2942          finally
2943            TmpLst.Free;
2944          end;
2945        end;
2946        if(RequireExposures(FNoteIEN, FNoteTitle)) then
2947        begin
2948          NeedSC := FALSE;
2949          EC :=  EligbleConditions;
2950          if (EC.SCAllow and (SCRelated = SCC_NA)) then
2951            NeedSC := TRUE
2952          else   if(SCRelated <> SCC_YES) then  //if screlated = yes, the others are not asked.
2953          begin
2954                 if(EC.AOAllow and (AORelated = SCC_NA)) then NeedSC := TRUE
2955            else if(EC.IRAllow and (IRRelated = SCC_NA)) then NeedSC := TRUE
2956            else if(EC.ECAllow and (ECRelated = SCC_NA)) then NeedSC := TRUE
2957          end;
2958          if(EC.MSTAllow and (MSTRelated = SCC_NA)) then NeedSC := TRUE;
2959  //        if HNCOK and (EC.HNCAllow and (HNCRelated = SCC_NA)) then NeedSC := TRUE;
2960          if(EC.HNCAllow and (HNCRelated = SCC_NA)) then NeedSC := TRUE;
2961          if(EC.CVAllow and (CVRelated = SCC_NA) and (SHADRelated = SCC_NA)) then NeedSC := TRUE;
2962          if(NeedSC) then
2963            Include(Result, ndSC);
2964        end;
2965  (*      if(Result = []) and (FNoteIEN > 0) then   //  **** block removed in v19.1  {RV} ****
2966          ClearCPTRequired(FNoteIEN);*)
2967      end;
2968    end;
2969  end;
2970  
2971  
2972  function TPCEData.OK2SignNote: boolean;
2973  var
2974    Req: tRequiredPCEDataTypes;
2975    msg: string;
2976    Asked, DoAsk, Primary, Needed: boolean;
2977    Outpatient, First, DoSave, NeedSave, Done: boolean;
2978    Ans: integer;
2979    Flags: word;
2980    Ask: TAskPCE;
2981  
2982    procedure Add(Typ: tRequiredPCEDataType; txt: string);
2983    begin
2984      if(Typ in Req) then
2985        msg := msg + txt + CRLF;
2986    end;
2987  
2988  begin
2989    if not CanEditPCE(Self) then
2990    begin
2991      Result := TRUE;
2992      exit;
2993    end;
2994    if IsNonCountClinic(FEncLocation) then
2995    begin
2996      Result := TRUE;
2997      exit;
2998    end;
2999    if IsCancelOrNoShow(NoteIEN) then
3000    begin
3001      Result := TRUE;
3002      exit;
3003    end;
3004    Ask := GetAskPCE(FEncLocation);
3005    if(Ask = apNever) or (Ask = apDisable) then
3006      Result := TRUE
3007    else
3008    begin
3009      DoSave := FALSE;
3010      try
3011        Asked := FALSE;
3012        First := TRUE;
3013        Outpatient := ((FEncSvcCat = 'A') or (FEncSvcCat = 'I') or (FEncSvcCat = 'T'));
3014        repeat
3015          Result := TRUE;
3016          Done := TRUE;
3017          Req := NeededPCEData;
3018          Needed := (Req <> []);
3019          if(First) then
3020          begin
3021            if Needed and (not Outpatient) then
3022              OutPatient := TRUE;
3023            if((Ask = apPrimaryAlways) or Needed or
3024               ((Ask = apPrimaryOutpatient) and Outpatient)) then
3025            begin
3026              if(Providers.PrimaryIdx < 0) then
3027              begin
3028                NoPrimaryPCEProvider(FProviders, Self);
3029                if(not DoSave) then
3030                  DoSave := (Providers.PrimaryIdx >= 0);
3031                if(DoSave and (FProviders.PendingIEN(FALSE) <> 0) and
3032                  (FProviders.IndexOfProvider(IntToStr(FProviders.PendingIEN(FALSE))) < 0)) then
3033                  FProviders.AddProvider(IntToStr(FProviders.PendingIEN(FALSE)), FProviders.PendingName(FALSE), FALSE);
3034              end;
3035            end;
3036            First := FALSE;
3037          end;
3038          Primary := (Providers.PrimaryIEN = User.DUZ);
3039          case Ask of
3040            apPrimaryOutpatient: DoAsk := (Primary and Outpatient);
3041            apPrimaryAlways:     DoAsk := Primary;
3042            apNeeded:            DoAsk := Needed;
3043            apOutpatient:        DoAsk := Outpatient;
3044            apAlways:            DoAsk := TRUE;
3045            else
3046          { apPrimaryNeeded }    DoAsk := (Primary and Needed);
3047          end;
3048          if(DoAsk) then
3049          begin
3050            if(Asked and ((not Needed) or (not Primary))) then
3051              exit;
3052            if(Needed) then
3053            begin
3054              msg := TX_NEED1;
3055              Add(ndDiag, TX_NEED_DIAG);
3056              Add(ndProc, TX_NEED_PROC);
3057              Add(ndSC,   TX_NEED_SC);
3058              if(Primary and ForcePCEEntry(FEncLocation)) then
3059              begin
3060                Flags := MB_OKCANCEL;
3061                msg :=  msg + CRLF + TX_NEED3;
3062              end
3063              else
3064              begin
3065                if(Primary) then
3066                  Flags := MB_YESNOCANCEL
3067                else
3068                  Flags := MB_YESNO;
3069                msg :=  msg + CRLF + TX_NEED2;
3070              end;
3071              Flags := Flags + MB_ICONWARNING;
3072            end
3073            else
3074            begin
3075              Flags := MB_YESNO + MB_ICONQUESTION;
3076              msg :=  TX_NEED2;
3077            end;
3078            Ans := InfoBox(msg, TX_NEED_T, Flags);
3079            if(Ans = ID_CANCEL) then
3080            begin
3081              Result := FALSE;
3082              InfoBox(TX_NEEDABORT, TX_NEED_T, MB_OK);
3083              exit;
3084            end;
3085            Result := (Ans = ID_NO);
3086            if(not Result) then
3087            begin
3088              if(not MissingProviderInfo(Self)) then
3089              begin
3090                NeedSave := UpdatePCE(Self, FALSE);
3091                if(not DoSave) then
3092                  DoSave := NeedSave;
3093                FUpdated := TRUE;
3094              end;
3095              Done := frmFrame.Closing;
3096              Asked := TRUE;
3097            end;
3098          end;
3099        until(Done);
3100      finally
3101        if(DoSave) then
3102          Save;
3103      end;
3104    end;
3105  end;
3106  
3107  procedure TPCEData.AddStrData(List: TStrings);
3108  
3109    procedure Add(Txt: string);
3110    begin
3111      if(length(Txt) > 0) then List.Add(Txt);
3112    end;
3113  
3114  begin
3115    Add(StrVisitType);
3116    Add(StrDiagnoses);
3117    Add(StrProcedures);
3118    Add(StrImmunizations);
3119    Add(StrSkinTests);
3120    Add(StrPatientEds);
3121    Add(StrHealthFactors);
3122    Add(StrExams);
3123  end;
3124  
3125  procedure TPCEData.AddVitalData(Data, List: TStrings);
3126  var
3127    i: integer;
3128  
3129  begin
3130    for i := 0 to Data.Count-1 do
3131      List.Add(FormatVitalForNote(Data[i]));
3132  end;
3133  
3134  function TPCEData.PersonClassDate: TFMDateTime;
3135  begin
3136    if(FEncSvcCat = 'H') then
3137      Result := FMToday
3138    else
3139      Result := FEncDateTime; //Encounter.DateTime;
3140  end;
3141  
3142  function TPCEData.VisitDateTime: TFMDateTime;
3143  begin
3144    if(IsSecondaryVisit) then
3145      Result := FNoteDateTime
3146    else
3147      Result := FEncDateTime;
3148  end;
3149  
3150  function TPCEData.IsSecondaryVisit: boolean;
3151  begin
3152    Result := ((FEncSvcCat = 'H') and (FNoteDateTime > 0) and (FEncInpatient));
3153  end;
3154  
3155  function TPCEData.NeedProviderInfo: boolean;
3156  var
3157    i: integer;
3158    TmpLst: TStringList;
3159  
3160  begin
3161    if(FProviders.PrimaryIdx < 0) then
3162    begin
3163      Result := AutoCheckout(FEncLocation);
3164      if not Result then
3165      begin
3166        for i := 0 to fDiagnoses.Count - 1 do
3167        begin
3168          if not TPCEDiag(fDiagnoses[i]).FDelete then
3169          begin
3170            Result := TRUE;
3171            break;
3172          end;
3173        end;
3174      end;
3175      if not Result then
3176      begin
3177        for i := 0 to FProcedures.Count - 1 do
3178        begin
3179          if not TPCEProc(FProcedures[i]).FDelete then
3180          begin
3181            Result := TRUE;
3182            break;
3183          end;
3184        end;
3185      end;
3186      if not Result then
3187      begin
3188        for i := 0 to FProviders.Count - 1 do
3189        begin
3190          if not FProviders[i].Delete then
3191          begin
3192            Result := TRUE;
3193            break;
3194          end;
3195        end;
3196      end;
3197      if not Result then
3198      begin
3199        TmpLst := TStringList.Create;
3200        try
3201          GetHasCPTList(TmpLst);
3202          if(DataHasCPTCodes(TmpLst)) then
3203            Result := TRUE;
3204        finally
3205          TmpLst.Free;
3206        end;
3207      end;
3208    end
3209    else
3210      Result := FALSE;
3211  end;
3212  
3213  procedure TPCEData.GetHasCPTList(AList: TStrings);
3214  
3215    procedure AddList(List: TList);
3216    var
3217      i: integer;
3218      tmp: string;
3219  
3220    begin
3221      for i := 0 to List.Count-1 do
3222      begin
3223        tmp := TPCEItem(List[i]).HasCPTStr;
3224        if(tmp <> '') then
3225          AList.Add(tmp);
3226      end;
3227    end;
3228  
3229  begin
3230    AddList(FImmunizations);
3231    AddList(FSkinTests);
3232    AddList(FPatientEds);
3233    AddList(FHealthFactors);
3234    AddList(FExams);
3235  end;
3236  
3237  procedure TPCEData.CopyPCEItems(Src: TList; Dest: TObject; ItemClass: TPCEItemClass);
3238  var
3239    AItem: TPCEItem;
3240    i: Integer;
3241    IsStrings: boolean;
3242    
3243  begin
3244    if(Dest is TStrings) then
3245      IsStrings := TRUE
3246    else
3247    if(Dest is TList) then
3248      IsStrings := FALSE
3249    else
3250      exit;
3251    for i := 0 to Src.Count - 1 do
3252    begin
3253      if(not TPCEItem(Src[i]).FDelete) then
3254      begin
3255        AItem := ItemClass.Create;
3256        AItem.Assign(TPCEItem(Src[i]));
3257        if(IsStrings) then
3258          TStrings(Dest).AddObject(AItem.ItemStr, AItem)
3259        else
3260          TList(Dest).Add(AItem);
3261      end;
3262    end;
3263  end;
3264  
3265  function TPCEData.Empty: boolean;
3266  begin
3267    Result := (FProviders.Count = 0);
3268    if(Result) then Result := (FSCRelated  = SCC_NA);
3269    if(Result) then Result := (FAORelated  = SCC_NA);
3270    if(Result) then Result := (FIRRelated  = SCC_NA);
3271    if(Result) then Result := (FECRelated  = SCC_NA);
3272    if(Result) then Result := (FMSTRelated = SCC_NA);
3273  //  if(Result) and HNCOK then Result := (FHNCRelated = SCC_NA);
3274    if(Result) then Result := (FHNCRelated = SCC_NA);
3275    if(Result) then Result := (FCVRelated = SCC_NA);
3276    if(Result) then Result := (FSHADRelated = SCC_NA);
3277    if(Result) then Result := (fDiagnoses.Count = 0);
3278    if(Result) then Result := (FProcedures.Count = 0);
3279    if(Result) then Result := (FImmunizations.Count = 0);
3280    if(Result) then Result := (FSkinTests.Count = 0);
3281    if(Result) then Result := (FPatientEds.Count = 0);
3282    if(Result) then Result := (FHealthFactors.Count = 0);
3283    if(Result) then Result := (fExams.Count = 0);
3284    if(Result) then Result := (fVisitType.Empty);
3285  end;
3286  
3287  { TPCEProviderList }
3288  
3289  function TPCEProviderList.Add(const S: string): Integer;
3290  var
3291    SIEN: string;
3292    LastPrimary: integer;
3293  
3294  begin
3295    SIEN := IntToStr(StrToInt64Def(Piece(S, U, pnumPrvdrIEN), 0));
3296    if(SIEN = '0') then
3297      Result := -1
3298    else
3299    begin
3300      LastPrimary := PrimaryIdx;
3301      Result := IndexOfProvider(SIEN);
3302      if(Result < 0) then
3303        Result := inherited Add(S)
3304      else
3305        Strings[Result] := S;
3306      if(Piece(S, U, pnumPrvdrPrimary) = '1') then
3307      begin
3308        FNoUpdate := TRUE;
3309        try
3310          SetPrimaryIdx(Result);
3311        finally
3312          FNoUpdate := FALSE;
3313        end;
3314        if(assigned(FOnPrimaryChanged) and (LastPrimary <> PrimaryIdx)) then
3315          FOnPrimaryChanged(Self);
3316      end;
3317    end;
3318  end;
3319  
3320  function TPCEProviderList.AddProvider(AIEN, AName: string; APrimary: boolean): integer;
3321  var
3322    tmp: string;
3323  
3324  begin
3325    tmp := 'PRV' + U + AIEN + U + U + U + AName + U;
3326    if(APrimary) then tmp := tmp + '1';
3327    Result := Add(tmp);
3328  end;
3329  
3330  procedure TPCEProviderList.Clear;
3331  var
3332    DoNotify: boolean;
3333  
3334  begin
3335    DoNotify := (assigned(FOnPrimaryChanged) and (GetPrimaryIdx >= 0));
3336    FPendingDefault := '';
3337    FPendingUser := '';
3338    FPCEProviderIEN := 0;
3339    FPCEProviderName := '';
3340    inherited;
3341    if(DoNotify) then
3342      FOnPrimaryChanged(Self);
3343  end;
3344  
3345  procedure TPCEProviderList.Delete(Index: Integer);
3346  var
3347    DoNotify: boolean;
3348  
3349  begin
3350    DoNotify := (assigned(FOnPrimaryChanged) and (Piece(Strings[Index], U, pnumPrvdrPrimary) = '1'));
3351    inherited Delete(Index);
3352    if(DoNotify) then
3353      FOnPrimaryChanged(Self);
3354  end;
3355  
3356  function TPCEProviderList.PCEProvider: Int64;
3357  
3358    function Check(AIEN: Int64): Int64;
3359    begin
3360      if(AIEN = 0) or (IndexOfProvider(IntToStr(AIEN)) < 0) then
3361        Result := 0
3362      else
3363        Result := AIEN;
3364    end;
3365  
3366  begin
3367    Result := Check(Encounter.Provider);
3368    if(Result = 0) then Result := Check(User.DUZ);
3369    if(Result = 0) then Result := PrimaryIEN;
3370  end;
3371  
3372  function TPCEProviderList.PCEProviderName: string;
3373  var
3374    NewProv: Int64;
3375  
3376  begin
3377    NewProv := PCEProvider;
3378    if(FPCEProviderIEN <> NewProv) then
3379    begin
3380      FPCEProviderIEN := NewProv;
3381      FPCEProviderName := ExternalName(PCEProvider, FN_NEW_PERSON);
3382    end;
3383    Result := FPCEProviderName;
3384  end;
3385  
3386  function TPCEProviderList.GetPrimaryIdx: integer;
3387  begin
3388    Result := IndexOfPiece('1', U, pnumPrvdrPrimary);
3389  end;
3390  
3391  function TPCEProviderList.GetProviderData(Index: integer): TPCEProviderRec;
3392  var
3393    X: string;
3394  
3395  begin
3396    X := Strings[Index];
3397    Result.IEN     := StrToInt64Def(Piece(X, U, pnumPrvdrIEN), 0);
3398    Result.Name    := Piece(X, U, pnumPrvdrName);
3399    Result.Primary := (Piece(X, U, pnumPrvdrPrimary) = '1');
3400    Result.Delete  := (Piece(X, U, 1) = 'PRV-');
3401  end;
3402  
3403  function TPCEProviderList.IndexOfProvider(AIEN: string): integer;
3404  begin
3405    Result := IndexOfPiece(AIEN, U, pnumPrvdrIEN);
3406  end;
3407  
3408  procedure TPCEProviderList.Merge(AList: TPCEProviderList);
3409  var
3410    i, idx: integer;
3411    tmp: string;
3412  
3413  begin
3414    for i := 0 to Count-1 do
3415    begin
3416      tmp := Strings[i];
3417      idx := AList.IndexOfProvider(Piece(tmp, U, pnumPrvdrIEN));
3418      if(idx < 0) then
3419      begin
3420        SetPiece(tmp, U, 1, 'PRV-');
3421        Strings[i] := tmp;
3422      end;
3423    end;
3424    for i := 0 to AList.Count-1 do
3425      Add(AList.Strings[i]); // Add already filters out duplicates
3426  end;
3427  
3428  function TPCEProviderList.PendingIEN(ADefault: boolean): Int64;
3429  begin
3430    if(ADefault) then
3431      Result := StrToInt64Def(Piece(FPendingDefault, U, 1), 0)
3432    else
3433      Result := StrToInt64Def(Piece(FPendingUser, U, 1), 0);
3434  end;
3435  
3436  function TPCEProviderList.PendingName(ADefault: boolean): string;
3437  begin
3438    if(ADefault) then
3439      Result := Piece(FPendingDefault, U, 2)
3440    else
3441      Result := Piece(FPendingUser, U, 2);
3442  end;
3443  
3444  function TPCEProviderList.PrimaryIEN: int64;
3445  var
3446    idx: integer;
3447  
3448  begin
3449    idx := GetPrimaryIdx;
3450    if(idx < 0) then
3451      Result := 0
3452    else
3453      Result := StrToInt64Def(Piece(Strings[idx], U, pnumPrvdrIEN), 0);
3454  end;
3455  
3456  function TPCEProviderList.PrimaryName: string;
3457  var
3458    idx: integer;
3459  
3460  begin
3461    idx := GetPrimaryIdx;
3462    if(idx < 0) then
3463      Result := ''
3464    else
3465      Result := Piece(Strings[idx], U, pnumPrvdrName);
3466  end;
3467  
3468  procedure TPCEProviderList.SetPrimary(index: integer; Primary: boolean);
3469  var
3470    tmp, x: string;
3471  
3472  begin
3473    tmp := Strings[index];
3474    if(Primary) then
3475      x := '1'
3476    else
3477      x := '';
3478    SetPiece(tmp, U, pnumPrvdrPrimary, x);
3479    Strings[Index] := tmp;
3480  end;
3481  
3482  procedure TPCEProviderList.SetPrimaryIdx(const Value: integer);
3483  var
3484    LastPrimary, idx: integer;
3485    Found: boolean;
3486  
3487  begin
3488    LastPrimary := GetPrimaryIdx;
3489    idx := -1;
3490    Found := FALSE;
3491    repeat
3492      idx := IndexOfPiece('1', U, pnumPrvdrPrimary, idx);
3493      if(idx >= 0) then
3494      begin
3495        if(idx = Value) then
3496          Found := TRUE
3497        else
3498          SetPrimary(idx, FALSE);
3499      end;
3500    until(idx < 0);
3501    if(not Found) and (Value >= 0) and (Value < Count) then
3502      SetPrimary(Value, TRUE);
3503    if((not FNoUpdate) and assigned(FOnPrimaryChanged) and (LastPrimary <> Value)) then
3504      FOnPrimaryChanged(Self);
3505  end;
3506  
3507  procedure TPCEProviderList.SetProviderData(Index: integer;
3508    const Value: TPCEProviderRec);
3509  var
3510    tmp, SIEN: string;
3511  
3512  begin
3513    if(Value.IEN = 0) or (index < 0) or (index >= Count) then exit;
3514    SIEN := IntToStr(Value.IEN);
3515    if(IndexOfPiece(SIEN, U, pnumPrvdrIEN) = index) then
3516    begin
3517      tmp := 'PRV';
3518      if(Value.Delete) then tmp := tmp + '-';
3519      tmp := tmp + U + SIEN + U + U + U + Value.Name + U;
3520      Strings[index] := tmp;
3521      if Value.Primary then
3522        SetPrimaryIdx(Index);
3523    end;
3524  end;
3525  
3526  procedure TPCEProviderList.Assign(Source: TPersistent);
3527  var
3528    Src: TPCEProviderList;
3529  
3530  begin
3531    inherited Assign(Source);
3532    if(Source is TPCEProviderList) then
3533    begin
3534      Src := TPCEProviderList(Source);
3535      Src.FOnPrimaryChanged := FOnPrimaryChanged;
3536      Src.FPendingDefault := FPendingDefault;
3537      Src.FPendingUser := FPendingUser;
3538      Src.FPCEProviderIEN := FPCEProviderIEN;
3539      Src.FPCEProviderName := FPCEProviderName;
3540    end;
3541  end;
3542  
3543  initialization
3544  
3545  finalization
3546    KillObj(@PCESetsOfCodes);
3547    KillObj(@HistLocations);
3548  
3549  end.

Module Calls (2 levels)


uPCE
 ├uConst
 ├uCore
 │ ├rCore
 │ ├uConst
 │ ├uCombatVet
 │ ├rTIU
 │ ├rOrders
 │ ├rConsults
 │ └uOrders
 ├rPCE
 │ ├uPCE...
 │ ├UBACore
 │ ├rCore...
 │ ├uCore...
 │ ├uConst
 │ ├fEncounterFrame
 │ ├UBAGlobals
 │ └UBAConst
 ├rCore...
 ├rTIU...
 ├fEncounterFrame...
 ├uVitals
 │ ├uCore...
 │ ├rCore...
 │ ├rVitals
 │ └fVitalsDate
 ├fFrame
 │ ├fPage
 │ ├uConst
 │ ├VERGENCECONTEXTORLib_TLB
 │ ├fBase508Form
 │ ├XuDsigS
 │ ├rCore...
 │ ├fPtSelMsg
 │ ├fPtSel
 │ ├fCover
 │ ├fProbs
 │ ├fMeds
 │ ├fOrders
 │ ├rOrders...
 │ ├fNotes
 │ ├fConsults
 │ ├fDCSumm
 │ ├rMisc
 │ ├fLabs
 │ ├fReports
 │ ├rReports
 │ ├fPtDemo
 │ ├fEncnt
 │ ├fPtCWAD
 │ ├uCore...
 │ ├fAbout
 │ ├fReview
 │ ├fxBroker
 │ ├fxLists
 │ ├fxServer
 │ ├fRptBox
 │ ├rODAllergy
 │ ├uInit
 │ ├fLabInfo
 │ ├uReminders
 │ ├fReminderTree
 │ ├fDeviceSelect
 │ ├fDrawers
 │ ├fReminderDialog
 │ ├fOptions
 │ ├fGraphs
 │ ├fGraphData
 │ ├rTemplates
 │ ├fSurgery
 │ ├rSurgery
 │ ├uEventHooks
 │ ├uSignItems
 │ ├rECS
 │ ├fIconLegend
 │ ├uOrders...
 │ ├uSpell
 │ ├uOrPtf
 │ ├fPatientFlagMulti
 │ ├fAlertForward
 │ ├UBAGlobals...
 │ ├UBACore...
 │ ├fOrdersSign
 │ ├uVitals...
 │ ├fMHTest
 │ ├uFormMonitor
 │ ├fOtherSchedule
 │ ├uVA508CPRSCompatibility
 │ ├fIVRoutes
 │ ├fPrintLocation
 │ ├fTemplateEditor
 │ └fCombatVet
 ├fPCEProvider
 │ ├uPCE...
 │ ├fBase508Form...
 │ ├rCore...
 │ └uCore...
 └rVitals

Module Called-By (2 levels)


                   uPCE
           uReminders┤ 
             fFrame┤ │ 
           fDrawers┤ │ 
             fCover┤ │ 
             rCover┤ │ 
             fNotes┤ │ 
          fConsults┤ │ 
    fTemplateEditor┤ │ 
    fReminderDialog┤ │ 
      fReminderTree┤ │ 
         rReminders┤ │ 
           fSurgery┤ │ 
     fRemCoverSheet┘ │ 
                 rPCE┤ 
            uOrders┤ │ 
      uReminders...┤ │ 
            uPCE...┤ │ 
  fBALocalDiagnoses┤ │ 
            fPCELex┤ │ 
    fEncounterFrame┤ │ 
         fVisitType┤ │ 
      mVisitRelated┤ │ 
         fDiagnoses┤ │ 
       fPCEBaseMain┤ │ 
         fProcedure┤ │ 
          fPCEOther┤ │ 
      fImmunization┤ │ 
          fSkinTest┤ │ 
         fPatientEd┤ │ 
      fHealthFactor┤ │ 
              fExam┤ │ 
         fEncVitals┤ │ 
         mCoPayDesc┤ │ 
          fNotes...┤ │ 
             fEncnt┤ │ 
             fProbs┤ │ 
           fProbEdt┤ │ 
           fProbLex┤ │ 
       fConsults...┤ │ 
            fDCSumm┤ │ 
 fReminderDialog...┤ │ 
fBAOptionsDiagnoses┤ │ 
        fSurgery...┤ │ 
         fODConsult┤ │ 
            fODProc┤ │ 
       fAddlSigners┤ │ 
       fDCSummProps┤ │ 
          fEditProc┤ │ 
       fEditConsult┤ │ 
               fGAF┤ │ 
          fHFSearch┘ │ 
   fEncounterFrame...┤ 
        fVisitType...┤ 
     mVisitRelated...┤ 
        fDiagnoses...┤ 
      fPCEBaseMain...┤ 
        fProcedure...┤ 
     fImmunization...┤ 
         fSkinTest...┤ 
        fPatientEd...┤ 
     fHealthFactor...┤ 
             fExam...┤ 
            fNotes...┤ 
         fConsults...┤ 
         fPCEProvider┤ 
            uPCE...┤ │ 
 fEncounterFrame...┘ │ 
           fDCSumm...┤ 
   fReminderDialog...┤ 
          fSurgery...┤ 
      fDCSummProps...┤ 
              fGAF...┤ 
    fRemCoverSheet...┤ 
             fPCEEdit┘ 
          fNotes...┤   
        fSurgery...┘