Module

fGraphs

Path

C:\CPRS\CPRS30\fGraphs.pas

Last Modified

7/15/2014 3:26:36 PM

Initialization Code

initialization
  CoInitialize (nil);
end.

Units Used in Interface

Name Comments
fBase508Form -
uGraphs -

Units Used in Implementation

Name Comments
fFrame -
fGraphData -
fGraphOthers -
fGraphProfiles -
fGraphSettings -
fReports -
fRptBox -
rCore -
rGraphs -
uConst -
uCore -
uFormMonitor -

Classes

Name Comments
TfrmGraphs -
TGraphItem -

Procedures

Name Owner Declaration Scope Comments
AddOnLabGroups TfrmGraphs procedure AddOnLabGroups(aListBox: TORListBox; personien: int64); Private -
AddRow - procedure AddRow(worksheet: variant; linestring, typename, itemname, date1, date2, result, other: string); Local -
AdjustTimeframe TfrmGraphs procedure AdjustTimeframe; Private -
AllDetails TfrmGraphs procedure AllDetails(aDate1, aDate2: TFMDateTime; aTempList: TStrings); Private -
AllTypeDate TfrmGraphs procedure AllTypeDate(aType, aTypeName, firstline, secondline: string; aDate, aDate2: double); Private -
AssignProfile TfrmGraphs procedure AssignProfile(aProfile, aSection: string); Private -
AutoSelect TfrmGraphs procedure AutoSelect(aListView: TListView); Private -
BaseResize TfrmGraphs procedure BaseResize(aScrollBox: TScrollBox); Private -
BorderValue TfrmGraphs procedure BorderValue(var bordervalue: double; value: double); Private -
BottomAxis TfrmGraphs procedure BottomAxis(aScrollBox: TScrollBox); Private -
BPAdd TfrmGraphs procedure BPAdd(itemvalue: string; adatetime: TDateTime; var fixeddatevalue: double; serLine, serBPDiastolic, serBPMean: TLineSeries); Private -
BPCheck TfrmGraphs procedure BPCheck(aChart: TChart; aFileType: string; serLine, serBPDiastolic, serBPMean: TLineSeries); Private -
btnChangeSettingsClick TfrmGraphs procedure btnChangeSettingsClick(Sender: TObject); Public/Published -
btnCloseClick TfrmGraphs procedure btnCloseClick(Sender: TObject); Public/Published -
btnGraphSelectionsClick TfrmGraphs procedure btnGraphSelectionsClick(Sender: TObject); Public/Published -
cboDateRangeChange TfrmGraphs procedure cboDateRangeChange(Sender: TObject); Public/Published -
cboDateRangeDropDown TfrmGraphs procedure cboDateRangeDropDown(Sender: TObject); Public/Published -
ChangeStyle TfrmGraphs procedure ChangeStyle; Private -
chartBaseClickLegend TfrmGraphs procedure chartBaseClickLegend(Sender: TCustomChart; Button: TMouseButton; Shift: TShiftState; X, Y: Integer); Public/Published -
chartBaseClickSeries TfrmGraphs procedure chartBaseClickSeries(Sender: TCustomChart; Series: TChartSeries; ValueIndex: Integer; Button: TMouseButton; Shift: TShiftState; X, Y: Integer); Public/Published -
chartBaseMouseDown TfrmGraphs procedure chartBaseMouseDown(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer); Public/Published -
chartBaseMouseMove TfrmGraphs procedure chartBaseMouseMove(Sender: TObject; Shift: TShiftState; X, Y: Integer); Public/Published -
chartBaseMouseUp TfrmGraphs procedure chartBaseMouseUp(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer); Public/Published -
ChartColor TfrmGraphs procedure ChartColor(aColor: TColor); Private -
ChartOnUndoZoom TfrmGraphs procedure ChartOnUndoZoom(Sender: TObject); Public/Published -
ChartOnZoom TfrmGraphs procedure ChartOnZoom(Sender: TObject); Public/Published -
ChartStyle TfrmGraphs procedure ChartStyle(aChart: TChart); Private -
CheckContext TfrmGraphs procedure CheckContext(var usecontext: boolean); Public -
CheckExpandedLabs TfrmGraphs procedure CheckExpandedLabs(aListView: TListView); Private When using Reports graph and Float graph, multispec lab tests need to update correctly
CheckMedNum TfrmGraphs procedure CheckMedNum(var typenum: string; aSeries: TChartSeries); Private -
CheckProfile TfrmGraphs procedure CheckProfile(var aProfile: string; var Updated: boolean); Private -
CheckRef - procedure CheckRef(selection: string; var value: string; var ok: boolean); Local Check ref range for AGE and SEX variables in $S statement
CheckToAddData TfrmGraphs procedure CheckToAddData(aListView: TListView; aSection, TypeToCheck: string); Private -
chkDualViewsClick TfrmGraphs procedure chkDualViewsClick(Sender: TObject); Public/Published -
chkItemsBottomClick TfrmGraphs procedure chkItemsBottomClick(Sender: TObject); Public/Published -
chkItemsBottomEnter TfrmGraphs procedure chkItemsBottomEnter(Sender: TObject); Public/Published -
chkItemsTopClick TfrmGraphs procedure chkItemsTopClick(Sender: TObject); Public/Published -
CreateExcelPatientHeader TfrmGraphs procedure CreateExcelPatientHeader(var HeaderList: TStringList; PageTitle, Warning, DateRange: string); Private This procedure modified from rReports
CreatePatientHeader TfrmGraphs procedure CreatePatientHeader(var HeaderList: TStringList; PageTitle, Warning, DateRange: string); Private This procedure modified from rReports
DateDefaults TfrmGraphs procedure DateDefaults; Public -
DateRangeItems TfrmGraphs procedure DateRangeItems(oldestdate, newestdate: double; filenum: string); Private -
DateSteps TfrmGraphs procedure DateSteps(dateranges: string); Public/Published -
DisplayData TfrmGraphs procedure DisplayData(aSection: string); Public/Published -
DisplayDataInfo TfrmGraphs procedure DisplayDataInfo(aScrollBox: TScrollBox; aMemo: TMemo); Public/Published -
DisplayFreeText TfrmGraphs procedure DisplayFreeText(aChart: TChart); Public -
DisplayType TfrmGraphs procedure DisplayType(itemtype, displayed: string); Private -
FastLab TfrmGraphs procedure FastLab(aList: TStringList); Private -
FillData - procedure FillData(aListView: TListView; worksheet: variant; var cnt: integer); Local -
FillViews TfrmGraphs procedure FillViews; Private -
FilterListView TfrmGraphs procedure FilterListView(oldestdate, newestdate: double); Private -
FixedDates TfrmGraphs procedure FixedDates(var adatetime, adatetime1: TDateTime); Private -
FormatHint TfrmGraphs procedure FormatHint(var astring: string); Public/Published -
FormClose TfrmGraphs procedure FormClose(Sender: TObject; var Action: TCloseAction); Public/Published -
FormCreate TfrmGraphs procedure FormCreate(Sender: TObject); Public/Published -
FormDestroy TfrmGraphs procedure FormDestroy(Sender: TObject); Public/Published -
FormShow TfrmGraphs procedure FormShow(Sender: TObject); Public/Published -
GetData TfrmGraphs procedure GetData(aString: string); Private -
GetSize TfrmGraphs procedure GetSize; Public/Published -
GetWidth - procedure GetWidth(aListView: TListView; var v1, v2, v3, v4: string); Local -
GraphBoundry TfrmGraphs procedure GraphBoundry(singlepoint: boolean); Private -
GraphFooter TfrmGraphs procedure GraphFooter(aChart: TChart; datediff: integer; aDate: TDateTime); Private -
GraphSwap TfrmGraphs procedure GraphSwap(bottomview, topview: integer); Public/Published -
GraphSwitch TfrmGraphs procedure GraphSwitch(bottomview, topview: integer); Public/Published -
HideDates TfrmGraphs procedure HideDates(aChart: TChart); Public/Published -
HideGraphs TfrmGraphs procedure HideGraphs(action: boolean); Private -
HighLow TfrmGraphs procedure HighLow(fmtime, fmtime1: string; aChart: TChart; var adatetime, adatetime1: TDateTime); Private -
InactivateHint TfrmGraphs procedure InactivateHint; Private -
InfoMessage TfrmGraphs procedure InfoMessage(aCaption: string; aColor: TColor; aVisible: boolean); Private -
InitialData TfrmGraphs procedure InitialData; Public -
Initialize TfrmGraphs procedure Initialize; Public -
InitialRetain TfrmGraphs procedure InitialRetain; Public -
ItemCheck TfrmGraphs procedure ItemCheck(aListView: TListView; aItemName: string; var aNum: integer; var aTypeItem: string); Private -
ItemDateRange TfrmGraphs procedure ItemDateRange(Sender: TCustomChart); Private -
ItemsClick TfrmGraphs procedure ItemsClick(Sender: TObject; aListView, aOtherListView: TListView; aCheckBox: TCheckBox; aListBox: TORListBox; aList: TStrings; aSection: string); Private -
LabAdd TfrmGraphs procedure LabAdd(aListView: TListView; filename: string; aIndex, oldlisting: integer; selectlab: boolean); Private -
LabCheck TfrmGraphs procedure LabCheck(aListView: TListView; aItemType: string; var oldlisting: integer); Private -
LabData TfrmGraphs procedure LabData(aItemType, aItemName, aSection: string; getdata: boolean); Private -
LabelClicks TfrmGraphs procedure LabelClicks(aChart: TChart; aSeries: TChartSeries; lbutton: boolean; tmp: integer); Public/Published -
LabNameResults TfrmGraphs procedure LabNameResults(astring: string; var labname, labresult: string); Public/Published -
Layout - procedure Layout(aList: TStrings; FR, v1, v2, v3, v4: string); Local -
Layout - procedure Layout(name, FR: string; v1, v2, v3, v4: integer); Local -
LoadDateRange TfrmGraphs procedure LoadDateRange; Private -
LoadDisplayCheck TfrmGraphs procedure LoadDisplayCheck(typeofitem: string; var updated: boolean); Private -
LoadListView TfrmGraphs procedure LoadListView(aList: TStrings); Public -
LoadType TfrmGraphs procedure LoadType(itemtype, displayed: string); Private -
lstViewsBottomChange TfrmGraphs procedure lstViewsBottomChange(Sender: TObject); Public/Published -
lstViewsBottomEnter TfrmGraphs procedure lstViewsBottomEnter(Sender: TObject); Public/Published -
lstViewsTopChange TfrmGraphs procedure lstViewsTopChange(Sender: TObject); Public/Published -
lstViewsTopEnter TfrmGraphs procedure lstViewsTopEnter(Sender: TObject); Public/Published -
lstViewsTopMouseDown TfrmGraphs procedure lstViewsTopMouseDown(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer); Public/Published -
lvwItemsBottomChange TfrmGraphs procedure lvwItemsBottomChange(Sender: TObject; Item: TListItem; Change: TItemChange); Public/Published -
lvwItemsBottomClick TfrmGraphs procedure lvwItemsBottomClick(Sender: TObject); Public/Published -
lvwItemsBottomColumnClick TfrmGraphs procedure lvwItemsBottomColumnClick(Sender: TObject; Column: TListColumn); Public/Published -
lvwItemsBottomCompare TfrmGraphs procedure lvwItemsBottomCompare(Sender: TObject; Item1, Item2: TListItem; Data: Integer; var Compare: Integer); Public/Published -
lvwItemsBottomEnter TfrmGraphs procedure lvwItemsBottomEnter(Sender: TObject); Public/Published -
lvwItemsTopChange TfrmGraphs procedure lvwItemsTopChange(Sender: TObject; Item: TListItem; Change: TItemChange); Public/Published -
lvwItemsTopClick TfrmGraphs procedure lvwItemsTopClick(Sender: TObject); Public/Published -
lvwItemsTopColumnClick TfrmGraphs procedure lvwItemsTopColumnClick(Sender: TObject; Column: TListColumn); Public/Published -
lvwItemsTopCompare TfrmGraphs procedure lvwItemsTopCompare(Sender: TObject; Item1, Item2: TListItem; Data: Integer; var Compare: Integer); Public/Published -
lvwItemsTopEnter TfrmGraphs procedure lvwItemsTopEnter(Sender: TObject); Public/Published -
lvwItemsTopKeyDown TfrmGraphs procedure lvwItemsTopKeyDown(Sender: TObject; var Key: Word; Shift: TShiftState); Public/Published -
MakeBarSeries TfrmGraphs procedure MakeBarSeries(aChart: TChart; aTitle, aFileType: string; var aSerCnt: integer); Private -
MakeChart TfrmGraphs procedure MakeChart(aChart: TChart; aScrollBox: TScrollBox); Private -
MakeComments TfrmGraphs procedure MakeComments(aChart: TChart); Private -
MakeDateline TfrmGraphs procedure MakeDateline(section, aTitle, aFileType: string; aChart: TChart; graphtype: integer; var bcnt, pcnt, gcnt, vcnt: integer); Private -
MakeGanttSeries TfrmGraphs procedure MakeGanttSeries(aChart: TChart; aTitle, aFileType: string; var aSerCnt: integer); Private Good one
MakeLineSeries TfrmGraphs procedure MakeLineSeries(aChart: TChart; aTitle, aFileType, section: string; var aSerCnt, aNonCnt: integer; multiline: boolean); Private -
MakeNonNumerics TfrmGraphs procedure MakeNonNumerics(aChart: TChart); Private -
MakeNonNumSeries TfrmGraphs procedure MakeNonNumSeries(aChart: TChart; padvalue, highestvalue, lowestvalue: double; listofseries, section: string); Private -
MakeOtherSeries TfrmGraphs procedure MakeOtherSeries(aChart: TChart); Private -
MakePointSeries TfrmGraphs procedure MakePointSeries(aChart: TChart; aTitle, aFileType: string; var aSerCnt: integer); Private -
MakeSeparate TfrmGraphs procedure MakeSeparate(aScrollBox: TScrollBox; aListView: TListView; aPadPanel: TPanel; section: string); Private -
MakeSeparateItems TfrmGraphs procedure MakeSeparateItems(aScrollBox: TScrollBox; aListView: TListView; section: string); Private -
MakeSeriesBP TfrmGraphs procedure MakeSeriesBP(aChart: TChart; aTest, aBP: TLineSeries; aFileType: string); Private -
MakeSeriesInfo TfrmGraphs procedure MakeSeriesInfo(aChart: TChart; aSeries: TChartSeries; aTitle, aFileType: string; aSerCnt: integer); Private -
MakeSeriesPoint TfrmGraphs procedure MakeSeriesPoint(aChart: TChart; aPointSeries: TPointSeries); Private -
MakeSeriesRef TfrmGraphs procedure MakeSeriesRef(aChart: TChart; aTest, aRef: TLineSeries; aTitle, aValue: string; aDate: double); Private -
MakeTogether TfrmGraphs procedure MakeTogether(aScrollBox: TScrollBox; aListView: TListView; aPadPanel: TPanel; section: string); Private -
MakeTogetherAnyLines TfrmGraphs procedure MakeTogetherAnyLines(aListView: TListView; section: string; aChart: TChart); Private -
MakeTogetherMaybe TfrmGraphs procedure MakeTogetherMaybe(aScrollBox: TScrollBox; aListView: TListView; aPadPanel: TPanel; section: string); Private -
MakeTogetherNoLines TfrmGraphs procedure MakeTogetherNoLines(aListView: TListView; section: string); Private -
MakeTogetherOnlyLines TfrmGraphs procedure MakeTogetherOnlyLines(aListView: TListView; section: string; aChart: TChart); Private -
MakeVisitGanttSeries TfrmGraphs procedure MakeVisitGanttSeries(aChart: TChart; aTitle, aFileType: string; var aSerCnt: integer); Private -
memBottomEnter TfrmGraphs procedure memBottomEnter(Sender: TObject); Public/Published -
memBottomExit TfrmGraphs procedure memBottomExit(Sender: TObject); Public/Published -
memBottomKeyDown TfrmGraphs procedure memBottomKeyDown(Sender: TObject; var Key: Word; Shift: TShiftState); Public/Published -
memTopEnter TfrmGraphs procedure memTopEnter(Sender: TObject); Public/Published -
memTopExit TfrmGraphs procedure memTopExit(Sender: TObject); Public/Published -
memTopKeyDown TfrmGraphs procedure memTopKeyDown(Sender: TObject; var Key: Word; Shift: TShiftState); Public/Published -
mnuCustomClick TfrmGraphs procedure mnuCustomClick(Sender: TObject); Public/Published -
mnuGraphDataClick TfrmGraphs procedure mnuGraphDataClick(Sender: TObject); Public/Published -
mnuMHasNumeric1Click TfrmGraphs procedure mnuMHasNumeric1Click(Sender: TObject); Public/Published -
mnuPopGraph3DClick TfrmGraphs procedure mnuPopGraph3DClick(Sender: TObject); Public/Published -
mnuPopGraphClearClick TfrmGraphs procedure mnuPopGraphClearClick(Sender: TObject); Public/Published -
mnuPopGraphDatesClick TfrmGraphs procedure mnuPopGraphDatesClick(Sender: TObject); Public/Published -
mnuPopGraphDetailsClick TfrmGraphs procedure mnuPopGraphDetailsClick(Sender: TObject); Public/Published -
mnuPopGraphDualViewsClick TfrmGraphs procedure mnuPopGraphDualViewsClick(Sender: TObject); Public/Published -
mnuPopGraphExportClick TfrmGraphs procedure mnuPopGraphExportClick(Sender: TObject); Public/Published -
mnuPopGraphFixedClick TfrmGraphs procedure mnuPopGraphFixedClick(Sender: TObject); Public/Published -
mnuPopGraphGradientClick TfrmGraphs procedure mnuPopGraphGradientClick(Sender: TObject); Public/Published -
mnuPopGraphHintsClick TfrmGraphs procedure mnuPopGraphHintsClick(Sender: TObject); Public/Published -
mnuPopGraphHorizontalClick TfrmGraphs procedure mnuPopGraphHorizontalClick(Sender: TObject); Public/Published -
mnuPopGraphIsolateClick TfrmGraphs procedure mnuPopGraphIsolateClick(Sender: TObject); Public/Published -
mnuPopGraphLegendClick TfrmGraphs procedure mnuPopGraphLegendClick(Sender: TObject); Public/Published -
mnuPopGraphLinesClick TfrmGraphs procedure mnuPopGraphLinesClick(Sender: TObject); Public/Published -
mnuPopGraphMergeLabsClick TfrmGraphs procedure mnuPopGraphMergeLabsClick(Sender: TObject); Public/Published -
mnuPopGraphPrintClick TfrmGraphs procedure mnuPopGraphPrintClick(Sender: TObject); Public/Published -
mnuPopGraphRemoveClick TfrmGraphs procedure mnuPopGraphRemoveClick(Sender: TObject); Public/Published -
mnuPopGraphResetClick TfrmGraphs procedure mnuPopGraphResetClick(Sender: TObject); Public/Published -
mnuPopGraphSeparate1Click TfrmGraphs procedure mnuPopGraphSeparate1Click(Sender: TObject); Public/Published -
mnuPopGraphSortClick TfrmGraphs procedure mnuPopGraphSortClick(Sender: TObject); Public/Published -
mnuPopGraphSplitClick TfrmGraphs procedure mnuPopGraphSplitClick(Sender: TObject); Public/Published -
mnuPopGraphStayOnTopClick TfrmGraphs procedure mnuPopGraphStayOnTopClick(Sender: TObject); Public/Published -
mnuPopGraphStuffPopup TfrmGraphs procedure mnuPopGraphStuffPopup(Sender: TObject); Public/Published -
mnuPopGraphSwapClick TfrmGraphs procedure mnuPopGraphSwapClick(Sender: TObject); Public/Published -
mnuPopGraphTodayClick TfrmGraphs procedure mnuPopGraphTodayClick(Sender: TObject); Public/Published -
mnuPopGraphValueMarksClick TfrmGraphs procedure mnuPopGraphValueMarksClick(Sender: TObject); Public/Published -
mnuPopGraphValuesClick TfrmGraphs procedure mnuPopGraphValuesClick(Sender: TObject); Public/Published -
mnuPopGraphVerticalClick TfrmGraphs procedure mnuPopGraphVerticalClick(Sender: TObject); Public/Published -
mnuPopGraphViewDefinitionClick TfrmGraphs procedure mnuPopGraphViewDefinitionClick(Sender: TObject); Public/Published -
mnuPopGraphZoomBackClick TfrmGraphs procedure mnuPopGraphZoomBackClick(Sender: TObject); Public/Published -
MouseClicks TfrmGraphs procedure MouseClicks(aChart: TChart; lbutton: boolean; X, Y: Integer); Public/Published -
NextPointerStyle TfrmGraphs procedure NextPointerStyle(aSeries: TChartSeries; aSerCnt: integer); Private -
NonNumSave TfrmGraphs procedure NonNumSave(aChart: TChart; aTitle, aSection: string; adatetime: TDateTime; var noncnt: integer; newcnt, aIndex: integer); Private -
NotifyApps TfrmGraphs procedure NotifyApps(aList: TStrings); Private -
NumAdd TfrmGraphs procedure NumAdd(serLine: TLineSeries; value: double; adatetime: TDateTime; var fixeddatevalue, hi, lo: double; var high, low: string); Private -
OneDayTypeDetails TfrmGraphs procedure OneDayTypeDetails(aTypeItem: string); Private -
OtherInfo TfrmGraphs procedure OtherInfo(aTypeItem, aResult: string; aDateTime: double; var moreinfo: string); Private -
PadNonNum TfrmGraphs procedure PadNonNum(aChart: TChart; aSection: string; var listofseries: string; var bmax, tmax: integer); Private -
PainAdd TfrmGraphs procedure PainAdd(serBlank: TPointSeries); Private -
pnlScrollTopBaseResize TfrmGraphs procedure pnlScrollTopBaseResize(Sender: TObject); Public/Published -
PositionSelections TfrmGraphs procedure PositionSelections(aListView: TListView); Public/Published -
RefUnits TfrmGraphs procedure RefUnits(aItem, aSpec: string; var low, high, units: string); Private -
ResultValue TfrmGraphs procedure ResultValue(var resultstring, seriestitle: string; typenum, typeitem: string; Sender: TCustomChart; aSeries: TChartSeries; ValueIndex, SeriesNum: Integer; var OKToUse: boolean); Private -
SaveTestData TfrmGraphs procedure SaveTestData(typeitem: string); Private -
SelCopy TfrmGraphs procedure SelCopy(aListView: TListView; aList: TStrings); Private -
SelectItem TfrmGraphs procedure SelectItem(aListView: TListView; typeitem: string); Private -
SelReset TfrmGraphs procedure SelReset(aList: TStrings; aListView: TListView); Private -
serDatelineTopGetMarkText TfrmGraphs procedure serDatelineTopGetMarkText(Sender: TChartSeries; ValueIndex: Integer; var MarkText: String); Public/Published -
SeriesClicks TfrmGraphs procedure SeriesClicks(aChart: TChart; aSeries: TChartSeries; aIndex: integer; lbutton: boolean); Public/Published -
SeriesForLabels TfrmGraphs procedure SeriesForLabels(aChart: TChart; aID: string; pad: double); Private -
SetFontSize TfrmGraphs procedure SetFontSize(FontSize: integer); Public -
SetProfile TfrmGraphs procedure SetProfile(aProfile, aName: string; aListView: TListView); Private -
SetRef TfrmGraphs procedure SetRef(var datax: string); Private -
SetRefNonNum TfrmGraphs procedure SetRefNonNum(var datax: string); Private -
SetSize TfrmGraphs procedure SetSize; Public/Published -
SetupFields TfrmGraphs procedure SetupFields(settings: string); Public/Published -
SetWidth - procedure SetWidth(aListView: TListView; v1, v2, v3, v4: integer); Local -
SizeDates TfrmGraphs procedure SizeDates(aChart: TChart; aSmallTime, aBigTime: TDateTime); Private -
SizeTogether TfrmGraphs procedure SizeTogether(onlylines, nolines, anylines: Boolean; aScroll: TScrollBox; aChart: TChart; aPanel, aPanelBase: TPanel; portion: Double); Private -
SortListView TfrmGraphs procedure SortListView; Private -
SourceContext TfrmGraphs procedure SourceContext; Public -
SourcesDefault TfrmGraphs procedure SourcesDefault; Public/Published -
SpecRefCheck TfrmGraphs procedure SpecRefCheck(aItemType, aItemName: string; var singlespec: boolean); Private Sort out for multiple spec or ref ranges
SpecRefSet TfrmGraphs procedure SpecRefSet(aItemType, aItemName: string); Private For mutiple spec ranges replace data and items
splGraphsMoved TfrmGraphs procedure splGraphsMoved(Sender: TObject); Public/Published -
SplitClick TfrmGraphs procedure SplitClick; Private -
splItemsBottomMoved TfrmGraphs procedure splItemsBottomMoved(Sender: TObject); Public/Published -
splItemsTopMoved TfrmGraphs procedure splItemsTopMoved(Sender: TObject); Public/Published -
SplitGraphs - procedure SplitGraphs(aListView: TListView); Local -
splViewsTopMoved TfrmGraphs procedure splViewsTopMoved(Sender: TObject); Public/Published -
StackNonNum TfrmGraphs procedure StackNonNum(astring: string; var offset, bmax, tmax: integer; var blabelon, tlabelon: boolean); Private -
StayOnTop TfrmGraphs procedure StayOnTop; Public/Published -
Switch TfrmGraphs procedure Switch; Public -
TempCheck TfrmGraphs procedure TempCheck(typeitem: string; var levelseq: double); Private -
TempData TfrmGraphs procedure TempData(aStringList: TStringList; aType: string; dt1, dt2: double); Private -
timHintPauseTimer TfrmGraphs procedure timHintPauseTimer(Sender: TObject); Public/Published -
UpdateAccessibilityActions TfrmGraphs procedure UpdateAccessibilityActions(var Actions: TAccessibilityActions); override; Protected -
UpdateView TfrmGraphs procedure UpdateView(filename, filenum, itemnum, aString: string; aListView: TListView); Private -
ValueDates TfrmGraphs procedure ValueDates(aSeries: TChartSeries; ValueIndex: Integer; var resultdate, otherdate: string; var startdate: double); Private -
ViewDefinition TfrmGraphs procedure ViewDefinition(profile: string; amemo: TRichEdit); Public -
ViewsChange TfrmGraphs procedure ViewsChange(aListView: TListView; aListBox: TORListBox; aSection: string); Private -
ViewSelections TfrmGraphs procedure ViewSelections; Public -
ZoomTo TfrmGraphs procedure ZoomTo(SmallTime, BigTime: TDateTime); Public/Published -
ZoomUpdate TfrmGraphs procedure ZoomUpdate; Public/Published -
ZoomUpdateInfo TfrmGraphs procedure ZoomUpdateInfo(SmallTime, BigTime: TDateTime); Public/Published -

Functions

Name Owner Declaration Scope Comments
BPValue TfrmGraphs function BPValue(aDateTime: TDateTime): string; Private -
DateRangeMultiItems TfrmGraphs function DateRangeMultiItems(aOldDate, aNewDate: double; aMultiItem: string): boolean; Private -
DatesInRange TfrmGraphs function DatesInRange(EarlyDate, RecentDate, Date1, Date2: double): boolean; Private -
DCName TfrmGraphs function DCName(aDCien: string): string; Private -
ExpandTax TfrmGraphs function ExpandTax(profile: string): string; Private -
FileNameX TfrmGraphs function FileNameX(filenum: string): string; Private -
FMCorrectedDate TfrmGraphs function FMCorrectedDate(fmtime: string): string; Private -
FMToDateTime TfrmGraphs function FMToDateTime(FMDateTime: string): TDateTime; Public -
GraphTypeNum TfrmGraphs function GraphTypeNum(aType: string): integer; Private -
HSAbbrev TfrmGraphs function HSAbbrev(aType: string): boolean; Private -
InvVal TfrmGraphs function InvVal(value: double): double; Private -
ItemName TfrmGraphs function ItemName(filenum, itemnum: string): string; Private -
MergedLabsSelected TfrmGraphs function MergedLabsSelected: boolean; Private -
MultiRef - function MultiRef(aline: string): boolean; Local -
NextColor TfrmGraphs function NextColor(aCnt: integer): TColor; Private -
NonNumText TfrmGraphs function NonNumText(listnum, seriesnum, valueindex: integer): string; Private -
PadLeftEvent TfrmGraphs function PadLeftEvent(aWidth: integer): integer; Private -
PadLeftNonNumeric TfrmGraphs function PadLeftNonNumeric(aWidth: integer): integer; Private -
PortionSize TfrmGraphs function PortionSize(lcnt, pcnt, gcnt, vcnt, bcnt: integer): double; Private -
ProfileName TfrmGraphs function ProfileName(aProfile, aName, aString: string): string; Private -
SelectRef TfrmGraphs function SelectRef(aRef: string): string; Private Check ref range for AGE and SEX variables in $S statement
SingleLabTest TfrmGraphs function SingleLabTest(aListView: TListView): boolean; Private -
StdDev TfrmGraphs function StdDev(value, high, low: double): double; Private -
TitleInfo TfrmGraphs function TitleInfo(filetype, typeitem, caption: string): string; Private -
TitleOK - function TitleOK(aTitle: string): boolean; Local -
TypeIsDisplayed TfrmGraphs function TypeIsDisplayed(itemtype: string): boolean; Private -
TypeIsLoaded TfrmGraphs function TypeIsLoaded(itemtype: string): boolean; Private -
TypeString TfrmGraphs function TypeString(filenum: string): string; Private -
ValueText TfrmGraphs function ValueText(Sender: TCustomChart; aSeries: TChartSeries; ValueIndex: Integer): string; Private -

Global Variables

Name Type Declaration Comments
FHintStop Boolean FHintStop: boolean; -
FHintWin Simple (unknown) FHintWin: THintWindow; -
FHintWinActive Boolean FHintWinActive: boolean; -
frmGraphs TfrmGraphs frmGraphs: TfrmGraphs; -
uDateStart Double uDateStart, uDateStop: double; -
uDateStop Double uDateStart, uDateStop: double; -


Module Source

1     unit fGraphs;
2     
3     interface
4     
5     uses
6       Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
7       ExtCtrls, StdCtrls, ORCtrls, Menus, TeeProcs, TeEngine, Series, Chart, Math,
8       ComCtrls, GanttCh, ClipBrd, StrUtils, ORFn, ORDtTmRng, DateUtils, Printers,
9       OleServer, Variants, Word2000, ArrowCha, ORDtTm, uGraphs, fBase508Form
10      {$IFDEF VER140}
11      ,Word97;
12      {$ELSE}
13      ,WordXP, VA508AccessibilityManager;
14      {$ENDIF}
15    
16    type
17      TfrmGraphs = class(TfrmBase508Form)
18        btnChangeSettings: TButton;
19        btnClose: TButton;
20        btnGraphSelections: TButton;
21        bvlBottomLeft: TBevel;
22        bvlBottomRight: TBevel;
23        bvlTopLeft: TBevel;
24        bvlTopRight: TBevel;
25        calDateRange: TORDateRangeDlg;
26        cboDateRange: TORComboBox;
27        chartBase: TChart;
28        chartDatelineBottom: TChart;
29        chartDatelineTop: TChart;
30        chkDualViews: TCheckBox;
31        chkItemsBottom: TCheckBox;
32        chkItemsTop: TCheckBox;
33        dlgDate: TORDateTimeDlg;
34        lblDateRange: TLabel;
35        lstViewsBottom: TORListBox;
36        lstViewsTop: TORListBox;
37        lvwItemsBottom: TListView;
38        lvwItemsTop: TListView;
39        memBottom: TMemo;
40        memTop: TMemo;
41        memViewsBottom: TRichEdit;
42        memViewsTop: TRichEdit;
43        mnuCustom: TMenuItem;
44        mnuFunctions1: TMenuItem;
45        mnuGraphData: TMenuItem;
46        mnuInverseValues: TMenuItem;
47        mnuMHasNumeric1: TMenuItem;
48        mnuPopGraph3D: TMenuItem;
49        mnuPopGraphClear: TMenuItem;
50        mnuPopGraphCopy: TMenuItem;
51        mnuPopGraphDates: TMenuItem;
52        mnuPopGraphDefineViews: TMenuItem;
53        mnuPopGraphDetails: TMenuItem;
54        mnuPopGraphDualViews: TMenuItem;
55        mnuPopGraphGradient: TMenuItem;
56        mnuPopGraphExport: TMenuItem;
57        mnuPopGraphFixed: TMenuItem;
58        mnuPopGraphHints: TMenuItem;
59        mnuPopGraphHorizontal: TMenuItem;
60        mnuPopGraphIsolate: TMenuItem;
61        mnuPopGraphLegend: TMenuItem;
62        mnuPopGraphLines: TMenuItem;
63        mnuPopGraphMergeLabs: TMenuItem;
64        mnuPopGraphPrint: TMenuItem;
65        mnuPopGraphRemove: TMenuItem;
66        mnuPopGraphReset: TMenuItem;
67        mnuPopGraphSeparate1: TMenuItem;
68        mnuPopGraphSort: TMenuItem;
69        mnuPopGraphSplit: TMenuItem;
70        mnuPopGraphStayOnTop: TMenuItem;
71        mnuPopGraphStuff: TPopupMenu;
72        mnuPopGraphSwap: TMenuItem;
73        mnuPopGraphToday: TMenuItem;
74        mnuPopGraphValues: TMenuItem;
75        mnuPopGraphValueMarks: TMenuItem;
76        mnuPopGraphVertical: TMenuItem;
77        mnuPopGraphViewDefinition: TMenuItem;
78        mnuPopGraphZoomBack: TMenuItem;
79        mnuStandardDeviations: TMenuItem;
80        mnuTest: TMenuItem;
81        mnuTestCount: TMenuItem;
82        N1: TMenuItem;
83        N2: TMenuItem;
84        N3: TMenuItem;
85        N4: TMenuItem;
86        pcBottom: TPageControl;
87        pcTop: TPageControl;
88        pnlBlankBottom: TPanel;
89        pnlBlankTop: TPanel;
90        pnlBottom: TPanel;
91        pnlBottomRightPad: TPanel;
92        pnlDatelineBottom: TPanel;
93        pnlDatelineBottomSpacer: TORAutoPanel;
94        pnlDatelineTop: TPanel;
95        pnlDatelineTopSpacer: TORAutoPanel;
96        pnlFooter: TPanel;
97        pnlHeader: TPanel;
98        pnlInfo: TORAutoPanel;
99        pnlItemsBottom: TPanel;
100       pnlItemsBottomInfo: TPanel;
101       pnlItemsTop: TPanel;
102       pnlItemsTopInfo: TPanel;
103       pnlMain: TPanel;
104       pnlScrollBottomBase: TPanel;
105       pnlScrollTopBase: TPanel;
106       pnlTemp: TPanel;
107       pnlTop: TPanel;
108       pnlTopRightPad: TPanel;
109       scrlBottom: TScrollBox;
110       scrlTop: TScrollBox;
111       serDatelineBottom: TGanttSeries;
112       serDatelineTop: TGanttSeries;
113       splGraphs: TSplitter;
114       splItemsBottom: TSplitter;
115       splItemsTop: TSplitter;
116       splViewsBottom: TSplitter;
117       splViewsTop: TSplitter;
118       timHintPause: TTimer;
119       tsBottomCustom: TTabSheet;
120       tsBottomItems: TTabSheet;
121       tsBottomViews: TTabSheet;
122       tsTopCustom: TTabSheet;
123       tsTopItems: TTabSheet;
124       tsTopViews: TTabSheet;
125   
126       procedure FormCreate(Sender: TObject);
127       procedure FormShow(Sender: TObject);
128       procedure FormClose(Sender: TObject; var Action: TCloseAction);
129       procedure FormDestroy(Sender: TObject);
130   
131       procedure btnCloseClick(Sender: TObject);
132       procedure btnChangeSettingsClick(Sender: TObject);
133       procedure btnGraphSelectionsClick(Sender: TObject);
134   
135       procedure chkDualViewsClick(Sender: TObject);
136       procedure chkItemsBottomClick(Sender: TObject);
137       procedure chkItemsBottomEnter(Sender: TObject);
138       procedure chkItemsTopClick(Sender: TObject);
139       procedure mnuPopGraph3DClick(Sender: TObject);
140       procedure mnuPopGraphClearClick(Sender: TObject);
141       procedure mnuPopGraphDatesClick(Sender: TObject);
142       procedure mnuPopGraphDetailsClick(Sender: TObject);
143       procedure mnuPopGraphDualViewsClick(Sender: TObject);
144       procedure mnuPopGraphExportClick(Sender: TObject);
145       procedure mnuPopGraphFixedClick(Sender: TObject);
146       procedure mnuPopGraphGradientClick(Sender: TObject);
147       procedure mnuPopGraphHintsClick(Sender: TObject);
148       procedure mnuPopGraphHorizontalClick(Sender: TObject);
149       procedure mnuPopGraphIsolateClick(Sender: TObject);
150       procedure mnuPopGraphLegendClick(Sender: TObject);
151       procedure mnuPopGraphLinesClick(Sender: TObject);
152       procedure mnuPopGraphMergeLabsClick(Sender: TObject);
153       procedure mnuPopGraphPrintClick(Sender: TObject);
154       procedure mnuPopGraphRemoveClick(Sender: TObject);
155       procedure mnuPopGraphResetClick(Sender: TObject);
156       procedure mnuPopGraphSeparate1Click(Sender: TObject);
157       procedure mnuPopGraphStayOnTopClick(Sender: TObject);
158       procedure mnuPopGraphSortClick(Sender: TObject);
159       procedure mnuPopGraphSplitClick(Sender: TObject);
160       procedure mnuPopGraphStuffPopup(Sender: TObject);
161       procedure mnuPopGraphSwapClick(Sender: TObject);
162       procedure mnuPopGraphTodayClick(Sender: TObject);
163       procedure mnuPopGraphValueMarksClick(Sender: TObject);
164       procedure mnuPopGraphValuesClick(Sender: TObject);
165       procedure mnuPopGraphVerticalClick(Sender: TObject);
166       procedure mnuPopGraphZoomBackClick(Sender: TObject);
167   
168       procedure splGraphsMoved(Sender: TObject);
169       procedure splItemsBottomMoved(Sender: TObject);
170       procedure splItemsTopMoved(Sender: TObject);
171   
172       procedure lvwItemsBottomChange(Sender: TObject; Item: TListItem;
173         Change: TItemChange);
174       procedure lvwItemsBottomClick(Sender: TObject);
175       procedure lvwItemsBottomColumnClick(Sender: TObject; Column: TListColumn);
176       procedure lvwItemsBottomCompare(Sender: TObject; Item1,
177         Item2: TListItem; Data: Integer; var Compare: Integer);
178       procedure lvwItemsTopChange(Sender: TObject; Item: TListItem;
179         Change: TItemChange);
180       procedure lvwItemsTopClick(Sender: TObject);
181       procedure lvwItemsTopColumnClick(Sender: TObject; Column: TListColumn);
182       procedure lvwItemsTopCompare(Sender: TObject; Item1, Item2: TListItem;
183         Data: Integer; var Compare: Integer);
184       procedure lvwItemsTopKeyDown(Sender: TObject; var Key: Word;
185         Shift: TShiftState);
186   
187       procedure cboDateRangeChange(Sender: TObject);
188       procedure cboDateRangeDropDown(Sender: TObject);
189   
190       procedure chartBaseClickLegend(Sender: TCustomChart;
191         Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
192       procedure chartBaseClickSeries(Sender: TCustomChart; Series: TChartSeries;
193         ValueIndex: Integer; Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
194       procedure chartBaseMouseDown(Sender: TObject; Button: TMouseButton;
195         Shift: TShiftState; X, Y: Integer);
196       procedure chartBaseMouseUp(Sender: TObject; Button: TMouseButton;
197         Shift: TShiftState; X, Y: Integer);
198       procedure chartBaseMouseMove(Sender: TObject; Shift: TShiftState; X, Y: Integer);
199       procedure serDatelineTopGetMarkText(Sender: TChartSeries;
200         ValueIndex: Integer; var MarkText: String);
201   
202       procedure ChartOnUndoZoom(Sender: TObject);
203       procedure ChartOnZoom(Sender: TObject);
204       procedure DateSteps(dateranges: string);
205       procedure DisplayData(aSection: string);
206       procedure DisplayDataInfo(aScrollBox: TScrollBox; aMemo: TMemo);
207       procedure GraphSwap(bottomview, topview: integer);
208       procedure GraphSwitch(bottomview, topview: integer);
209       procedure FormatHint(var astring: string);
210       procedure HideDates(aChart: TChart);
211       procedure LabelClicks(aChart: TChart; aSeries: TChartSeries; lbutton: boolean; tmp: integer);
212       procedure LabNameResults(astring: string; var labname, labresult: string);
213       procedure MouseClicks(aChart: TChart; lbutton: boolean; X, Y: Integer);
214       procedure PositionSelections(aListView: TListView);
215       procedure SeriesClicks(aChart: TChart; aSeries: TChartSeries; aIndex: integer; lbutton: boolean);
216       procedure SetupFields(settings: string);
217       procedure SourcesDefault;
218       procedure StayOnTop;
219   
220       procedure ZoomUpdate;
221       procedure ZoomUpdateInfo(SmallTime, BigTime: TDateTime);
222       procedure ZoomTo(SmallTime, BigTime: TDateTime);
223   
224       procedure lvwItemsBottomEnter(Sender: TObject);
225       procedure lvwItemsTopEnter(Sender: TObject);
226   
227       procedure memBottomEnter(Sender: TObject);
228       procedure memBottomExit(Sender: TObject);
229       procedure memBottomKeyDown(Sender: TObject; var Key: Word; Shift: TShiftState);
230       procedure memTopEnter(Sender: TObject);
231       procedure memTopExit(Sender: TObject);
232       procedure memTopKeyDown(Sender: TObject; var Key: Word; Shift: TShiftState);
233   
234       procedure pnlScrollTopBaseResize(Sender: TObject);
235       procedure timHintPauseTimer(Sender: TObject);
236   
237       procedure GetSize;
238       procedure SetSize;
239       procedure lstViewsBottomChange(Sender: TObject);
240       procedure lstViewsBottomEnter(Sender: TObject);
241       procedure lstViewsTopChange(Sender: TObject);
242       procedure lstViewsTopEnter(Sender: TObject);
243       procedure lstViewsTopMouseDown(Sender: TObject; Button: TMouseButton;
244         Shift: TShiftState; X, Y: Integer);
245       procedure mnuCustomClick(Sender: TObject);
246       procedure mnuGraphDataClick(Sender: TObject);
247       procedure mnuMHasNumeric1Click(Sender: TObject);
248       procedure mnuPopGraphViewDefinitionClick(Sender: TObject);
249       procedure splViewsTopMoved(Sender: TObject);
250   
251     private
252       FBSortAscending: boolean;
253       FBSortCol: integer;
254       FDate1: Double;
255       FDate2: Double;
256       FSortAscending: boolean;
257       FSortCol: integer;
258   
259       FActiveGraph: TChart;
260       FArrowKeys: boolean;
261       FBHighTime, FBLowTime: Double;
262       FCreate: boolean;
263       FDisplayFreeText: boolean;
264       FFastData: boolean;
265       FFastItems: boolean;
266       FFastLabs: boolean;
267       FFastTrack: boolean;
268       FFirstClick: boolean;
269       FFirstSwitch: boolean;
270       FGraphClick: TCustomChart;
271       FGraphSeries: TChartSeries;
272       FGraphSetting: TGraphSetting;
273       FGraphType: char;
274       FGraphValueIndex: integer;
275       FItemsSortedTop: boolean;
276       FItemsSortedBottom: boolean;
277       FMouseDown: boolean;
278       FMTimestamp: string;
279       FMToday: TFMDateTime;
280       FNonNumerics: boolean; // used with pnlItemsTop.Tag & pnlItemsBottom.Tag
281       FOnLegend:  integer;
282       FOnMark: boolean;
283       FOnSeries: integer;
284       FOnValue: integer;
285       FPointClick: boolean;
286       FPrevEvent: string;
287       FRetainZoom: boolean;
288       FSources: TStrings;
289       FSourcesDefault: TStrings;
290       FTHighTime, FTLowTime: Double;
291       FWarning: boolean;
292       FX, FY: integer;
293       FYMinValue: Double;
294       FYMaxValue: Double;
295   
296       procedure AddOnLabGroups(aListBox: TORListBox; personien: int64);
297       procedure AdjustTimeframe;
298       procedure AllTypeDate(aType, aTypeName, firstline, secondline: string; aDate, aDate2: double);
299       procedure AllDetails(aDate1, aDate2: TFMDateTime; aTempList: TStrings);
300       procedure AssignProfile(aProfile, aSection: string);
301       procedure AutoSelect(aListView: TListView);
302       procedure BaseResize(aScrollBox: TScrollBox);
303       procedure BorderValue(var BorderValue: double; value: double);
304       procedure BottomAxis(aScrollBox: TScrollBox);
305       procedure BPAdd(itemvalue: string; adatetime: TDateTime; var fixeddatevalue: double; serLine, serBPDiastolic, serBPMean: TLineSeries);
306       procedure BPCheck(aChart: TChart; aFileType: string; serLine, serBPDiastolic, serBPMean: TLineSeries);
307       procedure ChangeStyle;
308       procedure ChartColor(aColor: TColor);
309       procedure ChartStyle(aChart: TChart);
310       procedure CheckExpandedLabs(aListView: TListView);
311       procedure CheckMedNum(var typenum: string; aSeries: TChartSeries);
312       procedure CheckProfile(var aProfile: string; var Updated: boolean);
313       procedure CheckToAddData(aListView: TListView; aSection, TypeToCheck: string);
314       procedure CreateExcelPatientHeader(var HeaderList: TStringList; PageTitle, Warning, DateRange: string);
315       procedure CreatePatientHeader(var HeaderList: TStringList; PageTitle, Warning, DateRange: string);
316       procedure DateRangeItems(oldestdate, newestdate: double; filenum: string);
317       procedure DisplayType(itemtype, displayed: string);
318       procedure FastLab(aList: TStringList);
319       procedure FillViews;
320       procedure FilterListView(oldestdate, newestdate: double);
321       procedure FixedDates(var adatetime, adatetime1: TDateTime);
322       procedure GetData(aString: string);
323       procedure GraphBoundry(singlepoint: boolean);
324       procedure GraphFooter(aChart: TChart; datediff: integer; aDate: TDateTime);
325       procedure HideGraphs(action: boolean);
326       procedure HighLow(fmtime, fmtime1: string; aChart: TChart; var adatetime, adatetime1: TDateTime);
327       procedure InactivateHint;
328       procedure InfoMessage(aCaption: string; aColor: TColor; aVisible: boolean);
329       procedure ItemCheck(aListView: TListView; aItemName: string;
330         var aNum: integer; var aTypeItem: string);
331       procedure ItemDateRange(Sender: TCustomChart);
332       procedure ItemsClick(Sender: TObject; aListView, aOtherListView: TListView;
333         aCheckBox: TCheckBox; aListBox: TORListBox; aList: TStrings; aSection: string);
334       procedure LabAdd(aListView: TListView; filename: string; aIndex, oldlisting: integer; selectlab: boolean);
335       procedure LabCheck(aListView: TListView; aItemType: string; var oldlisting: integer);
336       procedure LabData(aItemType, aItemName, aSection: string; getdata: boolean);
337       procedure LoadDateRange;
338       procedure LoadDisplayCheck(typeofitem: string; var updated: boolean);
339       procedure LoadType(itemtype, displayed: string);
340       procedure NextPointerStyle(aSeries: TChartSeries; aSerCnt: integer);
341       procedure NonNumSave(aChart: TChart; aTitle, aSection: string; adatetime: TDateTime;
342         var noncnt: integer; newcnt, aIndex: integer);
343       procedure NotifyApps(aList: TStrings);
344       procedure NumAdd(serLine: TLineSeries; value: double; adatetime: TDateTime;
345         var fixeddatevalue, hi, lo: double; var high, low: string);
346       procedure OneDayTypeDetails(aTypeItem: string);
347       procedure OtherInfo(aTypeItem, aResult: string; aDateTime: double; var moreinfo: string);
348       procedure PadNonNum(aChart: TChart; aSection: string; var listofseries: string; var bmax, tmax: integer);
349       procedure PainAdd(serBlank: TPointSeries);
350       procedure RefUnits(aItem, aSpec: string; var low, high, units: string);
351       procedure ResultValue(var resultstring, seriestitle: string; typenum, typeitem: string;
352         Sender: TCustomChart; aSeries: TChartSeries; ValueIndex, SeriesNum: Integer; var OKToUse: boolean);
353       procedure SaveTestData(typeitem: string);
354       procedure SelCopy(aListView: TListView; aList: TStrings);
355       procedure SelReset(aList: TStrings; aListView: TListView);
356       procedure SelectItem(aListView: TListView; typeitem: string);
357       procedure SeriesForLabels(aChart: TChart; aID: string; pad: double);
358       procedure SetProfile(aProfile, aName: string; aListView: TListView);
359       procedure SetRef(var datax: string);
360       procedure SetRefNonNum(var datax: string);
361       procedure SizeDates(aChart: TChart; aSmallTime, aBigTime: TDateTime);
362       procedure SizeTogether(onlylines, nolines, anylines: Boolean; aScroll: TScrollBox;
363         aChart: TChart; aPanel, aPanelBase: TPanel; portion: Double);
364       procedure SpecRefCheck(aItemType, aItemName: string; var singlespec: boolean);
365       procedure SpecRefSet(aItemType, aItemName: string);
366       procedure SplitClick;
367       procedure SortListView;
368       procedure StackNonNum(astring: string; var offset, bmax, tmax: integer; var blabelon, tlabelon: boolean);
369       procedure TempCheck(typeitem: string; var levelseq: double);
370       procedure TempData(aStringList: TStringList; aType: string; dt1, dt2: double);
371       procedure UpdateView(filename, filenum, itemnum, aString: string; aListView: TListView);
372       procedure ValueDates(aSeries: TChartSeries; ValueIndex: Integer; var resultdate, otherdate: string; var startdate: double);
373       procedure ViewsChange(aListView: TListView; aListBox: TORListBox; aSection: string);
374   
375       procedure MakeSeparate(aScrollBox: TScrollBox; aListView: TListView; aPadPanel: TPanel; section: string);
376       procedure MakeSeparateItems(aScrollBox: TScrollBox; aListView: TListView; section: string);
377       procedure MakeTogether(aScrollBox: TScrollBox; aListView: TListView; aPadPanel: TPanel; section: string);
378       procedure MakeTogetherMaybe(aScrollBox: TScrollBox; aListView: TListView; aPadPanel: TPanel; section: string);
379       procedure MakeTogetherNoLines(aListView: TListView; section: string);
380       procedure MakeTogetherOnlyLines(aListView: TListView; section: string; aChart: TChart);
381       procedure MakeTogetherAnyLines(aListView: TListView; section: string; aChart: TChart);
382   
383       procedure MakeChart(aChart: TChart; aScrollBox: TScrollBox);
384       procedure MakeComments(aChart: TChart);
385       procedure MakeDateline(section, aTitle, aFileType: string; aChart: TChart; graphtype: integer;
386         var bcnt, pcnt, gcnt, vcnt: integer);
387       procedure MakeNonNumerics(aChart: TChart);
388       procedure MakeNonNumSeries(aChart: TChart; padvalue, highestvalue, lowestvalue: double; listofseries, section: string);
389       procedure MakeOtherSeries(aChart: TChart);
390       procedure MakeSeriesInfo(aChart: TChart; aSeries: TChartSeries; aTitle, aFileType: string; aSerCnt: integer);
391       procedure MakeSeriesPoint(aChart: TChart; aPointSeries: TPointSeries);
392       procedure MakeSeriesRef(aChart: TChart; aTest, aRef: TLineSeries; aTitle, aValue: string; aDate: double);
393       procedure MakeSeriesBP(aChart: TChart; aTest, aBP: TLineSeries; aFileType: string);
394   
395       procedure MakeBarSeries(aChart: TChart; aTitle, aFileType: string; var aSerCnt: integer);
396       procedure MakeLineSeries(aChart: TChart; aTitle, aFileType, section: string;
397         var aSerCnt, aNonCnt: integer; multiline: boolean);
398       procedure MakeGanttSeries(aChart: TChart; aTitle, aFileType: string; var aSerCnt: integer);  // good one
399       procedure MakePointSeries(aChart: TChart; aTitle, aFileType: string; var aSerCnt: integer);
400       procedure MakeVisitGanttSeries(aChart: TChart; aTitle, aFileType: string; var aSerCnt: integer);
401   
402       function BPValue(aDateTime: TDateTime): string;
403       function DateRangeMultiItems(aOldDate, aNewDate: double; aMultiItem: string): boolean;
404       function DatesInRange(EarlyDate, RecentDate, Date1, Date2: double): boolean;
405       function DCName(aDCien: string): string;
406       function ExpandTax(profile: string): string;
407       function FileNameX(filenum: string): string;
408       function FMCorrectedDate(fmtime: string): string;
409       function GraphTypeNum(aType: string): integer;
410       function HSAbbrev(aType: string): boolean;
411       function InvVal(value: double): double;
412       function ItemName(filenum, itemnum: string): string;
413       function MergedLabsSelected: boolean;
414       function NextColor(aCnt: integer): TColor;
415       function NonNumText(listnum, seriesnum, valueindex: integer): string;
416       function PadLeftEvent(aWidth: integer): integer;
417       function PadLeftNonNumeric(aWidth: integer): integer;
418       function PortionSize(lcnt, pcnt, gcnt, vcnt, bcnt: integer): double;
419       function ProfileName(aProfile, aName, aString: string): string;
420       function SelectRef(aRef: string): string;
421       function SingleLabTest(aListView: TListView): boolean;
422       function StdDev(value, high, low: double): double;
423       function TitleInfo(filetype, typeitem, caption: string): string;
424       function TypeIsDisplayed(itemtype: string): boolean;
425       function TypeIsLoaded(itemtype: string): boolean;
426       function TypeString(filenum: string): string;
427       function ValueText(Sender: TCustomChart; aSeries: TChartSeries; ValueIndex: Integer): string;
428     protected
429       procedure UpdateAccessibilityActions(var Actions: TAccessibilityActions); override;
430     public
431       procedure CheckContext(var usecontext: boolean);
432       procedure DateDefaults;
433       procedure DisplayFreeText(aChart: TChart);
434       procedure InitialData;
435       procedure Initialize;
436       procedure InitialRetain;
437       procedure LoadListView(aList: TStrings);
438       procedure SetFontSize(FontSize: integer);
439       procedure SourceContext;
440       procedure Switch;
441       procedure ViewDefinition(profile: string; amemo: TRichEdit);
442       procedure ViewSelections;
443   
444       function FMToDateTime(FMDateTime: string): TDateTime;
445     end;
446   
447   var
448     frmGraphs: TfrmGraphs;
449     FHintWin: THintWindow;
450     FHintWinActive: boolean;
451     FHintStop: boolean;
452     uDateStart, uDateStop: double;
453   
454   implementation
455   
456   uses fGraphSettings, fGraphProfiles, fGraphData, fGraphOthers, rGraphs,
457     ComObj, ActiveX, ShellAPI, fFrame, uCore, rCore, uConst, fRptBox, fReports,
458     uFormMonitor, VAUtils;
459   
460   {$R *.DFM}
461   
462   type
463     TGraphItem = class
464     public
465       Values: string;
466   end;
467   
468   procedure TfrmGraphs.FormCreate(Sender: TObject);
469   var
470     i: integer;
471     dfntype, listline, settings, settings1: string;
472   begin
473     btnClose.Tag := 0;
474     settings := GetCurrentSetting;
475     if (length(settings) < 1) then
476     begin
477       Screen.Cursor := crDefault;
478       ShowMsg(TXT_NOGRAPHING);
479       btnClose.Tag := 1;
480       Close;
481       Exit;
482     end;
483     SetupFields(settings);
484     settings1 := Piece(settings, '|', 1);
485     pnlInfo.Caption := TXT_INFO;
486     for i := 1 to BIG_NUMBER do
487     begin
488       dfntype := Piece(settings1, ';', i);
489       if length(dfntype) = 0 then break;
490       listline := dfntype + '^' + FileNameX(dfntype) + '^1';
491       FSources.Add(listline);
492       FSourcesDefault.Add(listline);
493     end;
494     serDatelineTop.Active := false;
495     serDatelineBottom.Active := false;
496     chartDatelineTop.Gradient.EndColor := clGradientActiveCaption;
497     chartDatelineTop.Gradient.StartColor := clWindow;
498     chartDatelineBottom.Gradient.EndColor := clGradientActiveCaption;
499     chartDatelineBottom.Gradient.StartColor := clWindow;
500     LoadDateRange;
501     //chkItemsTop.Checked := true;
502     //chkItemsBottom.Checked := true;
503     FillViews;
504     pcTop.ActivePage := tsTopItems;
505     pcBottom.ActivePage := tsBottomItems;
506   end;
507   
508   procedure TfrmGraphs.SetupFields(settings: string);
509   begin
510     FArrowKeys := false;
511     FBHighTime := 0;
512     FBLowTime := BIG_NUMBER;
513     FCreate := true;
514     FDisplayFreeText := true;
515     FGraphType := Char(32);
516     FFirstClick := true;
517     FFirstSwitch := true;
518     FGraphSetting := GraphSettingsInit(settings);
519     FHintStop := false;
520     FHintWin := THintWindow.Create(self);
521     FHintWin.Color := clInfoBk;
522     FHintWin.Canvas.Font.Color := clInfoBk;
523     FHintWinActive := false;
524     FItemsSortedBottom := false;
525     FItemsSortedTop := false;
526     FMouseDown := false;
527     FMTimestamp := floattostr(FMNow);
528     FMToday := DateTimeToFMDateTime(Date);
529     FNonNumerics := false;
530     FOnLegend := BIG_NUMBER;
531     FOnMark := false;
532     FOnSeries := BIG_NUMBER;
533     FOnValue := BIG_NUMBER;
534     FPointClick := false;
535     FPrevEvent := '';
536     FRetainZoom := false;
537     FSources := TStringList.Create;
538     FSourcesDefault := TStringList.Create;
539     FTHighTime := 0;
540     FTLowTime := BIG_NUMBER;
541     FWarning := false;
542     FX := 0; FY :=0;
543     FYMinValue := 0;
544     FYMaxValue := 0;
545     uDateStart := 0;
546     uDateStop  := 0;
547   end;
548   
549   procedure TfrmGraphs.SourcesDefault;
550   var
551     i: integer;
552     dfntype, listline, settings, settings1: string;
553   begin
554     settings := GetCurrentSetting;
555     settings1 := Piece(settings, '|', 1);
556     for i := 1 to BIG_NUMBER do
557     begin
558       dfntype := Piece(settings1, ';', i);
559       if length(dfntype) = 0 then break;
560       listline := dfntype + '^' + FileNameX(dfntype) + '^1';
561       FSourcesDefault.Add(listline);
562     end;
563   end;
564   
565   procedure TfrmGraphs.Initialize;
566   var                                        // from fFrame and fReports
567     i: integer;
568     rptview1, rptview2, rptviews: string;
569   begin
570     InitialData;
571     SourceContext;
572     LoadListView(GtslItems);
573     if pnlMain.Tag > 0 then
574     begin
575       rptviews := MixedCase(rpcReportParams(pnlMain.Tag));
576       if length(rptviews) > 1 then
577       begin
578         lstViewsTop.ClearSelection;
579         lvwItemsTop.ClearSelection;
580         GtslSelCopyTop.Clear;
581         GtslSelPrevTopFloat.Clear;
582         lstViewsBottom.ClearSelection;
583         lvwItemsBottom.ClearSelection;
584         GtslSelCopyBottom.Clear;
585         GtslSelPrevBottomFloat.Clear;
586         rptview1 := Piece(rptviews, '^', 1);
587         rptview2 := Piece(rptviews, '^', 2);
588         if length(rptview1) > 0 then
589         begin
590           for i := 0 to lstViewsTop.Items.Count - 1 do
591           if Piece(lstViewsTop.Items[i], '^', 2) = rptview1 then
592           begin
593             lstViewsTop.ItemIndex := i;
594             break;
595           end;
596         end;
597         if length(rptview2) > 0 then
598         begin
599           chkDualViews.Checked := true;
600           chkDualViewsClick(self);
601           for i := 0 to lstViewsBottom.Items.Count - 1 do
602           if Piece(lstViewsBottom.Items[i], '^', 2) = rptview2 then
603           begin
604             lstViewsBottom.ItemIndex := i;
605             break;
606           end;
607         end;
608       end;
609     end;
610     if lstViewsTop.ItemIndex > -1 then
611       lstViewsTopChange(self)
612     else
613       lvwItemsTopClick(self);
614     if lstViewsBottom.ItemIndex > -1 then
615     begin
616       //lstViewsBottom.Tag := 0;     // **** reset to allow bottom graphs
617       lstViewsBottomChange(self);
618     end
619     else
620       lvwItemsBottomClick(self);
621     if pnlMain.Tag > 0 then
622     begin
623       pnlMain.Tag := 0;
624       cboDateRangeChange(self);
625       if lstViewsTop.ItemIndex > -1 then
626         lstViewsTopChange(self)
627       else
628         lvwItemsTopClick(self);
629       if lstViewsBottom.ItemIndex > -1 then
630         lstViewsBottomChange(self)
631       else
632         lvwItemsBottomClick(self);
633     end;
634   end;
635   
636   procedure TfrmGraphs.InitialRetain;
637   begin
638     // from fFrame
639   end;
640   
641   procedure TfrmGraphs.FillViews;
642   var
643     i: integer;
644     listline: string;
645   begin
646     lstViewsTop.Tag := BIG_NUMBER;
647     lstViewsBottom.Tag := BIG_NUMBER;
648     lstViewsTop.Sorted := false;
649     lstViewsBottom.Sorted := false;
650     lstViewsTop.Items.Clear;
651     lstViewsBottom.Items.Clear;
652     GtslViewPersonal.Sorted := true;
653     FastAssign(GetGraphProfiles('1', '0', 0, User.DUZ), GtslViewPersonal);
654     GtslViewPublic.Sorted := true;
655     FastAssign(GetGraphProfiles('1', '1', 0, 0), GtslViewPublic);
656     with lstViewsTop do
657     begin
658       if GtslViews.Count > 0 then
659       begin
660         if not ((GtslViews.Count = 1) and (Piece(GtslViews[0], '^', 1) = VIEW_CURRENT)) then
661         begin
662           Items.Add(LLS_FRONT + copy('Temporary Views' + LLS_BACK, 0, 60) + '^0');
663           for i := 0 to GtslViews.Count - 1 do
664           begin
665             listline := GtslViews[i];
666             if Piece(listline, '^', 1) <> VIEW_CURRENT then
667               Items.Add(VIEW_TEMPORARY + '^' + listline + '^');
668           end;
669         end;
670       end;
671       if GtslViewPersonal.Count > 0 then
672       begin
673         Items.Add(LLS_FRONT + copy('Personal Views' + LLS_BACK, 0, 60) + '^0');
674         for i := 0 to GtslViewPersonal.Count - 1 do
675           Items.Add(VIEW_PERSONAL + '^' + GtslViewPersonal[i] + '^');
676       end;
677       if GtslViewPublic.Count > 0 then
678       begin
679         Items.Add(LLS_FRONT + copy('Public Views' + LLS_BACK, 0, 60) + '^0');
680         for i := 0 to GtslViewPublic.Count - 1 do
681           Items.Add(VIEW_PUBLIC + '^' + GtslViewPublic[i] + '^');
682       end;
683       AddOnLabGroups(lstViewsTop, 0);
684     end;
685     FastAssign(lstViewsTop.Items, lstViewsBottom.Items);
686   end;
687   
688   procedure TfrmGraphs.AddOnLabGroups(aListBox: TORListBox; personien: int64);
689   var
690     i: integer;
691   begin
692     if personien < 1 then personien := User.DUZ;
693     FastAssign(rpcTestGroups(personien), GtslLabGroup);
694     GtslLabGroup.Sorted := true;
695     if GtslLabGroup.Count > 0 then
696     begin
697       aListBox.Items.Add(LLS_FRONT + copy('Lab Groups' + LLS_BACK, 0, 60) + '^0');
698       for i := 0 to GtslLabGroup.Count - 1 do
699         aListBox.Items.Add(VIEW_LABS + '^' + Piece(GtslLabGroup[i], '^', 2)
700           + '^' + Piece(GtslLabGroup[i], '^', 1) + '^' + inttostr(personien));
701     end;
702   end;
703   
704   procedure TfrmGraphs.SourceContext;
705   begin
706     if frmFrame.GraphContext = '' then exit;
707     frmFrame.GraphContext := '';
708   end;
709   
710   procedure TfrmGraphs.FormShow(Sender: TObject);
711   var
712     context: boolean;
713   begin
714     Font := MainFont;
715     ChangeStyle;
716     StayOnTop;
717     mnuPopGraphResetClick(self);
718     if pnlFooter.Tag = 1 then  // do not show footer controls on reports tab
719     begin
720       pnlFooter.Visible := false;
721       if FCreate then
722       begin
723         FGraphType := GRAPH_REPORT;
724         FCreate := false;
725         GetSize;
726       end;
727     end
728     else
729     begin
730       chkDualViews.Checked := false;
731       chkDualViewsClick(self);
732       if FCreate then
733       begin
734         FGraphType := GRAPH_FLOAT;
735         FCreate := false;
736         GetSize;
737       end;
738     end;
739     if length(pnlFooter.Hint) > 1 then      // if context use all results
740       cboDateRange.ItemIndex := 8
741     else
742       DateDefaults;
743     cboDateRangeChange(self);
744     CheckContext(context);
745     lvwItemsTopClick(self);
746     if lvwItemsTop.Items.Count = 0 then
747     begin
748       lstViewsTop.ItemIndex := -1
749     end;
750     if not mnuPopGraphViewDefinition.Checked then
751       mnuPopGraphViewDefinitionClick(self);
752     tsTopCustom.TabVisible := false;
753     tsBottomCustom.TabVisible := false;
754   end;
755   
756   procedure TfrmGraphs.CheckContext(var usecontext: boolean);
757   var
758     i, topitem: integer;
759     contextvalue, itemcheck, itemvalue, typecheck, typeitem: string;
760     aGraphItem: TGraphItem;
761     aListItem: TListItem;
762   begin
763     usecontext := false;
764     if length(pnlFooter.Hint) > 1 then
765     begin
766       lvwItemsBottom.ClearSelection;
767       lvwItemsBottomClick(self);
768       contextvalue := pnlFooter.Hint;
769       //chkItemsTop.Caption := contextvalue;    // testing
770       typecheck := Piece(contextvalue, '^', 1);
771       itemcheck := Piece(contextvalue, '^', 2);
772       lvwItemsTop.ClearSelection;
773       topitem := 0;
774       for i := 0 to lvwItemsTop.Items.Count - 1 do
775       begin
776         aListItem := lvwItemsTop.Items[i];
777         aGraphItem := TGraphItem(aListItem.SubItems.Objects[3]);
778         typeitem := UpperCase(aGraphItem.Values);
779         if Piece(typeitem, '^', 1) = typecheck then
780         begin
781           itemvalue := Piece(Piece(typeitem, '^', 2), '.', 1);
782           if itemvalue = itemcheck then
783           begin
784             lvwItemsTop.Items[i].Selected := true;
785             topitem := i;
786           end;
787         end;
788       end;
789       GtslSelCopyTop.Clear;
790       if lvwItemsTop.SelCount > 0 then
791         usecontext := true;
792       if topitem > 0 then
793         lvwItemsTop.Items[topitem].MakeVisible(true);
794     end;
795     pnlFooter.Hint := '';
796   end;
797   
798   procedure TfrmGraphs.DateDefaults;
799   begin
800     if Patient.Inpatient then
801        cboDateRange.SelectByID(FGraphSetting.DateRangeInpatient)
802     else
803        cboDateRange.SelectByID(FGraphSetting.DateRangeOutpatient);
804     if cboDateRange.ItemIndex < 0 then
805       cboDateRange.ItemIndex := cboDateRange.Items.Count - 1;
806   end;
807   
808   procedure TfrmGraphs.FormClose(Sender: TObject; var Action: TCloseAction);
809   begin
810     if btnClose.Tag = 1 then
811       exit;
812     SetSize;
813     timHintPause.Enabled := false;
814     InactivateHint;
815     frmFrame.GraphFloatActive := false;
816   end;
817   
818   procedure TfrmGraphs.GetSize;
819   
820     procedure SetWidth(aListView: TListView; v1, v2, v3, v4: integer);
821     begin
822       if v1 > 0 then aListView.Column[0].Width := v1;
823       if v2 > 0 then aListView.Column[1].Width := v2;
824       if v3 > 0 then aListView.Column[2].Width := v3;
825       if v4 > 0 then aListView.Column[3].Width := v4;
826     end;
827   
828     procedure Layout(name, FR: string; v1, v2, v3, v4: integer);
829     begin  // FR indicates Float or Report graph
830       if name = (FR + 'WIDTH') then
831       begin
832         if v1 > 0 then
833         begin
834           pnlItemsTop.Width := v1;
835           splItemsTopMoved(self);
836         end;
837       end
838       else if name = (FR + 'BOTTOM') then
839       begin
840         if v1 > 0 then
841         begin
842           chkDualViews.Checked := true;
843           chkDualViewsClick(self);
844           pnlBottom.Height := v1;
845         end;
846       end
847       else if name = (FR + 'COLUMN') then
848         SetWidth(lvwItemsTop, v1, v2, v3, v4)
849       else if name = (FR + 'BCOLUMN') then
850         SetWidth(lvwItemsBottom, v1, v2, v3, v4);
851     end;
852   
853   
854   var
855     i, v1, v2, v3, v4: integer;
856     name, settings, value: string;
857     aList: TStrings;
858   begin
859     aList := TStringList.Create;
860     FastAssign(rpcGetGraphSizing, aList);
861     for i := 0 to aList.Count - 1 do
862     begin
863       settings := aList[i];
864       name := Piece(settings, '^', 1);
865       value := Piece(settings, '^', 2);
866       if length(value) > 1 then
867       begin
868         v1 := strtointdef(Piece(value, ',', 1), 0);
869         v2 := strtointdef(Piece(value, ',', 2), 0);
870         v3 := strtointdef(Piece(value, ',', 3), 0);
871         v4 := strtointdef(Piece(value, ',', 4), 0);
872         if FGraphType = GRAPH_FLOAT then
873         begin
874           if name = 'FBOUNDS' then
875           begin
876             if value = '0,0,0,0' then
877               WindowState := wsMaximized
878             else
879             begin
880               if v1 > 0 then Left :=   v1;
881               if v2 > 0 then Top :=    v2;
882               if v3 > 0 then Width :=  v3;
883               if v4 > 0 then Height := v4;
884             end;
885           end
886           else
887             Layout(name, 'F', v1, v2, v3, v4);
888         end
889         else
890           Layout(name, 'R', v1, v2, v3, v4);
891       end;
892     end;
893     FreeAndNil(aList);
894   end;
895   
896   procedure TfrmGraphs.SetSize;
897   
898     procedure GetWidth(aListView: TListView; var v1, v2, v3, v4: string);
899     begin
900       v1 := inttostr(aListView.Column[0].Width);
901       v2 := inttostr(aListView.Column[1].Width);
902       v3 := inttostr(aListView.Column[2].Width);
903       v4 := inttostr(aListView.Column[3].Width);
904     end;
905   
906     procedure Layout(aList: TStrings; FR, v1, v2, v3, v4: string);
907     begin // FR indicates Float or Report graph
908       v1 := inttostr(splItemsTop.Left);
909       aList.Add(FR + 'WIDTH^' + v1);
910       if chkDualViews.Checked then
911         v1 := inttostr(pnlBottom.Height)
912       else
913         v1 := '0';
914       aList.Add(FR + 'BOTTOM^' + v1);
915       GetWidth(lvwItemsTop, v1, v2, v3, v4);
916       aList.Add(FR + 'COLUMN^' + v1 + ',' + v2 + ',' + v3 + ',' + v4);
917       GetWidth(lvwItemsBottom, v1, v2, v3, v4);
918       aList.Add(FR + 'BCOLUMN^' + v1 + ',' + v2 + ',' + v3 + ',' + v4);
919     end;
920   
921   
922   var
923     v1, v2, v3, v4: string;
924     //values: array[0..3] of string;
925     aList: TStrings;
926   begin
927     aList := TStringList.Create;
928     if FGraphType = GRAPH_FLOAT then
929     begin
930       v1 := inttostr(Left);
931       v2 := inttostr(Top);
932       v3 := inttostr(Width);
933       v4 := inttostr(Height);
934       if WindowState = wsMaximized then
935         aList.Add('FBOUNDS^0,0,0,0')
936       else
937         aList.Add('FBOUNDS^' + v1 + ',' + v2 + ',' + v3 + ',' + v4);
938       Layout(aList, 'F', v1, v2, v3, v4);
939     end
940     else
941       Layout(aList, 'R', v1, v2, v3, v4);
942     rpcSetGraphSizing(aList);
943     FreeAndNil(aList);
944   end;
945   
946   procedure TfrmGraphs.btnCloseClick(Sender: TObject);
947   begin
948     Close;
949   end;
950   
951   procedure TfrmGraphs.btnChangeSettingsClick(Sender: TObject);
952   var
953     needtoupdate, okbutton: boolean;
954     conv, i, preconv: integer;
955     PreMaxGraphs: integer;
956     PreMaxSelect: integer;
957     PreMinGraphHeight: integer;
958     PreSortColumn: integer;
959     PreFixedDateRange: boolean;
960     PreMergeLabs: boolean;
961     aSettings, filetype, sourcetype: string;
962     PreSources: TStrings;
963   begin
964     Application.ProcessMessages;
965     okbutton := false;
966     conv := btnChangeSettings.Tag;
967     preconv := conv;
968     with FGraphSetting do
969     begin
970       PreMaxGraphs := MaxGraphs;
971       PreMaxSelect := MaxSelect;
972       PreMinGraphHeight := MinGraphHeight;
973       PreSortColumn := SortColumn;
974       PreFixedDateRange := FixedDateRange;
975       MaxSelectMin := Max(Max(lvwItemsTop.SelCount, lvwItemsBottom.SelCount), 1);
976       PreMergeLabs := MergeLabs;
977     end;
978     PreSources := TStringList.Create;
979     FastAssign(FSources, PreSources);
980     DialogGraphSettings(Font.Size, okbutton, FGraphSetting, FSources, conv, aSettings);
981     if not okbutton then exit;
982     if length(aSettings) > 0 then SetCurrentSetting(aSettings);
983     btnChangeSettings.Tag := conv;
984     pnlInfo.Font.Size := chkItemsTop.Font.Size;
985     SetFontSize(chkItemsTop.Font.Size);
986     InfoMessage(TXT_WARNING, COLOR_WARNING, (conv > 0));
987     if MergedLabsSelected then
988       InfoMessage(pnlInfo.Caption + ' ' + TXT_WARNING_MERGED_LABS, COLOR_WARNING, true);
989     pnlHeader.Visible := pnlInfo.Visible;
990     StayOnTop;
991     needtoupdate := (conv <> preconv);
992     for i := 0 to FSources.Count - 1 do
993     begin
994       sourcetype := FSources[i];
995       if Copy(sourcetype, 1, 1) = '*' then
996       begin
997         FSources[i] := Pieces(sourcetype, '^', 2, 4);
998         if not FFastItems then
999         begin
1000          filetype := Piece(FSources[i], '^', 1);
1001          FastAddStrings(rpcGetItems(filetype, Patient.DFN), GtslItems);
1002          needtoupdate := true;
1003        end;
1004      end;
1005      if not needtoupdate then
1006        if Piece(PreSources[i], '^', 3) = '0' then
1007          needtoupdate := TypeIsDisplayed(Piece(sourcetype, '^', 1))
1008        else
1009          needtoupdate := not TypeIsDisplayed(Piece(sourcetype, '^', 1));
1010    end;
1011    if not needtoupdate then
1012    with FGraphSetting do
1013      if MaxGraphs <> PreMaxGraphs then
1014        needtoupdate := true
1015      else if MaxSelect <> PreMaxSelect then
1016        needtoupdate := true
1017      else if MinGraphHeight <> PreMinGraphHeight then
1018        needtoupdate := true
1019      else if SortColumn <> PreSortColumn then
1020        needtoupdate := true
1021      else if MergeLabs <> PreMergeLabs then
1022        needtoupdate := true
1023      else if FixedDateRange <> PreFixedDateRange then
1024        needtoupdate := true;
1025    if needtoupdate then
1026    begin
1027      cboDateRangeChange(self);
1028      if FGraphSetting.MergeLabs <> PreMergeLabs then
1029      begin
1030        PositionSelections(lvwItemsTop);
1031        PositionSelections(lvwItemsBottom);
1032      end;
1033    end;
1034    ChangeStyle;
1035    if lvwItemsTop.SelCount = 0 then
1036    begin
1037      lstViewsTop.ItemIndex := -1;
1038    end;
1039    if lvwItemsBottom.SelCount = 0 then
1040    begin
1041      lstViewsBottom.ItemIndex := -1;
1042    end;
1043    FreeAndNil(PreSources);
1044  end;
1045  
1046  procedure TfrmGraphs.chkDualViewsClick(Sender: TObject);
1047  begin
1048    if chkDualViews.Checked then
1049    begin
1050      pnlBottom.Height := pnlMain.Height div 2;
1051      lvwItemsTopClick(self);
1052    end
1053    else
1054    begin
1055      lvwItemsBottom.ClearSelection;
1056      lvwItemsBottomClick(self);
1057      pnlBottom.Height := 1;
1058    end;
1059    mnuPopGraphDualViews.Checked := chkDualViews.Checked;
1060    with pnlMain.Parent do
1061      if BorderWidth <> 1 then            // only do on Graph in Reports tab
1062        frmReports.chkDualViews.Checked := chkDualViews.Checked;
1063  end;
1064  
1065  procedure TfrmGraphs.LoadListView(aList: TStrings);
1066  var
1067    i: integer;
1068    filename, filenum, itemnum: string;
1069  begin
1070    lvwItemsTop.Items.Clear;
1071    lvwItemsBottom.Items.Clear;
1072    lvwItemsTop.Items.BeginUpdate;
1073    lvwItemsBottom.Items.BeginUpdate;
1074    lvwItemsTop.SortType := stNone; // if Sorting during load then potential error
1075    lvwItemsBottom.SortType := stNone; // if Sorting during load then potential error
1076    with lvwItemsTop do
1077    for i := 0 to aList.Count - 1 do
1078    begin
1079      filenum := Piece(aList[i], '^', 1);
1080      filename := FileNameX(filenum);    // change rpc **********
1081      itemnum := Piece(aList[i], '^', 2);
1082      UpdateView(filename, filenum, itemnum, aList[i], lvwItemsTop);
1083    end;
1084    lvwItemsBottom.Items.Assign(lvwItemsTop.Items);
1085    lvwItemsTop.SortType := stBoth;
1086    lvwItemsBottom.SortType := stBoth;
1087    if not FItemsSortedTop then
1088    begin
1089      lvwItemsTopColumnClick(lvwItemsTop, lvwItemsTop.Column[0]);
1090      FItemsSortedTop := true;
1091    end;
1092    if not FItemsSortedBottom then
1093    begin
1094      lvwItemsBottomColumnClick(lvwItemsBottom, lvwItemsBottom.Column[0]);
1095      FItemsSortedBottom := true;
1096    end;
1097    with FGraphSetting do
1098    if SortColumn > 0 then
1099    begin
1100      lvwItemsTopColumnClick(lvwItemsTop, lvwItemsTop.Column[SortColumn]);
1101      lvwItemsBottomColumnClick(lvwItemsBottom, lvwItemsBottom.Column[SortColumn]);
1102      FItemsSortedTop := false;
1103      FItemsSortedBottom := false;
1104    end;
1105    lvwItemsTop.Items.EndUpdate;
1106    lvwItemsBottom.Items.EndUpdate;
1107  end;
1108  
1109  procedure TfrmGraphs.FilterListView(oldestdate, newestdate: double);
1110  var
1111    i: integer;
1112    lastdate: double;
1113    filename, filenum, itemnum: string;
1114  begin
1115    lvwItemsTop.Scroll(-BIG_NUMBER, -BIG_NUMBER);      //faster to set scroll at top
1116    lvwItemsBottom.Scroll(-BIG_NUMBER, -BIG_NUMBER);
1117    lvwItemsTop.Items.Clear;
1118    lvwItemsBottom.Items.Clear;
1119    lvwItemsTop.SortType := stNone; // if Sorting during load then potential error
1120    lvwItemsBottom.SortType := stNone; // if Sorting during load then potential error
1121    if (cboDateRange.ItemIndex > 0) and (cboDateRange.ItemIndex < 9) then
1122    begin
1123      if TypeIsDisplayed('405') then
1124        DateRangeItems(oldestdate, newestdate, '405');  // does not matter for all results ******************
1125      if TypeIsDisplayed('52') then
1126        DateRangeItems(oldestdate, newestdate, '52');  // does not matter for all results ******************
1127      if TypeIsDisplayed('55') then
1128        DateRangeItems(oldestdate, newestdate, '55');
1129      if TypeIsDisplayed('55NVA') then
1130        DateRangeItems(oldestdate, newestdate, '55NVA');
1131      if TypeIsDisplayed('9999911') then
1132        DateRangeItems(oldestdate, newestdate, '9999911');
1133      for i := 0 to GtslItems.Count - 1 do
1134      begin
1135        filenum := UpperCase(Piece(GtslItems[i], '^', 1));
1136        if filenum <> '405' then
1137        if filenum <> '52' then
1138        if filenum <> '55' then
1139        if filenum <> '55NVA' then
1140        if filenum <> '9999911' then
1141        if TypeIsDisplayed(filenum) then
1142        begin
1143          lastdate := strtofloatdef(Piece(GtslItems[i], '^', 6), -BIG_NUMBER);
1144          if (lastdate > oldestdate) and (lastdate < newestdate) then
1145          begin
1146            filename := FileNameX(filenum);
1147            itemnum := Piece(GtslItems[i], '^', 2);
1148            UpdateView(filename, filenum, itemnum, GtslItems[i], lvwItemsTop);
1149          end;
1150        end;
1151      end;
1152    end
1153    else if (cboDateRange.ItemIndex = 0) or (cboDateRange.ItemIndex > 8) then
1154    begin     // manual date range selection
1155      for i := 0 to GtslAllTypes.Count - 1 do
1156      begin
1157        filenum := Piece(GtslAllTypes[i], '^', 1);
1158        if TypeIsDisplayed(filenum) then
1159        begin
1160          DateRangeItems(oldestdate, newestdate, filenum);
1161        end;
1162      end;
1163    end;
1164    lvwItemsBottom.Items.Assign(lvwItemsTop.Items);
1165    SortListView;
1166  end;
1167  
1168  procedure TfrmGraphs.SortListView;
1169  var
1170    colnum: integer;
1171    aProfile: string;
1172  begin
1173    lvwItemsTop.SortType := stBoth;
1174    lvwItemsBottom.SortType := stBoth;
1175    colnum := 0;
1176    if not FItemsSortedTop then
1177    begin
1178      lvwItemsTopColumnClick(lvwItemsTop, lvwItemsTop.Column[0]);
1179      FItemsSortedTop := true;
1180    end;
1181    if not FItemsSortedBottom then
1182    begin
1183      lvwItemsBottomColumnClick(lvwItemsBottom, lvwItemsBottom.Column[0]);
1184      FItemsSortedBottom := true;
1185    end;
1186    with FGraphSetting do
1187    if SortColumn > 0 then
1188    begin
1189      colnum := SortColumn;
1190      lvwItemsTopColumnClick(lvwItemsTop, lvwItemsTop.Column[SortColumn]);
1191      lvwItemsBottomColumnClick(lvwItemsBottom, lvwItemsBottom.Column[SortColumn]);
1192      FItemsSortedTop := false;
1193      FItemsSortedBottom := false;
1194    end;
1195    if lstViewsTop.ItemIndex > 1 then                         // sort by view
1196    begin
1197      aProfile := lstViewsTop.Items[lstViewsTop.ItemIndex];
1198      AssignProfile(aProfile, 'top');
1199      if not FItemsSortedTop then lvwItemsTopColumnClick(lvwItemsTop, lvwItemsTop.Column[colnum]);
1200      lvwItemsTopColumnClick(lvwItemsTop, lvwItemsTop.Column[2]);
1201      lvwItemsTopColumnClick(lvwItemsTop, lvwItemsTop.Column[2]);
1202      FItemsSortedTop := false;
1203    end;
1204    if lstViewsBottom.ItemIndex > 1 then                      // sort by view
1205    begin
1206      aProfile := lstViewsBottom.Items[lstViewsBottom.ItemIndex];
1207      AssignProfile(aProfile, 'bottom');
1208      if not FItemsSortedBottom then lvwItemsBottomColumnClick(lvwItemsBottom, lvwItemsBottom.Column[colnum]);
1209      lvwItemsBottomColumnClick(lvwItemsBottom, lvwItemsBottom.Column[2]);
1210      lvwItemsBottomColumnClick(lvwItemsBottom, lvwItemsBottom.Column[2]);
1211      FItemsSortedBottom := false;
1212    end;
1213  end;
1214  
1215  procedure TfrmGraphs.DateRangeItems(oldestdate, newestdate: double; filenum: string);
1216  var
1217    i, j: integer;
1218    meddate: double;
1219    filename, iteminfo, itemnum, oldtempiteminfo, tempiteminfo, tempitemnum: string;
1220  begin
1221    FastAssign(rpcDateItem(oldestdate, newestdate, filenum, Patient.DFN), GtslScratchTemp);
1222    filename := FileNameX(filenum);
1223    lvwItemsTop.Items.BeginUpdate;
1224    oldtempiteminfo := '';
1225    with lvwItemsTop do
1226    for i := 0 to GtslScratchTemp.Count - 1 do
1227    begin
1228      tempiteminfo := GtslScratchTemp[i];
1229      tempitemnum := UpperCase(Piece(tempiteminfo, '^',2));
1230      for j := 0 to GtslItems.Count - 1 do
1231      begin
1232        iteminfo := GtslItems[j];
1233        if filenum = UpperCase(Piece(iteminfo, '^', 1)) then
1234        begin
1235          if filenum = '690' then  // recheck medicine dates & duplicates
1236          begin
1237            meddate := strtofloatdef(Piece(iteminfo, '^', 6), -BIG_NUMBER);
1238            if tempiteminfo <> oldtempiteminfo then
1239              if (meddate <> -BIG_NUMBER) and (meddate > oldestdate) and (meddate < newestdate) then
1240                if tempitemnum = UpperCase(Piece(iteminfo, '^', 2)) then
1241                begin
1242                  UpdateView(filename, filenum, tempitemnum, iteminfo, lvwItemsTop);
1243                  oldtempiteminfo := tempiteminfo;
1244                end;
1245          end
1246          else if tempitemnum = UpperCase(Piece(iteminfo, '^', 2)) then
1247            UpdateView(filename, filenum, tempitemnum, iteminfo, lvwItemsTop)
1248          else
1249            if filenum = '63' then
1250            begin
1251              itemnum := UpperCase(Piece(iteminfo, '^', 2));
1252              if tempitemnum = Piece(itemnum, '.', 1) then
1253                if DateRangeMultiItems(oldestdate, newestdate, itemnum) then
1254                  UpdateView(filename, filenum, itemnum, iteminfo, lvwItemsTop);
1255            end;
1256        end;
1257      end;
1258    end;
1259    lvwItemsTop.Items.EndUpdate;
1260  end;
1261  
1262  procedure TfrmGraphs.UpdateView(filename, filenum, itemnum, aString: string; aListView: TListView);
1263  var
1264    drugclass, itemname, itemqualifier: string;
1265    aGraphItem: TGraphItem;
1266    aListItem: TListItem;
1267  begin
1268    if filenum = '63' then
1269    begin
1270      itemqualifier := Piece(itemnum, '.', 2);
1271      if length(itemqualifier) > 0 then
1272      begin
1273        if FGraphSetting.MergeLabs then
1274          if itemqualifier  <> '0' then exit;
1275        if not FGraphSetting.MergeLabs then
1276          if itemqualifier  = '0' then exit;
1277      end;
1278    end;
1279    itemname := Piece(aString, '^', 4);
1280    itemqualifier := Pieces(aString, '^', 5, 9);
1281    itemqualifier := filenum + '^' + itemnum + '^' + itemqualifier;
1282    drugclass := Piece(aString, '^', 8);
1283    aListItem := aListView.Items.Add;
1284    with aListItem do
1285    begin
1286      Caption := itemname;
1287      SubItems.Add(filename);
1288      SubItems.Add('');
1289      SubItems.Add(drugclass);
1290      aGraphItem := TGraphItem.Create;
1291      aGraphItem.Values := itemqualifier;
1292      SubItems.AddObject('', aGraphItem);
1293    end;
1294  end;
1295  
1296  function TfrmGraphs.DateRangeMultiItems(aOldDate, aNewDate: double; aMultiItem: string): boolean;
1297  var
1298    i: integer;
1299    checkdate: double;
1300    fileitem: string;
1301  begin
1302    Result := false;
1303    fileitem := '63^' + aMultiItem;
1304    for i := 0 to GtslData.Count - 1 do
1305      if Pieces(GtslData[i], '^', 1, 2) = fileitem then
1306      begin
1307        checkdate := strtofloatdef(Piece(GtslData[i], '^', 3), BIG_NUMBER);
1308        if checkdate <> BIG_NUMBER then
1309          if checkdate >= aOldDate then
1310            if checkdate <= aNewDate then
1311            begin
1312              Result := true;
1313              break;
1314            end;
1315      end;
1316  end;
1317  
1318  function TfrmGraphs.DatesInRange(EarlyDate, RecentDate, Date1, Date2: double): boolean;
1319  begin
1320    Result := true;
1321    if Date2 < 0 then   // instance
1322    begin
1323      if Date1 < EarlyDate then
1324        Result := false
1325      else if Date1 > RecentDate then
1326        Result := false;
1327    end
1328    else                // durations
1329    begin
1330      if Date1 > RecentDate then
1331        Result := false
1332      else if Date2 < EarlyDate then
1333        Result := false;
1334    end;
1335  end;
1336  
1337  function TfrmGraphs.FileNameX(filenum: string): string;
1338  var
1339    i: integer;
1340    typestring: string;
1341  begin
1342    Result := '';
1343    for i := 0 to GtslAllTypes.Count - 1 do
1344    begin
1345      typestring := GtslAllTypes[i];
1346      if Piece(typestring, '^', 1) = filenum then
1347      begin
1348        Result := Piece(GtslAllTypes[i], '^', 2);
1349        break;
1350      end;
1351    end;
1352    if Result = '' then
1353    begin
1354      for i := 0 to GtslAllTypes.Count - 1 do
1355      begin
1356        typestring := GtslAllTypes[i];
1357        if lowercase(Piece(typestring, '^', 1)) = filenum then
1358        begin
1359          Result := Piece(GtslAllTypes[i], '^', 2);
1360          break;
1361        end;
1362      end;
1363    end;
1364  end;
1365  
1366  function TfrmGraphs.TypeString(filenum: string): string;
1367  var
1368    i: integer;
1369    typestring: string;
1370  begin
1371    Result := '';
1372    for i := 0 to GtslAllTypes.Count - 1 do
1373    begin
1374      typestring := GtslAllTypes[i];
1375      if Piece(typestring, '^', 1) = filenum then
1376      begin
1377        Result := typestring;
1378        break;
1379      end;
1380    end;
1381    if Result = '' then
1382    begin
1383      for i := 0 to GtslAllTypes.Count - 1 do
1384      begin
1385        typestring := GtslAllTypes[i];
1386        if lowercase(Piece(typestring, '^', 1)) = filenum then
1387        begin
1388          Result := typestring;
1389          break;
1390        end;
1391      end;
1392    end;
1393  end;
1394  
1395  function TfrmGraphs.ItemName(filenum, itemnum: string): string;
1396  var
1397    i: integer;
1398    typestring: string;
1399  begin
1400    Result := '';
1401    filenum := UpperCase(filenum);
1402    itemnum := UpperCase(itemnum);
1403    for i := 0 to GtslItems.Count - 1 do
1404    begin
1405      typestring := UpperCase(GtslItems[i]);
1406      if (Piece(typestring, '^', 1) = filenum) and
1407        (Piece(typestring, '^', 2) = itemnum) then
1408      begin
1409        Result := Piece(typestring, '^', 4);
1410        break;
1411      end;
1412    end;
1413  end;
1414  
1415  procedure TfrmGraphs.Switch;
1416  var
1417    aList: TStringList;
1418  begin
1419    if FFastTrack then
1420      exit;
1421    aList := TStringList.Create;
1422    if not FFastItems then
1423    begin
1424      rpcFastItems(Patient.DFN, aList, FFastItems);  // ***
1425      if FFastItems then
1426      begin
1427        FastAssign(aList, GtslItems);
1428        rpcFastData(Patient.DFN, aList, FFastData);  // ***
1429        if FFastData then
1430        begin
1431          FastAssign(aList, GtslData);
1432          aList.Clear;
1433          rpcFastLabs(Patient.DFN, aList, FFastLabs);  // ***
1434          if FFastLabs then
1435            FastLab(aList);
1436          FastAssign(GtslData, GtslCheck);
1437        end;
1438      end;
1439    end;
1440    if not FFastTrack then
1441      FFastTrack := FFastItems and FFastData and FFastLabs;
1442    if not FFastTrack then
1443    begin
1444      FFastItems := false;
1445      FFastData := false;
1446      FFastLabs := false;
1447    end;
1448    FreeAndNil(aList);
1449  end;
1450  
1451  procedure TfrmGraphs.InitialData;
1452  var
1453    i: integer;
1454    dfntype, listline: string;
1455  begin
1456    Application.ProcessMessages;
1457    FMTimestamp := floattostr(FMNow);
1458    //SourcesDefault;
1459    //FastAssign(FSourcesDefault, FSources);
1460    for i := 0 to GtslTypes.Count - 1 do
1461    begin
1462      listline := GtslTypes[i];
1463      dfntype := UpperCase(Piece(listline, '^', 1));
1464      SetPiece(listline, '^', 1, dfntype);
1465      GtslTypes[i] := listline;
1466    end;
1467    btnChangeSettings.Tag := 0;
1468    btnClose.Tag := 0;
1469    lstViewsBottom.Tag := 0;
1470    lstViewsTop.Tag := 0;
1471    chartDatelineTop.Tag := 0;
1472    lvwItemsBottom.Tag := 0;
1473    lvwItemsTop.Tag := 0;
1474    pnlFooter.Parent.Tag := 0;
1475    pnlItemsBottom.Tag := 0;
1476    pnlItemsTop.Tag := 0;
1477    pnlTop.Tag := 0;
1478    scrlTop.Tag := 0;
1479    splGraphs.Tag := 0;
1480    lstViewsBottom.ItemIndex := -1;
1481    lstViewsTop.ItemIndex := -1;
1482    frmGraphData.pnlData.Hint := Patient.DFN;      // use to check for patient change
1483    FPrevEvent := '';
1484    FWarning := false;
1485    FFirstSwitch := true;
1486    Application.ProcessMessages;
1487    FFastData := false;
1488    FFastItems := false;
1489    FFastLabs := false;
1490    FFastTrack := false;
1491    if GraphTurboOn then
1492      Switch;
1493    //if not FFastItems then
1494    if GtslItems.Count = 0 then
1495    begin
1496      for i := 0 to GtslTypes.Count - 1 do
1497      begin
1498        dfntype := Piece(GtslTypes[i], '^', 1);
1499        if TypeIsLoaded(dfntype) then
1500          FastAddStrings(rpcGetItems(dfntype, Patient.DFN), GtslItems);
1501      end;
1502    end;
1503  end;
1504  
1505  procedure TfrmGraphs.SaveTestData(typeitem: string);
1506  var
1507    aType, aItem, aItemName: string;
1508  begin
1509    aType := Piece(typeitem, '^', 1);
1510    aItem := Piece(typeitem, '^', 2);
1511    aItemName := MixedCase(ItemName(aType, aItem));
1512    LabData(typeitem, aItemName, 'top', false);  // already have lab data
1513    GtslScratchLab.Clear;
1514  end;
1515  
1516  procedure TfrmGraphs.FastLab(aList: TStringList);
1517  var
1518    i, lastnum: integer;
1519    newtypeitem, oldtypeitem, listline: string;
1520  begin
1521    lastnum := aList.Count - 1;
1522    if lastnum < 0 then
1523      exit;
1524    GtslScratchLab.Clear;
1525    aList.Sort;
1526    oldtypeitem := Pieces(aList[0], '^', 1, 2);
1527    for i := 0 to lastnum do
1528    begin
1529      listline := aList[i];
1530      newtypeitem := Pieces(listline, '^', 1 , 2);
1531      if lastnum = i then
1532      begin
1533        if newtypeitem <> oldtypeitem then
1534        begin
1535          SaveTestData(oldtypeitem);
1536          oldtypeitem := newtypeitem;
1537        end;
1538        GtslScratchLab.Add(listline);
1539        SaveTestData(oldtypeitem);
1540      end
1541      else if newtypeitem <> oldtypeitem then
1542      begin
1543        SaveTestData(oldtypeitem);
1544        GtslScratchLab.Add(listline);
1545        oldtypeitem := newtypeitem;
1546      end
1547      else
1548        GtslScratchLab.Add(listline);
1549    end;
1550  end;
1551  
1552  function TfrmGraphs.TypeIsLoaded(itemtype: string): boolean;
1553  var
1554    i: integer;
1555    filetype: string;
1556  begin
1557    if FFastItems then
1558    begin
1559      Result := true;
1560      exit;
1561    end;
1562    Result := false;
1563    for i := 0 to FSources.Count - 1 do
1564    begin
1565      filetype := Piece(FSources[i], '^', 1);
1566      if itemtype = filetype then
1567      begin
1568        Result := true;
1569        break;
1570      end;
1571    end;
1572  end;
1573  
1574  function TfrmGraphs.TypeIsDisplayed(itemtype: string): boolean;
1575  var
1576    i: integer;
1577    displayed, filetype: string;
1578  begin
1579    Result := false;
1580    for i := 0 to FSources.Count - 1 do
1581    begin
1582      filetype := Piece(FSources[i], '^', 1);
1583      displayed := Piece(FSources[i], '^', 3);
1584      if (itemtype = filetype) then
1585      begin
1586        if displayed = '1' then Result := true;
1587        break;
1588      end;
1589    end;
1590  end;
1591  
1592  procedure TfrmGraphs.LoadDateRange;
1593  var
1594    defaults, defaultrange: string;
1595  begin
1596    FastAssign(rpcGetGraphDateRange('OR_GRAPHS'), cboDateRange.Items);
1597    with cboDateRange do
1598    begin
1599      defaults := Items[Items.Count - 1];        // ***** CHANGE TO DEFAULTS
1600      defaultrange := Piece(defaults, '^', 1);
1601      //get report views - param 1 and param 2
1602      lvwItemsTop.Hint := Piece(defaults,'^', 8);     // top view
1603      lvwItemsBottom.Hint := Piece(defaults,'^', 9);  // bottom view
1604      //check if default range already exists
1605      if strtointdef(defaultrange, BIG_NUMBER) = BIG_NUMBER then
1606        ItemIndex := Items.Count - 1
1607      else
1608        ItemIndex := strtoint(defaultrange);
1609    end;
1610  end;
1611  
1612  procedure TfrmGraphs.LoadType(itemtype, displayed: string);
1613  var
1614    needtoadd: boolean;
1615    i: integer;
1616    filename, filetype, zzz: string;
1617  begin
1618    if displayed <> '1' then displayed := '';
1619    needtoadd := true;
1620    for i := 0 to FSources.Count - 1 do
1621    begin
1622      zzz := FSources[i];
1623      filetype := Piece(FSources[i], '^', 1);
1624      if itemtype = filetype then
1625      begin
1626        needtoadd := false;
1627        break;
1628      end;
1629    end;
1630    if needtoadd then
1631    begin
1632      filename := FileNameX(itemtype);
1633      FSources.Add(itemtype + '^' + filename + '^' + displayed);
1634      FastAddStrings(rpcGetItems(itemtype, Patient.DFN), GtslItems);
1635    end;
1636  end;
1637  
1638  procedure TfrmGraphs.DisplayType(itemtype, displayed: string);
1639  var
1640    i: integer;
1641    filename, filetype: string;
1642  begin
1643    if displayed <> '1' then displayed := '';
1644    for i := 0 to FSources.Count - 1 do
1645    begin
1646      filetype := Piece(FSources[i], '^', 1);
1647      if itemtype = filetype then
1648      begin
1649        filename := FileNameX(itemtype);
1650        FSources[i] := itemtype + '^' + filename + '^' + displayed;
1651        break;
1652      end;
1653    end;
1654  end;
1655  
1656  procedure TfrmGraphs.DisplayData(aSection: string);
1657  var
1658    i: integer;
1659    astring: string;
1660    aChart: TChart;
1661    aCheckBox: TCheckBox;
1662    aListView, aOtherListView: TListView;
1663    aDateline, aRightPad: TPanel;
1664    aScrollBox: TScrollBox;
1665    aMemo: TMemo;
1666  begin
1667    FHintStop := true;
1668    SetFontSize(chkItemsTop.Font.Size);
1669    if aSection = 'top' then
1670    begin
1671      aListView := lvwItemsTop;         aOtherListView := lvwItemsBottom;
1672      aDateline := pnlDatelineTop;      aChart := chartDatelineTop;
1673      aRightPad := pnlTopRightPad;      aScrollBox := scrlTop;
1674      aCheckBox := chkItemsTop;         aMemo := memTop;
1675    end
1676    else
1677    begin
1678      aListView := lvwItemsBottom;      aOtherListView := lvwItemsTop;
1679      aDateline := pnlDatelineBottom;   aChart := chartDatelineBottom;
1680      aRightPad := pnlBottomRightPad;   aScrollBox := scrlBottom;
1681      aCheckBox := chkItemsBottom;      aMemo := memBottom;
1682    end;
1683    if aListView.SelCount < 1 then
1684    begin
1685      if not FFirstClick then
1686      begin
1687        FFirstClick := true;
1688        while aScrollBox.ControlCount > 0 do aScrollBox.Controls[0].Free;
1689        exit;
1690      end;
1691      FFirstClick := false;
1692      aDateline.Visible := false;
1693      while aScrollBox.ControlCount > 0 do
1694        aScrollBox.Controls[0].Free;
1695      if aOtherListView.SelCount > 0 then
1696        if aOtherListView = lvwItemsTop then
1697          ItemsClick(self, lvwItemsTop, lvwItemsBottom, chkItemsTop, lstViewsTop, GtslSelCopyTop, 'top')
1698        else
1699          ItemsClick(self, lvwItemsBottom, lvwItemsTop, chkItemsBottom, lstViewsBottom, GtslSelCopyBottom, 'bottom');
1700      exit;
1701    end;
1702    aScrollBox.VertScrollBar.Visible := false;
1703    aScrollBox.HorzScrollBar.Visible := false;
1704    amemo.Visible := false;
1705    aChart.RemoveAllSeries;    // this would leave bottom dateline visible on date change
1706    for i := GtslNonNum.Count - 1 downto 0 do
1707    begin
1708      astring := GtslNonNum[i];
1709      if Piece(astring, '^', 7) = aSection then
1710        GtslNonNum.Delete(i);
1711    end;
1712    if aCheckBox.Checked then
1713      MakeSeparate(aScrollBox, aListView, aRightPad, aSection)
1714    else
1715      MakeTogetherMaybe(aScrollBox, aListView, aRightPad, aSection);
1716    DisplayDataInfo(aScrollBox, aMemo);
1717  end;
1718  
1719  procedure TfrmGraphs.DisplayDataInfo(aScrollBox: TScrollBox; aMemo: TMemo);
1720  begin
1721    ChangeStyle;
1722    pnlInfo.Font.Size := chkItemsTop.Font.Size;
1723    if ((lvwItemsTop.SelCount > MAX_ITEM_DISCLAIMER) and (not chkItemsTop.Checked))
1724      or ((lvwItemsBottom.SelCount > MAX_ITEM_DISCLAIMER) and (not chkItemsBottom.Checked)) then
1725      InfoMessage(TXT_DISCLAIMER, COLOR_WARNING, true)
1726    else
1727      pnlInfo.Visible := false;
1728    if btnChangeSettings.Tag > 0 then
1729      InfoMessage(TXT_WARNING, COLOR_WARNING, true);
1730    if FWarning then
1731      pnlInfo.Visible := true;
1732    if MergedLabsSelected then
1733      if (not ansicontainsstr(pnlInfo.Caption, TXT_WARNING_MERGED_LABS)) and pnlInfo.Visible then
1734        InfoMessage(pnlInfo.Caption + ' ' + TXT_WARNING_MERGED_LABS, COLOR_WARNING, true)
1735      else
1736        InfoMessage(TXT_WARNING_MERGED_LABS, COLOR_WARNING, true);
1737    pnlHeader.Visible := pnlInfo.Visible;
1738    aScrollBox.VertScrollBar.Visible := true;
1739    aScrollBox.HorzScrollBar.Visible := false;
1740    if (aScrollBox.ControlCount > FGraphSetting.MaxGraphs)
1741    or (aScrollBox.Height < FGraphSetting.MinGraphHeight) then
1742      aMemo.Visible:= true;
1743  end;
1744  
1745  function TfrmGraphs.MergedLabsSelected: boolean;
1746  var
1747    i: integer;
1748    filetype, typeitem: string;
1749    aGraphItem: TGraphItem;
1750    aListItem: TListItem;
1751    aListView: TListView;
1752  begin
1753    Result := false;
1754    if not FGraphSetting.MergeLabs then exit;
1755    for i := 1 to 2 do
1756    begin
1757      if i = 1 then
1758        aListView := lvwItemsTop
1759      else
1760        aListView := lvwItemsBottom;
1761      aListItem := aListView.Selected;
1762      while aListItem <> nil do
1763      begin
1764        aGraphItem := TGraphItem(aListItem.SubItems.Objects[3]);
1765        filetype := Piece(aGraphItem.Values, '^', 1);
1766        if filetype = '63' then
1767        begin
1768          typeitem := UpperCase(Piece(aGraphItem.Values, '^', 2));
1769          if Piece(typeitem, '.', 2) = '0' then
1770          begin
1771            Result := true;
1772            exit;
1773          end;
1774        end;
1775        aListItem := aListView.GetNextItem(aListItem, sdAll, [isSelected]);
1776      end;
1777    end;
1778  end;
1779  
1780  
1781  procedure TfrmGraphs.chkItemsTopClick(Sender: TObject);
1782  begin
1783    Screen.Cursor := crHourGlass;
1784    DisplayData('top');
1785    if FFirstSwitch then   // this code makes events appear better (on first click was not displaying bar)
1786    begin
1787      chartBaseMouseDown(chartDatelineTop, mbLeft, [], 1, 1);
1788      DisplayData('top');
1789      FFirstSwitch := false;
1790    end;
1791    Screen.Cursor := crDefault;
1792  end;
1793  
1794  procedure TfrmGraphs.chkItemsBottomClick(Sender: TObject);
1795  begin
1796    Screen.Cursor := crHourGlass;
1797    DisplayData('bottom');
1798    if FFirstSwitch then   // this code makes events appear better (on first click was not displaying bar)
1799    begin
1800      chartBaseMouseDown(chartDatelineBottom, mbLeft, [], 1, 1);
1801      DisplayData('bottom');
1802      FFirstSwitch := false;
1803    end;
1804    Screen.Cursor := crDefault;
1805  end;
1806  
1807  procedure TfrmGraphs.BottomAxis(aScrollBox: TScrollBox);
1808  var
1809    i: integer;
1810    ChildControl: TControl;
1811  begin
1812    for i := 0 to aScrollBox.ControlCount - 1 do
1813    begin
1814      ChildControl := aScrollBox.Controls[i];
1815      with (ChildControl as TChart).BottomAxis do
1816      begin
1817        Automatic := false;
1818        Minimum := 0;
1819        Maximum := chartDatelineTop.BottomAxis.Maximum;
1820        Minimum := chartDatelineTop.BottomAxis.Minimum;
1821      end;
1822    end;
1823  end;
1824  
1825  procedure TfrmGraphs.AdjustTimeframe;
1826  begin
1827    with FGraphSetting do
1828    begin
1829      if HighTime = 0 then exit;  // no data to chart clear form ???
1830      chartDatelineTop.BottomAxis.Minimum := 0;  // avoid possible error
1831      chartDatelineTop.BottomAxis.Maximum := HighTime;
1832      if LowTime < HighTime then
1833        chartDatelineTop.BottomAxis.Minimum := LowTime;
1834      chartDatelineBottom.BottomAxis.Minimum := 0;  // avoid possible error
1835      chartDatelineBottom.BottomAxis.Maximum := HighTime;
1836      if HighTime > FMDateTimeToDateTime(FMStopDate) then
1837        chartDatelineTop.BottomAxis.Maximum := FMDateTimeToDateTime(FMStopDate);
1838      if LowTime < FMDateTimeToDateTime(FMStartDate) then
1839        chartDatelineTop.BottomAxis.Minimum := FMDateTimeToDateTime(FMStartDate);  // *****
1840    end;
1841    BottomAxis(scrlTop);
1842    BottomAxis(scrlBottom);
1843  end;
1844  
1845  procedure TfrmGraphs.ChartOnZoom(Sender: TObject);
1846  var
1847    i: integer;
1848    padding: double;
1849    datehx: string;
1850    BigTime, SmallTime: TDateTime;
1851    ChildControl: TControl;
1852    aChart: TChart;
1853  begin
1854    if not (Sender is TChart) then exit;
1855    aChart := (Sender as TChart);
1856    if Not Assigned(FGraphSetting) then Exit;
1857  
1858    if not FGraphSetting.VerticalZoom then
1859    begin
1860      padding := 0; //(FYMaxValue - FYMinValue) * ((100 - ZOOM_PERCENT) * 0.01);
1861      aChart.LeftAxis.Maximum := BIG_NUMBER;    // avoid min>max error
1862      aChart.LeftAxis.Minimum := -BIG_NUMBER;
1863      aChart.LeftAxis.Maximum := FYMaxValue + padding;    //padding 0?
1864      aChart.LeftAxis.Minimum := FYMinValue - padding;    //padding 0?
1865    end;
1866    SmallTime := aChart.BottomAxis.Minimum;
1867    BigTime := aChart.BottomAxis.Maximum;
1868    if BigTime < SmallTime then BigTime := SmallTime;   // avoid min>max error
1869    for i := 0 to scrlTop.ControlCount - 1 do
1870    begin
1871      ChildControl := scrlTop.Controls[i];
1872      SizeDates((ChildControl as TChart), SmallTime, BigTime);
1873    end;
1874    SizeDates(chartDatelineTop, SmallTime, BigTime);
1875    for i := 0 to scrlBottom.ControlCount - 1 do
1876    begin
1877      ChildControl := scrlBottom.Controls[i];
1878      SizeDates((ChildControl as TChart), SmallTime, BigTime);
1879    end;
1880    SizeDates(chartDatelineBottom, SmallTime, BigTime);
1881    if FMouseDown and aChart.Zoomed then
1882    begin
1883      datehx := FloatToStr(SmallTime) + '^' + FloatToStr(BigTime);
1884      GtslZoomHistoryFloat.Add(datehx);
1885      mnuPopGraphZoomBack.Enabled := true;
1886      FMouseDown := false;
1887      ZoomUpdateInfo(SmallTime, BigTime);
1888    end;
1889  end;
1890  
1891  procedure TfrmGraphs.ChartOnUndoZoom(Sender: TObject);
1892  var
1893    i: integer;
1894    padding: double;
1895    BigTime, SmallTime: TDateTime;
1896    ChildControl: TControl;
1897    aChart: TChart;
1898  begin
1899    if not (Sender is TChart) then exit;
1900    aChart:= (Sender as TChart);
1901    FRetainZoom := false;
1902    mnuPopGraphZoomBack.Enabled := false;
1903    GtslZoomHistoryFloat.Clear;
1904    if not FGraphSetting.VerticalZoom then
1905    begin
1906      padding := 0; //(FYMaxValue - FYMinValue) * ((100 - ZOOM_PERCENT) * 0.01);
1907      aChart.LeftAxis.Maximum := BIG_NUMBER;    // avoid min>max error
1908      aChart.LeftAxis.Minimum := -BIG_NUMBER;
1909      aChart.LeftAxis.Maximum := FYMaxValue + padding;    //padding 0?
1910      aChart.LeftAxis.Minimum := FYMinValue - padding;    //padding 0?
1911    end;
1912    SmallTime := aChart.BottomAxis.Minimum;
1913    BigTime := aChart.BottomAxis.Maximum;
1914    if BigTime < SmallTime then BigTime := SmallTime;   // avoid min>max error
1915    for i := 0 to scrlTop.ControlCount - 1 do
1916    begin
1917      ChildControl := scrlTop.Controls[i];
1918      SizeDates((ChildControl as TChart), SmallTime, BigTime);
1919    end;
1920    SizeDates(chartDatelineTop, SmallTime, BigTime);
1921    for i := 0 to scrlBottom.ControlCount - 1 do
1922    begin
1923      ChildControl := scrlBottom.Controls[i];
1924      SizeDates((ChildControl as TChart), SmallTime, BigTime);
1925    end;
1926    SizeDates(chartDatelineBottom, SmallTime, BigTime);
1927    if FMouseDown then
1928    begin
1929      FMouseDown := false;
1930      InfoMessage('', COLOR_INFO, false);
1931    if MergedLabsSelected then
1932      InfoMessage(TXT_WARNING_MERGED_LABS, COLOR_WARNING, true);
1933    pnlHeader.Visible := pnlInfo.Visible;
1934    end;
1935  end;
1936  
1937  procedure TfrmGraphs.SizeDates(aChart: TChart; aSmallTime, aBigTime: TDateTime);
1938  var
1939    datediff, yeardiff: integer;
1940    pad: double;
1941  begin
1942    with aChart.BottomAxis do
1943    begin
1944      Automatic := false;
1945      Maximum := BIG_NUMBER;    // avoid min>max error
1946      Minimum := -BIG_NUMBER;
1947      Minimum := aSmallTime;
1948      Maximum := aBigTime;
1949      Increment := DateTimeStep[dtOneMinute];
1950      datediff := DaysBetween(aBigTime, aSmallTime);
1951      yeardiff := datediff div 365;
1952      DateTimeFormat := '';
1953      Labels := true;
1954      if yeardiff > 0 then
1955      begin
1956        if (pnlScrollTopBase.Width div yeardiff) < DWIDTH_MDY then
1957          DateTimeFormat := DFORMAT_MYY;
1958        if (pnlScrollTopBase.Width div yeardiff) < DWIDTH_MYY then
1959          DateTimeFormat := DFORMAT_YY;
1960        if (pnlScrollTopBase.Width div yeardiff) < DWIDTH_YY then
1961          Labels := false;
1962      end;
1963    end;
1964    GraphFooter(aChart, datediff, aSmallTime);
1965    pad := (aBigTime - aSmallTime) * 0.07;
1966    SeriesForLabels(aChart, 'serNonNumBottom', pad);
1967    SeriesForLabels(aChart, 'serNonNumTop', pad);
1968    if length(aChart.Hint) > 0 then SeriesForLabels(aChart, 'serComments', pad);
1969  end;
1970  
1971  procedure TfrmGraphs.SeriesForLabels(aChart: TChart; aID: string; pad: double);
1972  var
1973    i: integer;
1974    aPointSeries: TPointSeries;
1975    max, min: double;
1976  begin
1977    for i := 0 to aChart.SeriesCount - 1 do
1978    begin
1979      if aChart.Series[i].Identifier = aID then
1980      begin
1981        aPointSeries := (aChart.Series[i] as TPointSeries);
1982        aPointSeries.Clear;
1983        if aID = 'serNonNumBottom' then
1984        begin
1985          min := aChart.LeftAxis.Minimum;
1986          if min > aChart.MinYValue(aChart.LeftAxis) then
1987             min := aChart.MinYValue(aChart.LeftAxis);
1988          if min < 0 then min := 0;
1989          aPointSeries.AddXY(aChart.BottomAxis.Minimum, min, '', clTeeColor) ;
1990        end
1991        else if aID  = 'serNonNumTop' then
1992        begin
1993          max := aChart.LeftAxis.Maximum;
1994          if max < aChart.MaxYValue(aChart.LeftAxis) then
1995             max := aChart.MaxYValue(aChart.LeftAxis);
1996          aPointSeries.AddXY(aChart.BottomAxis.Minimum, max, '', clTeeColor) ;
1997        end
1998        else if aID = 'serComments' then
1999        begin
2000          min := aChart.MinYValue(aChart.LeftAxis);
2001          if aChart.SeriesCount = 2 then        // only 1 series (besides comment)
2002            if aChart.Series[0].Count = 1 then  // only 1 numeric
2003              min := min - 1;                   // force comment label to bottom
2004          if min < 0 then min := 0;
2005          aPointSeries.AddXY((aChart.BottomAxis.Maximum - pad), min, '', clTeeColor) ;
2006        end;
2007        aPointSeries.Marks.Visible := true;
2008        break;
2009      end;
2010    end;
2011  end;
2012  
2013  procedure TfrmGraphs.GraphFooter(aChart: TChart; datediff: integer; aDate: TDateTime);
2014  begin
2015    if datediff < 1 then
2016    begin
2017      if not aChart.Foot.Visible then
2018      begin
2019        aChart.Foot.Text.Clear;
2020        aChart.Foot.Text.Insert(0, FormatDateTime('mmm d, yyyy', aDate));
2021        aChart.Foot.Font.Color := clBtnText;
2022        aChart.Foot.Visible := true;
2023      end;
2024    end
2025    else
2026      aChart.Foot.Visible := false;
2027  end;
2028  
2029  procedure TfrmGraphs.MakeSeparate(aScrollBox: TScrollBox; aListView:
2030    TListView; aPadPanel: TPanel; section: string);
2031  var
2032    displayheight, displaynum, i: integer;
2033  begin
2034    FNonNumerics := false;
2035    if section = 'top' then pnlItemsTop.Tag := 0 else pnlItemsBottom.Tag := 0;
2036    while aScrollBox.ControlCount > 0 do
2037      aScrollBox.Controls[0].Free;
2038    aPadPanel.Visible := false;
2039    if FGraphSetting.Hints then         //**************
2040    begin
2041      chartDatelineTop.OnMouseMove := chartBaseMouseMove;
2042      chartDatelineBottom.OnMouseMove := chartBaseMouseMove;
2043    end
2044    else
2045    begin
2046      chartDatelineTop.OnMouseMove := nil;
2047      chartDatelineBottom.OnMouseMove := nil;
2048    end;
2049    MakeSeparateItems(aScrollBox, aListView, section);
2050    if section = 'top' then
2051    begin
2052      pnlDatelineTop.Align := alBottom;
2053      pnlDatelineTop.Height := 30;
2054      scrlTop.Align := alClient;
2055      pnlDatelineTop.Visible := false;
2056    end
2057    else
2058    begin
2059      pnlDatelineBottom.Align := alBottom;
2060      pnlDatelineBottom.Height := 30;
2061      scrlBottom.Align := alClient;
2062      pnlDatelineBottom.Visible := false;
2063    end;
2064    with aScrollBox do
2065    begin
2066      if ControlCount < FGraphSetting.MaxGraphs then        //**** formating should be made for top & bottom
2067        displaynum := ControlCount
2068      else
2069        displaynum := FGraphSetting.MaxGraphs;
2070      if displaynum = 0 then
2071        displaynum := 3;
2072      if (Height div displaynum) < FGraphSetting.MinGraphHeight then
2073        displayheight := FGraphSetting.MinGraphHeight
2074      else
2075        displayheight := (Height div displaynum);
2076      for i := 0 to aScrollBox.ControlCount - 1 do
2077        Controls[i].height := displayheight;
2078    end;
2079    AdjustTimeframe;
2080    if chartDatelineTop.Visible then chartDatelineTop.ZoomPercent(ZOOM_PERCENT);
2081    if chartDatelineBottom.Visible then chartDatelineBottom.ZoomPercent(ZOOM_PERCENT);
2082    if FNonNumerics then
2083      if section = 'top' then pnlItemsTop.Tag := 1
2084      else pnlItemsBottom.Tag := 1;
2085  end;
2086  
2087  function TfrmGraphs.TitleInfo(filetype, typeitem, caption: string): string;
2088  var
2089    i: integer;
2090    checkdata, high, low, refrange, specimen, specnum, units: string;
2091  begin
2092    if (filetype = '63') and (GtslData.Count > 0) then
2093    begin
2094      checkdata := '';
2095      for i := 0 to GtslData.Count - 1 do
2096      begin
2097        checkdata := GtslData[i];
2098        if (Piece(checkdata, '^', 1) = '63') and (Piece(checkdata, '^', 2) = typeitem) then
2099          break;
2100      end;
2101      refrange := Piece(checkdata, '^', 10);
2102      specimen := Piece(checkdata, '^', 8);
2103      if length(refrange) > 0  then
2104      begin
2105        low := Piece(refrange, '!', 1);
2106        high := Piece(refrange, '!', 2);
2107        units := Piece(checkdata, '^', 11);
2108      end
2109      else
2110      begin
2111        specnum := Piece(checkdata, '^', 7);
2112        RefUnits(typeitem, specnum, low, high, units);
2113        units := LowerCase(units);
2114      end;
2115      if units = '' then units := '  ';
2116    end
2117    else
2118    begin
2119      specimen := ''; low := ''; high := ''; units := '';
2120    end;
2121    if (filetype = '63') and (Piece(typeitem, '.', 2) = '0') then
2122    begin
2123      specimen := ''; low := ''; high := '';
2124    end;
2125    Result := filetype + '^' + typeitem + '^' + caption + '^' +
2126              specimen + '^' + low + '^' + high + '^' + units + '^';
2127  end;
2128  
2129  procedure TfrmGraphs.MakeSeparateItems(aScrollBox: TScrollBox; aListView: TListView; section: string);
2130  var
2131    bcnt, gcnt, graphtype, lcnt, ncnt, pcnt, vcnt: integer;
2132    aTitle, filetype, typeitem: string;
2133    newchart: TChart;
2134    aGraphItem: TGraphItem;
2135    aListItem: TListItem;
2136  begin
2137    pcnt := 0; gcnt := 0; vcnt := 0; lcnt := 0; ncnt := 0; bcnt := 0;
2138    aListItem := aListView.Selected;
2139    while aListItem <> nil do
2140    begin
2141      aGraphItem := TGraphItem(aListItem.SubItems.Objects[3]);
2142      filetype := UpperCase(Piece(aGraphItem.Values, '^', 1));
2143      typeitem := UpperCase(Piece(aGraphItem.Values, '^', 2));
2144      graphtype := GraphTypeNum(filetype); //*****strtointdef(Piece(aListBox.Items[j], '^', 2), 1);
2145      aTitle := TitleInfo(filetype, typeitem, aListItem.Caption);
2146      newchart := TChart.Create(self);
2147      newchart.Tag := GtslNonNum.Count;
2148      MakeChart(newchart, aScrollBox);
2149      with newchart do
2150      begin
2151        Height := 170;
2152        Align := alBottom;
2153        Align := alTop;
2154        Tag := aListItem.Index;
2155        //SetPiece(aTitle, '^', 3, 'zzzz: ' + Piece(aTitle, '^', 3)); // test prefix
2156        if (graphtype = 1) and (btnChangeSettings.Tag = 1) then
2157          LeftAxis.Title.Caption := 'StdDev'
2158        else if (graphtype = 1) and (btnChangeSettings.Tag = 2) then
2159        begin
2160          LeftAxis.Title.Caption := '1/' + Piece(aTitle, '^', 7);
2161          SetPiece(aTitle, '^', 3, 'Inverse ' + Piece(aTitle, '^', 3));
2162        end
2163        else
2164          LeftAxis.Title.Caption := Piece(aTitle, '^', 7);
2165        if graphtype <> 1 then
2166        begin
2167          LeftAxis.Visible := false;
2168          MarginLeft := PadLeftEvent(pnlScrollTopBase.Width);
2169          //MarginLeft := round((65 / (pnlScrollTopBase.Width + 1)) * 100);       // ************* marginleft is a %
2170        end;
2171      end;
2172      splGraphs.Tag := 1;    // show ref ranges
2173      if graphtype = 4 then graphtype := 2;         // change points to be bars
2174      case graphtype of
2175        1:  MakeLineSeries(newchart, aTitle, filetype, section, lcnt, ncnt, false);
2176        2:  MakeBarSeries(newchart, aTitle, filetype, bcnt);
2177        3:  MakeVisitGanttSeries(newchart, aTitle, filetype, vcnt);
2178        4:  MakePointSeries(newchart, aTitle, filetype, pcnt);
2179        8:  MakeGanttSeries(newchart, aTitle, filetype, gcnt);
2180      end;
2181      MakeOtherSeries(newchart);
2182      aListItem := aListView.GetNextItem(aListItem, sdAll, [isSelected]);
2183    end;
2184    if (FGraphSetting.HighTime = FGraphSetting.LowTime)
2185    or (lcnt = 1) or (pcnt = 1) or (bcnt = 1) or (vcnt = 1) then
2186    begin
2187      FGraphSetting.HighTime := FGraphSetting.HighTime + 1;
2188      FGraphSetting.LowTime := FGraphSetting.LowTime - 1;
2189    end;
2190  end;
2191  
2192  function TfrmGraphs.PadLeftEvent(aWidth: integer): integer;
2193  begin
2194    if aWidth < 50 then
2195      Result := 10
2196    else if aWidth < 100 then
2197      Result := 36
2198    else if aWidth < 200 then
2199      Result := 28
2200    else if aWidth < 220 then
2201      Result := 24
2202    else if aWidth < 240 then
2203      Result := 23
2204    else if aWidth < 270 then
2205      Result := 21
2206    else if aWidth < 300 then
2207      Result := 18
2208    else if aWidth < 400 then
2209      Result := 14
2210    else if aWidth < 500 then
2211      Result := 11
2212    else if aWidth < 600 then
2213      Result := 10
2214    else if aWidth < 700 then
2215      Result := 9
2216    else if aWidth < 800 then
2217      Result := 8
2218    else if aWidth < 900 then
2219      Result := 7
2220    else if aWidth < 1000 then
2221      Result := 6
2222    else
2223      Result := 5;
2224  end;
2225  
2226  function TfrmGraphs.PadLeftNonNumeric(aWidth: integer): integer;
2227  begin
2228    if aWidth < 50 then
2229      Result := 10
2230    else if aWidth < 100 then
2231      Result := 36
2232    else if aWidth < 200 then
2233      Result := 16
2234    else if aWidth < 220 then
2235      Result := 14
2236    else if aWidth < 240 then
2237      Result := 12
2238    else if aWidth < 270 then
2239      Result := 10
2240    else if aWidth < 300 then
2241      Result := 9
2242    else if aWidth < 400 then
2243      Result := 8
2244    else if aWidth < 500 then
2245      Result := 7
2246    else if aWidth < 600 then
2247      Result := 6
2248    else
2249      Result := 5;
2250  end;
2251  
2252  procedure TfrmGraphs.MakeTogetherMaybe(aScrollBox: TScrollBox; aListView:
2253    TListView; aPadPanel: TPanel; section: string);
2254  var
2255    filetype: string;
2256    aGraphItem: TGraphItem;
2257    aListItem: TListItem;
2258  begin
2259    FNonNumerics := false;
2260    if section = 'top' then pnlItemsTop.Tag := 0 else pnlItemsBottom.Tag := 0;
2261    if aListView.SelCount = 1 then                 // one lab test - make separate
2262    begin
2263      aListItem := aListView.Selected;
2264      aGraphItem := TGraphItem(aListItem.SubItems.Objects[3]);
2265      filetype := UpperCase(Piece(aGraphItem.Values, '^', 1));
2266      if (filetype = '63') or (filetype = '120.5') then
2267      begin
2268        MakeSeparate(aScrollBox, aListView, aPadPanel, section);
2269        exit;
2270      end;
2271    end;
2272    MakeTogether(aScrollBox, aListView, aPadPanel, section);
2273  end;
2274  
2275  procedure TfrmGraphs.MakeTogether(aScrollBox: TScrollBox; aListView:
2276    TListView; aPadPanel: TPanel; section: string);
2277  var
2278    anylines, nolines, onlylines, singlepoint: boolean;
2279    bcnt, gcnt, graphtype, lcnt, pcnt, vcnt: integer;
2280    portion: double;
2281    filetype, typeitem: string;
2282    newchart: TChart;
2283    aGraphItem: TGraphItem;
2284    aListItem: TListItem;
2285  begin
2286    pcnt := 0; gcnt := 0; lcnt := 0; bcnt := 0; vcnt := 0;
2287    onlylines := true;
2288    anylines := false;
2289    nolines := true;
2290    FNonNumerics := false;
2291    if section = 'top' then pnlItemsTop.Tag := 0 else pnlItemsBottom.Tag := 0;
2292    aListItem := aListView.Selected;
2293    while aListItem <> nil do
2294    begin
2295      aGraphItem := TGraphItem(aListItem.SubItems.Objects[3]);
2296      filetype := UpperCase(Piece(aGraphItem.Values, '^', 1));
2297      typeitem := UpperCase(Piece(aGraphItem.Values, '^', 2));
2298      graphtype := GraphTypeNum(filetype);
2299      case graphtype of
2300      1: lcnt := lcnt + 1;
2301      2: bcnt := bcnt + 1;
2302      3: vcnt := vcnt + 1;
2303      4: pcnt := pcnt + 1;
2304      8: gcnt := gcnt + 1;
2305      end;
2306      if graphtype = 1 then
2307      begin
2308        anylines := true;
2309        nolines := false;
2310      end
2311      else
2312        onlylines := false;
2313      aListItem := aListView.GetNextItem(aListItem, sdAll, [isSelected]);
2314    end;
2315    if section = 'top' then
2316      chkItemsTop.Checked := false
2317    else
2318      chkItemsBottom.Checked := false;
2319    GtslTempCheck.Clear;
2320    while aScrollBox.ControlCount > 0 do aScrollBox.Controls[0].Free;
2321    newchart := TChart.Create(self);  // whynot use base?
2322    MakeChart(newchart, aScrollBox);
2323    with newchart do          // if a single line graph do lab stuff (ref range, units) ****************************************
2324    begin
2325      Align := alClient;
2326      LeftAxis.Title.Caption := ' ';
2327    end;
2328    aPadPanel.Visible := true;
2329    portion := PortionSize(lcnt, pcnt, gcnt, vcnt, bcnt);
2330    if section = 'top' then
2331      SizeTogether(onlylines, nolines, anylines, scrlTop, newchart,
2332        pnlDatelineTop, pnlScrollTopBase, portion)
2333    else
2334      SizeTogether(onlylines, nolines, anylines, scrlBottom, newchart,
2335        pnlDatelineBottom, pnlScrollBottomBase, portion);
2336    if btnChangeSettings.Tag = 1 then  splGraphs.Tag := 1 // show ref ranges
2337    else splGraphs.Tag := 0;
2338  
2339    if nolines then MakeTogetherNoLines(aListView, section)
2340    else if onlylines then MakeTogetherOnlyLines(aListView, section, newchart)
2341    else if anylines then MakeTogetherAnyLines(aListView, section, newchart);
2342    MakeOtherSeries(newchart);
2343  
2344    singlepoint := (lcnt = 1) or (pcnt = 1) or (bcnt = 1) or (vcnt = 1);
2345    GraphBoundry(singlepoint);
2346    if FNonNumerics then
2347      if section = 'top' then pnlItemsTop.Tag := 1
2348      else pnlItemsBottom.Tag := 1;
2349  end;
2350  
2351  procedure TfrmGraphs.GraphBoundry(singlepoint: boolean);
2352  begin
2353    if (FGraphSetting.HighTime = FGraphSetting.LowTime)
2354    or singlepoint then
2355    begin
2356      FGraphSetting.HighTime := FGraphSetting.HighTime + 1;
2357      FGraphSetting.LowTime := FGraphSetting.LowTime - 1;
2358      chartDatelineTop.LeftAxis.Minimum := chartDatelineTop.LeftAxis.Minimum - 0.5;
2359      chartDatelineTop.LeftAxis.Maximum := chartDatelineTop.LeftAxis.Maximum + 0.5;
2360      chartDatelineBottom.LeftAxis.Minimum := chartDatelineBottom.LeftAxis.Minimum - 0.5;
2361      chartDatelineBottom.LeftAxis.Maximum := chartDatelineBottom.LeftAxis.Maximum + 0.5;
2362    end;
2363    if FGraphSetting.Hints then
2364    begin
2365      chartDatelineTop.OnMouseMove := chartBaseMouseMove;
2366      chartDatelineBottom.OnMouseMove := chartBaseMouseMove;
2367    end
2368    else
2369    begin
2370      chartDatelineTop.OnMouseMove := nil;
2371      chartDatelineBottom.OnMouseMove := nil;
2372    end;
2373    AdjustTimeframe;
2374    if chartDatelineTop.Visible then chartDatelineTop.ZoomPercent(ZOOM_PERCENT);
2375    if chartDatelineBottom.Visible then chartDatelineBottom.ZoomPercent(ZOOM_PERCENT);
2376  end;
2377  
2378  procedure TfrmGraphs.MakeTogetherNoLines(aListView: TListView; section: string);
2379  var
2380    bcnt, gcnt, graphtype, pcnt, vcnt: integer;
2381    aTitle, filetype, typeitem: string;
2382    aGraphItem: TGraphItem;
2383    aListItem: TListItem;
2384  begin
2385    pcnt := 0; gcnt := 0; vcnt := 0; bcnt := 0;
2386    aListItem := aListView.Selected;
2387    while aListItem <> nil do
2388    begin
2389      aGraphItem := TGraphItem(aListItem.SubItems.Objects[3]);
2390      filetype := Piece(aGraphItem.Values, '^', 1);
2391      typeitem := Piece(aGraphItem.Values, '^', 2);
2392      aTitle := filetype + '^' + typeitem + '^' + aListItem.Caption + '^';
2393      graphtype := GraphTypeNum(filetype);
2394      if section = 'top' then
2395        MakeDateline(section, aTitle, filetype, chartDatelineTop, graphtype, bcnt, pcnt, gcnt, vcnt)
2396      else
2397        MakeDateline(section, aTitle, filetype, chartDatelineBottom, graphtype, bcnt, pcnt, gcnt, vcnt);
2398      aListItem := aListView.GetNextItem(aListItem, sdAll, [isSelected]);
2399    end;
2400    if section = 'top' then
2401    begin
2402      scrlTop.Align := alTop;
2403      scrlTop.Height := 1; //pnlScrollTopBase.Height div 4;
2404      pnlDatelineTop.Align := alClient;
2405      pnlDatelineTop.Visible := true;
2406    end
2407    else
2408    begin
2409      scrlBottom.Align := alTop;
2410      scrlBottom.Height := 1; //pnlScrollBottomBase.Height div 4;
2411      pnlDatelineBottom.Align := alClient;
2412      pnlDatelineBottom.Visible := true;
2413    end;
2414  end;
2415  
2416  procedure TfrmGraphs.MakeTogetherOnlyLines(aListView: TListView; section: string; aChart: TChart);
2417  var
2418    lcnt, ncnt: integer;
2419    aTitle, filetype, typeitem: string;
2420    aGraphItem: TGraphItem;
2421    aListItem: TListItem;
2422  begin
2423    lcnt := 0;
2424    aListItem := aListView.Selected;
2425    while aListItem <> nil do
2426    begin
2427      aGraphItem := TGraphItem(aListItem.SubItems.Objects[3]);
2428      filetype := Piece(aGraphItem.Values, '^', 1);
2429      typeitem := Piece(aGraphItem.Values, '^', 2);
2430      aTitle := TitleInfo(filetype, typeitem, aListItem.Caption);
2431      MakeLineSeries(aChart, aTitle, filetype, section, lcnt, ncnt, true);
2432      if FDisplayFreeText = true then DisplayFreeText(aChart);
2433      aListItem := aListView.GetNextItem(aListItem, sdAll, [isSelected]);
2434    end;
2435    if section = 'top' then
2436    begin
2437      pnlDatelineTop.Align := alBottom;
2438      pnlDatelineTop.Height := 5;
2439      scrlTop.Align := alClient;
2440      pnlDatelineTop.Visible := false;
2441    end
2442    else
2443    begin
2444      pnlDatelineBottom.Align := alBottom;
2445      pnlDatelineBottom.Height := 5;
2446      scrlBottom.Align := alClient;
2447      pnlDatelineBottom.Visible := false;
2448    end;
2449    with aChart do
2450    begin
2451      if btnChangeSettings.Tag = 1 then
2452        LeftAxis.Title.Caption := 'StdDev';
2453      Visible := true;
2454    end;
2455  end;
2456  
2457  procedure TfrmGraphs.MakeTogetherAnyLines(aListView: TListView; section: string; aChart: TChart);
2458  var
2459    singletest: boolean;
2460    bcnt, gcnt, graphtype, lcnt, ncnt, pcnt, vcnt: integer;
2461    aTitle, filetype, typeitem: string;
2462    aGraphItem: TGraphItem;
2463    aListItem: TListItem;
2464  begin
2465    singletest := SingleLabTest(aListView);
2466    pcnt := 0; gcnt := 0; vcnt := 0; lcnt := 0; bcnt := 0;
2467    aListItem := aListView.Selected;
2468    while aListItem <> nil do
2469    begin
2470      aGraphItem := TGraphItem(aListItem.SubItems.Objects[3]);
2471      filetype := Piece(aGraphItem.Values, '^', 1);
2472      typeitem := Piece(aGraphItem.Values, '^', 2);
2473      aTitle := TitleInfo(filetype, typeitem, aListItem.Caption);
2474      graphtype := GraphTypeNum(filetype);
2475      if graphtype = 1 then
2476      begin
2477        if btnChangeSettings.Tag = 1 then
2478          aChart.LeftAxis.Title.Caption := 'StdDev'
2479        else
2480          aChart.LeftAxis.Title.Caption := Piece(aTitle, '^', 7);
2481        if singletest then
2482          splGraphs.Tag := 1
2483        else
2484          splGraphs.Tag := 0;
2485        MakeLineSeries(aChart, aTitle, filetype, section, lcnt, ncnt, true);
2486        if FDisplayFreeText = true then DisplayFreeText(aChart);
2487      end
2488      else if section = 'top' then
2489        MakeDateline(section, aTitle, filetype, chartDatelineTop, graphtype, bcnt, pcnt, gcnt, vcnt)
2490      else
2491        MakeDateline(section, aTitle, filetype, chartDatelineBottom, graphtype, bcnt, pcnt, gcnt, vcnt);
2492      aListItem := aListView.GetNextItem(aListItem, sdAll, [isSelected]);
2493    end;
2494    if section = 'top' then
2495    begin
2496      scrlTop.Align := alTop;
2497      pnlDatelineTop.Align := alBottom;
2498      pnlDatelineTop.Height := pnlScrollTopBase.Height div 2;
2499      scrlTop.Align := alClient;
2500      pnlDatelineTop.Visible := true;
2501    end
2502    else
2503    begin
2504      scrlBottom.Align := alTop;
2505      pnlDatelineBottom.Align := alBottom;
2506      pnlDatelineBottom.Height := pnlScrollBottomBase.Height div 2;
2507      scrlBottom.Align := alClient;
2508      pnlDatelineBottom.Visible := true;
2509    end;
2510    with aChart do
2511    begin
2512      if btnChangeSettings.Tag = 1 then
2513        LeftAxis.Title.Caption := 'StdDev';
2514      Visible := true;
2515    end;
2516  end;
2517  
2518  function TfrmGraphs.SingleLabTest(aListView: TListView): boolean;
2519  var
2520    cnt: integer;
2521    filetype: string;
2522    aGraphItem: TGraphItem;
2523    aListItem: TListItem;
2524  begin
2525    cnt := 0;
2526    aListItem := aListView.Selected;
2527    while aListItem <> nil do
2528    begin
2529      aGraphItem := TGraphItem(aListItem.SubItems.Objects[3]);
2530      filetype := Piece(aGraphItem.Values, '^', 1);
2531      if filetype = '120.5' then
2532      begin
2533        cnt := BIG_NUMBER;
2534        break;
2535      end;
2536      if filetype = '63' then
2537        cnt := cnt + 1;
2538      if cnt > 1 then
2539        break;
2540      aListItem := aListView.GetNextItem(aListItem, sdAll, [isSelected]);
2541    end;
2542    Result := (cnt = 1);
2543  end;
2544  
2545  procedure TfrmGraphs.MakeChart(aChart: TChart; aScrollBox: TScrollBox);
2546  begin
2547    with aChart do
2548    begin
2549      Parent := aScrollBox;
2550      View3D := false;
2551      Chart3DPercent := 10;
2552      AllowPanning := pmNone;
2553      Gradient.EndColor := clGradientActiveCaption;
2554      Gradient.StartColor := clWindow;
2555      Legend.LegendStyle := lsSeries;
2556      Legend.ShadowSize := 1;
2557      Legend.Color := clCream;
2558      Legend.VertMargin := 0;
2559      Legend.Alignment := laTop;
2560      Legend.Visible := true;
2561      BottomAxis.ExactDateTime := true;
2562      BottomAxis.Increment := DateTimeStep[dtOneMinute];
2563      HideDates(aChart);
2564      BevelOuter := bvNone;
2565      OnZoom := ChartOnZoom;
2566      OnUndoZoom := ChartOnUndoZoom;
2567      OnClickSeries := chartBaseClickSeries;
2568      OnClickLegend := chartBaseClickLegend;
2569      OnDblClick := mnuPopGraphDetailsClick;
2570      OnMouseDown := chartBaseMouseDown;
2571      OnMouseUp := chartBaseMouseUp;
2572      if FGraphSetting.Hints then
2573        OnMouseMove := chartBaseMouseMove
2574      else
2575        OnMouseMove := nil;
2576    end;
2577  end;
2578  
2579  procedure TfrmGraphs.MakeSeriesInfo(aChart: TChart; aSeries: TChartSeries; aTitle, aFileType: string; aSerCnt: integer);
2580  begin
2581    with aSeries do
2582    begin
2583      Active := true;
2584      ParentChart := aChart;
2585      Title := Piece(aTitle, '^', 3);
2586      GetData(aTitle);
2587      Identifier := aFileType;
2588      SeriesColor := NextColor(aSerCnt);
2589      ColorEachPoint := false;
2590      ShowInLegend := true;
2591      Marks.Style := smsLabel;
2592      Marks.BackColor := clInfoBk;
2593      Marks.Frame.Visible := true;
2594      Marks.Visible := false;
2595      OnGetMarkText := serDatelineTop.OnGetMarkText;
2596      XValues.DateTime := True;
2597      GetHorizAxis.ExactDateTime := True;
2598      GetHorizAxis.Increment := DateTimeStep[dtOneMinute];
2599    end;
2600  end;
2601  
2602  procedure TfrmGraphs.MakeSeriesPoint(aChart: TChart; aPointSeries: TPointSeries);
2603  begin
2604    with aPointSeries do
2605    begin
2606      Active := true;
2607      ParentChart := aChart;
2608      Title := '';
2609      Identifier := '';
2610      SeriesColor := aChart.Color;
2611      ColorEachPoint := false;
2612      ShowInLegend := false;
2613      Marks.Style := smsLabel;
2614      Marks.BackColor := clInfoBk;
2615      Marks.Frame.Visible := true;
2616      Marks.Visible := false;
2617      OnGetMarkText := serDatelineTop.OnGetMarkText;
2618      XValues.DateTime := true;
2619      Pointer.Visible := true;
2620      Pointer.InflateMargins := true;
2621      Pointer.Style := psSmallDot;
2622      Pointer.Pen.Visible := true;
2623    end;
2624  end;
2625  
2626  procedure TfrmGraphs.MakeSeriesRef(aChart: TChart; aTest, aRef: TLineSeries; aTitle, aValue: string; aDate: double);
2627  var
2628    value: double;
2629  begin
2630    with aRef do
2631    begin
2632      Active := true;
2633      ParentChart := aChart;
2634      XValues.DateTime := True;
2635      Pointer.Visible := false;
2636      Pointer.InflateMargins := true;
2637      OnGetMarkText := serDatelineTop.OnGetMarkText;
2638      ColorEachPoint := false;
2639      Title := aTitle + aValue;
2640      Pointer.Style := psCircle;
2641      SeriesColor := clTeeColor; //aTest.SeriesColor; // clBtnShadow;  //
2642      Marks.Visible := false;
2643      LinePen.Visible := true;
2644      LinePen.Width := 1;
2645      LinePen.Style := psDash;  //does not show when width <> 1
2646    end;
2647    value := strtofloatdef(aValue, -BIG_NUMBER);
2648    if value <> -BIG_NUMBER then
2649    begin
2650      aRef.AddXY(IncDay(FGraphSetting.LowTime, -1), value, '', clTeeColor);
2651      aRef.AddXY(IncDay(FGraphSetting.HighTime, 1), value, '', clTeeColor);
2652      BorderValue(aDate, value);
2653    end;
2654  end;
2655  
2656  procedure TfrmGraphs.MakeSeriesBP(aChart: TChart; aTest, aBP: TLineSeries; aFileType: string);
2657  begin
2658    with aBP do
2659    begin
2660      ParentChart := aChart;
2661      Title := 'Blood Pressure';
2662      XValues.DateTime := true;
2663      Pointer.Style := aTest.Pointer.Style;
2664      ShowInLegend := false;    //****
2665      Identifier := aFileType;
2666      Pointer.Visible := true;
2667      Pointer.InflateMargins := true;
2668      ColorEachPoint := false;
2669      SeriesColor := aTest.SeriesColor;
2670      Marks.BackColor := clInfoBk;
2671    end;
2672  end;
2673  
2674  procedure TfrmGraphs.MakeOtherSeries(aChart: TChart);
2675  begin
2676    if GtslNonNum.Count > 0 then
2677    begin
2678      MakeNonNumerics(aChart);
2679      if FDisplayFreeText = true then DisplayFreeText(aChart);
2680    end;
2681    if length(aChart.Hint) > 0 then
2682    begin
2683      MakeComments(aChart);
2684    end;
2685  end;
2686  
2687  procedure TfrmGraphs.MakeComments(aChart: TChart);
2688  var
2689    serComment: TPointSeries;
2690  begin
2691    serComment := TPointSeries.Create(aChart);
2692    MakeSeriesPoint(aChart, serComment);
2693    with serComment do
2694    begin
2695      Identifier := 'serComments';
2696      Title := TXT_COMMENTS;
2697      SeriesColor := clTeeColor;
2698      Marks.ArrowLength := -24;
2699      Marks.Visible := true;
2700      end;
2701  end;
2702  
2703  procedure TfrmGraphs.MakeNonNumerics(aChart: TChart);
2704  var
2705    nonnumericonly, nonnumsection: boolean;
2706    i, bmax, tmax: integer;
2707    diffvalue, highestvalue, lowestvalue, padvalue: double;
2708    astring, listofseries, section: string;
2709    serBlank: TPointSeries;
2710  begin
2711    if aChart.Parent = scrlBottom then section := 'bottom'
2712    else section := 'top';
2713    nonnumericonly := true;
2714    for i := 0 to aChart.SeriesCount - 1 do
2715    begin
2716      if (aChart.Series[i] is TLineSeries) then
2717        if aChart.Series[i].Count > 0 then
2718        begin
2719          nonnumericonly := false;
2720          break;
2721        end;
2722    end;
2723    PadNonNum(aChart, section, listofseries, bmax, tmax);
2724    if bmax = 0 then bmax := 1;
2725    if tmax = 0 then tmax := 1;
2726    if nonnumericonly then
2727    begin
2728      highestvalue := 1;
2729      lowestvalue := 0;
2730    end
2731    else
2732    begin
2733      highestvalue := aChart.MaxYValue(aChart.LeftAxis);
2734      lowestvalue := aChart.MinYValue(aChart.LeftAxis);
2735    end;
2736    diffvalue := highestvalue - lowestvalue;
2737    if diffvalue = 0 then
2738      padvalue := highestvalue / 2
2739    else
2740      padvalue := POINT_PADDING * diffvalue;
2741    highestvalue := highestvalue + (tmax * padvalue);
2742    lowestvalue := lowestvalue - (bmax * padvalue);
2743    if not (aChart.MinYValue(aChart.LeftAxis) < 0) then
2744    begin
2745      if highestvalue < 0 then highestvalue := 0;
2746      if lowestvalue < 0 then lowestvalue := 0;
2747    end;
2748    if lowestvalue > highestvalue then
2749       lowestvalue := highestvalue;
2750    aChart.LeftAxis.Maximum := highestvalue;
2751    aChart.LeftAxis.Minimum := lowestvalue;
2752    nonnumsection := false;
2753    for i := 0 to GtslNonNum.Count - 1 do
2754    begin
2755      astring := GtslNonNum[i];
2756      if Piece(astring, '^', 7) = section then
2757      begin
2758        nonnumsection := true;
2759        break;
2760      end;
2761    end;
2762    if nonnumericonly and nonnumsection then
2763    begin
2764      serBlank := TPointSeries.Create(aChart);
2765      MakeSeriesPoint(aChart, serBlank);
2766      with serBlank do
2767      begin
2768        AddXY(aChart.BottomAxis.Minimum, highestvalue, '', aChart.Color);
2769        AddXY(aChart.BottomAxis.Minimum, lowestvalue, '', aChart.Color);
2770      end;
2771      aChart.LeftAxis.Labels := false;
2772      aChart.MarginLeft := PadLeftNonNumeric(pnlScrollTopBase.Width);
2773      //aChart.MarginLeft := round((40 / (pnlScrollTopBase.Width + 1)) * 100);       // ************* marginleft is a %
2774      ChartOnUndoZoom(aChart);
2775    end;
2776    MakeNonNumSeries(aChart, padvalue, highestvalue, lowestvalue, listofseries, section);
2777  end;
2778  
2779  procedure TfrmGraphs.MakeNonNumSeries(aChart: TChart; padvalue, highestvalue, lowestvalue: double; listofseries, section: string);
2780  var
2781    asernum, i, j, offset, originalindex, linenum: integer;
2782    graphvalue, nonvalue: double;
2783    avalue, line: string;
2784    adatetime: TDateTime;
2785    serPoint: TPointSeries;
2786  begin
2787    for j := 2 to BIG_NUMBER do
2788    begin
2789      line := Piece(listofseries, '^' , j);
2790      if length(line) < 1 then break;
2791      linenum := strtointdef(line, -BIG_NUMBER);
2792      if linenum = -BIG_NUMBER then break;
2793      serPoint := TPointSeries.Create(aChart);
2794      MakeSeriesPoint(aChart, serPoint);
2795      with serPoint do
2796      begin
2797        serPoint.Title := '(non-numeric)';
2798        serPoint.Identifier := (aChart.Series[linenum] as TCustomSeries).Title;
2799        serPoint.Pointer.Style := (aChart.Series[linenum] as TCustomSeries).Pointer.Style;
2800        serPoint.SeriesColor := (aChart.Series[linenum] as TCustomSeries).SeriesColor;
2801        serPoint.Tag := BIG_NUMBER + linenum;
2802      end;
2803      for i := 0 to GtslNonNum.Count - 1 do
2804      begin
2805        avalue := GtslNonNum[i];
2806        if Piece(avalue, '^', 7) = section then
2807        begin
2808          originalindex := strtointdef(Piece(avalue, '^', 3), 0);
2809          if originalindex = linenum then
2810          begin
2811            adatetime := strtofloatdef(Piece(avalue, '^', 1), -BIG_NUMBER);
2812            asernum := aChart.Tag;
2813            if adatetime = -BIG_NUMBER then break;
2814            if asernum = strtointdef(Piece(avalue, '^', 2), -BIG_NUMBER) then
2815            begin
2816              offset := strtointdef(Piece(avalue, '^', 5), 1);
2817              graphvalue := padvalue * offset;
2818              if copy(Piece(avalue, '^', 13), 0, 1) = '>' then
2819                nonvalue := highestvalue
2820              else
2821                nonvalue := lowestvalue;
2822              nonvalue := nonvalue + graphvalue;
2823              with serPoint do
2824              begin
2825                Hint := Piece(avalue, '^', 9);
2826                AddXY(adatetime, nonvalue, '', serPoint.SeriesColor);
2827              end;
2828            end;
2829          end;
2830        end;
2831      end;
2832    end;
2833  end;
2834  
2835  procedure TfrmGraphs.StackNonNum(astring: string; var offset, bmax, tmax: integer; var blabelon, tlabelon: boolean);
2836  var
2837    inlist: boolean;
2838    i, lastnum, plusminus: integer;
2839    avalue, checktime, lasttime: string;
2840  begin
2841    inlist := false;
2842    offset := 0;
2843    checktime := Piece(astring, '^', 1);
2844    if length(checktime) < 4 then exit;
2845    if copy(Piece(astring, '^', 13), 0, 1) = '>' then
2846    begin
2847      checktime := checktime + ';t';    // top values will stack downwards
2848      plusminus := -1;
2849      tlabelon := true;
2850    end
2851    else
2852    begin
2853      checktime := checktime + ';b';    // bottom values will stack upwards
2854      plusminus := 1;
2855      blabelon := true;
2856    end;
2857    for i := 0 to GtslNonNumDates.Count - 1 do
2858    begin
2859      avalue := GtslNonNumDates[i];
2860      lasttime := Piece(avalue, '^' , 1);
2861      if checktime = lasttime then
2862      begin
2863        lastnum := strtointdef(Piece(avalue, '^', 2), 0);
2864        offset := lastnum + 1;
2865        if offset > 0 then bmax := bmax + 1
2866        else tmax := tmax + 1;
2867        GtslNonNumDates[i] := checktime + '^' + inttostr(offset * plusminus);
2868        inlist := true;
2869        break;
2870      end;
2871    end;
2872    if not inlist then
2873      GtslNonNumDates.Add(checktime + '^' + inttostr(offset * plusminus));
2874  end;
2875  
2876  procedure TfrmGraphs.PadNonNum(aChart: TChart; aSection: string; var listofseries: string; var bmax, tmax: integer);
2877  var
2878    blabelon, tlabelon: boolean;
2879    i, offset: integer;
2880    astring, avalue, charttag, lasttime, newseries, newtime: string;
2881    serNonNumBottom, serNonNumTop: TPointSeries;
2882  begin
2883    GtslNonNumDates.Clear;
2884    listofseries := '^';
2885    blabelon := false; tlabelon := false;
2886    bmax := 0; tmax := 0;
2887    lasttime := '';
2888    for i := 0 to GtslNonNum.Count - 1 do
2889    begin
2890      astring   := GtslNonNum[i];
2891      if Piece(astring, '^', 7) = aSection then
2892      begin
2893        charttag := Piece(astring, '^', 2);
2894        if charttag = inttostr(aChart.Tag) then
2895        begin
2896          newtime   := Piece(astring, '^', 1);
2897          avalue    := Piece(astring, '^', 13);
2898          newseries := '^' + Piece(astring, '^', 3) + '^';
2899          if Pos(newseries, listofseries) = 0 then
2900            listofseries := listofseries + Piece(astring, '^', 3) + '^';
2901          StackNonNum(astring, offset, bmax, tmax, blabelon, tlabelon);
2902          SetPiece(astring, '^', 5, inttostr(offset));
2903          GtslNonNum[i] := astring;
2904        end;
2905      end;
2906    end;
2907    if blabelon then
2908    begin
2909      serNonNumBottom := TPointSeries.Create(aChart);
2910      MakeSeriesPoint(aChart, serNonNumBottom);
2911      with serNonNumBottom do
2912      begin
2913        Identifier := 'serNonNumBottom';
2914        Title := TXT_NONNUMERICS;
2915        Marks.ArrowLength := -11;
2916        Marks.Visible := true;
2917      end;
2918    end;
2919    if tlabelon then
2920    begin
2921      serNonNumTop := TPointSeries.Create(aChart);
2922      MakeSeriesPoint(aChart, serNonNumTop);
2923      with serNonNumTop do
2924      begin
2925        Identifier := 'serNonNumTop';
2926        Title := TXT_NONNUMERICS;
2927        Marks.ArrowLength := -11;
2928        Marks.Visible := true;
2929      end;
2930    end;
2931  end;
2932  
2933  function TfrmGraphs.PortionSize(lcnt, pcnt, gcnt, vcnt, bcnt: integer): double;
2934  var
2935    dvalue, etotal, evalue, value: double;
2936  begin
2937    dvalue := (gcnt + vcnt);
2938    evalue := (pcnt + bcnt) / 2;
2939    etotal := dvalue + evalue;
2940    if etotal > 0 then
2941    begin
2942      value := lcnt / etotal;
2943      if value > 4 then Result := 0.2
2944      else if etotal < 5 then Result := 0.2
2945      else if value < 0.25 then Result := 0.8
2946      else if value < 0.4 then Result := 0.6
2947      else Result := 0.5;
2948    end
2949    else
2950      Result := 0;
2951  end;
2952  
2953  procedure TfrmGraphs.MakeDateline(section, aTitle, aFileType: string; aChart: TChart; graphtype: integer;
2954    var bcnt, pcnt, gcnt, vcnt: integer);
2955  begin
2956    aChart.LeftAxis.Automatic := true;
2957    aChart.LeftAxis.Visible := true;
2958    //if graphtype = 4 then graphtype := 2;    // makes all points into bars
2959    case graphtype of
2960      2:  MakeBarSeries(aChart, aTitle, aFileType, bcnt);
2961      3:  MakeVisitGanttSeries(aChart, aTitle, aFileType, vcnt);
2962      4:  MakePointSeries(aChart, aTitle, aFileType, pcnt);
2963      8:  MakeGanttSeries(aChart, aTitle, aFileType, gcnt);
2964    end;
2965  end;
2966  
2967  procedure TfrmGraphs.SizeTogether(onlylines, nolines, anylines: Boolean; aScroll: TScrollBox;
2968    aChart: TChart; aPanel, aPanelBase: TPanel; portion: Double);
2969  begin
2970    if onlylines then                     //top &bottom
2971    begin
2972      aScroll.Align := alTop;
2973      aScroll.Height := 1;
2974      aChart.Visible := false;
2975      aPanel.Align := alClient;
2976      aPanel.Visible := true;
2977    end
2978    else if nolines then
2979    begin
2980      aPanel.Align := alBottom;
2981      aPanel.Height := 5;
2982      aScroll.Align := alClient;
2983      aPanel.Visible := false;
2984      if btnChangeSettings.Tag = 1 then
2985        aChart.LeftAxis.Title.Caption := 'StdDev';
2986    end
2987    else if anylines then
2988    begin
2989      aScroll.Align := alTop;
2990      aPanel.Align := alBottom;
2991      aPanel.Height := round(aPanelBase.Height * portion);
2992      if aPanel.Height < 60 then
2993        if aPanelBase.Height > 100 then aPanel.Height := 60;           //***
2994      aScroll.Align := alClient;
2995      aPanel.Visible := true;
2996      if btnChangeSettings.Tag = 1 then
2997        aChart.LeftAxis.Title.Caption := 'StdDev';
2998    end;
2999  end;
3000  
3001  function TfrmGraphs.NextColor(aCnt: integer): TColor;
3002  begin
3003    case (aCnt mod NUM_COLORS) of
3004      1: Result := clRed;
3005      2: Result := clBlue;
3006      3: Result := clYellow;
3007      4: Result := clGreen;
3008      5: Result := clFuchsia;
3009      6: Result := clMoneyGreen;
3010      7: Result := clOlive;
3011      8: Result := clLime;
3012      9: Result := clMedGray;
3013     10: Result := clNavy;
3014     11: Result := clAqua;
3015     12: Result := clGray;
3016     13: Result := clSkyBlue;
3017     14: Result := clTeal;
3018     15: Result := clBlack;
3019      0: Result := clPurple;
3020     16: Result := clMaroon;
3021     17: Result := clCream;
3022     18: Result := clSilver;
3023     else
3024         Result := clWhite;
3025     end;
3026  end;
3027  
3028  
3029  procedure TfrmGraphs.mnuPopGraphSwapClick(Sender: TObject);
3030  var
3031    tempcheck: boolean;
3032    bottomview, topview: integer;
3033    aGraphItem: TGraphItem;
3034    aListItem: TListItem;
3035  begin
3036    FFirstClick := true;
3037    if (lvwItemsTop.SelCount = 0) and (lvwItemsBottom.SelCount = 0) then exit;
3038    topview := lstViewsTop.ItemIndex;
3039    bottomview := lstViewsBottom.ItemIndex;
3040    HideGraphs(true);
3041    with chkDualViews do
3042      if not Checked then
3043      begin
3044        Checked := true;
3045        Click;
3046      end;
3047    tempcheck := chkItemsTop.Checked;
3048    chkItemsTop.Checked := chkItemsBottom.Checked;
3049    chkItemsBottom.Checked := tempcheck;
3050    pnlBottom.Height := pnlMain.Height - pnlBottom.Height;
3051    GtslScratchSwap.Clear;
3052    if topview < 1 then
3053    begin
3054      aListItem := lvwItemsTop.Selected;
3055      while aListItem <> nil do
3056      begin
3057        aGraphItem := TGraphItem(aListItem.SubItems.Objects[3]);
3058        GtslScratchSwap.Add(aGraphItem.Values);
3059        aListItem := lvwItemsTop.GetNextItem(aListItem, sdAll, [isSelected]);
3060      end;
3061    end;
3062    GraphSwap(bottomview, topview);
3063    GtslScratchSwap.Clear;
3064    HideGraphs(false);
3065  end;
3066  
3067  procedure TfrmGraphs.GraphSwap(bottomview, topview: integer);
3068  var
3069    tempcheck: boolean;
3070  begin
3071    FFirstClick := true;
3072    if (lvwItemsTop.SelCount = 0) and (lvwItemsBottom.SelCount = 0) then exit;
3073    topview := lstViewsTop.ItemIndex;
3074    bottomview := lstViewsBottom.ItemIndex;
3075    HideGraphs(true);
3076    with chkDualViews do
3077      if not Checked then
3078      begin
3079        Checked := true;
3080        Click;
3081      end;
3082    tempcheck := chkItemsTop.Checked;
3083    chkItemsTop.Checked := chkItemsBottom.Checked;
3084    chkItemsBottom.Checked := tempcheck;
3085    pnlBottom.Height := pnlMain.Height - pnlBottom.Height;
3086    GtslScratchSwap.Clear;
3087    GraphSwitch(bottomview, topview);
3088    HideGraphs(false);
3089  end;
3090  
3091  procedure TfrmGraphs.GraphSwitch(bottomview, topview: integer);
3092  var
3093    i, j: integer;
3094    typeitem: string;
3095    aGraphItem: TGraphItem;
3096    aListItem: TListItem;
3097  begin
3098    GtslScratchSwap.Clear;
3099    if topview < 1 then
3100    begin
3101      aListItem := lvwItemsTop.Selected;
3102      while aListItem <> nil do
3103      begin
3104        aGraphItem := TGraphItem(aListItem.SubItems.Objects[3]);
3105        GtslScratchSwap.Add(aGraphItem.Values);
3106        aListItem := lvwItemsTop.GetNextItem(aListItem, sdAll, [isSelected]);
3107      end;
3108    end;
3109    if bottomview > 0 then
3110    begin
3111      lstViewsTop.ItemIndex := bottomview;
3112      lstViewsTopChange(self);
3113    end
3114    else
3115    begin
3116      lstViewsTop.ItemIndex := -1;
3117      lvwItemsTop.ClearSelection;
3118      aListItem := lvwItemsBottom.Selected;
3119      while aListItem <> nil do
3120      begin
3121        aGraphItem := TGraphItem(aListItem.SubItems.Objects[3]);
3122        typeitem := Pieces(aGraphItem.Values, '^', 1, 2);
3123        for j := 0 to lvwItemsTop.Items.Count - 1 do
3124        begin
3125          aGraphItem := TGraphItem(lvwItemsTop.Items[j].SubItems.Objects[3]);
3126          if typeitem = Pieces(aGraphItem.Values, '^', 1, 2) then
3127          begin
3128            lvwItemsTop.Items[j].Selected := true;
3129            break;
3130          end;
3131        end;
3132        aListItem := lvwItemsBottom.GetNextItem(aListItem, sdAll, [isSelected]);
3133      end;
3134      lvwItemsTopClick(self);
3135    end;
3136    if topview > 0 then
3137    begin
3138      lstViewsBottom.ItemIndex := topview;
3139      lstViewsBottomChange(self);
3140    end
3141    else
3142    begin
3143      lstViewsBottom.ItemIndex := -1;
3144      lvwItemsBottom.ClearSelection;
3145      for i := 0 to GtslScratchSwap.Count - 1 do
3146        for j := 0 to lvwItemsBottom.Items.Count - 1 do
3147        begin
3148          aGraphItem := TGraphItem(lvwItemsBottom.Items.Item[j].SubItems.Objects[3]);
3149          if aGraphItem.Values = GtslScratchSwap[i] then
3150          begin
3151            lvwItemsBottom.Items[j].Selected := true;
3152            break;
3153          end;
3154        end;
3155      lvwItemsBottomClick(self);
3156    end;
3157    GtslScratchSwap.Clear;
3158  end;