Ignore:
Timestamp:
Jul 7, 2010, 4:51:54 PM (14 years ago)
Author:
Kevin Toppenberg
Message:

Upgrading to version 27

File:
1 edited

Legend:

Unmodified
Added
Removed
  • cprs/trunk/CPRS-Chart/fGraphs.pas

    r456 r830  
    77  ExtCtrls, StdCtrls, ORCtrls, Menus, TeeProcs, TeEngine, Series, Chart, Math,
    88  ComCtrls, GanttCh, ClipBrd, StrUtils, ORFn, ORDtTmRng, DateUtils, Printers,
    9   OleServer, Variants, Word97, Word2000, ArrowCha, ORDtTm, uGraphs;
     9  OleServer, Variants, Word2000, ArrowCha, ORDtTm, uGraphs, fBase508Form
     10  {$IFDEF VER140}
     11  ,Word97;
     12  {$ELSE}
     13  ,WordXP, VA508AccessibilityManager;
     14  {$ENDIF}
    1015
    1116type
    12   TfrmGraphs = class(TForm)
     17  TfrmGraphs = class(TfrmBase508Form)
    1318    btnChangeSettings: TButton;
    1419    btnClose: TButton;
     
    2833    dlgDate: TORDateTimeDlg;
    2934    lblDateRange: TLabel;
    30     lblViewsBottom: TOROffsetLabel;
    31     lblViewsTop: TOROffsetLabel;
    32     lstAllTypes: TListBox;
    33     lstCheck: TListBox;
    34     lstData: TListBox;
    35     lstDrugClass: TListBox;
    36     lstItems: TListBox;
    37     lstItemsTemp: TListBox;
    38     lstMultiSpec: TListBox;
    39     lstNonNumeric: TListBox;
    40     lstScratchLab: TListBox;
    41     lstScratchSwap: TListBox;
    42     lstScratchTemp: TListBox;
    43     lstSelCopyBottom: TListBox;
    44     lstSelCopyTop: TListBox;
    45     lstSpec1: TListBox;
    46     lstSpec2: TListBox;
    47     lstSpec3: TListBox;
    48     lstSpec4: TListBox;
    49     lstTemp: TListBox;
    50     lstTempCheck: TListBox;
    51     lstTestSpec: TListBox;
    52     lstTypes: TListBox;
    53     lstViews: TListBox;
    54     lstZoomHistory: TListBox;
    55     lvwItemsBottom: TListView;
    56     lvwItemsTop: TListView;
    57     mnumedsasgantt: TMenuItem;
    58     mnumedsasganttvertheight: TMenuItem;
     35    memBottom: TMemo;
     36    memTop: TMemo;
     37    mnuGraphData: TMenuItem;
    5938    mnuPopGraph3D: TMenuItem;
    6039    mnuPopGraphClear: TMenuItem;
     
    6544    mnuPopGraphDualViews: TMenuItem;
    6645    mnuPopGraphGradient: TMenuItem;
     46    mnuPopGraphExport: TMenuItem;
    6747    mnuPopGraphFixed: TMenuItem;
    6848    mnuPopGraphHints: TMenuItem;
     
    8262    mnuPopGraphToday: TMenuItem;
    8363    mnuPopGraphValues: TMenuItem;
     64    mnuPopGraphValueMarks: TMenuItem;
    8465    mnuPopGraphVertical: TMenuItem;
    8566    mnuPopGraphZoomBack: TMenuItem;
     
    9273    pnlBottom: TPanel;
    9374    pnlBottomRightPad: TPanel;
    94     pnlData: TPanel;
    9575    pnlDatelineBottom: TPanel;
    9676    pnlDatelineBottomSpacer: TORAutoPanel;
     
    11797    splItemsBottom: TSplitter;
    11898    splItemsTop: TSplitter;
     99    mnuTestCount: TMenuItem;
    119100    timHintPause: TTimer;
    120     lstSelPrevTop: TListBox;
    121     lstSelPrevBottom: TListBox;
    122     lstComp: TListBox;
    123     pnlViewsTopSpacer: TPanel;
    124     cboViewsTop: TORComboBox;
    125     pnlViewsTopSpacerRight: TPanel;
    126     pnlViewsBottomSpacer: TPanel;
    127     cboViewsBottom: TORComboBox;
    128     pnlViewsBottomSpacerRight: TPanel;
    129     testcount1: TMenuItem;
     101    mnuMHasNumeric1: TMenuItem;
     102    mnuStandardDeviations: TMenuItem;
     103    mnuInverseValues: TMenuItem;
     104    mnuFunctions1: TMenuItem;
     105    pcTop: TPageControl;
     106    tsTopItems: TTabSheet;
     107    tsTopViews: TTabSheet;
     108    tsTopCustom: TTabSheet;
     109    lvwItemsTop: TListView;
     110    pcBottom: TPageControl;
     111    tsBottomItems: TTabSheet;
     112    tsBottomViews: TTabSheet;
     113    tsBottomCustom: TTabSheet;
     114    lvwItemsBottom: TListView;
     115    mnuCustom: TMenuItem;
     116    lstViewsTop: TORListBox;
     117    lstViewsBottom: TORListBox;
     118    memViewsTop: TRichEdit;
     119    splViewsTop: TSplitter;
     120    memViewsBottom: TRichEdit;
     121    splViewsBottom: TSplitter;
     122    mnuPopGraphViewDefinition: TMenuItem;
     123    mnutest: TMenuItem;
     124
    130125    procedure FormCreate(Sender: TObject);
    131126    procedure FormShow(Sender: TObject);
    132127    procedure FormClose(Sender: TObject; var Action: TCloseAction);
     128    procedure FormDestroy(Sender: TObject);
    133129
    134130    procedure btnCloseClick(Sender: TObject);
     
    137133
    138134    procedure chkDualViewsClick(Sender: TObject);
     135    procedure chkItemsBottomClick(Sender: TObject);
     136    procedure chkItemsBottomEnter(Sender: TObject);
    139137    procedure chkItemsTopClick(Sender: TObject);
    140     procedure chkItemsBottomClick(Sender: TObject);
    141 
    142     procedure mnuMedsasganttClick(Sender: TObject);
    143138    procedure mnuPopGraph3DClick(Sender: TObject);
    144139    procedure mnuPopGraphClearClick(Sender: TObject);
    145     procedure mnuPopGraphCopyClick(Sender: TObject);
    146140    procedure mnuPopGraphDatesClick(Sender: TObject);
    147141    procedure mnuPopGraphDetailsClick(Sender: TObject);
    148142    procedure mnuPopGraphDualViewsClick(Sender: TObject);
     143    procedure mnuPopGraphExportClick(Sender: TObject);
    149144    procedure mnuPopGraphFixedClick(Sender: TObject);
    150145    procedure mnuPopGraphGradientClick(Sender: TObject);
     
    163158    procedure mnuPopGraphSwapClick(Sender: TObject);
    164159    procedure mnuPopGraphTodayClick(Sender: TObject);
     160    procedure mnuPopGraphValueMarksClick(Sender: TObject);
    165161    procedure mnuPopGraphValuesClick(Sender: TObject);
    166162    procedure mnuPopGraphHorizontalClick(Sender: TObject);
     
    172168    procedure splItemsTopMoved(Sender: TObject);
    173169
    174     procedure GetSize;
    175     procedure SetSize;
    176 
     170    procedure lvwItemsBottomChange(Sender: TObject; Item: TListItem;
     171      Change: TItemChange);
    177172    procedure lvwItemsBottomClick(Sender: TObject);
    178173    procedure lvwItemsBottomColumnClick(Sender: TObject; Column: TListColumn);
    179174    procedure lvwItemsBottomCompare(Sender: TObject; Item1,
    180175      Item2: TListItem; Data: Integer; var Compare: Integer);
     176    procedure lvwItemsTopChange(Sender: TObject; Item: TListItem;
     177      Change: TItemChange);
    181178    procedure lvwItemsTopClick(Sender: TObject);
    182179    procedure lvwItemsTopColumnClick(Sender: TObject; Column: TListColumn);
    183180    procedure lvwItemsTopCompare(Sender: TObject; Item1, Item2: TListItem;
    184181      Data: Integer; var Compare: Integer);
     182    procedure lvwItemsTopKeyDown(Sender: TObject; var Key: Word;
     183      Shift: TShiftState);
    185184
    186185    procedure cboDateRangeChange(Sender: TObject);
    187     procedure cboViewsBottomChange(Sender: TObject);
    188     procedure cboViewsTopChange(Sender: TObject);
    189 
    190     procedure pnlScrollTopBaseResize(Sender: TObject);
     186    procedure cboDateRangeDropDown(Sender: TObject);
    191187
    192188    procedure chartBaseClickLegend(Sender: TCustomChart;
     
    196192    procedure chartBaseMouseDown(Sender: TObject; Button: TMouseButton;
    197193      Shift: TShiftState; X, Y: Integer);
     194    procedure chartBaseMouseUp(Sender: TObject; Button: TMouseButton;
     195      Shift: TShiftState; X, Y: Integer);
    198196    procedure chartBaseMouseMove(Sender: TObject; Shift: TShiftState; X, Y: Integer);
    199197    procedure serDatelineTopGetMarkText(Sender: TChartSeries;
     
    202200    procedure ChartOnUndoZoom(Sender: TObject);
    203201    procedure ChartOnZoom(Sender: TObject);
     202    procedure DateSteps(dateranges: string);
    204203    procedure DisplayData(aSection: string);
     204    procedure DisplayDataInfo(aScrollBox: TScrollBox; aMemo: TMemo);
     205    procedure GraphSwap(bottomview, topview: integer);
     206    procedure GraphSwitch(bottomview, topview: integer);
    205207    procedure HideDates(aChart: TChart);
     208    procedure LabelClicks(aChart: TChart; aSeries: TChartSeries; lbutton: boolean; tmp: integer);
     209    procedure MouseClicks(aChart: TChart; lbutton: boolean; X, Y: Integer);
     210    procedure SeriesClicks(aChart: TChart; aSeries: TChartSeries; aIndex: integer; lbutton: boolean);
     211    procedure SetupFields(settings: string);
    206212    procedure SourcesDefault;
    207213    procedure StayOnTop;
    208 
    209     procedure timHintPauseTimer(Sender: TObject);
     214    procedure FormatHint(var astring: string);
     215
    210216    procedure ZoomUpdate;
    211217    procedure ZoomUpdateInfo(SmallTime, BigTime: TDateTime);
    212218    procedure ZoomTo(SmallTime, BigTime: TDateTime);
    213     procedure lvwItemsTopChange(Sender: TObject; Item: TListItem;
    214       Change: TItemChange);
    215     procedure lvwItemsTopKeyDown(Sender: TObject; var Key: Word;
    216       Shift: TShiftState);
    217     procedure lvwItemsBottomChange(Sender: TObject; Item: TListItem;
    218       Change: TItemChange);
    219     procedure testcount1Click(Sender: TObject);
    220     procedure cboDateRangeDropDown(Sender: TObject);
    221     procedure cboViewsTopDropDown(Sender: TObject);
    222     procedure cboViewsTopDropDownClose(Sender: TObject);
    223     procedure cboViewsBottomDropDown(Sender: TObject);
    224     procedure cboViewsBottomDropDownClose(Sender: TObject);
    225     procedure FormDestroy(Sender: TObject);
     219
     220    procedure lvwItemsBottomEnter(Sender: TObject);
    226221    procedure lvwItemsTopEnter(Sender: TObject);
    227     procedure lvwItemsBottomEnter(Sender: TObject);
    228     procedure chkItemsBottomEnter(Sender: TObject);
    229     procedure cboViewsBottomEnter(Sender: TObject);
     222
     223    procedure memBottomEnter(Sender: TObject);
     224    procedure memBottomExit(Sender: TObject);
     225    procedure memBottomKeyDown(Sender: TObject; var Key: Word; Shift: TShiftState);
     226    procedure memTopEnter(Sender: TObject);
     227    procedure memTopExit(Sender: TObject);
     228    procedure memTopKeyDown(Sender: TObject; var Key: Word; Shift: TShiftState);
     229
     230    procedure pnlScrollTopBaseResize(Sender: TObject);
     231    procedure timHintPauseTimer(Sender: TObject);
     232
     233    procedure GetSize;
     234    procedure SetSize;
     235    procedure mnuGraphDataClick(Sender: TObject);
     236    procedure mnuCustomClick(Sender: TObject);
     237    procedure lstViewsTopChange(Sender: TObject);
     238    procedure lstViewsBottomChange(Sender: TObject);
     239    procedure mnuMHasNumeric1Click(Sender: TObject);
     240    procedure lstViewsTopEnter(Sender: TObject);
     241    procedure lstViewsBottomEnter(Sender: TObject);
     242    procedure mnuPopGraphViewDefinitionClick(Sender: TObject);
     243    procedure lstViewsTopMouseDown(Sender: TObject; Button: TMouseButton;
     244      Shift: TShiftState; X, Y: Integer);
     245    procedure splViewsTopMoved(Sender: TObject);
     246    procedure lstViewsBottomMouseDown(Sender: TObject; Button: TMouseButton;
     247      Shift: TShiftState; X, Y: Integer);
    230248
    231249  private
    232     { Private declarations }
    233250    FBSortAscending: boolean;
    234251    FBSortCol: integer;
     
    242259    FBHighTime, FBLowTime: Double;
    243260    FCreate: boolean;
     261    FDisplayFreeText: boolean;
     262    FFastData: boolean;
     263    FFastItems: boolean;
     264    FFastLabs: boolean;
     265    FFastTrack: boolean;
    244266    FFirstClick: boolean;
    245267    FFirstSwitch: boolean;
    246268    FGraphClick: TCustomChart;
    247269    FGraphSeries: TChartSeries;
    248     FGraphValueIndex: integer;
    249270    FGraphSetting: TGraphSetting;
    250271    FGraphType: char;
     272    FGraphValueIndex: integer;
    251273    FItemsSortedTop: boolean;
    252274    FItemsSortedBottom: boolean;
     
    254276    FMTimestamp: string;
    255277    FMToday: TFMDateTime;
    256     FMyProfiles, FProfiles: TStringList;
    257278    FNonNumerics: boolean; // used with pnlItemsTop.Tag & pnlItemsBottom.Tag
    258279    FOnLegend:  integer;
     280    FOnMark: boolean;
    259281    FOnSeries: integer;
    260282    FOnValue: integer;
     
    264286    FSourcesDefault: TStrings;
    265287    FTHighTime, FTLowTime: Double;
     288    FTooManyItems: boolean;
    266289    FWarning: boolean;
    267290    FX, FY: integer;
     
    269292    FYMaxValue: Double;
    270293
     294    procedure AddOnLabGroups(aListBox: TORListBox; personien: integer);
    271295    procedure AdjustTimeframe;
    272296    procedure AllTypeDate(aType, aTypeName, firstline, secondline: string; aDate, aDate2: double);
     
    275299    procedure AutoSelect(aListView: TListView);
    276300    procedure BaseResize(aScrollBox: TScrollBox);
     301    procedure BorderValue(var bordervalue: double; value: double);
    277302    procedure BottomAxis(aScrollBox: TScrollBox);
     303    procedure BPAdd(itemvalue: string; adatetime: TDateTime; var fixeddatevalue: double; serLine, serBPDiastolic, serBPMean: TLineSeries);
     304    procedure BPCheck(aChart: TChart; aFileType: string; serLine, serBPDiastolic, serBPMean: TLineSeries);
    278305    procedure ChangeStyle;
     306    procedure ChartColor(aColor: TColor);
    279307    procedure ChartStyle(aChart: TChart);
     308    procedure CheckMedNum(var typenum: string; aSeries: TChartSeries);
    280309    procedure CheckProfile(var aProfile: string; var Updated: boolean);
    281310    procedure CheckToAddData(aListView: TListView; aSection, TypeToCheck: string);
     311    procedure CreateExcelPatientHeader(var HeaderList: TStringList; PageTitle, DateRange: string);
    282312    procedure CreatePatientHeader(var HeaderList: TStringList; PageTitle, Warning, DateRange: string);
    283313    procedure DateRangeItems(oldestdate, newestdate: double; filenum: string);
    284     procedure UpdateView(filename, filenum, itemnum, aString: string; aListView: TListView);
    285314    procedure DisplayType(itemtype, displayed: string);
     315    procedure FastLab(aList: TStringList);
    286316    procedure FillViews;
    287317    procedure FilterListView(oldestdate, newestdate: double);
    288318    procedure FixedDates(var adatetime, adatetime1: TDateTime);
    289319    procedure GetData(aString: string);
     320    procedure GraphBoundry(singlepoint: boolean);
     321    procedure GraphFooter(aChart: TChart; datediff: integer; aDate: TDateTime);
    290322    procedure HideGraphs(action: boolean);
    291323    procedure HighLow(fmtime, fmtime1: string; aChart: TChart; var adatetime, adatetime1: TDateTime);
    292324    procedure InactivateHint;
     325    procedure InfoMessage(aCaption: string; aColor: TColor; aVisible: boolean);
    293326    procedure ItemCheck(aListView: TListView; aItemName: string;
    294327      var aNum: integer; var aTypeItem: string);
     328    procedure ItemDateRange(Sender: TCustomChart);
    295329    procedure ItemsClick(Sender: TObject; aListView, aOtherListView: TListView;
    296       aCheckBox: TCheckBox; aComboBox: TORComboBox; aList: TListBox; aSection: string);
    297     procedure ItemDateRange(Sender: TCustomChart);
    298     procedure LabData(aItemType, aItemName, aSection: string);
     330      aCheckBox: TCheckBox; aListBox: TORListBox; aList: TStrings; aSection: string);
     331    procedure LabAdd(aListView: TListView; filename: string; aIndex, oldlisting: integer; selectlab: boolean);
     332    procedure LabCheck(aListView: TListView; aItemType: string; var oldlisting: integer);
     333    procedure LabData(aItemType, aItemName, aSection: string; getdata: boolean);
    299334    procedure LoadDateRange;
    300335    procedure LoadDisplayCheck(typeofitem: string; var updated: boolean);
    301336    procedure LoadType(itemtype, displayed: string);
    302337    procedure NextPointerStyle(aSeries: TChartSeries; aSerCnt: integer);
     338    procedure NonNumSave(aChart: TChart; aTitle, aSection: string; adatetime: TDateTime;
     339      var noncnt: integer; newcnt, aIndex: integer);
     340    procedure NotifyApps(aList: TStrings);
     341    procedure NumAdd(serLine: TLineSeries; value: double; adatetime: TDateTime;
     342      var fixeddatevalue, hi, lo: double; var high, low: string);
    303343    procedure OneDayTypeDetails(aTypeItem: string);
     344    procedure PadNonNum(aChart: TChart; aSection: string; var listofseries: string; var bmax, tmax: integer);
     345    procedure PainAdd(serBlank: TPointSeries);
    304346    procedure RefUnits(aItem, aSpec: string; var low, high, units: string);
    305     procedure ResetSpec(aListBox: TListBox; aItemNum, aNewItemNum, aNewItemName, aNewString: string);
    306     procedure TempCheck(typeitem: string; var levelseq: double);
    307     procedure SelCopy(aListView: TListView; aListBox: TListBox);
    308     procedure SelReset(aListbox: TListBox; aListView: TListView);
     347    procedure ResetSpec(aList: TStrings; aItemNum, aNewItemNum, aNewItemName, aNewString: string);
     348    procedure ResultValue(var resultstring, seriestitle: string; typenum, typeitem: string;
     349      Sender: TCustomChart; aSeries: TChartSeries; ValueIndex, SeriesNum: Integer; var OKToUse: boolean);
     350    procedure SelCopy(aListView: TListView; aList: TStrings);
     351    procedure SelReset(aList: TStrings; aListView: TListView);
    309352    procedure SelectItem(aListView: TListView; typeitem: string);
     353    procedure SeriesForLabels(aChart: TChart; aID: string; pad: double);
    310354    procedure SetProfile(aProfile, aName: string; aListView: TListView);
    311355    procedure SizeDates(aChart: TChart; aSmallTime, aBigTime: TDateTime);
    312356    procedure SizeTogether(onlylines, nolines, anylines: Boolean; aScroll: TScrollBox;
    313357      aChart: TChart; aPanel, aPanelBase: TPanel; portion: Double);
    314     procedure ViewsChange(aListView: TListView; aComboBox: TORComboBox; aSection: string);
    315 
     358    procedure SpecCheck(var spec1, spec2, spec3, spec4: string; var singlespec: boolean);
     359    procedure SpecSet(var spec1, spec2, spec3, spec4: string; aItemType, aItemName: string);
     360    procedure SplitClick;
     361    procedure SortListView;
     362    procedure StackNonNum(astring: string; var offset, bmax, tmax: integer; var blabelon, tlabelon: boolean);
     363    procedure TempCheck(typeitem: string; var levelseq: double);
     364    procedure TempData(aStringList: TStringList; aType: string; dt1, dt2: double);
     365    procedure UpdateView(filename, filenum, itemnum, aString: string; aListView: TListView);
     366    procedure ValueDates(aSeries: TChartSeries; ValueIndex: Integer; var resultdate, otherdate: string);
     367    procedure ViewsChange(aListView: TListView; aListBox: TORListBox; aSection: string);
     368
     369    procedure MakeSeparate(aScrollBox: TScrollBox; aListView: TListView; aPadPanel: TPanel; section: string);
     370    procedure MakeSeparateItems(aScrollBox: TScrollBox; aListView: TListView; section: string);
     371    procedure MakeTogether(aScrollBox: TScrollBox; aListView: TListView; aPadPanel: TPanel; section: string);
     372    procedure MakeTogetherMaybe(aScrollBox: TScrollBox; aListView: TListView; aPadPanel: TPanel; section: string);
     373    procedure MakeTogetherNoLines(aListView: TListView; section: string);
     374    procedure MakeTogetherOnlyLines(aListView: TListView; section: string; aChart: TChart);
     375    procedure MakeTogetherAnyLines(aListView: TListView; section: string; aChart: TChart);
     376
     377    procedure MakeChart(aChart: TChart; aScrollBox: TScrollBox);
     378    procedure MakeComments(aChart: TChart);
    316379    procedure MakeDateline(section, aTitle, aFileType: string; aChart: TChart; graphtype: integer;
    317       var bcnt, pcnt, gcnt, vcnt, acnt: integer);
    318     procedure MakeSeparate(aScrollBox: TScrollBox; aListView: TListView; aPadPanel: TPanel; section: string);
    319     procedure MakeTogether(aScrollBox: TScrollBox; aListView: TListView; aPadPanel: TPanel; section: string);
    320 
    321     procedure MakeAGanttSeries(aChart: TChart; aTitle, aFileType: string; var aSerCnt: integer);
    322     procedure MakeArrowSeries(aChart: TChart; aTitle, aFileType: string; var aSerCnt: integer);
     380      var bcnt, pcnt, gcnt, vcnt: integer);
     381    procedure MakeNonNumerics(aChart: TChart);
     382    procedure MakeNonNumSeries(aChart: TChart; padvalue, highestvalue, lowestvalue: double; listofseries, section: string);
     383    procedure MakeOtherSeries(aChart: TChart);
     384    procedure MakeSeriesInfo(aChart: TChart; aSeries: TChartSeries; aTitle, aFileType: string; aSerCnt: integer);
     385    procedure MakeSeriesPoint(aChart: TChart; aPointSeries: TPointSeries);
     386    procedure MakeSeriesRef(aChart: TChart; aTest, aRef: TLineSeries; aTitle, aValue: string; aDate: double);
     387    procedure MakeSeriesBP(aChart: TChart; aTest, aBP: TLineSeries; aFileType: string);
     388
    323389    procedure MakeBarSeries(aChart: TChart; aTitle, aFileType: string; var aSerCnt: integer);
    324     procedure MakeGanttSeries(aChart: TChart; aTitle, aFileType: string; var aSerCnt: integer);
    325     procedure MakeLineSeries(aChart: TChart; aTitle, aFileType: string; var aSerCnt, aNonCnt: integer; multiline: boolean);
    326     procedure MakeManyGanttSeries(aChart: TChart; aTitle, aFileType: string; var aSerCnt: integer);  // good one
     390    procedure MakeLineSeries(aChart: TChart; aTitle, aFileType, section: string;
     391      var aSerCnt, aNonCnt: integer; multiline: boolean);
     392    procedure MakeGanttSeries(aChart: TChart; aTitle, aFileType: string; var aSerCnt: integer);  // good one
    327393    procedure MakePointSeries(aChart: TChart; aTitle, aFileType: string; var aSerCnt: integer);
    328394    procedure MakeVisitGanttSeries(aChart: TChart; aTitle, aFileType: string; var aSerCnt: integer);
    329     procedure MakeWeightedArrowSeries(aChart: TChart; aTitle, aFileType: string; var aSerCnt: integer);
    330     procedure MakeWeightedGanttSeries(aChart: TChart; aTitle, aFileType: string; var aSerCnt: integer);
    331395
    332396    function BPValue(aDateTime: TDateTime): string;
     
    341405    function ItemName(filenum, itemnum: string): string;
    342406    function NextColor(aCnt: integer): TColor;
    343     function PortionSize(lcnt, pcnt, gcnt, vcnt, bcnt, acnt: integer): double;
     407    function NonNumText(listnum, seriesnum, valueindex: integer): string;
     408    function PadLeftEvent(aWidth: integer): integer;
     409    function PadLeftNonNumeric(aWidth: integer): integer;
     410    function PortionSize(lcnt, pcnt, gcnt, vcnt, bcnt: integer): double;
     411    function ProfileName(aProfile, aName, aString: string): string;
    344412    function SelectRef(aRef: string): string;
     413    function SingleLabTest(aListView: TListView): boolean;
    345414    function StdDev(value, high, low: double): double;
     415    function TitleInfo(filetype, typeitem, caption: string): string;
    346416    function TypeIsDisplayed(itemtype: string): boolean;
    347417    function TypeIsLoaded(itemtype: string): boolean;
    348     function Vfactor(aTitle: string): double;
    349     function ValueText(Sender: TCustomChart; Series: TChartSeries; ValueIndex: Integer): string;
    350 
     418    function TypeString(filenum: string): string;
     419    function ValueText(Sender: TCustomChart; aSeries: TChartSeries; ValueIndex: Integer): string;
     420  protected
     421    procedure UpdateAccessabilityActions(var Actions: TAccessibilityActions); override;
    351422  public
    352     { Public declarations }
     423    procedure DateDefaults;
    353424    procedure InitialData;
    354425    procedure Initialize;
     
    356427    procedure LoadListView(aList: TStrings);
    357428    procedure SourceContext;
     429    procedure Switch;
     430    procedure ViewDefinition(profile: string; amemo: TRichEdit);
    358431    procedure ViewSelections;
     432    procedure DisplayFreeText(aChart: TChart);
    359433    procedure SetFontSize(FontSize: integer);
    360434    function FMToDateTime(FMDateTime: string): TDateTime;
     
    369443implementation
    370444
    371 uses fGraphSettings, fGraphProfiles, rGraphs,
    372   ComObj, ActiveX, ShellAPI, fFrame, uCore, rCore, fRptBox, fReports,
    373   uFormMonitor;
     445uses fGraphSettings, fGraphProfiles, fGraphData, fGraphOthers, rGraphs,
     446  ComObj, ActiveX, ShellAPI, fFrame, uCore, rCore, uConst, fRptBox, fReports,
     447  uFormMonitor, VAUtils
     448  { TODO -oRV -cWVEHR Long Age : Changed to use long age }
     449  , rWVEHR;
     450
    374451
    375452{$R *.DFM}
     
    384461var
    385462  i: integer;
    386   dfntype, listline, settings, settings1, t1, t2: string;
    387   aList: TStrings;
    388 begin
    389   FMToday := DateTimeToFMDateTime(Date);
    390   FHintWinActive := false;
    391   FHintStop := false;
    392   FNonNumerics := false;
    393   FMouseDown := false;
    394   FItemsSortedTop := false;
    395   FItemsSortedBottom := false;
    396   FRetainZoom := false;
    397   FFirstClick := true;
    398   FArrowKeys := false;
    399   FCreate := true;
    400   FGraphType := Char(32);
    401   aList := TStringList.Create;
    402   FastAssign(rpcGetGraphSettings, aList);
     463  dfntype, listline, settings, settings1: string;
     464begin
    403465  btnClose.Tag := 0;
    404   if aList.Count < 1 then
     466  settings := GetCurrentSetting;
     467  if (length(settings) < 1) then
    405468  begin
    406469    Screen.Cursor := crDefault;
    407     showmessage('CPRS is not configured for graphing.');
     470    ShowMsg(TXT_NOGRAPHING);
    408471    btnClose.Tag := 1;
    409     FreeAndNil(aList);
    410472    Close;
    411473    Exit;
    412474  end;
    413   t1 := aList[0]; t2 := aList[1];   // hint are current, t1 are personal, t2 public settings
    414   if length(frmFrame.mnuToolsGraphing.Hint) > 0 then settings := frmFrame.mnuToolsGraphing.Hint
    415   else if length(t1) > 0 then settings := t1
    416   else settings := t2;
    417   SetPiece(settings, '|', 8, Piece(t2, '|', 8)); //??????????
    418   frmFrame.mnuToolsGraphing.Hint := settings;
     475  SetupFields(settings);
    419476  settings1 := Piece(settings, '|', 1);
    420   FSources := TStringList.Create;
    421   FSourcesDefault := TStringList.Create;
    422   FMyProfiles := TStringList.Create;
    423   FProfiles := TStringList.Create;
    424   FYMinValue := 0;
    425   FYMaxValue := 0;
    426   FTHighTime := 0;
    427   FTLowTime := BIG_NUMBER;
    428   FBHighTime := 0;
    429   FBLowTime := BIG_NUMBER;
    430477  pnlInfo.Caption := TXT_INFO;
    431   FOnLegend := BIG_NUMBER;
    432   FOnSeries := BIG_NUMBER;
    433   FOnValue := BIG_NUMBER;
    434   FHintWin := THintWindow.Create(self);
    435   FHintWin.Color := clInfoBk;
    436   FHintWin.Canvas.Font.Color := clInfoBk;
    437   FX := 0; FY :=0;
    438   FastAssign(rpcGetTypes('0', false), lstAllTypes.Items);
    439   for i := 0 to lstAllTypes.Items.Count - 1 do
    440   begin
    441     listline := lstAllTypes.Items[i];
    442     dfntype := UpperCase(Piece(listline, '^', 1));
    443     SetPiece(listline, '^', 1, dfntype);
    444     lstAllTypes.Items[i] := listline;
    445   end;
    446   FGraphSetting := GraphSettingsInit(settings);
    447478  for i := 0 to BIG_NUMBER do
    448479  begin
     
    460491  chartDatelineBottom.Gradient.StartColor := clWindow;
    461492  LoadDateRange;
    462   chkItemsTop.Checked := true;
    463   chkItemsBottom.Checked := true;
    464   FastAssign(rpcGetTestSpec, lstTestSpec.Items);
     493  //chkItemsTop.Checked := true;
     494  //chkItemsBottom.Checked := true;
    465495  FillViews;
    466   FreeAndNil(aList);
     496  pcTop.ActivePage := tsTopItems;
     497  pcBottom.ActivePage := tsBottomItems;
     498end;
     499
     500procedure TfrmGraphs.SetupFields(settings: string);
     501begin
     502  FArrowKeys := false;
     503  FBHighTime := 0;
     504  FBLowTime := BIG_NUMBER;
     505  FCreate := true;
     506  FDisplayFreeText := true;
     507  FGraphType := Char(32);
     508  FFirstClick := true;
     509  FFirstSwitch := true;
     510  FGraphSetting := GraphSettingsInit(settings);
     511  FHintStop := false;
     512  FHintWin := THintWindow.Create(self);
     513  FHintWin.Color := clInfoBk;
     514  FHintWin.Canvas.Font.Color := clInfoBk;
     515  FHintWinActive := false;
     516  FItemsSortedBottom := false;
     517  FItemsSortedTop := false;
     518  FMouseDown := false;
     519  FMTimestamp := floattostr(FMNow);
     520  FMToday := DateTimeToFMDateTime(Date);
     521  FNonNumerics := false;
     522  FOnLegend := BIG_NUMBER;
     523  FOnMark := false;
     524  FOnSeries := BIG_NUMBER;
     525  FOnValue := BIG_NUMBER;
     526  FPrevEvent := '';
     527  FRetainZoom := false;
     528  FSources := TStringList.Create;
     529  FSourcesDefault := TStringList.Create;
     530  FTHighTime := 0;
     531  FTLowTime := BIG_NUMBER;
     532  FWarning := false;
     533  FTooManyItems := false;
     534  FX := 0; FY :=0;
     535  FYMinValue := 0;
     536  FYMaxValue := 0;
    467537end;
    468538
     
    470540var
    471541  i: integer;
    472   dfntype, listline, settings, settings1, t1, t2: string;
    473   aList: TStrings;
    474 begin
    475   aList := TStringList.Create;
    476   FastAssign(rpcGetGraphSettings, aList);
    477   t1 := aList[0]; t2 := aList[1];   // t1 are personal, t2 public settings
    478   if length(frmFrame.mnuToolsGraphing.Hint) > 0 then settings := frmFrame.mnuToolsGraphing.Hint
    479   else if length(t1) > 0 then settings := t1
    480   else settings := t2;
    481   SetPiece(settings, '|', 8, Piece(t2, '|', 8));
     542  dfntype, listline, settings, settings1: string;
     543begin
     544  settings := GetCurrentSetting;
    482545  settings1 := Piece(settings, '|', 1);
    483   FGraphSetting := GraphSettingsInit(settings);
    484546  for i := 0 to BIG_NUMBER do
    485547  begin
     
    489551    FSourcesDefault.Add(listline);
    490552  end;
    491   FreeAndNil(aList);
    492553end;
    493554
    494555procedure TfrmGraphs.Initialize;
    495 var
     556var                                        // from fFrame and fReports
    496557  i: integer;
    497558  rptview1, rptview2, rptviews: string;
     
    499560  InitialData;
    500561  SourceContext;
    501   LoadListView(lstItems.Items);
     562  LoadListView(GtslItems);
    502563  if pnlMain.Tag > 0 then
    503564  begin
     
    509570      if length(rptview1) > 0 then
    510571      begin
    511         for i := 0 to cboViewsTop.Items.Count - 1 do
    512         if Piece(cboViewsTop.Items[i], '^', 2) = rptview1 then
     572        //pcTop.ActivePage := tsTopViews;
     573        lstViewsTop.Tag := 0;
     574        for i := 0 to lstViewsTop.Items.Count - 1 do
     575        if Piece(lstViewsTop.Items[i], '^', 2) = rptview1 then
    513576        begin
    514           cboViewsTop.ItemIndex := i;
     577          lstViewsTop.ItemIndex := i;
    515578          break;
    516579        end;
     580        if lstViewsTop.ItemIndex < 0 then
     581          lvwItemsTopClick(self);
    517582      end;
    518583      if length(rptview2) > 0 then
     
    520585        chkDualViews.Checked := true;
    521586        chkDualViewsClick(self);
    522         for i := 0 to cboViewsBottom.Items.Count - 1 do
    523         if Piece(cboViewsBottom.Items[i], '^', 2) = rptview2 then
     587        //pcBottom.ActivePage := tsBottomViews;
     588        lstViewsBottom.Tag := 0;
     589        for i := 0 to lstViewsBottom.Items.Count - 1 do
     590        if Piece(lstViewsBottom.Items[i], '^', 2) = rptview2 then
    524591        begin
    525           cboViewsBottom.ItemIndex := i;
     592          lstViewsBottom.ItemIndex := i;
    526593          break;
    527594        end;
     595        if lstViewsBottom.ItemIndex < 0 then
     596          lvwItemsBottomClick(self);
    528597      end;
    529598    end;
    530   end;
    531   if cboViewsTop.ItemIndex > -1 then
    532     cboViewsTopChange(self)
     599    pnlMain.Tag := 0;
     600    cboDateRangeChange(self);
     601    exit;
     602  end;
     603  if lstViewsTop.ItemIndex > -1 then
     604    lstViewsTopChange(self)
    533605  else
    534606    lvwItemsTopClick(self);
    535   if cboViewsBottom.ItemIndex > -1 then
    536     cboViewsbottomChange(self)
     607  if lstViewsBottom.ItemIndex > -1 then
     608    lstViewsbottomChange(self)
    537609  else
    538610    lvwItemsBottomClick(self);
    539   if pnlMain.Tag > 0 then
    540   begin
    541     pnlMain.Tag := 0;
    542     cboDateRangeChange(self);
    543   if cboViewsTop.ItemIndex > -1 then
    544     cboViewsTopChange(self)
    545   else
    546     lvwItemsTopClick(self);
    547   if cboViewsBottom.ItemIndex > -1 then
    548     cboViewsbottomChange(self)
    549   else
    550     lvwItemsBottomClick(self);
    551   end;
    552611end;
    553612
    554613procedure TfrmGraphs.InitialRetain;
    555 //var
    556   //i: integer;
    557 begin
    558   {//
    559   allview=false
    560   fullview=false
    561   noview=true
    562   go thru items
    563         if selected
    564                 if view
    565                         noview=false
    566                 else
    567                         allview=false
    568 
    569         else
    570                 if view
    571                         allview=false
    572                         fullview=false
    573                         noview=false
    574                 else
    575                         //
    576   if noview
    577         //
    578   if allview
    579         //
    580   if fullview
    581         //
    582   else //partial view
    583         //
    584   //}
     614begin
     615  // from fFrame
    585616end;
    586617
     
    588619var
    589620  i: integer;
    590 begin
    591   with cboViewsTop do
    592   begin
    593     Items.Clear;
    594     Sorted := false;
    595     lstTemp.Sorted := true;
    596     FastAssign(rpcGetGraphProfiles('1', '0', 0), lstTemp.Items);
    597     if lstTemp.Items.Count > 0 then
    598     begin
    599       for i := 0 to lstTemp.Items.Count - 1 do
    600         Items.Add('-1^' + lstTemp.Items[i] + '^');
    601     end;
    602     FastAssign(rpcGetGraphProfiles('1', '1', 0), lstTemp.Items);
    603     if lstTemp.Items.Count > 0 then
    604     begin
    605       Items.Add(LLS_LINE);
    606       for i := 0 to lstTemp.Items.Count - 1 do
    607         Items.Add('-2^' + lstTemp.Items[i] + '^');
    608     end;
    609     Items.Insert(0, '^<clear all selections>^0');
    610     Items.Insert(1, '^<select items>^0');
    611   end;
    612   FastAssign(cboViewsTop.Items, cboViewsBottom.Items);
     621  listline: string;
     622begin
     623  lstViewsTop.Tag := BIG_NUMBER;
     624  lstViewsBottom.Tag := BIG_NUMBER;
     625  lstViewsTop.Sorted := false;
     626  lstViewsBottom.Sorted := false;
     627  lstViewsTop.Items.Clear;
     628  lstViewsBottom.Items.Clear;
     629  GtslViewPersonal.Sorted := true;
     630  FastAssign(GetGraphProfiles('1', '0', 0, User.DUZ), GtslViewPersonal);
     631  GtslViewPublic.Sorted := true;
     632  FastAssign(GetGraphProfiles('1', '1', 0, 0), GtslViewPublic);
     633  with lstViewsTop do
     634  begin
     635    if GtslViews.Count > 0 then
     636    begin
     637      if not ((GtslViews.Count = 1) and (Piece(GtslViews[0], '^', 1) = VIEW_CURRENT)) then
     638      begin
     639        Items.Add(LLS_FRONT + copy('Temporary Views' + LLS_BACK, 0, 60) + '^0');
     640        for i := 0 to GtslViews.Count - 1 do
     641        begin
     642          listline := GtslViews[i];
     643          if Piece(listline, '^', 1) <> VIEW_CURRENT then
     644            Items.Add(VIEW_TEMPORARY + '^' + listline + '^');
     645        end;
     646      end;
     647    end;
     648    if GtslViewPersonal.Count > 0 then
     649    begin
     650      Items.Add(LLS_FRONT + copy('Personal Views' + LLS_BACK, 0, 60) + '^0');
     651      for i := 0 to GtslViewPersonal.Count - 1 do
     652        Items.Add(VIEW_PERSONAL + '^' + GtslViewPersonal[i] + '^');
     653    end;
     654    if GtslViewPublic.Count > 0 then
     655    begin
     656      Items.Add(LLS_FRONT + copy('Public Views' + LLS_BACK, 0, 60) + '^0');
     657      for i := 0 to GtslViewPublic.Count - 1 do
     658        Items.Add(VIEW_PUBLIC + '^' + GtslViewPublic[i] + '^');
     659    end;
     660    AddOnLabGroups(lstViewsTop, 0);
     661  end;
     662  FastAssign(lstViewsTop.Items, lstViewsBottom.Items);
     663end;
     664
     665procedure TfrmGraphs.AddOnLabGroups(aListBox: TORListBox; personien: integer);
     666var
     667  i: integer;
     668begin
     669  if personien < 1 then personien := User.DUZ;
     670  FastAssign(rpcTestGroups(personien), GtslLabGroup);
     671  GtslLabGroup.Sorted := true;
     672  if GtslLabGroup.Count > 0 then
     673  begin
     674    aListBox.Items.Add(LLS_FRONT + copy('Lab Groups' + LLS_BACK, 0, 60) + '^0');
     675    for i := 0 to GtslLabGroup.Count - 1 do
     676      aListBox.Items.Add(VIEW_LABS + '^' + Piece(GtslLabGroup[i], '^', 2)
     677        + '^' + Piece(GtslLabGroup[i], '^', 1) + '^' + inttostr(personien));
     678  end;
    613679end;
    614680
     
    646712    end;
    647713  end;
    648   if cboDateRange.ItemIndex < 0 then
    649     cboDateRange.ItemIndex := cboDateRange.Items.Count - 1;
     714  DateDefaults;
    650715  cboDateRangeChange(self);
    651716  lvwItemsTopClick(self);
    652717  if lvwItemsTop.Items.Count = 0 then
    653718  begin
    654     cboViewsTop.ItemIndex := 0;
    655     cboViewsTop.Text := '';
    656   end;
    657   //else
    658   //  lvwItemsTop.SetFocus;
    659   //chkItemsTop.SetFocus;
    660   cboViewsTop.SetFocus;
    661   //Perform(WM_NextDlgCtl, 0, 0);
     719    lstViewsTop.ItemIndex := -1
     720  end;
     721  if not mnuPopGraphViewDefinition.Checked then
     722    mnuPopGraphViewDefinitionClick(self);
     723  tsTopCustom.TabVisible := false;
     724  tsBottomCustom.TabVisible := false;
     725end;
     726
     727procedure TfrmGraphs.DateDefaults;
     728begin
     729  if Patient.Inpatient then
     730     cboDateRange.SelectByID(GetDefaultInpatientDate)
     731  else
     732     cboDateRange.SelectByID(GetDefaultOutpatientDate);
     733  if cboDateRange.ItemIndex < 0 then
     734    cboDateRange.ItemIndex := cboDateRange.Items.Count - 1;
    662735end;
    663736
    664737procedure TfrmGraphs.FormClose(Sender: TObject; var Action: TCloseAction);
    665738begin
     739  if btnClose.Tag = 1 then
     740    exit;
    666741  SetSize;
    667742  timHintPause.Enabled := false;
     
    671746
    672747procedure TfrmGraphs.GetSize;
     748
     749  procedure SetWidth(aListView: TListView; v1, v2, v3, v4: integer);
     750  begin
     751    if v1 > 0 then aListView.Column[0].Width := v1;
     752    if v2 > 0 then aListView.Column[1].Width := v2;
     753    if v3 > 0 then aListView.Column[2].Width := v3;
     754    if v4 > 0 then aListView.Column[3].Width := v4;
     755  end;
     756
     757  procedure Layout(name, FR: string; v1, v2, v3, v4: integer);
     758  begin  // FR indicates Float or Report graph
     759    if name = (FR + 'WIDTH') then
     760    begin
     761      if v1 > 0 then
     762      begin
     763        pnlItemsTop.Width := v1;
     764        splItemsTopMoved(self);
     765      end;
     766    end
     767    else if name = (FR + 'BOTTOM') then
     768    begin
     769      if v1 > 0 then
     770      begin
     771        chkDualViews.Checked := true;
     772        chkDualViewsClick(self);
     773        pnlBottom.Height := v1;
     774      end;
     775    end
     776    else if name = (FR + 'COLUMN') then
     777      SetWidth(lvwItemsTop, v1, v2, v3, v4)
     778    else if name = (FR + 'BCOLUMN') then
     779      SetWidth(lvwItemsBottom, v1, v2, v3, v4);
     780  end;
     781
     782
    673783var
    674784  i, v1, v2, v3, v4: integer;
     
    697807          else
    698808          begin
    699             if v1 > 0 then Left := v1;
    700             if v2 > 0 then Top := v2;
    701             if v3 > 0 then Width := v3;
     809            if v1 > 0 then Left :=   v1;
     810            if v2 > 0 then Top :=    v2;
     811            if v3 > 0 then Width :=  v3;
    702812            if v4 > 0 then Height := v4;
    703813          end;
    704814        end
    705         else if name = 'FWIDTH' then
    706         begin
    707           if v1 > 0 then
    708           begin
    709             pnlItemsTop.Width := v1;
    710             splItemsTopMoved(self);
    711           end;
    712         end
    713         else if name = 'FBOTTOM' then
    714         begin
    715           if v1 > 0 then
    716           begin
    717             chkDualViews.Checked := true;
    718             chkDualViewsClick(self);
    719             pnlBottom.Height := v1;
    720           end;
    721         end
    722         else if name = 'FCOLUMN' then
    723         begin
    724           if v1 > 0 then lvwItemsTop.Column[0].Width := v1;
    725           if v2 > 0 then lvwItemsTop.Column[1].Width := v2;
    726           if v3 > 0 then lvwItemsTop.Column[2].Width := v3;
    727           if v4 > 0 then lvwItemsTop.Column[3].Width := v4;
    728         end
    729         else if name = 'FBCOLUMN' then
    730         begin
    731           if v1 > 0 then lvwItemsBottom.Column[0].Width := v1;
    732           if v2 > 0 then lvwItemsBottom.Column[1].Width := v2;
    733           if v3 > 0 then lvwItemsBottom.Column[2].Width := v3;
    734           if v4 > 0 then lvwItemsBottom.Column[3].Width := v4;
    735         end;
     815        else
     816          Layout(name, 'F', v1, v2, v3, v4);
    736817      end
    737818      else
    738       begin
    739         if name = 'RWIDTH' then
    740         begin
    741           if v1 > 0 then
    742           begin
    743             pnlItemsTop.Width := v1;
    744             splItemsTopMoved(self);
    745           end;
    746         end
    747         else if name = 'RBOTTOM' then
    748         begin
    749           if v1 > 0 then
    750           begin
    751             pnlBottom.Height := v1;
    752             splGraphsMoved(splGraphs);
    753           end;
    754         end
    755         else if name = 'RCOLUMN' then
    756         begin
    757           if v1 > 0 then lvwItemsTop.Column[0].Width := v1;
    758           if v2 > 0 then lvwItemsTop.Column[1].Width := v2;
    759           if v3 > 0 then lvwItemsTop.Column[2].Width := v3;
    760           if v4 > 0 then lvwItemsTop.Column[3].Width := v4;
    761         end
    762         else if name = 'RBCOLUMN' then
    763         begin
    764           if v1 > 0 then lvwItemsBottom.Column[0].Width := v1;
    765           if v2 > 0 then lvwItemsBottom.Column[1].Width := v2;
    766           if v3 > 0 then lvwItemsBottom.Column[2].Width := v3;
    767           if v4 > 0 then lvwItemsBottom.Column[3].Width := v4;
    768         end;
    769       end;
     819        Layout(name, 'R', v1, v2, v3, v4);
    770820    end;
    771821  end;
     
    774824
    775825procedure TfrmGraphs.SetSize;
    776 var
    777   name, v1, v2, v3, v4: string;
     826
     827  procedure GetWidth(aListView: TListView; var v1, v2, v3, v4: string);
     828  begin
     829    v1 := inttostr(aListView.Column[0].Width);
     830    v2 := inttostr(aListView.Column[1].Width);
     831    v3 := inttostr(aListView.Column[2].Width);
     832    v4 := inttostr(aListView.Column[3].Width);
     833  end;
     834
     835  procedure Layout(aList: TStrings; FR, v1, v2, v3, v4: string);
     836  begin // FR indicates Float or Report graph
     837    v1 := inttostr(splItemsTop.Left);
     838    aList.Add(FR + 'WIDTH^' + v1);
     839    if chkDualViews.Checked then
     840      v1 := inttostr(pnlBottom.Height)
     841    else
     842      v1 := '0';
     843    aList.Add(FR + 'BOTTOM^' + v1);
     844    GetWidth(lvwItemsTop, v1, v2, v3, v4);
     845    aList.Add(FR + 'COLUMN^' + v1 + ',' + v2 + ',' + v3 + ',' + v4);
     846    GetWidth(lvwItemsBottom, v1, v2, v3, v4);
     847    aList.Add(FR + 'BCOLUMN^' + v1 + ',' + v2 + ',' + v3 + ',' + v4);
     848  end;
     849
     850
     851var
     852  v1, v2, v3, v4: string;
     853  //values: array[0..3] of string;
    778854  aList: TStrings;
    779855begin
     
    781857  if FGraphType = GRAPH_FLOAT then
    782858  begin
    783     name := 'FBOUNDS';
    784859    v1 := inttostr(Left);
    785860    v2 := inttostr(Top);
     
    787862    v4 := inttostr(Height);
    788863    if WindowState = wsMaximized then
    789       aList.Add(name + '^0,0,0,0')
     864      aList.Add('FBOUNDS^0,0,0,0')
    790865    else
    791       aList.Add(name + '^' + v1 +',' + v2 +',' + v3 +',' + v4);
    792     name := 'FWIDTH';
    793     v1 := inttostr(splItemsTop.Left);
    794     aList.Add(name + '^' + v1);
    795     name := 'FBOTTOM';
    796     if chkDualViews.Checked then
    797       v1 := inttostr(pnlBottom.Height)
    798     else
    799       v1 := '0';
    800     aList.Add(name + '^' + v1);
    801     name := 'FCOLUMN';
    802     v1 := inttostr(lvwItemsTop.Column[0].Width);
    803     v2 := inttostr(lvwItemsTop.Column[1].Width);
    804     v3 := inttostr(lvwItemsTop.Column[2].Width);
    805     v4 := inttostr(lvwItemsTop.Column[3].Width);
    806     aList.Add(name + '^' + v1 +',' + v2 +',' + v3 +',' + v4);
    807     name := 'FBCOLUMN';
    808     v1 := inttostr(lvwItemsBottom.Column[0].Width);
    809     v2 := inttostr(lvwItemsBottom.Column[1].Width);
    810     v3 := inttostr(lvwItemsBottom.Column[2].Width);
    811     v4 := inttostr(lvwItemsBottom.Column[3].Width);
    812     aList.Add(name + '^' + v1 +',' + v2 +',' + v3 +',' + v4);
     866      aList.Add('FBOUNDS^' + v1 + ',' + v2 + ',' + v3 + ',' + v4);
     867    Layout(aList, 'F', v1, v2, v3, v4);
    813868  end
    814869  else
    815   begin
    816     name := 'RWIDTH';
    817     v1 := inttostr(splItemsTop.Left);
    818     aList.Add(name + '^' + v1);
    819     name := 'RBOTTOM';
    820     if chkDualViews.Checked then
    821       v1 := inttostr(pnlBottom.Height)
    822     else
    823       v1 := '0';
    824     aList.Add(name + '^' + v1);
    825     name := 'RCOLUMN';
    826     v1 := inttostr(lvwItemsTop.Column[0].Width);
    827     v2 := inttostr(lvwItemsTop.Column[1].Width);
    828     v3 := inttostr(lvwItemsTop.Column[2].Width);
    829     v4 := inttostr(lvwItemsTop.Column[3].Width);
    830     aList.Add(name + '^' + v1 +',' + v2 +',' + v3 +',' + v4);
    831     name := 'RBCOLUMN';
    832     v1 := inttostr(lvwItemsBottom.Column[0].Width);
    833     v2 := inttostr(lvwItemsBottom.Column[1].Width);
    834     v3 := inttostr(lvwItemsBottom.Column[2].Width);
    835     v4 := inttostr(lvwItemsBottom.Column[3].Width);
    836     aList.Add(name + '^' + v1 +',' + v2 +',' + v3 +',' + v4);
    837   end;
     870    Layout(aList, 'R', v1, v2, v3, v4);
    838871  rpcSetGraphSizing(aList);
    839872  FreeAndNil(aList);
     
    857890  PreSources: TStrings;
    858891begin
     892  Application.ProcessMessages;
    859893  okbutton := false;
    860894  conv := btnChangeSettings.Tag;
     
    868902    PreFixedDateRange := FixedDateRange;
    869903    MaxSelectMin := Max(Max(lvwItemsTop.SelCount, lvwItemsBottom.SelCount), 1);
     904    DateRangeOutpatient := FGraphSetting.DateRangeOutpatient;
    870905  end;
    871906  PreSources := TStringList.Create;
    872   PreSources.Assign(FSources);
     907  FastAssign(FSources, PreSources);
    873908  DialogGraphSettings(Font.Size, okbutton, FGraphSetting, FSources, conv, aSettings);
    874909  if not okbutton then exit;
    875   if length(aSettings) > 0 then frmFrame.mnuToolsGraphing.Hint := aSettings;
     910  if length(aSettings) > 0 then SetCurrentSetting(aSettings);
    876911  btnChangeSettings.Tag := conv;
    877   pnlInfo.Font.Size := lblViewsTop.Font.Size;
    878   SetFontSize(lblViewsTop.Font.Size);
    879   pnlInfo.Visible := conv > 0;
    880   if conv > 0 then
    881   begin
    882     pnlInfo.Caption := TXT_WARNING;
    883     pnlInfo.Color := COLOR_WARNING;
    884   end;
     912  pnlInfo.Font.Size := chkItemsTop.Font.Size;
     913  SetFontSize(chkItemsTop.Font.Size);
     914  InfoMessage(TXT_WARNING, COLOR_WARNING, (conv > 0));
    885915  pnlHeader.Visible := pnlInfo.Visible;
    886916  StayOnTop;
     
    892922    begin
    893923      FSources[i] := Pieces(sourcetype, '^', 2, 4);
    894       filetype := Piece(FSources[i], '^', 1);
    895       lstItems.Items.AddStrings(rpcGetItems(filetype, Patient.DFN));
    896       needtoupdate := true;
     924      if not FFastItems then
     925      begin
     926        filetype := Piece(FSources[i], '^', 1);
     927        FastAddStrings(rpcGetItems(filetype, Patient.DFN), GtslItems);
     928        needtoupdate := true;
     929      end;
    897930    end;
    898931    if not needtoupdate then
     
    921954  if lvwItemsTop.SelCount = 0 then
    922955  begin
    923     cboViewsTop.ItemIndex := -1;
    924     cboViewsTop.Text := '';
     956    lstViewsTop.ItemIndex := -1;
    925957  end;
    926958  if lvwItemsBottom.SelCount = 0 then
    927959  begin
    928     cboViewsBottom.ItemIndex := -1;
    929     cboViewsBottom.Text := '';
     960    lstViewsBottom.ItemIndex := -1;
    930961  end;
    931962end;
     
    957988  lvwItemsTop.Items.Clear;
    958989  lvwItemsBottom.Items.Clear;
     990  lvwItemsTop.Items.BeginUpdate;
     991  lvwItemsBottom.Items.BeginUpdate;
    959992  lvwItemsTop.SortType := stNone; // if Sorting during load then potential error
    960993  lvwItemsBottom.SortType := stNone; // if Sorting during load then potential error
     
    9881021    FItemsSortedBottom := false;
    9891022  end;
     1023  lvwItemsTop.Items.EndUpdate;
     1024  lvwItemsBottom.Items.EndUpdate;
    9901025end;
    9911026
    9921027procedure TfrmGraphs.FilterListView(oldestdate, newestdate: double);
    9931028var
    994   colnum, i: integer;
     1029  i: integer;
    9951030  lastdate: double;
    996   aProfile, filename, filenum, itemnum: string;
     1031  filename, filenum, itemnum: string;
    9971032begin
    9981033  lvwItemsTop.Scroll(-BIG_NUMBER, -BIG_NUMBER);      //faster to set scroll at top
     
    10041039  if (cboDateRange.ItemIndex > 0) and (cboDateRange.ItemIndex < 9) then
    10051040  begin
    1006     with lvwItemsTop do
    10071041    if TypeIsDisplayed('405') then
    10081042      DateRangeItems(oldestdate, newestdate, '405');  // does not matter for all results ******************
     
    10151049    if TypeIsDisplayed('9999911') then
    10161050      DateRangeItems(oldestdate, newestdate, '9999911');
    1017     for i := 0 to lstItems.Items.Count - 1 do
    1018     begin
    1019       filenum := UpperCase(Piece(lstItems.Items[i], '^', 1));
     1051    for i := 0 to GtslItems.Count - 1 do
     1052    begin
     1053      filenum := UpperCase(Piece(GtslItems[i], '^', 1));
    10201054      if filenum <> '405' then
    10211055      if filenum <> '52' then
    1022         if filenum <> '55' then
    1023         if filenum <> '55NVA' then
    1024         if filenum <> '9999911' then
    1025           if TypeIsDisplayed(filenum) then
    1026           begin
    1027             lastdate := strtofloatdef(Piece(lstItems.Items[i], '^', 6), -BIG_NUMBER);
    1028             if (lastdate > oldestdate) and (lastdate < newestdate) then
    1029             begin
    1030               filename := FileNameX(filenum);
    1031               itemnum := Piece(lstItems.Items[i], '^', 2);
    1032               UpdateView(filename, filenum, itemnum, lstItems.Items[i], lvwItemsTop);
    1033             end;
    1034           end;
     1056      if filenum <> '55' then
     1057      if filenum <> '55NVA' then
     1058      if filenum <> '9999911' then
     1059      if TypeIsDisplayed(filenum) then
     1060      begin
     1061        lastdate := strtofloatdef(Piece(GtslItems[i], '^', 6), -BIG_NUMBER);
     1062        if (lastdate > oldestdate) and (lastdate < newestdate) then
     1063        begin
     1064          filename := FileNameX(filenum);
     1065          itemnum := Piece(GtslItems[i], '^', 2);
     1066          UpdateView(filename, filenum, itemnum, GtslItems[i], lvwItemsTop);
     1067        end;
     1068      end;
    10351069    end;
    10361070  end
    10371071  else if (cboDateRange.ItemIndex = 0) or (cboDateRange.ItemIndex > 8) then
    10381072  begin     // manual date range selection
    1039     for i := 0 to lstAllTypes.Items.Count - 1 do
    1040     begin
    1041       filenum := Piece(lstAllTypes.Items[i], '^', 1);
     1073    for i := 0 to GtslAllTypes.Count - 1 do
     1074    begin
     1075      filenum := Piece(GtslAllTypes[i], '^', 1);
    10421076      if TypeIsDisplayed(filenum) then
    10431077      begin
     
    10471081  end;
    10481082  lvwItemsBottom.Items.Assign(lvwItemsTop.Items);
     1083  SortListView;
     1084end;
     1085
     1086procedure TfrmGraphs.SortListView;
     1087var
     1088  colnum: integer;
     1089  aProfile: string;
     1090begin
    10491091  lvwItemsTop.SortType := stBoth;
    10501092  lvwItemsBottom.SortType := stBoth;
     
    10691111    FItemsSortedBottom := false;
    10701112  end;
    1071   if cboViewsTop.ItemIndex > 1 then                         // sort by view
    1072   begin
    1073     aProfile := cboViewsTop.Items[cboViewsTop.ItemIndex];
     1113  if lstViewsTop.ItemIndex > 1 then                         // sort by view
     1114  begin
     1115    aProfile := lstViewsTop.Items[lstViewsTop.ItemIndex];
    10741116    AssignProfile(aProfile, 'top');
    10751117    if not FItemsSortedTop then lvwItemsTopColumnClick(lvwItemsTop, lvwItemsTop.Column[colnum]);
     
    10781120    FItemsSortedTop := false;
    10791121  end;
    1080   if cboViewsBottom.ItemIndex > 1 then                      // sort by view
    1081   begin
    1082     aProfile := cboViewsBottom.Items[cboViewsBottom.ItemIndex];
     1122  if lstViewsBottom.ItemIndex > 1 then                      // sort by view
     1123  begin
     1124    aProfile := lstViewsBottom.Items[lstViewsBottom.ItemIndex];
    10831125    AssignProfile(aProfile, 'bottom');
    10841126    if not FItemsSortedBottom then lvwItemsBottomColumnClick(lvwItemsBottom, lvwItemsBottom.Column[colnum]);
     
    10941136  filename, itemnum, itemstuff, mitemnum: string;
    10951137begin
    1096   FastAssign(rpcDateItem(oldestdate, newestdate, filenum, Patient.DFN), lstScratchTemp.Items);
     1138  FastAssign(rpcDateItem(oldestdate, newestdate, filenum, Patient.DFN), GtslScratchTemp);
    10971139  filename := FileNameX(filenum);
     1140  lvwItemsTop.Items.BeginUpdate;
    10981141  with lvwItemsTop do
    1099   for i := 0 to lstScratchTemp.Items.Count - 1 do
    1100   begin
    1101     itemstuff := lstScratchTemp.Items[i];
     1142  for i := 0 to GtslScratchTemp.Count - 1 do
     1143  begin
     1144    itemstuff := GtslScratchTemp[i];
    11021145    itemnum := UpperCase(Piece(itemstuff, '^',2));
    1103     for j := 0 to lstItems.Items.Count - 1 do
    1104     if (filenum = UpperCase(Piece(lstItems.Items[j], '^', 1))) and (itemnum = UpperCase(Piece(lstItems.Items[j], '^', 2))) then
    1105       UpdateView(filename, filenum, itemnum, lstItems.Items[j], lvwItemsTop);
     1146    for j := 0 to GtslItems.Count - 1 do
     1147    if (filenum = UpperCase(Piece(GtslItems[j], '^', 1))) and (itemnum = UpperCase(Piece(GtslItems[j], '^', 2))) then
     1148      UpdateView(filename, filenum, itemnum, GtslItems[j], lvwItemsTop);
    11061149    if filenum = '63' then
    1107     for j := 0 to lstMultiSpec.Items.Count - 1 do
    1108     begin
    1109       mitemnum := Piece(lstMultiSpec.Items[j], '^', 2);
     1150    for j := 0 to GtslMultiSpec.Count - 1 do
     1151    begin
     1152      mitemnum := Piece(GtslMultiSpec[j], '^', 2);
    11101153      if itemnum = Piece(mitemnum, '.', 1) then
    11111154        if DateRangeMultiItems(oldestdate, newestdate, mitemnum) then     //******** check specific date range
    1112           UpdateView(filename, filenum, mitemnum, lstMultiSpec.Items[j], lvwItemsTop);
    1113     end;
    1114   end;
     1155          UpdateView(filename, filenum, mitemnum, GtslMultiSpec[j], lvwItemsTop);
     1156    end;
     1157  end;
     1158  lvwItemsTop.Items.EndUpdate;
    11151159end;
    11161160
     
    11341178    aGraphItem := TGraphItem.Create;
    11351179    aGraphItem.Values := itemqualifier;
    1136     SubItems.AddObject('info object', aGraphItem);
     1180    SubItems.AddObject('', aGraphItem);
    11371181  end;
    11381182end;
     
    11461190  Result := false;
    11471191  fileitem := '63^' + aMultiItem;
    1148   for i := 0 to lstData.Items.Count - 1 do
    1149     if Pieces(lstData.Items[i], '^', 1, 2) = fileitem then
    1150     begin
    1151       checkdate := strtofloatdef(Piece(lstData.Items[i], '^', 3), BIG_NUMBER);
     1192  for i := 0 to GtslData.Count - 1 do
     1193    if Pieces(GtslData[i], '^', 1, 2) = fileitem then
     1194    begin
     1195      checkdate := strtofloatdef(Piece(GtslData[i], '^', 3), BIG_NUMBER);
    11521196      if checkdate <> BIG_NUMBER then
    11531197        if checkdate >= aOldDate then
     
    11661210begin
    11671211  Result := '';
    1168   with lstAllTypes do
    1169   for i := 0 to Items.Count - 1 do
    1170   begin
    1171     typestring := Items[i];
     1212  for i := 0 to GtslAllTypes.Count - 1 do
     1213  begin
     1214    typestring := GtslAllTypes[i];
    11721215    if Piece(typestring, '^', 1) = filenum then
    11731216    begin
    1174       Result := Piece(Items[i], '^', 2);
     1217      Result := Piece(GtslAllTypes[i], '^', 2);
    11751218      break;
    11761219    end;
     
    11781221  if Result = '' then
    11791222  begin
    1180     with lstAllTypes do
    1181     for i := 0 to Items.Count - 1 do
    1182     begin
    1183       typestring := Items[i];
     1223    for i := 0 to GtslAllTypes.Count - 1 do
     1224    begin
     1225      typestring := GtslAllTypes[i];
    11841226      if lowercase(Piece(typestring, '^', 1)) = filenum then
    11851227      begin
    1186         Result := Piece(Items[i], '^', 2);
     1228        Result := Piece(GtslAllTypes[i], '^', 2);
     1229        break;
     1230      end;
     1231    end;
     1232  end;
     1233end;
     1234
     1235function TfrmGraphs.TypeString(filenum: string): string;
     1236var
     1237  i: integer;
     1238  typestring: string;
     1239begin
     1240  Result := '';
     1241  for i := 0 to GtslAllTypes.Count - 1 do
     1242  begin
     1243    typestring := GtslAllTypes[i];
     1244    if Piece(typestring, '^', 1) = filenum then
     1245    begin
     1246      Result := typestring;
     1247      break;
     1248    end;
     1249  end;
     1250  if Result = '' then
     1251  begin
     1252    for i := 0 to GtslAllTypes.Count - 1 do
     1253    begin
     1254      typestring := GtslAllTypes[i];
     1255      if lowercase(Piece(typestring, '^', 1)) = filenum then
     1256      begin
     1257        Result := typestring;
    11871258        break;
    11881259      end;
     
    11991270  filenum := UpperCase(filenum);
    12001271  itemnum := UpperCase(itemnum);
    1201   with lstItems do
    1202   for i := 0 to Items.Count - 1 do
    1203   begin
    1204     typestring := UpperCase(Items[i]);
     1272  for i := 0 to GtslItems.Count - 1 do
     1273  begin
     1274    typestring := UpperCase(GtslItems[i]);
    12051275    if (Piece(typestring, '^', 1) = filenum) and
    12061276      (Piece(typestring, '^', 2) = itemnum) then
     
    12121282end;
    12131283
     1284procedure TfrmGraphs.Switch;
     1285var
     1286  aList: TStringList;
     1287begin
     1288  if FFastTrack then
     1289    exit;
     1290  aList := TStringList.Create;
     1291  if not FFastItems then
     1292  begin
     1293    rpcFastItems(Patient.DFN, aList, FFastItems);  // ***
     1294    if FFastItems then
     1295    begin
     1296      FastAssign(aList, GtslItems);
     1297      rpcFastData(Patient.DFN, aList, FFastData);  // ***
     1298      if FFastData then
     1299      begin
     1300        FastAssign(aList, GtslData);
     1301        aList.Clear;
     1302        rpcFastLabs(Patient.DFN, aList, FFastLabs);  // ***
     1303        if FFastLabs then
     1304          FastLab(aList);
     1305        FastAssign(GtslData, GtslCheck);
     1306      end;
     1307    end;
     1308  end;
     1309  if not FFastTrack then
     1310    FFastTrack := FFastItems and FFastData and FFastLabs;
     1311  if not FFastTrack then
     1312  begin
     1313    FFastItems := false;
     1314    FFastData := false;
     1315    FFastLabs := false;
     1316  end;
     1317  FreeAndNil(aList);
     1318end;
     1319
    12141320procedure TfrmGraphs.InitialData;
    12151321var
    1216   i, total: integer;
     1322  i: integer;
    12171323  dfntype, listline: string;
    12181324begin
    1219   total := pnlData.ControlCount - 1;
    1220   with pnlData do
    1221   for i:= 0 to total do
    1222     if Controls[i] is TListBox then
    1223       if Controls[i] <> lstAllTypes then
    1224         if Controls[i] <> lstTestSpec then
    1225           (Controls[i] as TListBox).Items.Clear;
     1325  Application.ProcessMessages;
     1326  FMTimestamp := floattostr(FMNow);
    12261327  SourcesDefault;
    1227   FSources.Assign(FSourcesDefault);
    1228   btnChangeSettings.Tag :=0;
    1229   btnClose.Tag := 0;
    1230   cboViewsTop.Tag :=0;
    1231   chartDatelineTop.Tag :=0;
    1232   lvwItemsBottom.Tag :=0;
    1233   lvwItemsTop.Tag :=0;
    1234   pnlFooter.Parent.Tag :=0;
    1235   pnlItemsBottom.Tag :=0;
    1236   pnlItemsTop.Tag :=0;
    1237   pnlTop.Tag :=0;
    1238   scrlTop.Tag :=0;
    1239   splGraphs.Tag :=0;
    1240   cboViewsTop.ItemIndex := -1;
    1241   cboViewsBottom.ItemIndex := -1;
    1242   FastAssign(rpcGetTypes(Patient.DFN, false), lstTypes.Items);
    1243   for i := 0 to lstTypes.Items.Count - 1 do
    1244   begin
    1245     dfntype := UpperCase(Piece(lstTypes.Items[i], '^', 1));
    1246     if TypeIsLoaded(dfntype) then
    1247       lstItems.Items.AddStrings(rpcGetItems(dfntype, Patient.DFN));
    1248     listline := lstTypes.Items[i];
     1328  FastAssign(FSourcesDefault, FSources);
     1329  for i := 0 to GtslTypes.Count - 1 do
     1330  begin
     1331    listline := GtslTypes[i];
    12491332    dfntype := UpperCase(Piece(listline, '^', 1));
    12501333    SetPiece(listline, '^', 1, dfntype);
    1251     lstTypes.Items[i] := listline;
    1252   end;
    1253   lstTypes.Hint := Patient.DFN;  // use to check for patient change
    1254   FMTimestamp := floattostr(FMNow);
     1334    GtslTypes[i] := listline;
     1335  end;
     1336  btnChangeSettings.Tag := 0;
     1337  btnClose.Tag := 0;
     1338  lstViewsTop.Tag := 0;
     1339  chartDatelineTop.Tag := 0;
     1340  lvwItemsBottom.Tag := 0;
     1341  lvwItemsTop.Tag := 0;
     1342  pnlFooter.Parent.Tag := 0;
     1343  pnlItemsBottom.Tag := 0;
     1344  pnlItemsTop.Tag := 0;
     1345  pnlTop.Tag := 0;
     1346  scrlTop.Tag := 0;
     1347  splGraphs.Tag := 0;
     1348  lstViewsTop.ItemIndex := -1;
     1349  lstViewsBottom.ItemIndex := -1;
     1350  frmGraphData.pnlData.Hint := Patient.DFN;      // use to check for patient change
    12551351  FPrevEvent := '';
    12561352  FWarning := false;
    12571353  FFirstSwitch := true;
     1354  Application.ProcessMessages;
     1355  FFastData := false;
     1356  FFastItems := false;
     1357  FFastLabs := false;
     1358  FFastTrack := false;
     1359  if GraphTurboOn then
     1360    Switch;
     1361  //if not FFastItems then
     1362  if GtslItems.Count = 0 then
     1363  begin
     1364    for i := 0 to GtslTypes.Count - 1 do
     1365    begin
     1366      dfntype := Piece(GtslTypes[i], '^', 1);
     1367      if TypeIsLoaded(dfntype) then
     1368        FastAddStrings(rpcGetItems(dfntype, Patient.DFN), GtslItems);
     1369    end;
     1370  end;
     1371end;
     1372
     1373procedure TfrmGraphs.FastLab(aList: TStringList);
     1374var
     1375  lastone: boolean;
     1376  i: integer;
     1377  aType, aItem, aItemName, typeitem, oldtypeitem, listline: string;
     1378begin
     1379  if aList.Count < 1 then
     1380    exit;
     1381  GtslScratchLab.Clear;
     1382  aList.Sort;
     1383  listline := aList[0];
     1384  oldtypeitem := Pieces(listline, '^', 1, 2);
     1385  GtslScratchLab.Add(listline);
     1386  for i := 1 to aList.Count - 1 do
     1387  begin
     1388    lastone := i = aList.Count - 1;
     1389    listline := aList[i];
     1390    typeitem := Pieces(listline, '^', 1 , 2);
     1391    if (typeitem <> oldtypeitem) or lastone then
     1392    begin
     1393      if lastone then
     1394        oldtypeitem := typeitem;
     1395      aType := Piece(oldtypeitem, '^', 1);
     1396      aItem := Piece(oldtypeitem, '^', 2);
     1397      aItemName := MixedCase(ItemName(aType, aItem));
     1398      LabData(oldtypeitem, aItemName, 'top', false);  // already have lab data
     1399      GtslScratchLab.Clear;
     1400    end;
     1401    GtslScratchLab.Add(listline);
     1402    oldtypeitem := typeitem;
     1403  end;
    12581404end;
    12591405
     
    12631409  filetype: string;
    12641410begin
     1411  if FFastItems then
     1412  begin
     1413    Result := true;
     1414    exit;
     1415  end;
    12651416  Result := false;
    12661417  for i := 0 to FSources.Count - 1 do
     
    13001451  with cboDateRange do
    13011452  begin
    1302     defaults := Items[Items.Count - 1];
     1453    defaults := Items[Items.Count - 1];        // ***** CHANGE TO DEFAULTS
    13031454    defaultrange := Piece(defaults, '^', 1);
    13041455    //get report views - param 1 and param 2
     
    13071458    //check if default range already exists
    13081459    if strtointdef(defaultrange, BIG_NUMBER) = BIG_NUMBER then
    1309       ItemIndex := Items.Count - 1;
     1460      ItemIndex := Items.Count - 1
     1461    else
     1462      ItemIndex := strtoint(defaultrange);
    13101463  end;
    13111464end;
     
    13321485    filename := FileNameX(itemtype);
    13331486    FSources.Add(itemtype + '^' + filename + '^' + displayed);
    1334     lstItems.Items.AddStrings(rpcGetItems(itemtype, Patient.DFN));
     1487    FastAddStrings(rpcGetItems(itemtype, Patient.DFN), GtslItems);
    13351488  end;
    13361489end;
     
    13561509procedure TfrmGraphs.DisplayData(aSection: string);
    13571510var
     1511  i: integer;
     1512  astring: string;
    13581513  aChart: TChart;
    13591514  aCheckBox: TCheckBox;
     
    13611516  aDateline, aRightPad: TPanel;
    13621517  aScrollBox: TScrollBox;
     1518  aMemo: TMemo;
    13631519begin
    13641520  FHintStop := true;
    1365   SetFontSize(lblViewsTop.Font.Size);
     1521  SetFontSize(chkItemsTop.Font.Size);
    13661522  if aSection = 'top' then
    13671523  begin
    1368     aListView := lvwItemsTop;
    1369     aOtherListView := lvwItemsBottom;
    1370     aDateline := pnlDatelineTop;
    1371     aRightPad := pnlTopRightPad;
    1372     aScrollBox := scrlTop;
    1373     aChart := chartDatelineTop;
    1374     aCheckBox := chkItemsTop;
     1524    aListView := lvwItemsTop;         aOtherListView := lvwItemsBottom;
     1525    aDateline := pnlDatelineTop;      aChart := chartDatelineTop;
     1526    aRightPad := pnlTopRightPad;      aScrollBox := scrlTop;
     1527    aCheckBox := chkItemsTop;         aMemo := memTop;
    13751528  end
    13761529  else
    13771530  begin
    1378     aListView := lvwItemsBottom;
    1379     aOtherListView := lvwItemsTop;
    1380     aDateline := pnlDatelineBottom;
    1381     aRightPad := pnlBottomRightPad;
    1382     aScrollBox := scrlBottom;
    1383     aChart := chartDatelineBottom;
    1384     aCheckBox := chkItemsBottom;
     1531    aListView := lvwItemsBottom;      aOtherListView := lvwItemsTop;
     1532    aDateline := pnlDatelineBottom;   aChart := chartDatelineBottom;
     1533    aRightPad := pnlBottomRightPad;   aScrollBox := scrlBottom;
     1534    aCheckBox := chkItemsBottom;      aMemo := memBottom;
    13851535  end;
    13861536  if aListView.SelCount < 1 then
     
    13891539    begin
    13901540      FFirstClick := true;
    1391       while aScrollBox.ControlCount > 0 do
    1392         aScrollBox.Controls[0].Free;
     1541      while aScrollBox.ControlCount > 0 do aScrollBox.Controls[0].Free;
    13931542      exit;
    13941543    end;
     
    13991548    if aOtherListView.SelCount > 0 then
    14001549      if aOtherListView = lvwItemsTop then
    1401         ItemsClick(self, lvwItemsTop, lvwItemsBottom, chkItemsTop, cboViewsTop, lstSelCopyTop, 'top')
     1550        ItemsClick(self, lvwItemsTop, lvwItemsBottom, chkItemsTop, lstViewsTop, GtslSelCopyTop, 'top')
    14021551      else
    1403         ItemsClick(self, lvwItemsBottom, lvwItemsTop, chkItemsBottom, cboViewsBottom, lstSelCopyBottom, 'bottom');
     1552        ItemsClick(self, lvwItemsBottom, lvwItemsTop, chkItemsBottom, lstViewsBottom, GtslSelCopyBottom, 'bottom');
    14041553    exit;
    14051554  end;
    14061555  aScrollBox.VertScrollBar.Visible := false;
    14071556  aScrollBox.HorzScrollBar.Visible := false;
     1557  amemo.Visible := false;
    14081558  aChart.RemoveAllSeries;    // this would leave bottom dateline visible on date change
    1409   //chartDatelineTop.RemoveAllSeries;    // do both
    1410   //chartDatelineBottom.RemoveAllSeries; // do both
    1411   lstNonNumeric.Items.Clear;
     1559  for i := GtslNonNum.Count - 1 downto 0 do
     1560  begin
     1561    astring := GtslNonNum[i];
     1562    if Piece(astring, '^', 7) = aSection then
     1563      GtslNonNum.Delete(i);
     1564  end;
    14121565  if aCheckBox.Checked then
    14131566    MakeSeparate(aScrollBox, aListView, aRightPad, aSection)
    14141567  else
    1415   begin
    1416     MakeTogether(aScrollBox, aListView, aRightPad, aSection);
    1417   end;
     1568    MakeTogetherMaybe(aScrollBox, aListView, aRightPad, aSection);
     1569  DisplayDataInfo(aScrollBox, aMemo);
     1570end;
     1571
     1572procedure TfrmGraphs.DisplayDataInfo(aScrollBox: TScrollBox; aMemo: TMemo);
     1573begin
    14181574  ChangeStyle;
    1419   pnlInfo.Font.Size := lblViewsTop.Font.Size;
     1575  pnlInfo.Font.Size := chkItemsTop.Font.Size;
    14201576  if ((lvwItemsTop.SelCount > MAX_ITEM_DISCLAIMER) and (not chkItemsTop.Checked))
    14211577    or ((lvwItemsBottom.SelCount > MAX_ITEM_DISCLAIMER) and (not chkItemsBottom.Checked)) then
    1422   begin
    1423     pnlInfo.Caption := TXT_DISCLAIMER;
    1424     pnlInfo.Color := COLOR_WARNING;
    1425     pnlInfo.Visible := true;
    1426   end
     1578    InfoMessage(TXT_DISCLAIMER, COLOR_WARNING, true)
    14271579  else
    14281580    pnlInfo.Visible := false;
    14291581  if btnChangeSettings.Tag > 0 then
    1430   begin
    1431     pnlInfo.Caption := TXT_WARNING;
    1432     pnlInfo.Color := COLOR_WARNING;
    1433     pnlInfo.Visible := true;
    1434   end;
    1435   //if copy(pnlInfo.Caption, 1, 7) = 'Warning' then
     1582    InfoMessage(TXT_WARNING, COLOR_WARNING, true);
    14361583  if FWarning then
    14371584    pnlInfo.Visible := true;
     
    14391586  aScrollBox.VertScrollBar.Visible := true;
    14401587  aScrollBox.HorzScrollBar.Visible := false;
     1588  if (aScrollBox.ControlCount > FGraphSetting.MaxGraphs)
     1589  or (aScrollBox.Height < FGraphSetting.MinGraphHeight) then
     1590    aMemo.Visible:= true;
    14411591end;
    14421592
     
    15121662  BigTime, SmallTime: TDateTime;
    15131663  ChildControl: TControl;
     1664  aChart: TChart;
    15141665begin
    15151666  if not (Sender is TChart) then exit;
     1667  aChart := (Sender as TChart);
     1668  if Not Assigned(FGraphSetting) then Exit;
     1669 
    15161670  if not FGraphSetting.VerticalZoom then
    15171671  begin
    15181672    padding := 0; //(FYMaxValue - FYMinValue) * ((100 - ZOOM_PERCENT) * 0.01);
    1519     (Sender as TChart).LeftAxis.Maximum := BIG_NUMBER;    // avoid min>max error
    1520     (Sender as TChart).LeftAxis.Minimum := -BIG_NUMBER;
    1521     (Sender as TChart).LeftAxis.Maximum := FYMaxValue + padding;    //padding 0?
    1522     (Sender as TChart).LeftAxis.Minimum := FYMinValue - padding;    //padding 0?
    1523   end;
    1524   SmallTime := (Sender as TChart).BottomAxis.Minimum;
    1525   BigTime := (Sender as TChart).BottomAxis.Maximum;
     1673    aChart.LeftAxis.Maximum := BIG_NUMBER;    // avoid min>max error
     1674    aChart.LeftAxis.Minimum := -BIG_NUMBER;
     1675    aChart.LeftAxis.Maximum := FYMaxValue + padding;    //padding 0?
     1676    aChart.LeftAxis.Minimum := FYMinValue - padding;    //padding 0?
     1677  end;
     1678  SmallTime := aChart.BottomAxis.Minimum;
     1679  BigTime := aChart.BottomAxis.Maximum;
    15261680  if BigTime < SmallTime then BigTime := SmallTime;   // avoid min>max error
    15271681  for i := 0 to scrlTop.ControlCount - 1 do
     
    15371691  end;
    15381692  SizeDates(chartDatelineBottom, SmallTime, BigTime);
    1539   if FMouseDown and (Sender as TChart).Zoomed then
     1693  if FMouseDown and aChart.Zoomed then
    15401694  begin
    15411695    datehx := FloatToStr(SmallTime) + '^' + FloatToStr(BigTime);
    1542     lstZoomHistory.Items.Add(datehx);
     1696    GtslZoomHistoryFloat.Add(datehx);
    15431697    mnuPopGraphZoomBack.Enabled := true;
    15441698    FMouseDown := false;
     
    15531707  BigTime, SmallTime: TDateTime;
    15541708  ChildControl: TControl;
     1709  aChart: TChart;
    15551710begin
    15561711  if not (Sender is TChart) then exit;
     1712  aChart:= (Sender as TChart);
    15571713  FRetainZoom := false;
    15581714  mnuPopGraphZoomBack.Enabled := false;
    1559   lstZoomHistory.Items.Clear;
     1715  GtslZoomHistoryFloat.Clear;
    15601716  if not FGraphSetting.VerticalZoom then
    15611717  begin
    15621718    padding := 0; //(FYMaxValue - FYMinValue) * ((100 - ZOOM_PERCENT) * 0.01);
    1563     (Sender as TChart).LeftAxis.Maximum := BIG_NUMBER;    // avoid min>max error
    1564     (Sender as TChart).LeftAxis.Minimum := -BIG_NUMBER;
    1565     (Sender as TChart).LeftAxis.Maximum := FYMaxValue + padding;    //padding 0?
    1566     (Sender as TChart).LeftAxis.Minimum := FYMinValue - padding;    //padding 0?
    1567   end;
    1568   SmallTime := (Sender as TChart).BottomAxis.Minimum;
    1569   BigTime := (Sender as TChart).BottomAxis.Maximum;
     1719    aChart.LeftAxis.Maximum := BIG_NUMBER;    // avoid min>max error
     1720    aChart.LeftAxis.Minimum := -BIG_NUMBER;
     1721    aChart.LeftAxis.Maximum := FYMaxValue + padding;    //padding 0?
     1722    aChart.LeftAxis.Minimum := FYMinValue - padding;    //padding 0?
     1723  end;
     1724  SmallTime := aChart.BottomAxis.Minimum;
     1725  BigTime := aChart.BottomAxis.Maximum;
    15701726  if BigTime < SmallTime then BigTime := SmallTime;   // avoid min>max error
    15711727  for i := 0 to scrlTop.ControlCount - 1 do
     
    15841740  begin
    15851741    FMouseDown := false;
    1586     pnlInfo.Caption := '';
    1587     pnlInfo.Color := COLOR_INFO;
    1588     pnlInfo.Visible := false;
     1742    InfoMessage('', COLOR_INFO, false);
    15891743    pnlHeader.Visible := false;
    15901744  end;
     
    15941748var
    15951749  datediff, yeardiff: integer;
     1750  pad: double;
    15961751begin
    15971752  with aChart.BottomAxis do
     
    16171772    end;
    16181773  end;
     1774  GraphFooter(aChart, datediff, aSmallTime);
     1775  pad := (aBigTime - aSmallTime) * 0.07;
     1776  SeriesForLabels(aChart, 'serNonNumBottom', pad);
     1777  SeriesForLabels(aChart, 'serNonNumTop', pad);
     1778  if length(aChart.Hint) > 0 then SeriesForLabels(aChart, 'serComments', pad);
     1779end;
     1780
     1781procedure TfrmGraphs.SeriesForLabels(aChart: TChart; aID: string; pad: double);
     1782var
     1783  i: integer;
     1784  aPointSeries: TPointSeries;
     1785  max, min: double;
     1786begin
     1787  for i := 0 to aChart.SeriesCount - 1 do
     1788  begin
     1789    if aChart.Series[i].Identifier = aID then
     1790    begin
     1791      aPointSeries := (aChart.Series[i] as TPointSeries);
     1792      aPointSeries.Clear;
     1793      if aID = 'serNonNumBottom' then
     1794      begin
     1795        min := aChart.LeftAxis.Minimum;
     1796        if min > aChart.MinYValue(aChart.LeftAxis) then
     1797           min := aChart.MinYValue(aChart.LeftAxis);
     1798        if min < 0 then min := 0;
     1799        aPointSeries.AddXY(aChart.BottomAxis.Minimum, min, '', clTeeColor) ;
     1800      end
     1801      else if aID  = 'serNonNumTop' then
     1802      begin
     1803        max := aChart.LeftAxis.Maximum;
     1804        if max < aChart.MaxYValue(aChart.LeftAxis) then
     1805           max := aChart.MaxYValue(aChart.LeftAxis);
     1806        aPointSeries.AddXY(aChart.BottomAxis.Minimum, max, '', clTeeColor) ;
     1807      end
     1808      else if aID = 'serComments' then
     1809      begin
     1810        min := aChart.MinYValue(aChart.LeftAxis);
     1811        if aChart.SeriesCount = 2 then        // only 1 series (besides comment)
     1812          if aChart.Series[0].Count = 1 then  // only 1 numeric
     1813            min := min - 1;                   // force comment label to bottom
     1814        if min < 0 then min := 0;
     1815        aPointSeries.AddXY((aChart.BottomAxis.Maximum - pad), min, '', clTeeColor) ;
     1816      end;
     1817      aPointSeries.Marks.Visible := true;
     1818      break;
     1819    end;
     1820  end;
     1821end;
     1822
     1823procedure TfrmGraphs.GraphFooter(aChart: TChart; datediff: integer; aDate: TDateTime);
     1824begin
    16191825  if datediff < 1 then
    16201826  begin
     
    16221828    begin
    16231829      aChart.Foot.Text.Clear;
    1624       aChart.Foot.Text.Insert(0, FormatDateTime('mmm d, yyyy', aSmallTime));
     1830      aChart.Foot.Text.Insert(0, FormatDateTime('mmm d, yyyy', aDate));
    16251831      aChart.Foot.Font.Color := clBtnText;
    16261832      aChart.Foot.Visible := true;
     
    16341840  TListView; aPadPanel: TPanel; section: string);
    16351841var
    1636   acnt, bcnt, displayheight, displaynum, gcnt, graphtype, i, j, lcnt, ncnt, pcnt, vcnt: integer;
    1637   aTitle, checkdata, filetype, high, low, specimen, specnum, typeitem, units: string;
    1638   newchart: TChart;
    1639   aGraphItem: TGraphItem;
     1842  displayheight, displaynum, i: integer;
    16401843begin
    16411844  FNonNumerics := false;
     
    16541857    chartDatelineBottom.OnMouseMove := nil;
    16551858  end;
    1656   pcnt := 0; gcnt := 0; vcnt := 0; lcnt := 0; ncnt := 0; bcnt := 0; acnt := 0;
    1657   for j := 0 to aListView.Items.Count - 1 do
    1658   if aListView.Items[j].Selected then
    1659   begin
    1660     aGraphItem := TGraphItem(aListView.Items.Item[j].SubItems.Objects[3]);
    1661     filetype := UpperCase(Piece(aGraphItem.Values, '^', 1));
    1662     typeitem := UpperCase(Piece(aGraphItem.Values, '^', 2));
    1663     graphtype := GraphTypeNum(filetype); //*****strtointdef(Piece(aListBox.Items[j], '^', 2), 1);
    1664     if (filetype = '63') and (lstData.Items.Count > 0) then
    1665     begin
    1666       checkdata := '';
    1667       for i := 0 to lstData.Items.Count - 1 do
    1668       begin
    1669         checkdata := lstData.Items[i];
    1670         if (Piece(checkdata, '^', 1) = '63') and (Piece(checkdata, '^', 2) = typeitem) then
    1671           break;
    1672       end;
    1673       specnum := Piece(checkdata, '^', 7);
    1674       specimen := Piece(checkdata, '^', 8);
    1675       RefUnits(typeitem, specnum, low, high, units);
    1676       units := LowerCase(units);
    1677       if units = '' then units := '  ';
    1678     end
    1679     else
    1680     begin
    1681       specimen := ''; low := ''; high := ''; units := '';
    1682     end;
    1683     aTitle := filetype + '^' + typeitem + '^' + aListView.Items[j].Caption + '^' +
    1684               specimen + '^' + low + '^' + high + '^' + units;
    1685     newchart := TChart.Create(self);
    1686     with newchart do
    1687     begin
    1688       Parent := aScrollBox;
    1689       View3D := false;
    1690       height := 170;
    1691       Align := alBottom;
    1692       Align := alTop;
    1693       AllowPanning := pmNone;
    1694       Legend.LegendStyle := lsSeries;
    1695       Legend.ShadowSize := 1;
    1696       Legend.Color := clCream;
    1697       Legend.VertMargin := 0;
    1698       Legend.Alignment := laTop;
    1699       Legend.Visible := true;
    1700       Gradient.EndColor := clGradientActiveCaption;
    1701       //SetPiece(aTitle, '^', 3, 'zzzz: ' + Piece(aTitle, '^', 3)); // test prefix
    1702       if (graphtype = 1) and (btnChangeSettings.Tag = 1) then
    1703         LeftAxis.Title.Caption := 'StdDev'
    1704       else if (graphtype = 1) and (btnChangeSettings.Tag = 2) then
    1705       begin
    1706         LeftAxis.Title.Caption := '1/' + units;
    1707         SetPiece(aTitle, '^', 3, 'Inverse ' + Piece(aTitle, '^', 3));
    1708       end
    1709       else
    1710         LeftAxis.Title.Caption := units;
    1711       if graphtype <> 1 then
    1712       begin
    1713         LeftAxis.Visible := false;
    1714         MarginLeft := round((50 / (pnlScrollTopBase.Width + 1)) * 100);       // ************* marginleft is a %
    1715       end;
    1716       BottomAxis.ExactDateTime := true;
    1717       BottomAxis.Increment := DateTimeStep[dtOneMinute];
    1718       HideDates(newchart);
    1719       BevelOuter := bvNone;
    1720       OnZoom := ChartOnZoom;
    1721       OnUndoZoom := ChartOnUndoZoom;
    1722       OnClickSeries := chartBaseClickSeries;
    1723       OnClickLegend := chartBaseClickLegend;
    1724       OnDblClick := mnuPopGraphDetailsClick;
    1725       OnMouseDown := chartBaseMouseDown;
    1726       if FGraphSetting.Hints then             //*****
    1727         OnMouseMove := chartBaseMouseMove
    1728       else
    1729         OnMouseMove := nil;
    1730     end;
    1731     splGraphs.Tag := 1;    // show ref ranges
    1732     if graphtype = 4 then graphtype := 2;         // change points to be bars
    1733     case graphtype of
    1734       1:  MakeLineSeries(newchart, aTitle, filetype, lcnt, ncnt, false);
    1735       2:  MakeBarSeries(newchart, aTitle, filetype, bcnt);
    1736       3:  MakeVisitGanttSeries(newchart, aTitle, filetype, vcnt);
    1737       4:  MakePointSeries(newchart, aTitle, filetype, pcnt);
    1738       5:  MakeArrowSeries(newchart, aTitle, filetype, acnt);
    1739       6:  MakeGanttSeries(newchart, aTitle, filetype, gcnt);
    1740       7:  MakeAGanttSeries(newchart, aTitle, filetype, gcnt);
    1741       8:  MakeManyGanttSeries(newchart, aTitle, filetype, gcnt);
    1742       9:  MakeWeightedArrowSeries(newchart, aTitle, filetype, acnt);
    1743      10:  MakeWeightedGanttSeries(newchart, aTitle, filetype, gcnt);
    1744     end;
    1745   end;
     1859  MakeSeparateItems(aScrollBox, aListView, section);
    17461860  if section = 'top' then
    17471861  begin
     
    17731887      Controls[i].height := displayheight;
    17741888  end;
    1775   if (FGraphSetting.HighTime = FGraphSetting.LowTime)
    1776   or (lcnt = 1) or (pcnt = 1) or (bcnt = 1) or (vcnt = 1) then
    1777   begin
    1778     FGraphSetting.HighTime := FGraphSetting.HighTime + 1;
    1779     FGraphSetting.LowTime := FGraphSetting.LowTime - 1;
    1780   end;
    17811889  AdjustTimeframe;
    17821890  if chartDatelineTop.Visible then chartDatelineTop.ZoomPercent(ZOOM_PERCENT);
     
    17871895end;
    17881896
     1897function TfrmGraphs.TitleInfo(filetype, typeitem, caption: string): string;
     1898var
     1899  i: integer;
     1900  checkdata, high, low, specimen, specnum, units: string;
     1901begin
     1902  if (filetype = '63') and (GtslData.Count > 0) then
     1903  begin
     1904    checkdata := '';
     1905    for i := 0 to GtslData.Count - 1 do
     1906    begin
     1907      checkdata := GtslData[i];
     1908      if (Piece(checkdata, '^', 1) = '63') and (Piece(checkdata, '^', 2) = typeitem) then
     1909        break;
     1910    end;
     1911    specnum := Piece(checkdata, '^', 7);
     1912    specimen := Piece(checkdata, '^', 8);
     1913    RefUnits(typeitem, specnum, low, high, units);
     1914    units := LowerCase(units);
     1915    if units = '' then units := '  ';
     1916  end
     1917  else
     1918  begin
     1919    specimen := ''; low := ''; high := ''; units := '';
     1920  end;
     1921  Result := filetype + '^' + typeitem + '^' + caption + '^' +
     1922            specimen + '^' + low + '^' + high + '^' + units + '^';
     1923end;
     1924
     1925procedure TfrmGraphs.MakeSeparateItems(aScrollBox: TScrollBox; aListView: TListView; section: string);
     1926var
     1927  bcnt, gcnt, graphtype, lcnt, ncnt, pcnt, vcnt: integer;
     1928  aTitle, filetype, typeitem: string;
     1929  newchart: TChart;
     1930  aGraphItem: TGraphItem;
     1931  aListItem: TListItem;
     1932begin
     1933  pcnt := 0; gcnt := 0; vcnt := 0; lcnt := 0; ncnt := 0; bcnt := 0;
     1934  aListItem := aListView.Selected;
     1935  while aListItem <> nil do
     1936  begin
     1937    aGraphItem := TGraphItem(aListItem.SubItems.Objects[3]);
     1938    filetype := UpperCase(Piece(aGraphItem.Values, '^', 1));
     1939    typeitem := UpperCase(Piece(aGraphItem.Values, '^', 2));
     1940    graphtype := GraphTypeNum(filetype); //*****strtointdef(Piece(aListBox.Items[j], '^', 2), 1);
     1941    aTitle := TitleInfo(filetype, typeitem, aListItem.Caption);
     1942    newchart := TChart.Create(self);
     1943    newchart.Tag := GtslNonNum.Count;
     1944    MakeChart(newchart, aScrollBox);
     1945    with newchart do
     1946    begin
     1947      Height := 170;
     1948      Align := alBottom;
     1949      Align := alTop;
     1950      Tag := aListItem.Index;
     1951      //SetPiece(aTitle, '^', 3, 'zzzz: ' + Piece(aTitle, '^', 3)); // test prefix
     1952      if (graphtype = 1) and (btnChangeSettings.Tag = 1) then
     1953        LeftAxis.Title.Caption := 'StdDev'
     1954      else if (graphtype = 1) and (btnChangeSettings.Tag = 2) then
     1955      begin
     1956        LeftAxis.Title.Caption := '1/' + Piece(aTitle, '^', 7);
     1957        SetPiece(aTitle, '^', 3, 'Inverse ' + Piece(aTitle, '^', 3));
     1958      end
     1959      else
     1960        LeftAxis.Title.Caption := Piece(aTitle, '^', 7);
     1961      if graphtype <> 1 then
     1962      begin
     1963        LeftAxis.Visible := false;
     1964        MarginLeft := PadLeftEvent(pnlScrollTopBase.Width);
     1965        //MarginLeft := round((65 / (pnlScrollTopBase.Width + 1)) * 100);       // ************* marginleft is a %
     1966      end;
     1967    end;
     1968    splGraphs.Tag := 1;    // show ref ranges
     1969    if graphtype = 4 then graphtype := 2;         // change points to be bars
     1970    case graphtype of
     1971      1:  MakeLineSeries(newchart, aTitle, filetype, section, lcnt, ncnt, false);
     1972      2:  MakeBarSeries(newchart, aTitle, filetype, bcnt);
     1973      3:  MakeVisitGanttSeries(newchart, aTitle, filetype, vcnt);
     1974      4:  MakePointSeries(newchart, aTitle, filetype, pcnt);
     1975      8:  MakeGanttSeries(newchart, aTitle, filetype, gcnt);
     1976    end;
     1977    MakeOtherSeries(newchart);
     1978    aListItem := aListView.GetNextItem(aListItem, sdAll, [isSelected]);
     1979  end;
     1980  if (FGraphSetting.HighTime = FGraphSetting.LowTime)
     1981  or (lcnt = 1) or (pcnt = 1) or (bcnt = 1) or (vcnt = 1) then
     1982  begin
     1983    FGraphSetting.HighTime := FGraphSetting.HighTime + 1;
     1984    FGraphSetting.LowTime := FGraphSetting.LowTime - 1;
     1985  end;
     1986end;
     1987
     1988function TfrmGraphs.PadLeftEvent(aWidth: integer): integer;
     1989begin
     1990  if aWidth < 50 then
     1991    Result := 10
     1992  else if aWidth < 100 then
     1993    Result := 36
     1994  else if aWidth < 200 then
     1995    Result := 28
     1996  else if aWidth < 220 then
     1997    Result := 24
     1998  else if aWidth < 240 then
     1999    Result := 23
     2000  else if aWidth < 270 then
     2001    Result := 21
     2002  else if aWidth < 300 then
     2003    Result := 18
     2004  else if aWidth < 400 then
     2005    Result := 14
     2006  else if aWidth < 500 then
     2007    Result := 11
     2008  else if aWidth < 600 then
     2009    Result := 10
     2010  else if aWidth < 700 then
     2011    Result := 9
     2012  else if aWidth < 800 then
     2013    Result := 8
     2014  else if aWidth < 900 then
     2015    Result := 7
     2016  else if aWidth < 1000 then
     2017    Result := 6
     2018  else
     2019    Result := 5;
     2020end;
     2021
     2022function TfrmGraphs.PadLeftNonNumeric(aWidth: integer): integer;
     2023begin
     2024  if aWidth < 50 then
     2025    Result := 10
     2026  else if aWidth < 100 then
     2027    Result := 36
     2028  else if aWidth < 200 then
     2029    Result := 16
     2030  else if aWidth < 220 then
     2031    Result := 14
     2032  else if aWidth < 240 then
     2033    Result := 12
     2034  else if aWidth < 270 then
     2035    Result := 10
     2036  else if aWidth < 300 then
     2037    Result := 9
     2038  else if aWidth < 400 then
     2039    Result := 8
     2040  else if aWidth < 500 then
     2041    Result := 7
     2042  else if aWidth < 600 then
     2043    Result := 6
     2044  else
     2045    Result := 5;
     2046end;
     2047
     2048procedure TfrmGraphs.MakeTogetherMaybe(aScrollBox: TScrollBox; aListView:
     2049  TListView; aPadPanel: TPanel; section: string);
     2050var
     2051  filetype: string;
     2052  aGraphItem: TGraphItem;
     2053  aListItem: TListItem;
     2054begin
     2055  FNonNumerics := false;
     2056  if section = 'top' then pnlItemsTop.Tag := 0 else pnlItemsBottom.Tag := 0;
     2057  if aListView.SelCount = 1 then                 // one lab test - make separate
     2058  begin
     2059    aListItem := aListView.Selected;
     2060    aGraphItem := TGraphItem(aListItem.SubItems.Objects[3]);
     2061    filetype := UpperCase(Piece(aGraphItem.Values, '^', 1));
     2062    if (filetype = '63') or (filetype = '120.5') then
     2063    begin
     2064      MakeSeparate(aScrollBox, aListView, aPadPanel, section);
     2065      exit;
     2066    end;
     2067  end;
     2068  MakeTogether(aScrollBox, aListView, aPadPanel, section);
     2069end;
     2070
    17892071procedure TfrmGraphs.MakeTogether(aScrollBox: TScrollBox; aListView:
    17902072  TListView; aPadPanel: TPanel; section: string);
    17912073var
    1792   anylines, nolines, onlylines, singlelabtest: boolean;
    1793   acnt, bcnt, cnt, gcnt, graphtype, i, j, lcnt, ncnt, pcnt, vcnt: integer;
     2074  anylines, nolines, onlylines, singlepoint: boolean;
     2075  bcnt, gcnt, graphtype, lcnt, pcnt, vcnt: integer;
    17942076  portion: double;
    1795   aTitle, checkdata, filetype, high, low, specimen, specnum, typeitem, units: string;
     2077  filetype, typeitem: string;
    17962078  newchart: TChart;
    17972079  aGraphItem: TGraphItem;
    1798 begin
    1799   pcnt := 0; gcnt := 0; lcnt := 0; ncnt := 0; bcnt := 0; acnt := 0;
     2080  aListItem: TListItem;
     2081begin
     2082  pcnt := 0; gcnt := 0; lcnt := 0; bcnt := 0; vcnt := 0;
    18002083  onlylines := true;
    18012084  anylines := false;
     
    18032086  FNonNumerics := false;
    18042087  if section = 'top' then pnlItemsTop.Tag := 0 else pnlItemsBottom.Tag := 0;
    1805   if FGraphSetting.Hints then       //******
    1806   begin
    1807     chartDatelineTop.OnMouseMove := chartBaseMouseMove;
    1808     chartDatelineBottom.OnMouseMove := chartBaseMouseMove;
    1809   end
    1810   else
    1811   begin
    1812     chartDatelineTop.OnMouseMove := nil;
    1813     chartDatelineBottom.OnMouseMove := nil;
    1814   end;
    1815   for j := 0 to aListView.Items.Count - 1 do
    1816   if aListView.Items[j].Selected then
    1817   begin
    1818     aGraphItem := TGraphItem(aListView.Items.Item[j].SubItems.Objects[3]);
     2088  aListItem := aListView.Selected;
     2089  while aListItem <> nil do
     2090  begin
     2091    aGraphItem := TGraphItem(aListItem.SubItems.Objects[3]);
    18192092    filetype := UpperCase(Piece(aGraphItem.Values, '^', 1));
    18202093    typeitem := UpperCase(Piece(aGraphItem.Values, '^', 2));
    1821     if aListView.SelCount = 1 then                 // one lab test - make separate
    1822     begin
    1823       if filetype = '63' then
    1824       begin
    1825         MakeSeparate(aScrollBox, aListView, aPadPanel, section);
    1826         exit;
    1827       end;
    1828     end;
    18292094    graphtype := GraphTypeNum(filetype);
    18302095    case graphtype of
     
    18332098    3: vcnt := vcnt + 1;
    18342099    4: pcnt := pcnt + 1;
    1835     5: acnt := acnt + 1;
    1836     6: gcnt := gcnt + 1;
    1837     7: gcnt := gcnt + 1;
    18382100    8: gcnt := gcnt + 1;
    1839     9: acnt := acnt + 1;
    18402101    end;
    18412102    if graphtype = 1 then
     
    18462107    else
    18472108      onlylines := false;
     2109    aListItem := aListView.GetNextItem(aListItem, sdAll, [isSelected]);
    18482110  end;
    18492111  if section = 'top' then
     
    18512113  else
    18522114    chkItemsBottom.Checked := false;
    1853   lstTempCheck.Items.Clear;
    1854   while aScrollBox.ControlCount > 0 do
    1855     aScrollBox.Controls[0].Free;
     2115  GtslTempCheck.Clear;
     2116  while aScrollBox.ControlCount > 0 do aScrollBox.Controls[0].Free;
    18562117  newchart := TChart.Create(self);  // whynot use base?
     2118  MakeChart(newchart, aScrollBox);
    18572119  with newchart do          // if a single line graph do lab stuff (ref range, units) ****************************************
    18582120  begin
    1859     Parent := aScrollBox;
    1860     View3D := false;
    1861     Chart3DPercent := 10;
    1862     AllowPanning := pmNone;
    18632121    Align := alClient;
    1864     Gradient.EndColor := clGradientActiveCaption;
    1865     Legend.LegendStyle := lsSeries;
    1866     Legend.ShadowSize := 1;
    1867     Legend.Color := clCream;
    1868     Legend.VertMargin := 0;
    1869     Legend.Alignment := laTop;
    1870     Legend.Visible := true;
    18712122    LeftAxis.Title.Caption := ' ';
    1872     BottomAxis.ExactDateTime := true;
    1873     BottomAxis.Increment := DateTimeStep[dtOneMinute];
    1874     HideDates(newchart);
    1875     BevelOuter := bvNone;
    1876     OnZoom := ChartOnZoom;
    1877     OnUndoZoom := ChartOnUndoZoom;
    1878     OnClickSeries := chartBaseClickSeries;
    1879     OnClickLegend := chartBaseClickLegend;
    1880     OnDblClick := mnuPopGraphDetailsClick;
    1881     OnMouseDown := chartBaseMouseDown;
    1882     if FGraphSetting.Hints then               //******
    1883       OnMouseMove := chartBaseMouseMove
    1884     else
    1885       OnMouseMove := nil;
    1886     Visible := false;
    18872123  end;
    18882124  aPadPanel.Visible := true;
    1889   portion := PortionSize(lcnt, pcnt, gcnt, vcnt, bcnt, acnt);
     2125  portion := PortionSize(lcnt, pcnt, gcnt, vcnt, bcnt);
    18902126  if section = 'top' then
    18912127    SizeTogether(onlylines, nolines, anylines, scrlTop, newchart,
     
    18972133  else splGraphs.Tag := 0;
    18982134
    1899   if nolines then
    1900   begin
    1901     pcnt := 0; gcnt := 0; vcnt := 0; bcnt := 0; acnt := 0;
    1902     for j := 0 to aListView.Items.Count - 1 do
    1903     if aListView.Items[j].Selected then
    1904     begin
    1905       aGraphItem := TGraphItem(aListView.Items.Item[j].SubItems.Objects[3]);
    1906       filetype := Piece(aGraphItem.Values, '^', 1);
    1907       typeitem := Piece(aGraphItem.Values, '^', 2);
    1908       aTitle := filetype + '^' + typeitem + '^' + aListView.Items[j].Caption + '^';
    1909       graphtype := GraphTypeNum(filetype);
    1910       if section = 'top' then
    1911         MakeDateline(section, aTitle, filetype, chartDatelineTop, graphtype, bcnt, pcnt, gcnt, vcnt, acnt)
    1912       else
    1913         MakeDateline(section, aTitle, filetype, chartDatelineBottom, graphtype, bcnt, pcnt, gcnt, vcnt, acnt);
    1914     end;
    1915     if section = 'top' then
    1916     begin
    1917       scrlTop.Align := alTop;
    1918       scrlTop.Height := 1; //pnlScrollTopBase.Height div 4;
    1919       pnlDatelineTop.Align := alClient;
    1920       pnlDatelineTop.Visible := true;
    1921     end
    1922     else
    1923     begin
    1924       scrlBottom.Align := alTop;
    1925       scrlBottom.Height := 1; //pnlScrollBottomBase.Height div 4;
    1926       pnlDatelineBottom.Align := alClient;
    1927       pnlDatelineBottom.Visible := true;
    1928     end;
    1929   end
    1930   else if onlylines then
    1931   begin
    1932     lcnt := 0;
    1933     for j := 0 to aListView.Items.Count - 1 do
    1934     if aListView.Items[j].Selected then
    1935     begin
    1936       aGraphItem := TGraphItem(aListView.Items.Item[j].SubItems.Objects[3]);
    1937       filetype := Piece(aGraphItem.Values, '^', 1);
    1938       typeitem := Piece(aGraphItem.Values, '^', 2);
    1939       if (filetype = '63') and (lstData.Items.Count > 0) then    //***********
    1940       begin
    1941         checkdata := '';
    1942         for i := 0 to lstData.Items.Count - 1 do
    1943         begin
    1944           checkdata := lstData.Items[i];
    1945           if (Piece(checkdata, '^', 1) = '63') and (Piece(checkdata, '^', 2) = typeitem) then
    1946             break;
    1947         end;
    1948         specnum := Piece(checkdata, '^', 7);
    1949         specimen := Piece(checkdata, '^', 8);
    1950         RefUnits(typeitem, specnum, low, high, units);
    1951         units := LowerCase(units);
    1952         if units = '' then units := '  ';
    1953       end
    1954       else
    1955       begin
    1956         specimen := ''; low := ''; high := ''; units := '';
    1957       end;
    1958       aTitle := filetype + '^' + typeitem + '^' + aListView.Items[j].Caption + '^' +
    1959                 specimen + '^' + low + '^' + high + '^' + units;
    1960       MakeLineSeries(newchart, aTitle, filetype, lcnt, ncnt, true)
    1961     end;
    1962     if section = 'top' then
    1963     begin
    1964       pnlDatelineTop.Align := alBottom;
    1965       pnlDatelineTop.Height := 5;
    1966       scrlTop.Align := alClient;
    1967       pnlDatelineTop.Visible := false;
    1968     end
    1969     else
    1970     begin
    1971       pnlDatelineBottom.Align := alBottom;
    1972       pnlDatelineBottom.Height := 5;
    1973       scrlBottom.Align := alClient;
    1974       pnlDatelineBottom.Visible := false;
    1975     end;
    1976     with newchart do
    1977     begin
    1978       if btnChangeSettings.Tag = 1 then
    1979         LeftAxis.Title.Caption := 'StdDev';
    1980       Visible := true;
    1981     end;
    1982   end
    1983   else if anylines then
    1984   begin
    1985     pcnt := 0; gcnt := 0; vcnt := 0; lcnt := 0; ncnt := 0; bcnt := 0; acnt := 0;
    1986     cnt := 0;
    1987     for j := 0 to aListView.Items.Count - 1 do
    1988     if aListView.Items[j].Selected then
    1989     begin
    1990       aGraphItem := TGraphItem(aListView.Items.Item[j].SubItems.Objects[3]);
    1991       filetype := Piece(aGraphItem.Values, '^', 1);
    1992       if filetype = '120.5' then
    1993       begin
    1994         cnt := BIG_NUMBER;
    1995         break;
    1996       end;
    1997       if filetype = '63' then
    1998         cnt := cnt + 1;
    1999       if cnt > 1 then
    2000         break;
    2001     end;
    2002     singlelabtest := cnt = 1;
    2003     for j := 0 to aListView.Items.Count - 1 do
    2004     if aListView.Items[j].Selected then
    2005     begin
    2006       aGraphItem := TGraphItem(aListView.Items.Item[j].SubItems.Objects[3]);
    2007       filetype := Piece(aGraphItem.Values, '^', 1);
    2008       typeitem := Piece(aGraphItem.Values, '^', 2);
    2009       if (filetype = '63') and (lstData.Items.Count > 0) then    //***********
    2010       begin
    2011         checkdata := '';
    2012         for i := 0 to lstData.Items.Count - 1 do
    2013         begin
    2014           checkdata := lstData.Items[i];
    2015           if (Piece(checkdata, '^', 1) = '63') and (Piece(checkdata, '^', 2) = typeitem) then
    2016             break;
    2017         end;
    2018         specnum := Piece(checkdata, '^', 7);
    2019         specimen := Piece(checkdata, '^', 8);
    2020         RefUnits(typeitem, specnum, low, high, units);
    2021         units := LowerCase(units);
    2022         if units = '' then units := '  ';
    2023       end
    2024       else
    2025       begin
    2026         specimen := ''; low := ''; high := ''; units := '';
    2027       end;
    2028       aTitle := filetype + '^' + typeitem + '^' + aListView.Items[j].Caption + '^' +
    2029                 specimen + '^' + low + '^' + high + '^' + units;
    2030       graphtype := GraphTypeNum(filetype);
    2031       if graphtype = 1 then
    2032       begin
    2033         if btnChangeSettings.Tag = 1 then
    2034           newchart.LeftAxis.Title.Caption := 'StdDev'
    2035         else
    2036           newchart.LeftAxis.Title.Caption := units;
    2037         if singlelabtest then
    2038           splGraphs.Tag := 1
    2039         else
    2040           splGraphs.Tag := 0;
    2041         MakeLineSeries(newchart, aTitle, filetype, lcnt, ncnt, true);
    2042       end
    2043       else if section = 'top' then
    2044         MakeDateline(section, aTitle, filetype, chartDatelineTop, graphtype, bcnt, pcnt, gcnt, vcnt, acnt)
    2045       else
    2046         MakeDateline(section, aTitle, filetype, chartDatelineBottom, graphtype, bcnt, pcnt, gcnt, vcnt, acnt);
    2047     end;
    2048     if section = 'top' then
    2049     begin
    2050       scrlTop.Align := alTop;
    2051       pnlDatelineTop.Align := alBottom;
    2052       pnlDatelineTop.Height := pnlScrollTopBase.Height div 2;
    2053       scrlTop.Align := alClient;
    2054       pnlDatelineTop.Visible := true;
    2055     end
    2056     else
    2057     begin
    2058       scrlBottom.Align := alTop;
    2059       pnlDatelineBottom.Align := alBottom;
    2060       pnlDatelineBottom.Height := pnlScrollBottomBase.Height div 2;
    2061       scrlBottom.Align := alClient;
    2062       pnlDatelineBottom.Visible := true;
    2063     end;
    2064     with newchart do
    2065     begin
    2066       if btnChangeSettings.Tag = 1 then
    2067         LeftAxis.Title.Caption := 'StdDev';
    2068       Visible := true;
    2069     end;
    2070   end;
     2135  if nolines then MakeTogetherNoLines(aListView, section)
     2136  else if onlylines then MakeTogetherOnlyLines(aListView, section, newchart)
     2137  else if anylines then MakeTogetherAnyLines(aListView, section, newchart);
     2138  MakeOtherSeries(newchart);
     2139
     2140  singlepoint := (lcnt = 1) or (pcnt = 1) or (bcnt = 1) or (vcnt = 1);
     2141  GraphBoundry(singlepoint);
     2142  if FNonNumerics then
     2143    if section = 'top' then pnlItemsTop.Tag := 1
     2144    else pnlItemsBottom.Tag := 1;
     2145end;
     2146
     2147procedure TfrmGraphs.GraphBoundry(singlepoint: boolean);
     2148begin
    20712149  if (FGraphSetting.HighTime = FGraphSetting.LowTime)
    2072   or (lcnt = 1) or (pcnt = 1) or (bcnt = 1) or (acnt = 1) or (vcnt = 1) then
     2150  or singlepoint then
    20732151  begin
    20742152    FGraphSetting.HighTime := FGraphSetting.HighTime + 1;
     
    20792157    chartDatelineBottom.LeftAxis.Maximum := chartDatelineBottom.LeftAxis.Maximum + 0.5;
    20802158  end;
     2159  if FGraphSetting.Hints then
     2160  begin
     2161    chartDatelineTop.OnMouseMove := chartBaseMouseMove;
     2162    chartDatelineBottom.OnMouseMove := chartBaseMouseMove;
     2163  end
     2164  else
     2165  begin
     2166    chartDatelineTop.OnMouseMove := nil;
     2167    chartDatelineBottom.OnMouseMove := nil;
     2168  end;
    20812169  AdjustTimeframe;
    20822170  if chartDatelineTop.Visible then chartDatelineTop.ZoomPercent(ZOOM_PERCENT);
    20832171  if chartDatelineBottom.Visible then chartDatelineBottom.ZoomPercent(ZOOM_PERCENT);
    2084   if FNonNumerics then
    2085     if section = 'top' then pnlItemsTop.Tag := 1
    2086     else pnlItemsBottom.Tag := 1;
    2087 end;
    2088 
    2089 function TfrmGraphs.PortionSize(lcnt, pcnt, gcnt, vcnt, bcnt, acnt: integer): double;
     2172end;
     2173
     2174procedure TfrmGraphs.MakeTogetherNoLines(aListView: TListView; section: string);
     2175var
     2176  bcnt, gcnt, graphtype, pcnt, vcnt: integer;
     2177  aTitle, filetype, typeitem: string;
     2178  aGraphItem: TGraphItem;
     2179  aListItem: TListItem;
     2180begin
     2181  pcnt := 0; gcnt := 0; vcnt := 0; bcnt := 0;
     2182  aListItem := aListView.Selected;
     2183  while aListItem <> nil do
     2184  begin
     2185    aGraphItem := TGraphItem(aListItem.SubItems.Objects[3]);
     2186    filetype := Piece(aGraphItem.Values, '^', 1);
     2187    typeitem := Piece(aGraphItem.Values, '^', 2);
     2188    aTitle := filetype + '^' + typeitem + '^' + aListItem.Caption + '^';
     2189    graphtype := GraphTypeNum(filetype);
     2190    if section = 'top' then
     2191      MakeDateline(section, aTitle, filetype, chartDatelineTop, graphtype, bcnt, pcnt, gcnt, vcnt)
     2192    else
     2193      MakeDateline(section, aTitle, filetype, chartDatelineBottom, graphtype, bcnt, pcnt, gcnt, vcnt);
     2194    aListItem := aListView.GetNextItem(aListItem, sdAll, [isSelected]);
     2195  end;
     2196  if section = 'top' then
     2197  begin
     2198    scrlTop.Align := alTop;
     2199    scrlTop.Height := 1; //pnlScrollTopBase.Height div 4;
     2200    pnlDatelineTop.Align := alClient;
     2201    pnlDatelineTop.Visible := true;
     2202  end
     2203  else
     2204  begin
     2205    scrlBottom.Align := alTop;
     2206    scrlBottom.Height := 1; //pnlScrollBottomBase.Height div 4;
     2207    pnlDatelineBottom.Align := alClient;
     2208    pnlDatelineBottom.Visible := true;
     2209  end;
     2210end;
     2211
     2212procedure TfrmGraphs.MakeTogetherOnlyLines(aListView: TListView; section: string; aChart: TChart);
     2213var
     2214  lcnt, ncnt: integer;
     2215  aTitle, filetype, typeitem: string;
     2216  aGraphItem: TGraphItem;
     2217  aListItem: TListItem;
     2218begin
     2219  lcnt := 0;
     2220  aListItem := aListView.Selected;
     2221  while aListItem <> nil do
     2222  begin
     2223    aGraphItem := TGraphItem(aListItem.SubItems.Objects[3]);
     2224    filetype := Piece(aGraphItem.Values, '^', 1);
     2225    typeitem := Piece(aGraphItem.Values, '^', 2);
     2226    aTitle := TitleInfo(filetype, typeitem, aListItem.Caption);
     2227    MakeLineSeries(aChart, aTitle, filetype, section, lcnt, ncnt, true);
     2228    if FDisplayFreeText = true then DisplayFreeText(aChart);
     2229    aListItem := aListView.GetNextItem(aListItem, sdAll, [isSelected]);
     2230  end;
     2231  if section = 'top' then
     2232  begin
     2233    pnlDatelineTop.Align := alBottom;
     2234    pnlDatelineTop.Height := 5;
     2235    scrlTop.Align := alClient;
     2236    pnlDatelineTop.Visible := false;
     2237  end
     2238  else
     2239  begin
     2240    pnlDatelineBottom.Align := alBottom;
     2241    pnlDatelineBottom.Height := 5;
     2242    scrlBottom.Align := alClient;
     2243    pnlDatelineBottom.Visible := false;
     2244  end;
     2245  with aChart do
     2246  begin
     2247    if btnChangeSettings.Tag = 1 then
     2248      LeftAxis.Title.Caption := 'StdDev';
     2249    Visible := true;
     2250  end;
     2251end;
     2252
     2253procedure TfrmGraphs.MakeTogetherAnyLines(aListView: TListView; section: string; aChart: TChart);
     2254var
     2255  singletest: boolean;
     2256  bcnt, gcnt, graphtype, lcnt, ncnt, pcnt, vcnt: integer;
     2257  aTitle, filetype, typeitem: string;
     2258  aGraphItem: TGraphItem;
     2259  aListItem: TListItem;
     2260begin
     2261  singletest := SingleLabTest(aListView);
     2262  pcnt := 0; gcnt := 0; vcnt := 0; lcnt := 0; bcnt := 0;
     2263  aListItem := aListView.Selected;
     2264  while aListItem <> nil do
     2265  begin
     2266    aGraphItem := TGraphItem(aListItem.SubItems.Objects[3]);
     2267    filetype := Piece(aGraphItem.Values, '^', 1);
     2268    typeitem := Piece(aGraphItem.Values, '^', 2);
     2269    aTitle := TitleInfo(filetype, typeitem, aListItem.Caption);
     2270    graphtype := GraphTypeNum(filetype);
     2271    if graphtype = 1 then
     2272    begin
     2273      if btnChangeSettings.Tag = 1 then
     2274        aChart.LeftAxis.Title.Caption := 'StdDev'
     2275      else
     2276        aChart.LeftAxis.Title.Caption := Piece(aTitle, '^', 7);
     2277      if singletest then
     2278        splGraphs.Tag := 1
     2279      else
     2280        splGraphs.Tag := 0;
     2281      MakeLineSeries(aChart, aTitle, filetype, section, lcnt, ncnt, true);
     2282      if FDisplayFreeText = true then DisplayFreeText(aChart);
     2283    end
     2284    else if section = 'top' then
     2285      MakeDateline(section, aTitle, filetype, chartDatelineTop, graphtype, bcnt, pcnt, gcnt, vcnt)
     2286    else
     2287      MakeDateline(section, aTitle, filetype, chartDatelineBottom, graphtype, bcnt, pcnt, gcnt, vcnt);
     2288    aListItem := aListView.GetNextItem(aListItem, sdAll, [isSelected]);
     2289  end;
     2290  if section = 'top' then
     2291  begin
     2292    scrlTop.Align := alTop;
     2293    pnlDatelineTop.Align := alBottom;
     2294    pnlDatelineTop.Height := pnlScrollTopBase.Height div 2;
     2295    scrlTop.Align := alClient;
     2296    pnlDatelineTop.Visible := true;
     2297  end
     2298  else
     2299  begin
     2300    scrlBottom.Align := alTop;
     2301    pnlDatelineBottom.Align := alBottom;
     2302    pnlDatelineBottom.Height := pnlScrollBottomBase.Height div 2;
     2303    scrlBottom.Align := alClient;
     2304    pnlDatelineBottom.Visible := true;
     2305  end;
     2306  with aChart do
     2307  begin
     2308    if btnChangeSettings.Tag = 1 then
     2309      LeftAxis.Title.Caption := 'StdDev';
     2310    Visible := true;
     2311  end;
     2312end;
     2313
     2314function TfrmGraphs.SingleLabTest(aListView: TListView): boolean;
     2315var
     2316  cnt: integer;
     2317  filetype: string;
     2318  aGraphItem: TGraphItem;
     2319  aListItem: TListItem;
     2320begin
     2321  cnt := 0;
     2322  aListItem := aListView.Selected;
     2323  while aListItem <> nil do
     2324  begin
     2325    aGraphItem := TGraphItem(aListItem.SubItems.Objects[3]);
     2326    filetype := Piece(aGraphItem.Values, '^', 1);
     2327    if filetype = '120.5' then
     2328    begin
     2329      cnt := BIG_NUMBER;
     2330      break;
     2331    end;
     2332    if filetype = '63' then
     2333      cnt := cnt + 1;
     2334    if cnt > 1 then
     2335      break;
     2336    aListItem := aListView.GetNextItem(aListItem, sdAll, [isSelected]);
     2337  end;
     2338  Result := (cnt = 1);
     2339end;
     2340
     2341procedure TfrmGraphs.MakeChart(aChart: TChart; aScrollBox: TScrollBox);
     2342begin
     2343  with aChart do
     2344  begin
     2345    Parent := aScrollBox;
     2346    View3D := false;
     2347    Chart3DPercent := 10;
     2348    AllowPanning := pmNone;
     2349    Gradient.EndColor := clGradientActiveCaption;
     2350    Gradient.StartColor := clWindow;
     2351    Legend.LegendStyle := lsSeries;
     2352    Legend.ShadowSize := 1;
     2353    Legend.Color := clCream;
     2354    Legend.VertMargin := 0;
     2355    Legend.Alignment := laTop;
     2356    Legend.Visible := true;
     2357    BottomAxis.ExactDateTime := true;
     2358    BottomAxis.Increment := DateTimeStep[dtOneMinute];
     2359    HideDates(aChart);
     2360    BevelOuter := bvNone;
     2361    OnZoom := ChartOnZoom;
     2362    OnUndoZoom := ChartOnUndoZoom;
     2363    OnClickSeries := chartBaseClickSeries;
     2364    OnClickLegend := chartBaseClickLegend;
     2365    OnDblClick := mnuPopGraphDetailsClick;
     2366    OnMouseDown := chartBaseMouseDown;
     2367    OnMouseUp := chartBaseMouseUp;
     2368    if FGraphSetting.Hints then
     2369      OnMouseMove := chartBaseMouseMove
     2370    else
     2371      OnMouseMove := nil;
     2372  end;
     2373end;
     2374
     2375procedure TfrmGraphs.MakeSeriesInfo(aChart: TChart; aSeries: TChartSeries; aTitle, aFileType: string; aSerCnt: integer);
     2376begin
     2377  with aSeries do
     2378  begin
     2379    Active := true;
     2380    ParentChart := aChart;
     2381    Title := Piece(aTitle, '^', 3);
     2382    GetData(aTitle);
     2383    Identifier := aFileType;
     2384    SeriesColor := NextColor(aSerCnt);
     2385    ColorEachPoint := false;
     2386    ShowInLegend := true;
     2387    Marks.Style := smsLabel;
     2388    Marks.BackColor := clInfoBk;
     2389    Marks.Frame.Visible := true;
     2390    Marks.Visible := false;
     2391    OnGetMarkText := serDatelineTop.OnGetMarkText;
     2392    XValues.DateTime := True;
     2393    GetHorizAxis.ExactDateTime := True;
     2394    GetHorizAxis.Increment := DateTimeStep[dtOneMinute];
     2395  end;
     2396end;
     2397
     2398procedure TfrmGraphs.MakeSeriesPoint(aChart: TChart; aPointSeries: TPointSeries);
     2399begin
     2400  with aPointSeries do
     2401  begin
     2402    Active := true;
     2403    ParentChart := aChart;
     2404    Title := '';
     2405    Identifier := '';
     2406    SeriesColor := aChart.Color;
     2407    ColorEachPoint := false;
     2408    ShowInLegend := false;
     2409    Marks.Style := smsLabel;
     2410    Marks.BackColor := clInfoBk;
     2411    Marks.Frame.Visible := true;
     2412    Marks.Visible := false;
     2413    OnGetMarkText := serDatelineTop.OnGetMarkText;
     2414    XValues.DateTime := true;
     2415    Pointer.Visible := true;
     2416    Pointer.InflateMargins := true;
     2417    Pointer.Style := psSmallDot;
     2418    Pointer.Pen.Visible := true;
     2419  end;
     2420end;
     2421
     2422procedure TfrmGraphs.MakeSeriesRef(aChart: TChart; aTest, aRef: TLineSeries; aTitle, aValue: string; aDate: double);
     2423var
     2424  value: double;
     2425begin
     2426  with aRef do
     2427  begin
     2428    Active := true;
     2429    ParentChart := aChart;
     2430    XValues.DateTime := True;
     2431    Pointer.Visible := false;
     2432    Pointer.InflateMargins := true;
     2433    OnGetMarkText := serDatelineTop.OnGetMarkText;
     2434    ColorEachPoint := false;
     2435    Title := aTitle + aValue;
     2436    Pointer.Style := psCircle;
     2437    SeriesColor := clTeeColor; //aTest.SeriesColor; // clBtnShadow;  //
     2438    Marks.Visible := false;
     2439    LinePen.Visible := true;
     2440    LinePen.Width := 1;
     2441    LinePen.Style := psDash;  //does not show when width <> 1
     2442  end;
     2443  value := strtofloatdef(aValue, -BIG_NUMBER);
     2444  if value <> -BIG_NUMBER then
     2445  begin
     2446    aRef.AddXY(IncDay(FGraphSetting.LowTime, -1), value, '', clTeeColor);
     2447    aRef.AddXY(IncDay(FGraphSetting.HighTime, 1), value, '', clTeeColor);
     2448    BorderValue(aDate, value);
     2449  end;
     2450end;
     2451
     2452procedure TfrmGraphs.MakeSeriesBP(aChart: TChart; aTest, aBP: TLineSeries; aFileType: string);
     2453begin
     2454  with aBP do
     2455  begin
     2456    ParentChart := aChart;
     2457    Title := 'Blood Pressure';
     2458    XValues.DateTime := true;
     2459    Pointer.Style := aTest.Pointer.Style;
     2460    ShowInLegend := false;    //****
     2461    Identifier := aFileType;
     2462    Pointer.Visible := true;
     2463    Pointer.InflateMargins := true;
     2464    ColorEachPoint := false;
     2465    SeriesColor := aTest.SeriesColor;
     2466    Marks.BackColor := clInfoBk;
     2467  end;
     2468end;
     2469
     2470procedure TfrmGraphs.MakeOtherSeries(aChart: TChart);
     2471begin
     2472  if GtslNonNum.Count > 0 then
     2473  begin
     2474    MakeNonNumerics(aChart);
     2475    if FDisplayFreeText = true then DisplayFreeText(aChart);
     2476  end;
     2477  if length(aChart.Hint) > 0 then
     2478  begin
     2479    MakeComments(aChart);
     2480  end;
     2481end;
     2482
     2483procedure TfrmGraphs.MakeComments(aChart: TChart);
     2484var
     2485  serComment: TPointSeries;
     2486begin
     2487  serComment := TPointSeries.Create(aChart);
     2488  MakeSeriesPoint(aChart, serComment);
     2489  with serComment do
     2490  begin
     2491    Identifier := 'serComments';
     2492    Title := TXT_COMMENTS;
     2493    SeriesColor := clTeeColor;
     2494    Marks.ArrowLength := -24;
     2495    Marks.Visible := true;
     2496    end;
     2497end;
     2498
     2499procedure TfrmGraphs.MakeNonNumerics(aChart: TChart);
     2500var
     2501  nonnumericonly, nonnumsection: boolean;
     2502  i, bmax, tmax: integer;
     2503  padvalue, highestvalue, lowestvalue, diffvalue: double;
     2504  astring, listofseries, section: string;
     2505  serBlank: TPointSeries;
     2506begin
     2507  if aChart.Parent = scrlBottom then section := 'bottom'
     2508  else section := 'top';
     2509  nonnumericonly := true;
     2510  for i := 0 to aChart.SeriesCount - 1 do
     2511  begin
     2512    if (aChart.Series[i] is TLineSeries) then
     2513      if aChart.Series[i].Count > 0 then
     2514      begin
     2515        nonnumericonly := false;
     2516        break;
     2517      end;
     2518  end;
     2519  PadNonNum(aChart, section, listofseries, bmax, tmax);
     2520  if bmax = 0 then bmax := 1;
     2521  if tmax = 0 then tmax := 1;
     2522  if nonnumericonly then
     2523  begin
     2524    highestvalue := 1;
     2525    lowestvalue := 0;
     2526  end
     2527  else
     2528  begin
     2529    highestvalue := aChart.MaxYValue(aChart.LeftAxis);
     2530    lowestvalue := aChart.MinYValue(aChart.LeftAxis);
     2531  end;
     2532  diffvalue := highestvalue - lowestvalue;
     2533  if diffvalue = 0 then
     2534    padvalue := highestvalue / 2
     2535  else
     2536    padvalue := POINT_PADDING * diffvalue;
     2537  highestvalue := highestvalue + (tmax * padvalue);
     2538  lowestvalue := lowestvalue - (bmax * padvalue);
     2539  if not (aChart.MinYValue(aChart.LeftAxis) < 0) then
     2540  begin
     2541    if highestvalue < 0 then highestvalue := 0;
     2542    if lowestvalue < 0 then lowestvalue := 0;
     2543  end;
     2544  if lowestvalue > highestvalue then
     2545     lowestvalue := highestvalue;
     2546  aChart.LeftAxis.Maximum := highestvalue;
     2547  aChart.LeftAxis.Minimum := lowestvalue;
     2548  nonnumsection := false;
     2549  for i := 0 to GtslNonNum.Count - 1 do
     2550  begin
     2551    astring := GtslNonNum[i];
     2552    if Piece(astring, '^', 7) = section then
     2553    begin
     2554      nonnumsection := true;
     2555      break;
     2556    end;
     2557  end;
     2558  if nonnumericonly and nonnumsection then
     2559  begin
     2560    serBlank := TPointSeries.Create(aChart);
     2561    MakeSeriesPoint(aChart, serBlank);
     2562    with serBlank do
     2563    begin
     2564      AddXY(aChart.BottomAxis.Minimum, highestvalue, '', aChart.Color);
     2565      AddXY(aChart.BottomAxis.Minimum, lowestvalue, '', aChart.Color);
     2566    end;
     2567    aChart.LeftAxis.Labels := false;
     2568    aChart.MarginLeft := PadLeftNonNumeric(pnlScrollTopBase.Width);
     2569    //aChart.MarginLeft := round((40 / (pnlScrollTopBase.Width + 1)) * 100);       // ************* marginleft is a %
     2570    ChartOnUndoZoom(aChart);
     2571  end;
     2572  MakeNonNumSeries(aChart, padvalue, highestvalue, lowestvalue, listofseries, section);
     2573end;
     2574
     2575procedure TfrmGraphs.MakeNonNumSeries(aChart: TChart; padvalue, highestvalue, lowestvalue: double; listofseries, section: string);
     2576var
     2577  asernum, i, j, originalindex, linenum, offset: integer;
     2578  nonvalue, graphvalue: double;
     2579  avalue, line: string;
     2580  adatetime: TDateTime;
     2581  serPoint: TPointSeries;
     2582begin
     2583  for j := 2 to BIG_NUMBER do
     2584  begin
     2585    line := Piece(listofseries, '^' , j);
     2586    if length(line) < 1 then break;
     2587    linenum := strtointdef(line, -BIG_NUMBER);
     2588    if linenum = -BIG_NUMBER then break;
     2589    serPoint := TPointSeries.Create(aChart);
     2590    MakeSeriesPoint(aChart, serPoint);
     2591    with serPoint do
     2592    begin
     2593      serPoint.Title := '(non-numeric)';
     2594      serPoint.Identifier := (aChart.Series[linenum] as TCustomSeries).Title;
     2595      serPoint.Pointer.Style := (aChart.Series[linenum] as TCustomSeries).Pointer.Style;
     2596      serPoint.SeriesColor := (aChart.Series[linenum] as TCustomSeries).SeriesColor;
     2597      serPoint.Tag := BIG_NUMBER + linenum;
     2598    end;
     2599    for i := 0 to GtslNonNum.Count - 1 do
     2600    begin
     2601      avalue := GtslNonNum[i];
     2602      if Piece(avalue, '^', 7) = section then
     2603      begin
     2604        originalindex := strtointdef(Piece(avalue, '^', 3), 0);
     2605        if originalindex = linenum then
     2606        begin
     2607          adatetime := strtofloatdef(Piece(avalue, '^', 1), -BIG_NUMBER);
     2608          asernum := aChart.Tag;
     2609          if adatetime = -BIG_NUMBER then break;
     2610          if asernum = strtointdef(Piece(avalue, '^', 2), -BIG_NUMBER) then
     2611          begin
     2612            offset := strtointdef(Piece(avalue, '^', 5), 1);
     2613            graphvalue := padvalue * offset;
     2614            if copy(Piece(avalue, '^', 13), 0, 1) = '>' then
     2615              nonvalue := highestvalue
     2616            else
     2617              nonvalue := lowestvalue;
     2618            nonvalue := nonvalue + graphvalue;
     2619            with serPoint do
     2620            begin
     2621              Hint := Piece(avalue, '^', 9);
     2622              AddXY(adatetime, nonvalue, '', serPoint.SeriesColor);
     2623            end;
     2624          end;
     2625        end;
     2626      end;
     2627    end;
     2628  end;
     2629end;
     2630
     2631procedure TfrmGraphs.StackNonNum(astring: string; var offset, bmax, tmax: integer; var blabelon, tlabelon: boolean);
     2632var
     2633  inlist: boolean;
     2634  i, lastnum, plusminus: integer;
     2635  checktime, lasttime, avalue: string;
     2636begin
     2637  inlist := false;
     2638  offset := 0;
     2639  checktime := Piece(astring, '^', 1);
     2640  if length(checktime) < 4 then exit;
     2641  if copy(Piece(astring, '^', 13), 0, 1) = '>' then
     2642  begin
     2643    checktime := checktime + ';t';    // top values will stack downwards
     2644    plusminus := -1;
     2645    tlabelon := true;
     2646  end
     2647  else
     2648  begin
     2649    checktime := checktime + ';b';    // bottom values will stack upwards
     2650    plusminus := 1;
     2651    blabelon := true;
     2652  end;
     2653  for i := 0 to GtslNonNumDates.Count - 1 do
     2654  begin
     2655    avalue := GtslNonNumDates[i];
     2656    lasttime := Piece(avalue, '^' , 1);
     2657    if checktime = lasttime then
     2658    begin
     2659      lastnum := strtointdef(Piece(avalue, '^', 2), 0);
     2660      offset := lastnum + 1;
     2661      if offset > 0 then bmax := bmax + 1
     2662      else tmax := tmax + 1;
     2663      GtslNonNumDates[i] := checktime + '^' + inttostr(offset * plusminus);
     2664      inlist := true;
     2665      break;
     2666    end;
     2667  end;
     2668  if not inlist then
     2669    GtslNonNumDates.Add(checktime + '^' + inttostr(offset * plusminus));
     2670end;
     2671
     2672procedure TfrmGraphs.PadNonNum(aChart: TChart; aSection: string; var listofseries: string; var bmax, tmax: integer);
     2673var
     2674  blabelon, tlabelon: boolean;
     2675  i, offset: integer;
     2676  charttag, newtime, lasttime, astring, avalue, newseries: string;
     2677  serNonNumBottom, serNonNumTop: TPointSeries;
     2678begin
     2679  GtslNonNumDates.Clear;
     2680  listofseries := '^';
     2681  blabelon := false; tlabelon := false;
     2682  bmax := 0; tmax := 0;
     2683  lasttime := '';
     2684  for i := 0 to GtslNonNum.Count - 1 do
     2685  begin
     2686    astring   := GtslNonNum[i];
     2687    if Piece(astring, '^', 7) = aSection then
     2688    begin
     2689      charttag := Piece(astring, '^', 2);
     2690      if charttag = inttostr(aChart.Tag) then
     2691      begin
     2692        newtime   := Piece(astring, '^', 1);
     2693        avalue    := Piece(astring, '^', 13);
     2694        newseries := '^' + Piece(astring, '^', 3) + '^';
     2695        if Pos(newseries, listofseries) = 0 then
     2696          listofseries := listofseries + Piece(astring, '^', 3) + '^';
     2697        StackNonNum(astring, offset, bmax, tmax, blabelon, tlabelon);
     2698        SetPiece(astring, '^', 5, inttostr(offset));
     2699        GtslNonNum[i] := astring;
     2700      end;
     2701    end;
     2702  end;
     2703  if blabelon then
     2704  begin
     2705    serNonNumBottom := TPointSeries.Create(aChart);
     2706    MakeSeriesPoint(aChart, serNonNumBottom);
     2707    with serNonNumBottom do
     2708    begin
     2709      Identifier := 'serNonNumBottom';
     2710      Title := TXT_NONNUMERICS;
     2711      Marks.ArrowLength := -11;
     2712      Marks.Visible := true;
     2713    end;
     2714  end;
     2715  if tlabelon then
     2716  begin
     2717    serNonNumTop := TPointSeries.Create(aChart);
     2718    MakeSeriesPoint(aChart, serNonNumTop);
     2719    with serNonNumTop do
     2720    begin
     2721      Identifier := 'serNonNumTop';
     2722      Title := TXT_NONNUMERICS;
     2723      Marks.ArrowLength := -11;
     2724      Marks.Visible := true;
     2725    end;
     2726  end;
     2727end;
     2728
     2729function TfrmGraphs.PortionSize(lcnt, pcnt, gcnt, vcnt, bcnt: integer): double;
    20902730var
    20912731  etotal, evalue, dvalue, value: double;
    20922732begin
    2093   dvalue := (gcnt + vcnt + acnt);
     2733  dvalue := (gcnt + vcnt);
    20942734  evalue := (pcnt + bcnt) / 2;
    20952735  etotal := dvalue + evalue;
     
    21082748
    21092749procedure TfrmGraphs.MakeDateline(section, aTitle, aFileType: string; aChart: TChart; graphtype: integer;
    2110   var bcnt, pcnt, gcnt, vcnt, acnt: integer);
     2750  var bcnt, pcnt, gcnt, vcnt: integer);
    21112751begin
    21122752  aChart.LeftAxis.Automatic := true;
     
    21172757    3:  MakeVisitGanttSeries(aChart, aTitle, aFileType, vcnt);
    21182758    4:  MakePointSeries(aChart, aTitle, aFileType, pcnt);
    2119     5:  MakeArrowSeries(aChart, aTitle, aFileType, acnt);
    2120     6:  MakeGanttSeries(aChart, aTitle, aFileType, gcnt);
    2121     7:  MakeAGanttSeries(aChart, aTitle, aFileType, gcnt);
    2122     8:  MakeManyGanttSeries(aChart, aTitle, aFileType, gcnt);
    2123     9:  MakeWeightedArrowSeries(aChart, aTitle, aFileType, acnt);
    2124    10:  MakeWeightedGanttSeries(aChart, aTitle, aFileType, gcnt);
     2759    8:  MakeGanttSeries(aChart, aTitle, aFileType, gcnt);
    21252760  end;
    21262761end;
     
    21582793      aChart.LeftAxis.Title.Caption := 'StdDev';
    21592794  end;
    2160 end;
    2161 
    2162 function TfrmGraphs.Vfactor(aTitle: string): double;  // returns first numbers in string
    2163 var
    2164   firstnum: boolean;
    2165   i: integer;
    2166   vfactor: string;
    2167 begin
    2168   vfactor := '';
    2169   firstnum := false;
    2170   for i := 0 to length(aTitle) - 1 do
    2171     if IsDelimiter('1234567890.', aTitle, i) then
    2172     begin
    2173       vfactor := vfactor + aTitle[i];
    2174       firstnum := true;
    2175     end
    2176     else
    2177       if firstnum = true then break;
    2178   Result := strtofloatdef(vfactor, 1);
    21792795end;
    21802796
     
    22102826var
    22112827  tempcheck: boolean;
    2212   bottomview, i, j, topview: integer;
    2213   typeitem: string;
     2828  bottomview, topview: integer;
    22142829  aGraphItem: TGraphItem;
     2830  aListItem: TListItem;
    22152831begin
    22162832  FFirstClick := true;
    22172833  if (lvwItemsTop.SelCount = 0) and (lvwItemsBottom.SelCount = 0) then exit;
    2218   topview := cboViewsTop.ItemIndex;
    2219   bottomview := cboViewsBottom.ItemIndex;
     2834  topview := lstViewsTop.ItemIndex;
     2835  bottomview := lstViewsBottom.ItemIndex;
    22202836  HideGraphs(true);
    22212837  with chkDualViews do
     
    22292845  chkItemsBottom.Checked := tempcheck;
    22302846  pnlBottom.Height := pnlMain.Height - pnlBottom.Height;
    2231   lstScratchSwap.Items.Clear;
     2847  GtslScratchSwap.Clear;
    22322848  if topview < 1 then
    2233     with lvwItemsTop do
    2234     for i := 0 to Items.Count - 1 do
    2235       if Items[i].Selected then
    2236       begin
    2237         aGraphItem := TGraphItem(Items.Item[i].SubItems.Objects[3]);
    2238         lstScratchSwap.Items.Add(aGraphItem.Values);
    2239       end;
     2849  begin
     2850    aListItem := lvwItemsTop.Selected;
     2851    while aListItem <> nil do
     2852    begin
     2853      aGraphItem := TGraphItem(aListItem.SubItems.Objects[3]);
     2854      GtslScratchSwap.Add(aGraphItem.Values);
     2855      aListItem := lvwItemsTop.GetNextItem(aListItem, sdAll, [isSelected]);
     2856    end;
     2857  end;
     2858  GraphSwap(bottomview, topview);
     2859  GtslScratchSwap.Clear;
     2860  HideGraphs(false);
     2861end;
     2862
     2863procedure TfrmGraphs.GraphSwap(bottomview, topview: integer);
     2864var
     2865  tempcheck: boolean;
     2866begin
     2867  FFirstClick := true;
     2868  if (lvwItemsTop.SelCount = 0) and (lvwItemsBottom.SelCount = 0) then exit;
     2869  topview := lstViewsTop.ItemIndex;
     2870  bottomview := lstViewsBottom.ItemIndex;
     2871  HideGraphs(true);
     2872  with chkDualViews do
     2873    if not Checked then
     2874    begin
     2875      Checked := true;
     2876      Click;
     2877    end;
     2878  tempcheck := chkItemsTop.Checked;
     2879  chkItemsTop.Checked := chkItemsBottom.Checked;
     2880  chkItemsBottom.Checked := tempcheck;
     2881  pnlBottom.Height := pnlMain.Height - pnlBottom.Height;
     2882  GtslScratchSwap.Clear;
     2883  GraphSwitch(bottomview, topview);
     2884  HideGraphs(false);
     2885end;
     2886
     2887procedure TfrmGraphs.GraphSwitch(bottomview, topview: integer);
     2888var
     2889  i, j: integer;
     2890  typeitem: string;
     2891  aGraphItem: TGraphItem;
     2892  aListItem: TListItem;
     2893begin
     2894  GtslScratchSwap.Clear;
     2895  if topview < 1 then
     2896  begin
     2897    aListItem := lvwItemsTop.Selected;
     2898    while aListItem <> nil do
     2899    begin
     2900      aGraphItem := TGraphItem(aListItem.SubItems.Objects[3]);
     2901      GtslScratchSwap.Add(aGraphItem.Values);
     2902      aListItem := lvwItemsTop.GetNextItem(aListItem, sdAll, [isSelected]);
     2903    end;
     2904  end;
    22402905  if bottomview > 0 then
    22412906  begin
    2242     cboViewsTop.ItemIndex := bottomview;
    2243     cboViewsTopChange(self);
     2907    lstViewsTop.ItemIndex := bottomview;
     2908    lstViewsTopChange(self);
    22442909  end
    22452910  else
    22462911  begin
    2247     cboViewsTop.ItemIndex := -1;
    2248     cboViewsTop.Text := '';
     2912    lstViewsTop.ItemIndex := -1;
    22492913    lvwItemsTop.ClearSelection;
    2250     with lvwItemsBottom do
    2251     for i := 0 to Items.Count - 1 do
    2252     if Items[i].Selected then
    2253     begin
    2254       aGraphItem := TGraphItem(Items.Item[i].SubItems.Objects[3]);
     2914    aListItem := lvwItemsBottom.Selected;
     2915    while aListItem <> nil do
     2916    begin
     2917      aGraphItem := TGraphItem(aListItem.SubItems.Objects[3]);
    22552918      typeitem := Pieces(aGraphItem.Values, '^', 1, 2);
    22562919      for j := 0 to lvwItemsTop.Items.Count - 1 do
     
    22632926        end;
    22642927      end;
     2928      aListItem := lvwItemsBottom.GetNextItem(aListItem, sdAll, [isSelected]);
    22652929    end;
    22662930    lvwItemsTopClick(self);
     
    22682932  if topview > 0 then
    22692933  begin
    2270     cboViewsBottom.ItemIndex := topview;
    2271     cboViewsBottomChange(self);
     2934    lstViewsBottom.ItemIndex := topview;
     2935    lstViewsBottomChange(self);
    22722936  end
    22732937  else
    22742938  begin
    2275     cboViewsBottom.ItemIndex := -1;
    2276     cboViewsBottom.Text := '';
     2939    lstViewsBottom.ItemIndex := -1;
    22772940    lvwItemsBottom.ClearSelection;
    2278     with lstScratchSwap do
    2279     for i := 0 to Items.Count - 1 do
     2941    for i := 0 to GtslScratchSwap.Count - 1 do
    22802942      for j := 0 to lvwItemsBottom.Items.Count - 1 do
    22812943      begin
    22822944        aGraphItem := TGraphItem(lvwItemsBottom.Items.Item[j].SubItems.Objects[3]);
    2283         if aGraphItem.Values = Items[i] then
     2945        if aGraphItem.Values = GtslScratchSwap[i] then
    22842946        begin
    22852947          lvwItemsBottom.Items[j].Selected := true;
     
    22892951    lvwItemsBottomClick(self);
    22902952  end;
    2291   lstScratchSwap.Items.Clear;
    2292   HideGraphs(false);
     2953  GtslScratchSwap.Clear;
    22932954end;
    22942955
    22952956procedure TfrmGraphs.mnuPopGraphSplitClick(Sender: TObject);
    2296 var
    2297   i: integer;
    2298   typeitem, typenum: string;
    2299   aGraphItem: TGraphItem;
    23002957begin
    23012958  FFirstClick := true;
     
    23082965      Click;
    23092966    end;
    2310   with cboViewsTop do
     2967  with lstViewsTop do
    23112968    if ItemIndex > -1 then
    23122969    begin
    23132970      ItemIndex := -1;
    2314       Text := '';
    2315     end;
    2316   with cboViewsBottom do
     2971    end;
     2972  with lstViewsBottom do
    23172973    if ItemIndex > -1 then
    23182974    begin
    23192975      ItemIndex := -1;
    2320       Text := '';
    2321     end;
     2976    end;
     2977    SplitClick;
     2978end;
     2979
     2980procedure TfrmGraphs.SplitClick;
     2981
     2982  procedure SplitGraphs(aListView: TListView);
     2983  var
     2984    typeitem: string;
     2985    aGraphItem: TGraphItem;
     2986    aListItem: TListItem;
     2987  begin
     2988    aListItem := lvwItemsTop.Selected;
     2989    while aListItem <> nil do
     2990    begin
     2991      aGraphItem := TGraphItem(aListItem.SubItems.Objects[3]);
     2992      typeitem := Pieces(aGraphItem.Values, '^', 1, 2);
     2993      GtslScratchSwap.Add(typeitem);
     2994      aListItem := lvwItemsTop.GetNextItem(aListItem, sdAll, [isSelected]);
     2995    end;
     2996  end;
     2997
     2998var
     2999  i: integer;
     3000  typeitem, typenum: string;
     3001begin
    23223002  chkItemsTop.Checked := true;
    23233003  chkItemsBottom.Checked := false;
    23243004  pnlBottom.Height := pnlMain.Height - pnlBottom.Height;
    2325   lstScratchSwap.Items.Clear;
    2326   with lvwItemsTop do
    2327     for i := 0 to Items.Count - 1 do
    2328     if Items[i].Selected then
    2329     begin
    2330       aGraphItem := TGraphItem(Items.Item[i].SubItems.Objects[3]);
    2331       typeitem := Pieces(aGraphItem.Values, '^', 1, 2);
    2332       lstScratchSwap.Items.Add(typeitem);
    2333     end;
    2334   with lvwItemsBottom do
    2335     for i := 0 to Items.Count - 1 do
    2336     if Items[i].Selected then
    2337     begin
    2338       aGraphItem := TGraphItem(Items.Item[i].SubItems.Objects[3]);
    2339       typeitem := Pieces(aGraphItem.Values, '^', 1, 2);
    2340       lstScratchSwap.Items.Add(typeitem);
    2341     end;
     3005  GtslScratchSwap.Clear;
     3006  SplitGraphs(lvwItemsTop);
     3007  SplitGraphs(lvwItemsBottom);
    23423008  lvwItemsTop.ClearSelection;
    23433009  lvwItemsBottom.ClearSelection;
    2344   with lstScratchSwap do
    2345     for i := 0 to Items.Count - 1 do
    2346     begin
    2347       typeitem := Items[i];
    2348       typenum := Piece(typeitem, '^', 1);
    2349       if (typenum = '63') or (typenum = '120.5') then
    2350         SelectItem(lvwItemsTop, typeitem)
    2351       else
    2352         SelectItem(lvwItemsBottom, typeitem);
    2353     end;
     3010  for i := 0 to GtslScratchSwap.Count - 1 do
     3011  begin
     3012    typeitem := GtslScratchSwap[i];
     3013    typenum := Piece(typeitem, '^', 1);
     3014    if (typenum = '63') or (typenum = '120.5') then
     3015      SelectItem(lvwItemsTop, typeitem)
     3016    else
     3017      SelectItem(lvwItemsBottom, typeitem);
     3018  end;
    23543019  lvwItemsTopClick(self);
    23553020  lvwItemsBottomClick(self);
    2356   lstScratchSwap.Items.Clear;
     3021  GtslScratchSwap.Clear;
    23573022  HideGraphs(false);
    23583023end;
     
    23823047  with FGraphSetting do View3D := not View3D;
    23833048  ChangeStyle;
     3049end;
     3050
     3051procedure TfrmGraphs.mnuPopGraphValueMarksClick(Sender: TObject);
     3052var
     3053  i: integer;
     3054begin
     3055  if (FGraphSeries is TPointSeries) and not (FGraphSeries is TGanttSeries) then
     3056  begin
     3057    if (FGraphSeries as TPointSeries).Pointer.Style = psSmallDot then exit;    // keep non-numeric label unchanged
     3058    if Piece(FGraphSeries.Title, '^', 1) = '(non-numeric)' then
     3059    begin
     3060      FGraphSeries.Marks.Visible := not FGraphSeries.Marks.Visible;
     3061      for i := 0 to FGraphClick.SeriesCount - 1 do
     3062      begin
     3063        if FGraphClick.Series[i].Title = FGraphSeries.Identifier then
     3064        begin
     3065          FGraphClick.Series[i].Marks.Visible := FGraphSeries.Marks.Visible;
     3066          if FGraphSeries.Title <> 'Blood Pressure' then break;
     3067        end;
     3068      end;
     3069    end;
     3070  end
     3071  else if chartDatelineTop.Tag = 1 then               // series
     3072  begin
     3073    FGraphSeries.Marks.Visible := not FGraphSeries.Marks.Visible;
     3074    for i := 0 to FGraphClick.SeriesCount - 1 do
     3075    begin
     3076      if (FGraphClick.Series[i].Identifier = FGraphSeries.Title)
     3077      or (FGraphClick.Series[i].Title = FGraphSeries.Title) then
     3078      begin
     3079        FGraphClick.Series[i].Marks.Visible := FGraphSeries.Marks.Visible;
     3080        if FGraphSeries.Title <> 'Blood Pressure' then break;
     3081      end;
     3082    end;
     3083  end;
    23843084end;
    23853085
     
    24253125  end;
    24263126  ChangeStyle;
    2427   // redisplay if nonnumericonly graph exists
     3127  // ???redisplay if nonnumericonly graph exists
    24283128  if pnlItemsTop.Tag = 1 then lvwItemsTopClick(self);
    24293129  if pnlItemsBottom.Tag = 1 then lvwItemsBottomClick(self);
     
    24503150end;
    24513151
     3152procedure TfrmGraphs.mnuPopGraphViewDefinitionClick(Sender: TObject);
     3153begin
     3154  mnuPopGraphViewDefinition.Checked := not mnuPopGraphViewDefinition.Checked;
     3155  if mnuPopGraphViewDefinition.Checked  then
     3156  begin
     3157    memViewsTop.Height := (tsTopViews.Height div 3) + 1;
     3158    memViewsBottom.Height := (tsBottomViews.Height div 3) + 1;
     3159  end
     3160  else
     3161  begin
     3162    memViewsTop.Height := 1;
     3163    memViewsBottom.Height := 1;
     3164  end;
     3165end;
     3166
    24523167procedure TfrmGraphs.mnuPopGraphDatesClick(Sender: TObject);
    24533168begin
     
    24603175  chkDualViews.Checked := not chkDualViews.Checked;
    24613176  chkDualViewsClick(self);
     3177end;
     3178
     3179procedure TfrmGraphs.mnuPopGraphExportClick(Sender: TObject);
     3180
     3181  procedure AddRow(worksheet: variant;
     3182    linestring, typename, itemname, date1, date2, result, other: string);
     3183  begin
     3184    worksheet.range('A' + linestring) := typename;
     3185    worksheet.range('B' + linestring) := itemname;
     3186    worksheet.range('C' + linestring) := date1;
     3187    worksheet.range('D' + linestring) := date2;
     3188    worksheet.range('E' + linestring) := result;
     3189    worksheet.range('F' + linestring) := other;
     3190  end;
     3191
     3192var
     3193  ok, topflag: boolean;
     3194  i, j, cnt: integer;
     3195  dtdata1, dtdata2, dtdate1, dtdate2: double;
     3196  StrForFooter, StrForHeader, aTitle, aDateRange, aCustomDateRange: String;
     3197  cdate, itemtype, item, itemtypename, itemname, typeitem, specnum: String;
     3198  datax, fmdate1, fmdate2, linestring: String;
     3199  aHeader: TStringList;
     3200  aGraphItem: TGraphItem;
     3201  aListItem: TListItem;
     3202  excelApp, workbook, worksheet: Variant;
     3203begin
     3204  if (lvwItemsTop.SelCount = 0) and (lvwItemsBottom.SelCount = 0) then
     3205  begin
     3206    ShowMessage('No Items selected.');
     3207    exit;
     3208  end;
     3209  try
     3210    excelApp := CreateOleObject('Excel.Application');
     3211  except
     3212    raise Exception.Create('Cannot start MS Excel!');
     3213  end;
     3214  topflag := mnuPopGraphStayOnTop.Checked and mnuPopGraphStayOnTop.Enabled;
     3215  Screen.Cursor := crDefault;
     3216  aTitle := 'CPRS Graphing';
     3217  dtdate1 := FGraphSetting.FMStartDate; //DateTimeToFMDateTime(FGraphSetting.LowTime);
     3218  dtdate2 := FGraphSetting.FMStopDate; //DateTimeToFMDateTime(FGraphSetting.HighTime);
     3219  dtdate1 := FMDateTimeOffsetBy(dtdate1, 1);   // add a day to start
     3220  dtdate2 := dtdate2;
     3221
     3222  if (length(cboDateRange.Text) < 25) and
     3223     (cboDateRange.Text <> 'All Results') and
     3224     (cboDateRange.Text <> 'Today') then
     3225    aDateRange :=  'Date Range: ' + cboDateRange.Text + '  Selected Items from ' +
     3226      FormatFMDateTime('mm/dd/yy', dtdate1) + ' to ' +
     3227      FormatFMDateTime('mm/dd/yy', dtdate2)
     3228  else
     3229    aDateRange :=  'Date Range: Selected Items from ' + cboDateRange.Text;
     3230  dtdate1 := DateTimeToFMDateTime(FGraphSetting.LowTime);
     3231  dtdate2 := DateTimeToFMDateTime(FGraphSetting.HighTime);
     3232  aCustomDateRange := cboDateRange.Items[cboDateRange.ItemIndex];
     3233  if Piece(aCustomDateRange, '^', 1) = '' then           // custom date range
     3234  begin
     3235    dtdate1 := strtofloat(Piece(aCustomDateRange, '^', 6));
     3236    dtdate2 := strtofloat(Piece(aCustomDateRange, '^', 7));
     3237  end;
     3238  aHeader := TStringList.Create;
     3239  CreateExcelPatientHeader(aHeader, aTitle, aDateRange);
     3240  StrForHeader := '';
     3241  for i := 0 to aHeader.Count - 1 do
     3242  begin
     3243    StrForHeader := StrForHeader + aHeader[i] + #13;
     3244  end;
     3245  if length(StrForHeader) > 250 then
     3246    StrForHeader := copy(StrForHeader, 1, 250) + #13;  // VB script in Excel is limited to 253
     3247  StrForFooter := aTitle + '                    *** WORK COPY ONLY ***                            '
     3248                + 'Printed: ' + FormatDateTime('mmm dd, yyyy  hh:nn', Now) + #13
     3249                + TXT_COPY_DISCLAIMER + #13;
     3250  excelApp.Visible := true;
     3251  workbook := excelApp.workbooks.add;
     3252  worksheet := workbook.worksheets.add;
     3253  worksheet.name := aTitle;
     3254  worksheet.PageSetup.PrintArea := '';
     3255  worksheet.PageSetup.TopMargin := 110;
     3256  worksheet.PageSetup.CenterHeader := StrForHeader;
     3257  worksheet.PageSetup.BottomMargin := 75;
     3258  worksheet.PageSetup.LeftFooter := StrForFooter;
     3259  worksheet.PageSetup.RightFooter := 'Page &P of &N';
     3260  worksheet.PageSetup.PrintTitleRows := '$1:$1';
     3261  worksheet.PageSetup.PrintTitleColumns := '$A:$F';
     3262  AddRow(worksheet, '1', 'Type', 'Item', 'Date', 'End Date', 'Value', 'Other');
     3263  cnt := 1;
     3264  aListItem := lvwItemsTop.Selected;
     3265  while aListItem <> nil do
     3266  begin
     3267    itemname := aListItem.Caption;
     3268    itemtypename := aListItem.SubItems[0];
     3269    aGraphItem := TGraphItem(aListItem.SubItems.Objects[3]);
     3270    typeitem := UpperCase(aGraphItem.Values);
     3271    if Piece(typeitem, '^', 1) = '63' then
     3272    begin
     3273      specnum := Piece(Piece(typeitem, '^', 2), '.', 2);
     3274      if length(specnum) > 0 then  // multispecimen
     3275        if specnum = '1' then
     3276          typeitem := Piece(typeitem, '.', 1)
     3277        else
     3278          typeitem := '';
     3279    end;
     3280    itemtype := Piece(typeitem, '^', 1);
     3281    item := Piece(typeitem, '^', 2);
     3282    for j := 0 to GtslData.Count - 1 do
     3283    begin
     3284      datax := GtslData[j];
     3285      if Piece(datax, '^', 1) = itemtype then
     3286        if Piece(datax, '^', 2) = item then
     3287        begin
     3288          dtdata1 := strtofloatdef(Piece(datax, '^', 3), -1);
     3289          fmdate1 := FormatFMDateTime('mm/dd/yy hh:nn', dtdata1);
     3290          if copy(fmdate1, length(fmdate1) - 5, length(fmdate1)) = ' 00:00' then
     3291            fmdate1 := copy(fmdate1, 1, length(fmdate1) - 5) + '     ';
     3292          cdate := Piece(datax, '^', 4);
     3293          if Piece(cdate, '.', 2) = '24' then cdate := Piece(cdate, '.', 1) + '.2359';
     3294          dtdata2 := strtofloatdef(cdate, -1);      // restrict to within date range
     3295          fmdate2 := FormatFMDateTime('mm/dd/yy hh:nn', dtdata2);
     3296          if copy(fmdate2, length(fmdate2) - 5, length(fmdate2)) = ' 00:00' then
     3297            fmdate2 := copy(fmdate2, 1, length(fmdate2) - 5) + '     ';
     3298          if dtdata2 > 0 then           
     3299            ok := (dtdata1 <= dtdate2) and (dtdata2 >= dtdate1) // overlap for durations
     3300          else
     3301            ok := (dtdata1 >= dtdate1) and (dtdata1 <= dtdate2); // inclusion for instances
     3302          if ok then
     3303          begin
     3304            cnt := cnt + 1;
     3305            linestring := inttostr(cnt);
     3306            AddRow(worksheet, linestring, itemtypename, itemname, fmdate1, fmdate2, Piece(datax, '^', 5), Piece(datax, '^', 8));
     3307          end;
     3308        end;
     3309    end;
     3310    aListItem := lvwItemsTop.GetNextItem(aListItem, sdAll, [isSelected]);
     3311  end;
     3312  if lvwItemsBottom.Items.Count > 0 then        //rewrite to combine
     3313  begin
     3314    cnt := cnt + 1;
     3315    linestring := inttostr(cnt);
     3316    AddRow(worksheet, linestring, '', '', '', '', '', '');
     3317    aListItem := lvwItemsBottom.Selected;
     3318    while aListItem <> nil do
     3319    begin
     3320      itemname := aListItem.Caption;
     3321      itemtypename := aListItem.SubItems[0];
     3322      aGraphItem := TGraphItem(aListItem.SubItems.Objects[3]);
     3323      typeitem := UpperCase(aGraphItem.Values);
     3324      if Piece(typeitem, '^', 1) = '63' then
     3325      begin
     3326        specnum := Piece(Piece(typeitem, '^', 2), '.', 2);
     3327        if length(specnum) > 0 then  // multispecimen
     3328          if specnum = '1' then
     3329            typeitem := Piece(typeitem, '.', 1)
     3330          else
     3331            typeitem := '';
     3332      end;
     3333      itemtype := Piece(typeitem, '^', 1);
     3334      item := Piece(typeitem, '^', 2);
     3335      for j := 0 to GtslData.Count - 1 do
     3336      begin
     3337        datax := GtslData[j];
     3338        if Piece(datax, '^', 1) = itemtype then
     3339          if Piece(datax, '^', 2) = item then
     3340          begin
     3341            dtdata1 := strtofloatdef(Piece(datax, '^', 3), -1);
     3342            fmdate1 := FormatFMDateTime('mm/dd/yy hh:nn', dtdata1);
     3343            if copy(fmdate1, length(fmdate1) - 5, length(fmdate1)) = ' 00:00' then
     3344              fmdate1 := copy(fmdate1, 1, length(fmdate1) - 5) + '     ';
     3345            cdate := Piece(datax, '^', 4);
     3346            if Piece(cdate, '.', 2) = '24' then cdate := Piece(cdate, '.', 1) + '.2359';
     3347            dtdata2 := strtofloatdef(cdate, -1);
     3348            fmdate2 := FormatFMDateTime('mm/dd/yy hh:nn', dtdata2);
     3349            if copy(fmdate2, length(fmdate2) - 5, length(fmdate2)) = ' 00:00' then
     3350              fmdate2 := copy(fmdate2, 1, length(fmdate2) - 5) + '     ';
     3351            if dtdata2 > 0 then           
     3352              ok := (dtdata1 <= dtdate2) and (dtdata2 >= dtdate1) // overlap for durations
     3353            else
     3354              ok := (dtdata1 >= dtdate1) and (dtdata1 <= dtdate2); // inclusion for instances
     3355            if ok then
     3356            begin
     3357              cnt := cnt + 1;
     3358              linestring := inttostr(cnt);
     3359              AddRow(worksheet, linestring, itemtypename, itemname, fmdate1, fmdate2, Piece(datax, '^', 5), Piece(datax, '^', 8));
     3360            end;
     3361          end;
     3362      end;
     3363      aListItem := lvwItemsBottom.GetNextItem(aListItem, sdAll, [isSelected]);
     3364    end;
     3365  end;
     3366  worksheet.Range['A1', 'F' + LineString].Columns.AutoFit;
     3367  worksheet.Range['A1', 'F' + LineString].Select;
     3368  worksheet.Range['A1', 'F' + LineString].AutoFormat(12, true, true, true, true, true, true);
     3369
     3370  if topflag then
     3371    mnuPopGraphStayOnTopClick(self);
     3372  Screen.Cursor := crDefault;
    24623373end;
    24633374
     
    24993410  with FGraphSetting do Legend := not Legend;
    25003411  ChangeStyle;
     3412end;
     3413
     3414procedure TfrmGraphs.ChartColor(aColor: TColor);
     3415begin
     3416  chartDatelineTop.Color := aColor;
     3417  chartDatelineTop.Legend.Color := aColor;
     3418  pnlDatelineTopSpacer.Color := aColor;
     3419  scrlTop.Color := aColor;
     3420  pnlTopRightPad.Color := aColor;
     3421  pnlScrollTopBase.Color := aColor;
     3422  pnlBlankTop.Color := aColor;
     3423  chartDatelineBottom.Color := aColor;
     3424  chartDatelineBottom.Legend.Color := aColor;
     3425  pnlDatelineBottomSpacer.Color := aColor;
     3426  scrlBottom.Color := aColor;
     3427  pnlBottomRightPad.Color := aColor;
     3428  pnlScrollBottomBase.Color := aColor;
     3429  pnlBlankBottom.Color := aColor;
    25013430end;
    25023431
     
    25383467      if Series[j] is TPointSeries then
    25393468        with (Series[j] as TPointSeries) do
     3469        if Pointer.Style <> psSmallDot then      // keep non-numeric label unchanged
    25403470        begin
    25413471          Marks.Visible := FGraphSetting.Values;
    25423472          LinePen.Visible := FGraphSetting.Lines;
     3473          if Title = '(non-numeric)' then Marks.Visible := FDisplayFreeText;
    25433474        end;
    25443475      if Series[j] is TBarSeries then
     
    25853516    ChartStyle(chartDateLineBottom);
    25863517  if FGraphSetting.ClearBackground then
    2587   begin
    2588     chartDatelineTop.Color := ClearColor;
    2589     chartDatelineTop.Legend.Color := ClearColor;
    2590     pnlDatelineTopSpacer.Color := ClearColor;
    2591     scrlTop.Color := ClearColor;
    2592     pnlTopRightPad.Color := ClearColor;
    2593     pnlScrollTopBase.Color := ClearColor;
    2594     pnlBlankTop.Color := ClearColor;
    2595     chartDatelineBottom.Color := ClearColor;
    2596     chartDatelineBottom.Legend.Color := ClearColor;
    2597     pnlDatelineBottomSpacer.Color := ClearColor;
    2598     scrlBottom.Color := ClearColor;
    2599     pnlBottomRightPad.Color := ClearColor;
    2600     pnlScrollBottomBase.Color := ClearColor;
    2601     pnlBlankBottom.Color := ClearColor;
    2602   end
     3518    ChartColor(ClearColor)
    26033519  else
    2604   begin
    2605     chartDatelineTop.Color := OriginalColor;
    2606     chartDatelineTop.Legend.Color := clCream;
    2607     pnlDatelineTopSpacer.Color := OriginalColor;
    2608     scrlTop.Color := OriginalColor;
    2609     pnlTopRightPad.Color := OriginalColor;
    2610     pnlScrollTopBase.Color := OriginalColor;
    2611     pnlBlankTop.Color := OriginalColor;
    2612     chartDatelineBottom.Color := OriginalColor;
    2613     chartDatelineBottom.Legend.Color := clCream;
    2614     pnlDatelineBottomSpacer.Color := OriginalColor;
    2615     scrlBottom.Color := OriginalColor;
    2616     pnlBottomRightPad.Color := OriginalColor;
    2617     pnlScrollBottomBase.Color := OriginalColor;
    2618     pnlBlankBottom.Color := OriginalColor;
    2619   end;
     3520    ChartColor(OriginalColor);
    26203521  mnuPopGraphLines.Checked := FGraphSetting.Lines;
    26213522  mnuPopGraph3D.Checked := FGraphSetting.View3D;
     
    26363537  ValueIndex: Integer; Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
    26373538var
    2638   dttm, seriestitle, textvalue, textvalue1, textvalue2, typename, typenum: string;
    2639 begin
     3539  lbutton: boolean;
     3540begin
     3541  if FOnMark then       // action already taken by mousedown on a mark
     3542  begin
     3543    FOnMark := false;
     3544    exit;
     3545  end;
     3546  FOnMark := false;
    26403547  timHintPause.Enabled := false;
    26413548  InactivateHint;
     
    26543561    FDate2 := FDate1;
    26553562  end;
    2656   seriestitle := Series.Title;
    2657   if Button <> mbRight then
    2658   begin
    2659     textvalue := ValueText(Sender, Series, ValueIndex);
     3563  lbutton := Button <> mbRight;
     3564  SeriesClicks(Sender as TChart, Series, ValueIndex, lbutton);
     3565  FMouseDown := false;
     3566end;
     3567
     3568
     3569procedure TfrmGraphs.SeriesClicks(aChart: TChart; aSeries: TChartSeries; aIndex: integer; lbutton: boolean);
     3570var
     3571  originalindex: integer;
     3572  dttm, seriestitle, showing, textvalue, textvalue1, textvalue2, typename, typenum: string;
     3573begin
     3574  if lbutton then
     3575  begin
     3576    textvalue := ValueText(aChart, aSeries, aIndex);
    26603577    dttm := Piece(textvalue, '^', 3);
    26613578    if copy(textvalue, length(textvalue) - 5, length(textvalue)) = ' 00:00' then
     
    26693586  else
    26703587  begin
     3588    seriestitle := Piece(aSeries.Title, '^', 1);
     3589    if seriestitle = '(non-numeric)' then
     3590    begin
     3591      originalindex := strtointdef(Piece(GtslNonNum[aIndex], '^', 3), 0);
     3592      seriestitle := Piece(aChart.Series[originalindex].Title, '^', 1);
     3593    end;
    26713594    mnuPopGraphIsolate.Enabled := true;
    26723595    if pnlTop.Tag = 1 then
     
    26763599    scrlTop.Hint := 'Details - for ' + seriestitle + ' for ' +
    26773600      FormatDateTime('mmm d, yyyy  h:nn am/pm', FDate1);
    2678     scrlTop.Tag := ValueIndex + 1;
     3601    scrlTop.Tag := aIndex + 1;
    26793602    mnuPopGraphIsolate.Hint := seriestitle;
    26803603    mnuPopGraphRemove.Enabled := true;
    26813604    mnuPopGraphRemove.Caption := 'Remove - ' + seriestitle;
    26823605    mnuPopGraphDetails.Caption := 'Details - ' + seriestitle;
    2683   end;
    2684   FMouseDown := false;
     3606    if FGraphSeries.Marks.Visible then showing := ' - turn off' else showing := ' - turn on';
     3607    mnuPopGraphValueMarks.Caption := 'Values - ' + seriestitle + showing;
     3608    mnuPopGraphValueMarks.Enabled := true;
     3609  end;
    26853610end;
    26863611
     
    26883613var
    26893614  i: integer;
    2690   dttm, datax, datex1, datex2, fmdate1, fmdate2, newdata, newline, oldline, spacer, titlemsg: string;
    2691   dt1, dt2, dtdata, dtdata1, dtdata2: double;
     3615  datex1, datex2, newline, oldline, spacer, titlemsg: string;
     3616  dt1, dt2: double;
    26923617  tmpOtherList, templist: TStringList;
    26933618begin
     
    27043629  dt2 := strtofloatdef(datex2, BIG_NUMBER);
    27053630  CheckToAddData(lvwItemsTop, 'top', aType);    // if type is not loaded - load data
    2706   for i := 0 to lstData.Items.Count - 1 do
    2707   begin
    2708     datax := lstData.Items[i];
     3631  TempData(tmpOtherList, aType, dt1, dt2);
     3632  with tmpOtherList do
     3633  begin
     3634    Sort;
     3635    for i := Count - 1 downto 0 do
     3636    begin
     3637      newline := '';
     3638      oldline := tmpOtherList[i];
     3639      newline := Piece(oldline, '^', 4) + '   ' + Piece(oldline, '^', 5);
     3640      spacer := Copy(BIG_SPACES, 1, 40 - length(newline));
     3641      newline := newline + spacer + ' ' + Piece(oldline, '^', 3);
     3642      templist.Add(newline);
     3643    end;
     3644    Clear;
     3645    FastAssign(templist, tmpOtherList);
     3646    //Assign(templist);
     3647    if aDate <> aDate2 then
     3648      titlemsg := aTypeName + ' occurences for ' + FormatDateTime('mmm d, yyyy', aDate) +
     3649        ' - ' + FormatDateTime('mmm d, yyyy', aDate2)
     3650    else
     3651      titlemsg := aTypeName + ' occurences for ' + FormatDateTime('mmm d, yyyy', aDate);
     3652    Insert(0, firstline);
     3653    Insert(1, secondline);
     3654    Insert(2, '');
     3655    Insert(3, 'All ' + titlemsg + ':');
     3656    Insert(4, '');
     3657    Insert(0, TXT_REPORT_DISCLAIMER);
     3658    Insert(1, '');
     3659    ReportBox(tmpOtherList, titlemsg, true);
     3660  end;
     3661  tmpOtherList.Free;
     3662  templist.Free;
     3663  Screen.Cursor := crDefault;
     3664end;
     3665
     3666procedure TfrmGraphs.TempData(aStringList: TStringList; aType: string; dt1, dt2: double);
     3667var
     3668  i: integer;
     3669  dttm, datax, fmdate1, fmdate2, newdata: string;
     3670  dtdata, dtdata1, dtdata2: double;
     3671begin
     3672  for i := 0 to GtslData.Count - 1 do
     3673  begin
     3674    datax := GtslData[i];
    27093675    if Piece(datax, '^', 1) = aType then
    27103676    begin
     
    27273693                     ItemName(aType, Piece(datax, '^', 2)) + '^' +
    27283694                     Piece(datax, '^', 5);
    2729           tmpOtherList.Add(MixedCase(newdata));
     3695          aStringList.Add(MixedCase(newdata));
    27303696        end;
    27313697      end
     
    27443710          dttm + '^' +
    27453711          ItemName(aType, Piece(datax, '^', 2));
    2746           tmpOtherList.Add(MixedCase(newdata));
     3712          aStringList.Add(MixedCase(newdata));
    27473713        end;
    27483714      end;
    27493715    end;
    27503716  end;
    2751   with tmpOtherList do
    2752   begin
    2753     Sort;
    2754     for i := Count - 1 downto 0 do
    2755     begin
    2756       newline := '';
    2757       oldline := tmpOtherList[i];
    2758       newline := Piece(oldline, '^', 4) + '   ' +
    2759         Piece(oldline, '^', 5);
    2760         spacer := Copy(BIG_SPACES, 1, 40 - length(newline));
    2761       newline := newline + spacer + ' ' +
    2762         Piece(oldline, '^', 3);
    2763       templist.Add(newline);
    2764     end;
    2765     Clear;
    2766     Assign(templist);
    2767     if aDate <> aDate2 then
    2768       titlemsg := aTypeName + ' occurences for ' + FormatDateTime('mmm d, yyyy', aDate) +
    2769         ' - ' + FormatDateTime('mmm d, yyyy', aDate2)
    2770     else
    2771       titlemsg := aTypeName + ' occurences for ' + FormatDateTime('mmm d, yyyy', aDate);
    2772     Insert(0, firstline);
    2773     Insert(1, secondline);
    2774     Insert(2, '');
    2775     Insert(3, 'All ' + titlemsg + ':');
    2776     Insert(4, '');
    2777     Insert(0, TXT_REPORT_DISCLAIMER);
    2778     Insert(1, '');
    2779     ReportBox(tmpOtherList, titlemsg, true);
    2780   end;
    2781   tmpOtherList.Free;
    2782   templist.Free;
    2783   Screen.Cursor := crDefault;
    2784 end;
    2785 
     3717end;
    27863718
    27873719procedure TfrmGraphs.ItemDateRange(Sender: TCustomChart);
     
    28193751    seriestitle := Sender.Series[i].Title;
    28203752    if seriestitle = 'Blood Pressure' then
    2821       if bpnotdone = false then ok := false;
     3753      if not bpnotdone then ok := false;
    28223754    if ok then
    28233755    begin
     
    28593791  aGraphItem: TGraphItem;
    28603792  aListView, aOtherListView: TListView;
     3793  aListItem: TListItem;
    28613794begin
    28623795  FFirstClick := true;
    2863   cboViewsTop.ItemIndex := -1;
    2864   cboViewsTop.Text := '';
    2865   cboViewsBottom.ItemIndex := -1;
    2866   cboViewsBottom.Text := '';
     3796  lstViewsTop.ItemIndex := -1;
     3797  lstViewsBottom.ItemIndex := -1;
    28673798  if pnlTop.Tag = 1 then
    28683799  begin
    2869     aListView := lvwItemsTop;
    2870     aOtherListView := lvwItemsBottom;
    2871     aSection := 'top';
    2872     aOtherSection := 'bottom';
     3800    aListView := lvwItemsTop;       aOtherListView := lvwItemsBottom;
     3801    aSection := 'top';              aOtherSection := 'bottom';
    28733802  end
    28743803  else
    28753804  begin
    2876     aListView := lvwItemsBottom;
    2877     aOtherListView := lvwItemsTop;
    2878     aSection := 'bottom';
    2879     aOtherSection := 'top';
     3805    aListView := lvwItemsBottom;    aOtherListView := lvwItemsTop;
     3806    aSection := 'bottom';           aOtherSection := 'top';
    28803807  end;
    28813808  if aListView.SelCount = 0 then exit;
    28823809  if StripHotKey(mnuPopGraphIsolate.Caption) = ('Move all selections to ' + aOtherSection) then
    28833810  begin
    2884     with aListView do
    2885     for i := 0 to Items.Count - 1 do
    2886     if Items[i].Selected then
    2887     begin
    2888       aGraphItem := TGraphItem(Items.Item[i].SubItems.Objects[3]);
     3811    aListItem := aListView.Selected;
     3812    while aListItem <> nil do
     3813    begin
     3814      aGraphItem := TGraphItem(aListItem.SubItems.Objects[3]);
    28893815      typeitem := Pieces(aGraphItem.Values, '^', 1, 2);
    28903816      for j := 0 to aOtherListView.Items.Count - 1 do
     
    28943820          aOtherListView.Items[j].Selected := true;
    28953821      end;
    2896       Items[i].Selected := false;
    2897     end;
    2898     with chkDualViews do
    2899     if not Checked then
    2900     begin
    2901       Checked := true;
    2902       Click;
    2903     end;
    2904     ChangeStyle;
    2905     DisplayData(aSection);
    2906     DisplayData(aOtherSection);
     3822      aListItem.Selected := false;
     3823      aListItem := aListView.GetNextItem(aListItem, sdAll, [isSelected]);
     3824    end;
    29073825  end
    29083826  else
     
    29173835    end;
    29183836    aListView.Items[selnum].Selected := false;
    2919     with chkDualViews do
    2920     if not Checked then
    2921     begin
    2922       Checked := true;
    2923       Click;
    2924     end;
    2925     ChangeStyle;
    2926     DisplayData(aSection);
    2927     DisplayData(aOtherSection);
    2928   end;
     3837  end;
     3838  with chkDualViews do
     3839  if not Checked then
     3840  begin
     3841    Checked := true;
     3842    Click;
     3843  end;
     3844  ChangeStyle;
     3845  DisplayData(aSection);
     3846  DisplayData(aOtherSection);
    29293847  mnuPopGraphIsolate.Enabled := false;
    29303848end;
     
    29673885procedure TfrmGraphs.chartBaseMouseDown(Sender: TObject; Button: TMouseButton;
    29683886  Shift: TShiftState; X, Y: Integer);
     3887var
     3888  lbutton: boolean;
    29693889begin
    29703890  FHintStop := true;
     
    29843904    mnuPopGraphIsolate.Caption := 'Move all selections to bottom';
    29853905    mnuPopGraphRemove.Caption := 'Remove all selections from top';
     3906    if memTop.Visible then
     3907      memTop.SetFocus;
    29863908  end
    29873909  else
     
    29893911    mnuPopGraphIsolate.Caption := 'Move all selections to top';
    29903912    mnuPopGraphRemove.Caption := 'Remove all selections from bottom';
    2991   end;
    2992   If Button = mbLeft then
     3913    if memBottom.Visible then
     3914      memBottom.SetFocus;
     3915  end;
     3916  if Button = mbLeft then
    29933917    FMouseDown := true;
     3918  lbutton := Button <> mbRight;
     3919  MouseClicks(Sender as TChart, lbutton, X, Y);
     3920end;
     3921
     3922procedure TfrmGraphs.MouseClicks(aChart: TChart; lbutton: boolean; X, Y: Integer);
     3923var
     3924  i, tmp: integer;
     3925  aSeries: TChartSeries;
     3926begin
     3927  tmp := -1;
     3928  for i := 0 to aChart.SeriesCount - 1 do
     3929  if aChart.Series[i].Marks.Visible then
     3930  begin
     3931    tmp := aChart.Series[i].Marks.Clicked(X, Y);
     3932    if tmp <> -1 then break;
     3933  end;
     3934  if tmp <> -1 then
     3935  begin
     3936    FOnMark := true;
     3937    aSeries := aChart.Series[i];
     3938    FGraphClick := aChart;
     3939    FGraphSeries := aSeries;
     3940    FGraphValueIndex := tmp;
     3941    chartDateLineTop.Tag := 1;       // indicates a series click
     3942    if (aSeries is TGanttSeries) then
     3943    begin
     3944      FDate1 := (aSeries as TGanttSeries).StartValues[tmp];
     3945      FDate2 := (aSeries as TGanttSeries).EndValues[tmp];
     3946    end
     3947    else
     3948    begin
     3949      FDate1 := aSeries.XValue[tmp];
     3950      FDate2 := FDate1;
     3951    end;
     3952    LabelClicks(aChart, aSeries, lbutton, tmp);
     3953    FMouseDown := false;
     3954    aChart.AllowZoom := false;
     3955  end;
     3956end;
     3957
     3958procedure TfrmGraphs.LabelClicks(aChart: TChart; aSeries: TChartSeries; lbutton: boolean; tmp: integer);
     3959var
     3960  firstnon, toggle: boolean;
     3961  i, originalindex: integer;
     3962  dttm, seriestitle, showing, textvalue, textvalue1, textvalue2, typename, typenum: string;
     3963begin
     3964    seriestitle := Piece(aSeries.Title, '^', 1);
     3965    if seriestitle = '(non-numeric)' then
     3966    begin
     3967      originalindex := strtointdef(Piece(GtslNonNum[tmp], '^', 3), 0);
     3968      seriestitle := Piece(aChart.Series[originalindex].Title, '^', 1);
     3969    end;
     3970    if (seriestitle = TXT_COMMENTS) and lbutton then
     3971    begin
     3972      chartDatelineTop.Tag := 0;
     3973      mnuPopGraphDetailsClick(self);
     3974    end
     3975    else if (seriestitle = TXT_NONNUMERICS) and lbutton then
     3976    begin
     3977      if (aSeries.Identifier = 'serNonNumBottom') or (aSeries.Identifier = 'serNonNumTop') then
     3978      begin
     3979        firstnon := true;
     3980        toggle := false;
     3981        for i := 0 to aChart.SeriesCount - 1 do
     3982        if Piece(aChart.Series[i].Title, '^', 1) = '(non-numeric)' then
     3983        begin
     3984          if firstnon then
     3985          begin
     3986           toggle := not aChart.Series[i].Marks.Visible;
     3987           firstnon := false;
     3988          end;
     3989          aChart.Series[i].Marks.Visible := toggle;
     3990        end;
     3991      end;
     3992    end
     3993    else if lbutton and (seriestitle <> TXT_NONNUMERICS) then
     3994    begin
     3995      textvalue := ValueText(aChart, aSeries, tmp);
     3996      dttm := Piece(textvalue, '^', 3);
     3997      if copy(textvalue, length(textvalue) - 5, length(textvalue)) = ' 00:00' then
     3998        dttm := Pieces(dttm, ' ', 1, 3);
     3999      textvalue1 := Piece(textvalue, '^', 2) + '  ' + dttm;
     4000      textvalue2 := Piece(textvalue, '^', 4) + '  ' + Piece(textvalue, '^', 5);
     4001      typenum := trim(Piece(textvalue, '^', 1));
     4002      typename := Piece(textvalue, '^', 2);
     4003      AllTypeDate(typenum, typename, textvalue1, textvalue2, FDate1, FDate2);
     4004    end
     4005    else if (Piece(aSeries.Title, '^', 1) <> TXT_NONNUMERICS)
     4006        and (Piece(aSeries.Title, '^', 1) <> TXT_COMMENTS) then
     4007    begin
     4008      mnuPopGraphIsolate.Enabled := true;
     4009      if pnlTop.Tag = 1 then
     4010        mnuPopGraphIsolate.Caption := 'Move - ' + seriestitle + ' - from Top to Bottom'
     4011      else
     4012        mnuPopGraphIsolate.Caption := 'Move - ' + seriestitle + ' - from Bottom to Top';
     4013      scrlTop.Hint := 'Details - for ' + seriestitle + ' for ' +
     4014        FormatDateTime('mmm d, yyyy  h:nn am/pm', FDate1);
     4015      scrlTop.Tag := tmp + 1;
     4016      mnuPopGraphIsolate.Hint := seriestitle;
     4017      mnuPopGraphRemove.Enabled := true;
     4018      mnuPopGraphRemove.Caption := 'Remove - ' + seriestitle;
     4019      mnuPopGraphDetails.Caption := 'Details - ' + seriestitle;
     4020      if FGraphSeries.Marks.Visible then showing := ' - turn off' else showing := ' - turn on';
     4021      mnuPopGraphValueMarks.Caption := 'Values - ' + seriestitle + showing;
     4022      mnuPopGraphValueMarks.Enabled := true;
     4023    end;
    29944024end;
    29954025
     
    30164046    mnuPopGraphDetails.Caption := 'Details...';
    30174047    mnuPopGraphDetails.Enabled := (lvwItemsTop.SelCount > 0) or (lvwItemsBottom.SelCount > 0);
     4048    mnuPopGraphValueMarks.Caption := 'Values - ';
     4049    mnuPopGraphValueMarks.Enabled := false;
    30184050  end
    30194051  else
     
    30224054    mnuPopGraphRemove.Enabled := true;
    30234055    mnuPopGraphDetails.Enabled := true;
    3024   end;
     4056    if chartDatelineTop.Tag <> -1 then
     4057      mnuPopGraphValueMarks.Enabled := true;
     4058  end;
     4059  {mnuPopGraphViewDefinition.Enabled := (pcTop.ActivePageIndex = 1)
     4060                                    or (pcBottom.ActivePageIndex = 1);}
    30254061  mnuPopGraphSwap.Enabled := (lvwItemsTop.SelCount > 0) or (lvwItemsBottom.SelCount > 0);
    30264062  mnuPopGraphReset.Enabled := mnuPopGraphSwap.Enabled;
    30274063  mnuPopGraphCopy.Enabled := mnuPopGraphSwap.Enabled;
    30284064  mnuPopGraphPrint.Enabled := mnuPopGraphSwap.Enabled;
    3029  
     4065  mnuPopGraphExport.Enabled := mnuPopGraphSwap.Enabled;
     4066
    30304067  with pnlMain.Parent do
    30314068  if BorderWidth <> 1 then            // only do on float Graph
     
    30374074procedure TfrmGraphs.mnuPopGraphDetailsClick(Sender: TObject);
    30384075var
    3039   aGraphItem: TGraphItem;
    30404076  tmpList: TStringList;
    30414077  date1, date2: TFMDateTime;
    30424078  teststring, typeitem, textvalue, textvalue1, textvalue2, typenum, typename: string;
    3043   i, selnum: integer;
     4079  selnum: integer;
     4080  aGraphItem: TGraphItem;
     4081  aListView: TListView;
     4082  aListItem: TListItem;
    30444083begin
    30454084  if chartDatelineTop.Tag = 1 then               // series
     
    30764115    tmpList := TStringList.Create;
    30774116    if pnlTop.Tag = 1 then
    3078     for i := 0  to lvwItemsTop.Items.Count - 1 do
    3079     begin
    3080       if lvwItemsTop.Items[i].Selected then
    3081       begin
    3082         aGraphItem := TGraphItem(lvwItemsTop.Items.Item[i].SubItems.Objects[3]);      //get file^ien match
    3083         teststring := aGraphItem.Values;
    3084         tmpList.Add(teststring);
    3085       end;
    3086     end
     4117      aListView := lvwItemsTop
    30874118    else
    3088     for i := 0  to lvwItemsBottom.Items.Count - 1 do
    3089     begin
    3090       if lvwItemsBottom.Items[i].Selected then
    3091       begin
    3092         aGraphItem := TGraphItem(lvwItemsBottom.Items.Item[i].SubItems.Objects[3]);    //get file^ien match
    3093         teststring := aGraphItem.Values;
    3094         tmpList.Add(teststring);
    3095       end;
     4119      aListView := lvwItemsBottom;
     4120    aListItem := aListView.Selected;
     4121    while aListItem <> nil do
     4122    begin
     4123      aGraphItem := TGraphItem(aListItem.SubItems.Objects[3]);      //get file^ien match
     4124      teststring := aGraphItem.Values;
     4125      tmpList.Add(teststring);
     4126      aListItem := aListView.GetNextItem(aListItem, sdAll, [isSelected]);
    30964127    end;
    30974128    if tmpList.Count > 0 then
     
    31004131  end;
    31014132  FMouseDown := false;
     4133  if (Sender is TChart) then
     4134    (Sender as TChart).AllowZoom := false;
    31024135end;
    31034136
    31044137procedure TfrmGraphs.AllDetails(aDate1, aDate2: TFMDateTime; aTempList: TStrings);
    31054138var
    3106   TypeList: TStringList;
    31074139  i: integer;
    31084140  detailsok: boolean;
    31094141  testnum, teststring, testtype: string;
    3110 begin
    3111   detailsok := true;
     4142  ztmpList: TStringList;
     4143  TypeList: TStringList;
     4144begin
     4145  //ShowMsg('This funtionality is currently unavailable.');
     4146  //exit;      // ****************** temporary 11-4-07
    31124147  TypeList := TStringList.Create;
     4148   detailsok := true;
    31134149  for i := 0 to aTempList.Count -1 do
    31144150  begin
     
    31274163  end;
    31284164  if detailsok then
    3129     ReportBox(rpcDetailSelected(Patient.DFN, aDate1, aDate2, TypeList, true), 'Graph results on ' + Patient.Name, True)
     4165  begin
     4166    ztmpList := TStringList.Create;
     4167    try
     4168      FastAssign(rpcDetailSelected(Patient.DFN, aDate1, aDate2, TypeList, true), ztmpList);
     4169      NotifyApps(ztmpList);
     4170      ReportBox(ztmpList, 'Graph results on ' + Patient.Name, True);
     4171    finally
     4172      ztmpList.Free;
     4173    end;
     4174  end
    31304175  else
    31314176    ItemDateRange(FGraphClick);
     
    31494194  titleitem := ItemName(Piece(aTypeItem, '^', 1), Piece(aTypeItem, '^', 2));
    31504195  rpcDetailDay(tmpList, Patient.DFN, date1, date2, aTypeItem, true);
     4196  NotifyApps(tmpList);
    31514197  ReportBox(tmpList, titletype + ': ' + titleitem + ' on ' + Patient.Name + ' for ' + FormatFMDateTime('mmm d, yyyy', date1), True);
    31524198  tmpList.Free;
    31534199end;
    31544200
    3155 procedure TfrmGraphs.mnuPopGraphCopyClick(Sender: TObject);
     4201procedure TfrmGraphs.NotifyApps(aList: TStrings);
    31564202var
    31574203  i: integer;
    3158   StrForFooter, StrForHeader, aTitle, aWarning, aDateRange: String;
    3159   aHeader: TStringList;
    3160   wrdApp, wrdDoc: Variant;
    3161   ChildControl: TControl;
    3162 begin
    3163   try
    3164     wrdApp := CreateOleObject('Word.Application');
    3165   except
    3166     raise Exception.Create('Cannot start MS Word!');
    3167   end;
    3168   Screen.Cursor := crHourGlass;
    3169   aTitle := 'CPRS Graphing';
    3170   aWarning := pnlInfo.Caption;
    3171   aDateRange :=  'Date Range: ' + cboDateRange.Text + '  Selected Items from ' +
    3172       FormatDateTime('mm/dd/yy', FGraphSetting.LowTime) + ' to ' +
    3173       FormatDateTime('mm/dd/yy', FGraphSetting.HighTime);
    3174   aHeader := TStringList.Create;
    3175   CreatePatientHeader(aHeader, aTitle, aWarning, aDateRange);
    3176   StrForHeader := '';
    3177   for i := 0 to aHeader.Count -1 do
    3178     StrForHeader := StrForHeader + aHeader[i] + Chr(13);
    3179   StrForFooter := aTitle + ' - *** WORK COPY ONLY ***' + Chr(13);
    3180   wrdApp.Visible := False;
    3181   wrdApp.Documents.Add;
    3182   wrdDoc := wrdApp.Documents.Item(1);
    3183   wrdDoc := wrdDoc.Sections.Item(1);
    3184   wrdDoc := wrdDoc.Headers.Item(1).Range;
    3185   wrdDoc.Font.Name := 'Courier New';
    3186   wrdDoc.Font.Size := 9;
    3187   wrdDoc.Text := StrForHeader;
    3188   wrdDoc := wrdApp.Documents.Item(1);
    3189   wrdDoc := wrdDoc.Sections.Item(1);
    3190   wrdDoc := wrdDoc.Footers.Item(1);
    3191   wrdDoc.Range.Font.Name := 'Courier New';
    3192   wrdDoc.Range.Font.Size := 9;
    3193   wrdDoc.Range.Text := StrForFooter;
    3194   wrdDoc.PageNumbers.Add;
    3195   wrdDoc := wrdApp.Documents.Item(1);
    3196   wrdDoc.Range.Font.Name := 'Courier New';
    3197   wrdDoc.Range.Font.Size := 9;
    3198   wrdDoc.Range.Text := StrForHeader;
    3199   wrdDoc.Range.InsertParagraphAfter;
    3200   for i := 0 to scrlTop.ControlCount - 1 do           // goes from top to bottom
    3201   begin
    3202     ChildControl := scrlTop.Controls[i];
    3203     if (ChildControl as TChart).Visible then
    3204     begin
    3205       (ChildControl as TChart).CopyToClipboardBitmap;
    3206       wrdDoc.Range.InsertParagraphAfter;
    3207       wrdDoc.Paragraphs.Last.Range.Paste;
    3208     end;
    3209   end;
    3210   if (chartDatelineTop.SeriesCount > 0) and (not chkItemsTop.Checked) then
    3211   begin
    3212     chartDatelineTop.CopyToClipboardBitmap;
    3213     wrdDoc.Range.InsertParagraphAfter;
    3214     wrdDoc.Paragraphs.Last.Range.Paste;
    3215   end;
    3216   wrdDoc.Range.InsertParagraphAfter;
    3217   wrdDoc.Paragraphs.Last.Range.Text := '   ';
    3218   for i := 0 to scrlBottom.ControlCount - 1 do
    3219   begin
    3220     ChildControl := scrlBottom.Controls[i];
    3221     if (ChildControl as TChart).Visible then
    3222     begin
    3223       (ChildControl as TChart).CopyToClipboardBitmap;
    3224       wrdDoc.Range.InsertParagraphAfter;
    3225       wrdDoc.Paragraphs.Last.Range.Paste;
    3226     end;
    3227   end;
    3228   if (chartDatelineBottom.SeriesCount > 0) and (chkDualViews.Checked)
    3229     and (not chkItemsBottom.Checked) then
    3230   begin
    3231     chartDatelineBottom.CopyToClipboardBitmap;
    3232     wrdDoc.Range.InsertParagraphAfter;
    3233     wrdDoc.Paragraphs.Last.Range.Paste;
    3234   end;
    3235   wrdDoc.Range.WholeStory;
    3236   wrdDoc.Range.Copy;
    3237   wrdDoc.Close(false);
    3238   wrdApp.DisplayAlerts := false;
    3239   wrdApp.Quit;
    3240   wrdApp := Unassigned; // releases variant
    3241   aHeader.Free;
    3242   Screen.Cursor := crDefault;
     4204  info, aID, aTag: string;
     4205begin
     4206  for i := aList.Count - 1 downto 0  do
     4207  begin
     4208    info := aList[i];
     4209    if Piece(info, '^', 1 ) = '~~~' then
     4210    begin
     4211      aList.Delete(i);
     4212      if length(Piece(info, '^', 11)) > 0 then
     4213      begin
     4214        aID := '';
     4215        aTag := 'SUR' + '^';
     4216        //NotifyOtherApps(NAE_REPORT, aTag + aID);
     4217      end;
     4218    end;
     4219  end;
    32434220end;
    32444221
     
    32504227  if Warning = TXT_INFO then Warning := '  ';
    32514228  with HeaderList do
    3252     begin
    3253       Add(' ');
    3254       Add(StringOfChar(' ', (74 - Length(PageTitle)) div 2) + PageTitle);
    3255       Add(' ');
    3256       tmpStr := Patient.Name + '   ' + Patient.SSN;
    3257       tmpItem := tmpStr + StringOfChar(' ', 39 - Length(tmpStr)) + Encounter.LocationName;
    3258       tmpStr := FormatFMDateTime('mmm dd, yyyy', Patient.DOB) + ' (' + IntToStr(Patient.Age) + ')';
    3259       tmpItem := tmpItem + StringOfChar(' ', 74 - (Length(tmpItem) + Length(tmpStr))) + tmpStr;
    3260       Add(tmpItem);
    3261       Add(StringOfChar('=', 74));
    3262       Add('*** WORK COPY ONLY ***' + StringOfChar(' ', 24) + 'Printed: '
    3263         + FormatFMDateTime('mmm dd, yyyy  hh:nn', FMNow));
    3264       Add(TXT_COPY_DISCLAIMER);
    3265       Add(StringOfChar(' ', (74 - Length(DateRange)) div 2) + DateRange);
    3266       Add(StringOfChar(' ', (74 - Length(Warning)) div 2) + Warning);
    3267       Add(' ');
    3268     end;
     4229  begin
     4230    Add(' ');
     4231    Add(StringOfChar(' ', (74 - Length(PageTitle)) div 2) + PageTitle);
     4232    Add(' ');
     4233    tmpStr := Patient.Name + '   ' + Patient.SSN;
     4234    tmpItem := tmpStr + StringOfChar(' ', 39 - Length(tmpStr)) + Encounter.LocationName;
     4235{ TODO -oRV -cWVEHR Long Age : Changed to use long age }
     4236    //tmpStr := FormatFMDateTime('mmm dd, yyyy', Patient.DOB) + ' (' + IntToStr(Patient.Age) + ')';
     4237    tmpStr := FormatFMDateTime('mmm dd, yyyy', Patient.DOB) + ' (' + GetPatientBriefAge(Patient.DFN) + ')';
     4238{}
     4239    tmpItem := tmpItem + StringOfChar(' ', 74 - (Length(tmpItem) + Length(tmpStr))) + tmpStr;
     4240    Add(tmpItem);
     4241    Add(StringOfChar('=', 74));
     4242    Add(' *** WORK COPY ONLY *** ' + StringOfChar(' ', 24) + 'Printed: '
     4243      + FormatFMDateTime('mmm dd, yyyy  hh:nn', FMNow));
     4244    Add('  ' + TXT_COPY_DISCLAIMER);
     4245    Add(StringOfChar(' ', (74 - Length(DateRange)) div 2) + DateRange);
     4246    Add(StringOfChar(' ', (74 - Length(Warning)) div 2) + Warning);
     4247    Add(' ');
     4248  end;
     4249end;
     4250
     4251procedure TfrmGraphs.CreateExcelPatientHeader(var HeaderList: TStringList; PageTitle, DateRange: string);
     4252// this procedure modified from rReports
     4253var
     4254  tmpItem: string;
     4255begin
     4256  with HeaderList do
     4257  begin
     4258    Add(' ');
     4259    Add(PageTitle);
     4260    Add(' ');
     4261    tmpItem := Patient.Name + '         ' + Patient.SSN + '          '
     4262             + Encounter.LocationName + '                            '
     4263             + FormatFMDateTime('mmm dd, yyyy', Patient.DOB) + ' (' + IntToStr(Patient.Age) + ')';
     4264    Add(tmpItem);
     4265    //Add(TXT_COPY_DISCLAIMER);  // put on footer to avoid length problems
     4266    Add(DateRange);
     4267  end;
    32694268end;
    32704269
     
    32754274  aDate, aDate1: double;
    32764275begin
    3277   lstTemp.Items.Clear;
     4276  GtslTemp.Clear;
    32784277  itemid := UpperCase(Pieces(aString, '^', 1, 2));
    3279   with lstData do
    3280   for i := Items.Count - 1 downto 0 do
    3281     if itemid = UpperCase(Pieces(Items[i], '^', 1, 2)) then
    3282     begin
    3283       itemdata := Items[i];
     4278  for i := GtslData.Count - 1 downto 0 do
     4279    if itemid = UpperCase(Pieces(GtslData[i], '^', 1, 2)) then
     4280    begin
     4281      itemdata := GtslData[i];
    32844282      filenum := Piece(itemdata, '^', 1);
    32854283      if (filenum = '52') or (filenum = '55') or (filenum = '55NVA')
     
    32894287        aDate1 := strtofloat(FMCorrectedDate(Piece(itemdata, '^', 4)));
    32904288        if (aDate < FGraphSetting.FMStopDate) and (aDate > FGraphSetting.FMStartDate) then
    3291           lstTemp.Items.Add(Items[i])
     4289          GtslTemp.Add(GtslData[i])
    32924290        else if (aDate < FGraphSetting.FMStopDate) and (aDate1 > FGraphSetting.FMStartDate) then
    3293           lstTemp.Items.Add(Items[i])
     4291          GtslTemp.Add(GtslData[i])
    32944292        else if (aDate < FGraphSetting.FMStartDate) and (aDate1 > FGraphSetting.FMStopDate) then
    3295           lstTemp.Items.Add(Items[i]);
     4293          GtslTemp.Add(GtslData[i]);
    32964294      end
    32974295      else if Piece(itemdata, '^', 3) <> '' then
     
    33004298        if (aDate < FGraphSetting.FMStopDate) and (aDate > FGraphSetting.FMStartDate) then
    33014299          if Copy(itemdata, 1, 4) = '63MI' then
    3302             lstTemp.Items.Add(Pieces(Items[i], '^', 1, 4))
     4300            GtslTemp.Add(Pieces(GtslData[i], '^', 1, 4))
    33034301          else if Copy(itemdata, 1, 4) = '63AP' then
    3304             lstTemp.Items.Add(Pieces(Items[i], '^', 1, 4))
    3305           //else lstTemp.Items.Add(Pieces(Items[i], '^', 1, 5));         // add in non micro, ap
    3306           else lstTemp.Items.Add(Items[i]);         // add in non micro, ap
     4302            GtslTemp.Add(Pieces(GtslData[i], '^', 1, 4))
     4303          //else GtslTemp.Add(Pieces(Items[i], '^', 1, 5));         // add in non micro, ap
     4304          else GtslTemp.Add(GtslData[i]);         // add in non micro, ap
    33074305      end;
    33084306    end;
     
    33284326  Result := 4;
    33294327  if (aType = '52') or (aType = '55') or (aType = '55NVA') or (aType = '9999911') then
    3330     if mnuMedsasgantt.Checked then Result := 8
    3331     else if mnuMedsasganttvertheight.Checked then Result := 3
    3332     else Result := 8
     4328    Result := 8
    33334329  else
    3334   for i := 0 to lstAllTypes.Items.Count - 1 do
    3335     if aType = Piece(lstAllTypes.Items[i], '^', 1) then
    3336     begin
    3337       Result := strtointdef(Piece(lstAllTypes.Items[i], '^', 3), 4);
     4330  for i := 0 to GtslAllTypes.Count - 1 do
     4331    if aType = Piece(GtslAllTypes[i], '^', 1) then
     4332    begin
     4333      Result := strtointdef(Piece(GtslAllTypes[i], '^', 3), 4);
    33384334      break;
    33394335    end;
     
    33434339var
    33444340  i: integer;
     4341  astring: string;
    33454342begin
    33464343  Result := false;
    3347   for i := 0 to lstTypes.Items.Count - 1 do
    3348   if Piece(lstTypes.Items[i], '^', 1) = aType then
    3349   begin
    3350     Result := length(Piece(lstTypes.Items[i], '^', 8)) > 0;
    3351     break;
     4344  for i := 0 to GtslTypes.Count - 1 do
     4345  begin
     4346    astring := GtslTypes[i];
     4347    if Piece(astring, '^', 1) = aType then
     4348    begin
     4349      Result := length(Piece(astring, '^', 8)) > 0;
     4350      break;
     4351    end;
    33524352  end;
    33534353end;
     
    33614361  done := false;
    33624362  j := 0;
    3363   with lstTempCheck do
    33644363  while not done do
    33654364  begin
    3366     if Items.Count = j then done := true
    3367     else if Items[j] = typeitem then
     4365    if GtslTempCheck.Count = j then done := true
     4366    else if GtslTempCheck[j] = typeitem then
    33684367    begin
    33694368      previous := true;
     
    33754374  if not previous then
    33764375  begin
    3377     lstTempCheck.Items.Add(UpperCase(typeitem));
    3378     levelseq := lstTempCheck.Items.Count;
     4376    GtslTempCheck.Add(UpperCase(typeitem));
     4377    levelseq := GtslTempCheck.Count;
    33794378  end;
    33804379end;
     
    33844383  i: integer;
    33854384begin
    3386   if lstDrugClass.Items.Count < 1 then
    3387     FastAssign(rpcClass('50.605'), lstDrugClass.Items);
     4385  if GtslDrugClass.Count < 1 then
     4386    FastAssign(rpcClass('50.605'), GtslDrugClass);
    33884387  Result := '';
    3389   for i := 0 to lstDrugClass.Items.Count - 1 do
    3390     if Piece(lstDrugClass.Items[i], '^', 2) = aDCien then
    3391     begin
    3392       Result := 'Drug - ' + Piece(lstDrugClass.Items[i], '^', 3);
     4388  for i := 0 to GtslDrugClass.Count - 1 do
     4389    if Piece(GtslDrugClass[i], '^', 2) = aDCien then
     4390    begin
     4391      Result := 'Drug - ' + Piece(GtslDrugClass[i], '^', 3);
    33934392      break;
    33944393    end;
     
    34094408end;
    34104409
     4410procedure TfrmGraphs.splViewsTopMoved(Sender: TObject);
     4411begin
     4412  mnuPopGraphViewDefinition.Checked := (memViewsTop.Height > 5)
     4413                                    or (memViewsBottom.Height > 5);
     4414end;
     4415
    34114416procedure TfrmGraphs.cboDateRangeChange(Sender: TObject);
    34124417var
    3413   datetag: integer;
    3414   endofday: double;
    3415   dateranges, manualstart, manualstop: string;
    3416 begin
    3417   endofday := FMDateTimeOffsetBy(FMToday, 1);
    3418   SelCopy(lvwItemsTop, lstSelCopyTop);
    3419   SelCopy(lvwItemsBottom, lstSelCopyBottom);
     4418  dateranges: string;
     4419begin
     4420  SelCopy(lvwItemsTop, GtslSelCopyTop);
     4421  SelCopy(lvwItemsBottom, GtslSelCopyBottom);
    34204422  dateranges := '';
    34214423  if (cboDateRange.ItemID = 'S') then
     
    34434445  end;
    34444446  HideGraphs(true);
     4447  DateSteps(dateranges);
     4448  FilterListView(FGraphSetting.FMStartDate, FGraphSetting.FMStopDate);
     4449  SelReset(GtslSelCopyTop, lvwItemsTop);
     4450  SelReset(GtslSelCopyBottom, lvwItemsBottom);
     4451  DisplayData('top');
     4452  DisplayData('bottom');
     4453  if lstViewsTop.ItemIndex > 1 then lstViewsTopChange(self);
     4454  if lstViewsBottom.ItemIndex > 1 then lstViewsBottomChange(self);
     4455  HideGraphs(false);
     4456end;
     4457
     4458procedure TfrmGraphs.DateSteps(dateranges: string);
     4459var
     4460  datetag: integer;
     4461  endofday: double;
     4462  manualstart, manualstop: string;
     4463begin
     4464  endofday := FMDateTimeOffsetBy(FMToday, 1);
    34454465  datetag := cboDateRange.ItemIEN;
     4466  FGraphSetting.FMStopDate := endofday;
    34464467  with FGraphSetting do
    34474468  case datetag of
     
    34644485        end;
    34654486      end;
    3466   1:  begin
    3467         FMStartDate := FMToday;
    3468         FMStopDate := endofday;
    3469       end;
    3470   2:  begin
    3471         FMStartDate := FMDateTimeOffsetBy(FMToday, -7);
    3472         FMStopDate := endofday;
    3473       end;
    3474   3:  begin
    3475         FMStartDate := FMDateTimeOffsetBy(FMToday, -14);
    3476         FMStopDate := endofday;
    3477       end;
    3478   4:  begin
    3479         FMStartDate := FMDateTimeOffsetBy(FMToday, -30);
    3480         FMStopDate := endofday;
    3481       end;
    3482   5:  begin
    3483         FMStartDate := FMDateTimeOffsetBy(FMToday, -183);
    3484         FMStopDate := endofday;
    3485       end;
    3486   6:  begin
    3487         FMStartDate := FMDateTimeOffsetBy(FMToday, -365);
    3488         FMStopDate := endofday;
    3489       end;
    3490   7:  begin
    3491         FMStartDate := FMDateTimeOffsetBy(FMToday, -730);
    3492         FMStopDate := endofday;
    3493       end;
    3494   8:  begin
    3495         FMStartDate := FM_START_DATE;   // earliest recorded values
    3496         FMStopDate := endofday;
    3497       end;
     4487  1:  FMStartDate := FMToday;
     4488  2:  FMStartDate := FMDateTimeOffsetBy(FMToday, -7);
     4489  3:  FMStartDate := FMDateTimeOffsetBy(FMToday, -14);
     4490  4:  FMStartDate := FMDateTimeOffsetBy(FMToday, -30);
     4491  5:  FMStartDate := FMDateTimeOffsetBy(FMToday, -183);
     4492  6:  FMStartDate := FMDateTimeOffsetBy(FMToday, -365);
     4493  7:  FMStartDate := FMDateTimeOffsetBy(FMToday, -730);
     4494  8:  FMStartDate := FM_START_DATE;   // earliest recorded values
    34984495  else
    34994496      begin
     
    35124509      end;
    35134510  end;
    3514   FilterListView(FGraphSetting.FMStartDate, FGraphSetting.FMStopDate);
    3515   SelReset(lstSelCopyTop, lvwItemsTop);
    3516   SelReset(lstSelCopyBottom, lvwItemsBottom);
    3517   DisplayData('top');
    3518   DisplayData('bottom');
    3519   if cboViewsTop.ItemIndex > 1 then cboViewsTopChange(self);
    3520   if cboViewsBottom.ItemIndex > 1 then cboViewsBottomChange(self);
    3521   HideGraphs(false);
    35224511end;
    35234512
     
    36094598var
    36104599  actionOK, checkaction: boolean;
    3611   counter, i, listnum: integer;
    3612   profile, profilestring, section, selections, specnum, typeitem: string;
     4600  counter: integer;
     4601  profile, profilestring, section, selections, specnum, typeitem, seltext: string;
    36134602  aGraphItem: TGraphItem;
     4603  aListItem: TListItem;
    36144604begin
    36154605  selections := '';
    3616   for i := 0 to lvwItemsTop.Items.Count - 1 do
    3617   if lvwItemsTop.Items[i].Selected then
    3618   begin
    3619     aGraphItem := TGraphItem(lvwItemsTop.Items.Item[i].SubItems.Objects[3]);
     4606  seltext := '';
     4607  aListItem := lvwItemsTop.Selected;
     4608  while aListItem <> nil do
     4609  begin
     4610    aGraphItem := TGraphItem(aListItem.SubItems.Objects[3]);
    36204611    typeitem := UpperCase(aGraphItem.Values);
    36214612    if Piece(typeitem, '^', 1) = '63' then
    36224613    begin
    36234614      specnum := Piece(Piece(typeitem, '^', 2), '.', 2);
    3624       if length(specnum) > 0 then  // mulispecimen
     4615      if length(specnum) > 0 then  // multispecimen
    36254616        if specnum = '1' then typeitem := Piece(typeitem, '.', 1)
    36264617        else typeitem := '';
    36274618    end;
    36284619    if length(typeitem) > 0 then
    3629       selections := selections + Piece(typeitem, '^', 1) + '~' + Piece(typeitem, '^', 2) +'~|';
    3630   end;
    3631   checkaction := chkDualViews.Checked;
     4620      selections := selections + Piece(typeitem, '^', 1) + '~' + Piece(typeitem, '^', 2) + '~|';
     4621    aListItem := lvwItemsTop.GetNextItem(aListItem, sdAll, [isSelected]);
     4622  end;
     4623  checkaction := false;
    36324624  actionOK := false;
    36334625  profile := '*';
    3634   counter := cboViewsTop.Tag;
    3635   // load lstItems with all patient items and pass to Define View    ????
    3636   DialogGraphProfiles(Font.Size, actionOK, checkaction, FGraphSetting,
     4626  counter := lstViewsTop.Tag;
     4627  // load GtslItems with all patient items and pass to Define View    ????
     4628  DialogGraphProfiles(actionOK, checkaction, FGraphSetting,
    36374629    profile, profilestring, section, Patient.DFN, counter, selections);
    36384630  if (not actionOK) then exit;
    36394631  FillViews;
    36404632  if (section = 'niether') then exit;
    3641   cboViewsTop.Tag := counter;
    3642 
    3643   lstViews.Items.Add(profilestring);
    3644   listnum := lstViews.Items.Count + 1;
    3645   for i := 0 to lstViews.Items.Count - 1 do
    3646   begin
    3647     profilestring := lstViews.Items[i];
    3648     cboViewsTop.Items.Insert(i + 2, profilestring);
    3649     cboViewsBottom.Items.Insert(i + 2, profilestring);
    3650   end;
     4633  lstViewsTop.Tag := counter;
    36514634  if (section = 'bottom') or (section = 'both') then
    3652     lvwItemsBottom.Tag := listnum;
     4635    lvwItemsBottom.Tag := counter;
    36534636  if (section = 'top') or (section = 'both') then
    3654     lvwItemsTop.Tag  := listnum;
     4637    lvwItemsTop.Tag  := counter;
    36554638  ViewSelections;
     4639end;
     4640
     4641procedure TfrmGraphs.DisplayFreeText(aChart: TChart);
     4642var
     4643  i: integer;
     4644begin
     4645  for i := 0 to aChart.SeriesCount - 1 do
     4646    if (Piece(aChart.Series[i].Title, '^', 1) = '(non-numeric)') then
     4647      aChart.Series[i].Marks.Visible := true;
    36564648end;
    36574649
     
    36644656    if (Tag = 0) and (length(lvwItemsBottom.Hint) > 0) then
    36654657    begin
    3666       for i := 0 to cboViewsBottom.Items.Count - 1 do
     4658      for i := 0 to lstViewsBottom.Items.Count - 1 do
    36674659      begin
    3668         showmessage(cboViewsBottom.Items[i]);
    3669         if lvwItemsBottom.Hint = Piece(cboViewsBottom.Items[i], '^', 2) then
     4660        ShowMsg(lstViewsBottom.Items[i]);
     4661        if lvwItemsBottom.Hint = Piece(lstViewsBottom.Items[i], '^', 2) then
    36704662        begin
    36714663          Tag := i;
     
    36824674      end;
    36834675      ClearSelection;
    3684       cboViewsBottom.ItemIndex := Tag;
     4676      lstViewsBottom.ItemIndex := Tag;
    36854677      Tag := 0;
    36864678      Hint := '';
    3687       cboViewsBottomChange(self);
     4679      lstViewsBottomChange(lstViewsBottom);
    36884680    end;
    36894681  end;
     
    36914683  begin
    36924684    if (Tag = 0) and (length(lvwItemsTop.Hint) > 0) then
    3693     begin
    3694       for i := 0 to cboViewsTop.Items.Count - 1 do
    3695       begin
    3696         if lvwItemsTop.Hint = Piece(cboViewsTop.Items[i], '^', 2) then
     4685      for i := 0 to lstViewsTop.Items.Count - 1 do
     4686        if lvwItemsTop.Hint = Piece(lstViewsTop.Items[i], '^', 2) then
    36974687        begin
    36984688          Tag := i;
    36994689          break;
    37004690        end;
    3701       end;
    3702     end;
    37034691    if Tag > 0 then
    37044692    begin
    37054693      ClearSelection;
    3706       cboViewsTop.ItemIndex := Tag;
     4694      lstViewsTop.ItemIndex := Tag;
    37074695      Tag := 0;
    37084696      Hint := '';
    3709       cboViewsTopChange(self);
     4697      lstViewsTopChange(lstViewsTop);
    37104698    end;
    37114699  end;
     
    37134701
    37144702procedure TfrmGraphs.ItemsClick(Sender: TObject; aListView, aOtherListView: TListView;
    3715   aCheckBox: TCheckBox; aComboBox: TORComboBox; aList: TListBox; aSection: string);
    3716 begin
    3717   FRetainZoom := (lstZoomHistory.Count > 0);
     4703  aCheckBox: TCheckBox; aListBox: TORListBox; aList: TStrings; aSection: string);
     4704begin
     4705  FRetainZoom := (GtslZoomHistoryFloat.Count > 0);
    37184706  FWarning := false;
    37194707  Screen.Cursor := crHourGlass;
     
    37214709  if Sender = aListView then
    37224710  begin
    3723     aComboBox.ItemIndex := -1;
    3724     aComboBox.Text := '';
     4711    aListBox.Tag := BIG_NUMBER;                   // avoids recurssion
     4712    aListBox.ItemIndex := -1;
     4713    aListBox.ClearSelection;
    37254714  end;
    37264715  if (Sender is TListView) then           // clear out selcopy list
    3727     aList.Items.Clear;
     4716    aList.Clear;
    37284717  if aOtherListView.SelCount < 1 then
    37294718  begin
     
    37554744  if (aListView.SelCount = 1) and (aOtherListView.SelCount = 0) then
    37564745  begin
    3757     lstZoomHistory.Items.Clear;
     4746    GtslZoomHistoryFloat.Clear;
    37584747    FRetainZoom := false;
    37594748    mnuPopGraphZoomBack.Enabled := false;
    37604749  end
    3761   else if FRetainZoom and (lstZoomHistory.Count > 0) then
     4750  else if FRetainZoom and (GtslZoomHistoryFloat.Count > 0) then
    37624751    ZoomUpdate;
    37634752  HideGraphs(false);
     
    37744763  aGraphItem: TGraphItem;
    37754764begin
     4765  if FFastTrack then
     4766    exit;
     4767  Application.ProcessMessages;
    37764768  TypeToCheck := UpperCase(TypeToCheck);
    37774769  if (TypeToCheck = 'SELECT') and (lvwItemsTop.SelCount = 0)
     
    37944786      done := false;
    37954787      j := 0;
    3796       with lstCheck do
    37974788      while not done do
    37984789      begin
    3799         if Items.Count = j then done := true
    3800         else if lstCheck.Items[j] = typeitem then
     4790        if GtslCheck.Count = j then done := true
     4791        else if Pieces(GtslCheck[j], '^', 1, 2) = typeitem then
    38014792        begin
    38024793          previous := true;
     
    38074798      if not previous then
    38084799      begin
    3809         lstCheck.Items.Add(typeitem);
     4800        GtslCheck.Add(typeitem);
    38104801        itemname := aListView.Items[i].Caption;
    38114802        if Piece(typeitem, '^', 1) = '63' then
    3812           LabData(typeitem, itemname, aSection)
     4803          LabData(typeitem, itemname, aSection, true) // need to get lab data
    38134804        else
    3814           lstData.Items.AddStrings(rpcGetItemData(typeitem, FMTimeStamp, Patient.DFN));
     4805          FastAddStrings(rpcGetItemData(typeitem, FMTimeStamp, Patient.DFN), GtslData);
    38154806      end;
    38164807    end;
     
    38184809end;
    38194810
    3820 procedure TfrmGraphs.lvwItemsTopClick(Sender: TObject);
     4811procedure TfrmGraphs.lvwItemsBottomClick(Sender: TObject);
    38214812var
    38224813  i: integer;
    38234814begin
    38244815  FFirstClick := true;
    3825   with FGraphSetting do
    3826   if lvwItemsTop.SelCount > MaxSelect then
    3827   begin
    3828     pnlItemsTopInfo.Tag := 1;
    3829     lvwItemsTop.ClearSelection;
    3830     showmessage('Too many items to graph');
    3831     for i := 0 to lstSelPrevTop.Items.Count - 1 do
    3832       lvwItemsTop.Items[strtoint(lstSelPrevTop.Items[i])].Selected := true;
    3833     pnlItemsTopInfo.Tag := 0;
    3834   end
    3835   else
    3836   begin
    3837     lstSelPrevTop.Clear;
    3838     for i := 0 to lvwItemsTop.Items.Count - 1 do
    3839       if lvwItemsTop.Items[i].Selected then lstSelPrevTop.Items.Add(inttostr(i));
    3840     ItemsClick(Sender, lvwItemsTop, lvwItemsBottom, chkItemsTop, cboViewsTop, lstSelCopyTop, 'top');
    3841   end;
    3842 end;
    3843 
    3844 procedure TfrmGraphs.lvwItemsBottomClick(Sender: TObject);
    3845 var
    3846   i: integer;
    3847 begin
    3848   FFirstClick := true;
    3849   with FGraphSetting do
    3850   if lvwItemsBottom.SelCount > MaxSelect then
     4816  if not FFastTrack then
     4817    if GraphTurboOn then
     4818      Switch;
     4819  if lvwItemsBottom.SelCount > FGraphSetting.MaxSelect then
    38514820  begin
    38524821    pnlItemsBottomInfo.Tag := 1;
    38534822    lvwItemsBottom.ClearSelection;
    3854     showmessage('Too many items to graph');
    3855     for i := 0 to lstSelPrevBottom.Items.Count - 1 do
    3856       lvwItemsBottom.Items[strtoint(lstSelPrevBottom.Items[i])].Selected := true;
     4823    if FTooManyItems then FTooManyItems := false
     4824    else
     4825    begin
     4826      ShowMsg('Too many items to graph');
     4827      FTooManyItems := true;  // flag so that warning will not be displayed twice
     4828    end;
     4829    for i := 0 to GtslSelPrevBottomFloat.Count - 1 do
     4830      lvwItemsBottom.Items[strtoint(GtslSelPrevBottomFloat[i])].Selected := true;
    38574831    pnlItemsBottomInfo.Tag := 0;
    38584832  end
    38594833  else
    38604834  begin
    3861     lstSelPrevBottom.Clear;
     4835    GtslSelPrevBottomFloat.Clear;
    38624836    for i := 0 to lvwItemsBottom.Items.Count - 1 do
    3863       if lvwItemsBottom.Items[i].Selected then lstSelPrevBottom.Items.Add(inttostr(i));
    3864     ItemsClick(Sender, lvwItemsBottom, lvwItemsTop, chkItemsBottom, cboViewsBottom, lstSelCopyBottom, 'bottom');
    3865   end;
    3866 end;
    3867 
    3868 procedure TfrmGraphs.SelCopy(aListView: TListView; aListBox: TListBox);
    3869 var
    3870   i: integer;
     4837    if lvwItemsBottom.Items[i].Selected then
     4838      GtslSelPrevBottomFloat.Add(inttostr(i));
     4839    ItemsClick(Sender, lvwItemsBottom, lvwItemsTop, chkItemsBottom, lstViewsBottom, GtslSelCopyBottom, 'bottom');
     4840  end;
     4841end;
     4842
     4843procedure TfrmGraphs.SelCopy(aListView: TListView; aList: TStrings);
     4844var
    38714845  aGraphItem: TGraphItem;
     4846  aListItem: TListItem;
    38724847begin
    38734848  if aListView.Items.Count > 0 then
    38744849  begin
    3875     for i := 0 to aListView.Items.Count - 1 do
    3876     if aListView.Items[i].Selected then
    3877     begin
    3878       aGraphItem := TGraphItem(aListView.Items.Item[i].SubItems.Objects[3]);    //get file^ien match
    3879       aListBox.Items.Add(aGraphItem.Values);
    3880     end;
    3881   end;
    3882 end;
    3883 
    3884 procedure TfrmGraphs.SelReset(aListbox: TListBox; aListView: TListView);
     4850    aListItem := aListView.Selected;
     4851    while aListItem <> nil do
     4852    begin
     4853      aGraphItem := TGraphItem(aListItem.SubItems.Objects[3]);    //get file^ien match
     4854      aList.Add(aGraphItem.Values);
     4855      aListItem := aListView.GetNextItem(aListItem, sdAll, [isSelected]);
     4856    end;
     4857  end;
     4858end;
     4859
     4860procedure TfrmGraphs.SelReset(aList: TStrings; aListView: TListView);
    38854861var
    38864862  i, j: integer;
     
    38924868    aGraphItem := TGraphItem(aListView.Items.Item[i].SubItems.Objects[3]);    //get file^ien match
    38934869    typeitem := UpperCase(Pieces(aGraphItem.Values, '^', 1, 3));
    3894     for j := 0 to aListBox.Items.Count - 1 do
    3895     begin
    3896       itemtype := UpperCase(Pieces(aListBox.Items[j], '^', 1, 3));
     4870    for j := 0 to aList.Count - 1 do
     4871    begin
     4872      itemtype := UpperCase(Pieces(aList[j], '^', 1, 3));
    38974873      if itemtype = typeitem then
    38984874      begin
     
    39044880end;
    39054881
    3906 procedure TfrmGraphs.ViewsChange(aListView: TListView; aComboBox: TORComboBox; aSection: string);
     4882procedure TfrmGraphs.ViewsChange(aListView: TListView; aListBox: TORListBox; aSection: string);
    39074883var
    39084884  Updated: boolean;
     
    39114887  timHintPause.Enabled := false;
    39124888  InactivateHint;
    3913   if aComboBox.ItemIndex = -1 then exit;  // or clear graph  ***************************
    3914   if aComboBox.ItemIndex = 0 then  // <clear all selections>
    3915   begin
    3916     aComboBox.Text := '';
     4889  if aListBox.ItemIndex = -1 then exit;  // or clear graph  ***************************
     4890  if aListBox.Tag = BIG_NUMBER then            // avoids recurssion
     4891    exit;
     4892  if pos(LLS_FRONT, aListBox.Items[aListBox.ItemIndex]) > 0 then  // <clear all selections>
     4893  begin
     4894    if aListBox.Tag = BIG_NUMBER then            // avoids recurssion
     4895      exit;
    39174896    aListView.ClearSelection;
    39184897    if aSection = 'top' then
     
    39204899      FTHighTime := 0;
    39214900      FTLowTime := BIG_NUMBER;
     4901      memViewsTop.Lines.Clear;
     4902      memViewsTop.Lines[0] := TXT_VIEW_DEFINITION;
    39224903    end
    39234904    else
     
    39254906      FBHighTime := 0;
    39264907      FBLowTime := BIG_NUMBER;
     4908      memViewsBottom.Lines.Clear;
     4909      memViewsBottom.Lines[0] := TXT_VIEW_DEFINITION;
    39274910    end;
    39284911    DisplayData(aSection);
     4912    aListBox.Tag := 0;                     // reset
    39294913    exit;
    39304914  end;
    3931   if aComboBox.ItemIndex = 1 then  // <make selections>
    3932   begin
    3933     btnGraphSelectionsClick(self);
    3934     if aComboBox.ItemIndex = -1 then
    3935       aComboBox.Text := '';
    3936     exit;
    3937   end;                            // view selected
    39384915  aListView.ClearSelection;
    39394916  Updated := false;
    3940   aProfile := aComboBox.Items[aComboBox.ItemIndex];
    3941   if (length(Piece(aProfile, '^', 3)) = 0) or (length(Piece(aProfile, '^', 1)) = 0) then        //or <custom>
     4917  aProfile := aListBox.Items[aListBox.ItemIndex];
     4918  if (length(Piece(aProfile, '^', 3)) = 0) or (length(Piece(aProfile, '^', 1)) = 0) or
     4919     (Piece(aProfile, '^', 1) = VIEW_LABS) then        //or <custom>
    39424920    CheckProfile(aProfile, Updated);
    3943   aComboBox.Text := Piece(aProfile, '^', 2);
    39444921  if Updated then
    39454922    cboDateRangeChange(self);
    39464923  if aSection = 'top' then
    39474924  begin
     4925    ViewDefinition(aProfile, memViewsTop);
    39484926    AssignProfile(aProfile, 'top');
    39494927    if not FItemsSortedTop then
     
    39574935  else
    39584936  begin
     4937    ViewDefinition(aProfile, memViewsBottom);
    39594938    AssignProfile(aProfile, 'bottom');
    39604939    if not FItemsSortedBottom then
     
    39714950end;
    39724951
    3973 procedure TfrmGraphs.cboViewsTopChange(Sender: TObject);
    3974 begin
    3975   ViewsChange(lvwItemsTop, cboViewsTop, 'top');
    3976 end;
    3977 
    3978 procedure TfrmGraphs.cboViewsBottomChange(Sender: TObject);
    3979 begin
    3980   ViewsChange(lvwItemsBottom, cboViewsBottom, 'bottom');
    3981 end;
    3982 
    39834952procedure TfrmGraphs.AssignProfile(aProfile, aSection: string);
    39844953var
     
    39964965procedure TfrmGraphs.SetProfile(aProfile, aName: string; aListView: TListView);
    39974966var
    3998   i, j: integer;
     4967  i: integer;
     4968  itemstring: string;
     4969  aGraphItem: TGraphItem;
     4970begin
     4971  aListView.Items.BeginUpdate;
     4972  if aProfile = '0' then
     4973    for i := 0 to aListView.Items.Count - 1 do
     4974      aListView.Items[i].SubItems[1] := ''
     4975  else
     4976    for i := 0 to aListView.Items.Count - 1 do
     4977    begin
     4978      aGraphItem := TGraphItem(aListView.Items.Item[i].SubItems.Objects[3]);   //get file^ien match
     4979      itemstring := aGraphItem.Values;
     4980      aListView.Items[i].SubItems[1] := ProfileName(aProfile, aName, itemstring);
     4981    end;
     4982  aListView.Items.EndUpdate;
     4983end;
     4984
     4985function TfrmGraphs.ProfileName(aProfile, aName, aString: string): string;
     4986var
     4987  j: integer;
    39994988  dcnm, itemdrugclass, itempart, itempart1, itempart2, itemnums: string;
    4000   itemstring, itemstring1, itemstringnums, profname: string;
    4001   aGraphItem: TGraphItem;
    4002 begin
    4003   if aProfile = '0' then
    4004   for i := 0 to aListView.Items.Count - 1 do
    4005     aListView.Items[i].SubItems[1] := ''
    4006   else
    4007   for i := 0 to aListView.Items.Count - 1 do
    4008   begin
    4009     profname := '';
    4010     aGraphItem := TGraphItem(aListView.Items.Item[i].SubItems.Objects[3]);   //get file^ien match
    4011     itemstring := aGraphItem.Values;
    4012     itemstring1 := UpperCase(Piece(itemstring, '^', 1));
    4013     itemdrugclass := Piece(itemstring, '^', 6);
    4014     itemstringnums := UpperCase(Pieces(itemstring, '^', 1, 2));
    4015     for j := 1 to BIG_NUMBER do
    4016     begin
    4017       itempart := Piece(aProfile, '|', j);
    4018       if itempart = '' then break;
    4019       itempart1 := Piece(itempart, '~', 1);
    4020       itempart2 := Piece(itempart, '~', 2);
    4021       itemnums := itempart1 + '^' + itempart2;
    4022       if (itempart1 = '50.605') and (length(itemdrugclass) > 0) then
     4989  itemstring1, itemstringnums: string;
     4990begin
     4991  Result := '';
     4992  itemstring1 := UpperCase(Piece(aString, '^', 1));
     4993  itemdrugclass := Piece(aString, '^', 6);
     4994  itemstringnums := UpperCase(Pieces(aString, '^', 1, 2));
     4995  for j := 1 to BIG_NUMBER do
     4996  begin
     4997    itempart := Piece(aProfile, '|', j);
     4998    if itempart = '' then
     4999      break;
     5000    itempart1 := Piece(itempart, '~', 1);
     5001    itempart2 := Piece(itempart, '~', 2);
     5002    itemnums := itempart1 + '^' + itempart2;
     5003    if (itempart1 = '50.605') and (length(itemdrugclass) > 0) then
     5004    begin
     5005      dcnm := DCName(itempart2);
     5006      if dcnm = itemdrugclass then
    40235007      begin
    4024         dcnm := DCName(itempart2);
    4025         if dcnm = itemdrugclass then
    4026         begin
    4027           profname := aName;
    4028           break;
    4029         end;
    4030       end
    4031       else if itempart1 = '63' then
    4032       begin
    4033         if itemnums = Piece(itemstringnums, '.', 1) then
    4034         begin
    4035           profname := aName;
    4036           break;
    4037         end;
    4038       end
    4039       else
    4040       begin
    4041         if itemnums = itemstringnums then
    4042         begin
    4043           profname := aName;
    4044           break;
    4045         end;
    4046       end;
    4047       if (itempart1 = '0') and (itempart2 = itemstring1) then
    4048       begin
    4049         profname := aName;
    4050         break;
    4051       end
    4052       else if (itempart1 = '0') and (length(Piece(itempart2, ';', 2)) > 0) then    // subtypes
    4053       if copy(itempart2, 1, length(itemstring1)) = Piece(itempart2, ';', 1) then
    4054       if Piece(itempart2, ';', 2) = UpperCase(Piece(Piece(itemstring, '^', 2), ';', 2)) then
    4055       begin
    4056         profname := aName;
     5008        Result := aName;
    40575009        break;
    40585010      end;
    4059     end;
    4060     aListView.Items[i].SubItems[1] := profname;
     5011    end
     5012    else if itempart1 = '63' then
     5013    begin
     5014      if itemnums = Piece(itemstringnums, '.', 1) then
     5015      begin
     5016        Result := aName;
     5017        break;
     5018      end;
     5019    end
     5020    else
     5021    begin
     5022      if itemnums = itemstringnums then
     5023      begin
     5024        Result := aName;
     5025        break;
     5026      end;
     5027    end;
     5028    if (itempart1 = '0') and (itempart2 = itemstring1) then
     5029    begin
     5030      Result := aName;
     5031      break;
     5032    end
     5033    else if (itempart1 = '0') and (length(Piece(itempart2, ';', 2)) > 0) then    // subtypes
     5034    if copy(itempart2, 1, length(itemstring1)) = Piece(itempart2, ';', 1) then
     5035    if Piece(itempart2, ';', 2) = UpperCase(Piece(Piece(aString, '^', 2), ';', 2)) then
     5036    begin
     5037      Result := aName;
     5038      break;
     5039    end;
     5040  end;
     5041end;
     5042
     5043procedure TfrmGraphs.ViewDefinition(profile: string; amemo: TRichEdit);
     5044var
     5045  i, defnum: integer;
     5046  vname, vdef, vlist, vtype, vnum: string;
     5047begin
     5048  vtype := Piece(profile, '^', 1);
     5049  defnum := strtointdef(vtype, BIG_NUMBER);
     5050  vname := Piece(profile, '^', 2);
     5051  case defnum of
     5052    -1:  vdef := 'Personal View';
     5053    -2:  vdef := 'Public View';
     5054    -3:  vdef := 'Lab Group';
     5055    else vdef := 'Temporary View';
     5056  end;
     5057  amemo.Clear;
     5058  amemo.Lines.Add(vname + ' [' + vdef + ']:');
     5059  if vdef = 'Temporary View' then
     5060  begin
     5061    for i := 4 to BIG_NUMBER do
     5062    begin
     5063      vlist := Piece(profile, '^', i);
     5064      if vlist = '' then break;
     5065      amemo.Lines.Add('  ' + vlist);
     5066    end;
     5067  end
     5068  else
     5069  begin
     5070    vnum := '';
     5071    for i := 0 to GtslAllViews.Count - 1 do
     5072    begin
     5073      vlist := GtslAllViews[i];
     5074      if Piece(vlist, '^', 4) = vname then
     5075        if Piece(vlist, '^', 1) = vtype then
     5076          if Piece(vlist, '^', 2) = 'V' then
     5077            vnum := Piece(vlist, '^', 3);
     5078      if vnum <> '' then
     5079        if Piece(vlist, '^', 2) = 'C' then
     5080           if Piece(vlist, '^', 3) = vnum then
     5081             amemo.Lines.Add('   ' + Piece(vlist, '^', 4));
     5082    end;
    40615083  end;
    40625084end;
     
    40815103    if length(itempart) = 0 then break;
    40825104    if Pos('811.2~', itempart) = 0 then
    4083       newprofile := newprofile + '|'
     5105      newprofile := newprofile + itempart + '|'
    40845106    else
    40855107      taxonomies.Add(itempart);
     
    41145136  itempart, itempart1, itempart2, profile, profilename, profiletype, xprofile: string;
    41155137begin
     5138  Application.ProcessMessages;
     5139  GtslTemp.Clear;
    41165140  profiletype := Piece(aProfile, '^', 1);
    41175141  profilename := Piece(aProfile, '^', 2);
    4118   if profiletype = '-2' then
    4119     FastAssign(rpcGetGraphProfiles(UpperCase(profilename), '1', 0), lstTemp.Items)
    4120   else if profiletype = '-1' then
    4121     FastAssign(rpcGetGraphProfiles(UpperCase(profilename), '0', 0), lstTemp.Items);
     5142  if profiletype = VIEW_PUBLIC then
     5143    FastAssign(GetGraphProfiles(UpperCase(profilename), '1', 0, 0), GtslTemp)
     5144  else if profiletype = VIEW_PERSONAL then
     5145    FastAssign(GetGraphProfiles(UpperCase(profilename), '0', 0, User.DUZ), GtslTemp)
     5146  else if profiletype = VIEW_LABS then
     5147  begin
     5148    FastAssign(GetATestGroup(strtoint(Piece(aProfile, '^', 3)), strtoint(Piece(aProfile, '^', 4))), GtslTemp);
     5149    aProfile := VIEW_LABS + '^' + Piece(aProfile, '^', 2) + '^';
     5150    for i := 0 to GtslTemp.Count - 1 do
     5151      aProfile := aProfile + '63~' + Piece(GtslTemp[i], '^', 1) + '~|';
     5152    GtslTemp.Clear;
     5153  end;
    41225154  if profiletype <> '' then
    41235155  begin
    4124     for i := 0 to lstTemp.Items.Count - 1 do
    4125       aProfile := aProfile + lstTemp.Items[i];
    4126     lstTemp.Items.Clear;
     5156    for i := 0 to GtslTemp.Count - 1 do
     5157      aProfile := aProfile + GtslTemp[i];
     5158    GtslTemp.Clear;
    41275159  end;
    41285160  Updated := false;
     
    41525184      LoadDisplayCheck('52', Updated);
    41535185      LoadDisplayCheck('55', Updated);
    4154       //LoadDisplayCheck('55NVAE', Updated);     // nonvameds as events are not being used
    41555186      LoadDisplayCheck('55NVA', Updated);
    41565187      LoadDisplayCheck('53.79', Updated);
     
    41635194procedure TfrmGraphs.LoadDisplayCheck(typeofitem: string; var Updated: boolean);
    41645195begin
     5196  if FFastTrack then
     5197  begin
     5198    exit;
     5199  end;
    41655200  if not TypeIsLoaded(typeofitem) then
    41665201  begin
     
    41975232    else if aListView = lvwItemsBottom then
    41985233      lvwItemsBottom.ClearSelection;
     5234    if FTooManyItems then FTooManyItems := false
     5235    else
     5236    begin
     5237      ShowMsg('Too many items to graph');
     5238      FTooManyItems := true;  // flag so that warning will not be displayed twice
     5239    end;
    41995240  end;
    42005241  if aListView = lvwItemsTop then
     
    42045245end;
    42055246
    4206 procedure TfrmGraphs.LabData(aItemType, aItemName, aSection: string);
    4207 var
    4208   singlespec: boolean;
    4209   i, oldlisting: integer;
    4210   checkitem, checkstring, datastring, filename, itemnum, newitemname, newitemnum, newstring: string;
    4211   spec1, spec2, spec3, spec4: string;
     5247procedure TfrmGraphs.SpecCheck(var spec1, spec2, spec3, spec4: string; var singlespec: boolean);
     5248var
     5249  i: integer;
     5250  checkstring, datastring: string;
     5251begin
     5252  singlespec := true;
     5253  spec1 := ''; spec2 := ''; spec3 := ''; spec4 := '';
     5254  GtslSpec1.Clear; GtslSpec2.Clear; GtslSpec3.Clear; GtslSpec4.Clear;
     5255  for i := 0 to GtslScratchLab.Count - 1 do
     5256  begin
     5257    datastring := GtslScratchLab[i];
     5258    checkstring := Pieces(datastring, '^', 1, 2) + '^' + Pieces(datastring, '^', 7, 8);
     5259    if length(spec1) = 0  then
     5260    begin
     5261      spec1 := checkstring;
     5262      GtslSpec1.Add(datastring)
     5263    end
     5264    else if spec1 = checkstring then
     5265      GtslSpec1.Add(datastring)
     5266    else if length(spec2) = 0 then
     5267    begin
     5268      singlespec := false;
     5269      spec2 := checkstring;
     5270      GtslSpec2.Add(datastring)
     5271    end
     5272    else if spec2 = checkstring then
     5273      GtslSpec2.Add(datastring)
     5274    else if length(spec3) = 0 then
     5275    begin
     5276      spec3 := checkstring;
     5277      GtslSpec3.Add(datastring)
     5278    end
     5279    else if spec3 = checkstring then
     5280      GtslSpec3.Add(datastring)
     5281    else
     5282    begin
     5283      spec4 := checkstring;
     5284      GtslSpec4.Add(datastring)
     5285    end;
     5286  end;
     5287end;
     5288
     5289procedure TfrmGraphs.SpecSet(var spec1, spec2, spec3, spec4: string; aItemType, aItemName: string);
     5290var
     5291  i: integer;
     5292  itemnum, newitemname, newitemnum, newstring: string;
     5293begin
     5294  GtslMultiSpec.Clear;
     5295  itemnum := Piece(aItemType, '^', 2);
     5296  if length(spec1) > 0 then
     5297  begin
     5298    newitemnum := itemnum + '.1';
     5299    newitemname := aItemName + ' (' + LowerCase(Piece(spec1, '^', 4)) + ')';
     5300    for i := 0 to GtslItems.Count - 1 do
     5301    if aItemType = Pieces(GtslItems[i], '^', 1, 2) then
     5302    begin
     5303      newstring := GtslItems[i];
     5304      GtslItems.Delete(i);
     5305      break;
     5306    end;
     5307    for i := 0 to GtslData.Count - 1 do
     5308    if aItemType = Pieces(GtslData[i], '^', 1, 2) then
     5309      GtslData.Delete(i);
     5310    ResetSpec(GtslSpec1, itemnum, newitemnum, newitemname, newstring);
     5311  end;
     5312  if length(spec2) > 0 then
     5313  begin
     5314    newitemnum := itemnum + '.2';
     5315    newitemname := aItemName + ' (' + LowerCase(Piece(spec2, '^', 4)) + ')';
     5316    ResetSpec(GtslSpec2, itemnum, newitemnum, newitemname, newstring);
     5317  end;
     5318  if length(spec3) > 0 then
     5319  begin
     5320    newitemnum := itemnum + '.3';
     5321    newitemname := aItemName + ' (' + LowerCase(Piece(spec3, '^', 4)) + ')';
     5322    ResetSpec(GtslSpec3, itemnum, newitemnum, newitemname, newstring);
     5323  end;
     5324  if length(spec4) > 0 then
     5325  begin
     5326    newitemnum := itemnum + '.4';
     5327    newitemname := aItemName + ' (other)';     // not specific after 3 specimens (from same time)
     5328    ResetSpec(GtslSpec4, itemnum, newitemnum, newitemname, newstring);
     5329  end;
     5330end;
     5331
     5332procedure TfrmGraphs.LabAdd(aListView: TListView; filename: string; aIndex, oldlisting: integer; selectlab: boolean);
     5333var
    42125334  aGraphItem: TGraphItem;
    42135335  aListItem: TListItem;
    42145336begin
    4215   singlespec := true;
    4216   spec1 := ''; spec2 := ''; spec3 := ''; spec4 := '';
    4217   lstSpec1.Items.Clear; lstSpec2.Items.Clear; lstSpec3.Items.Clear; lstSpec4.Items.Clear;
    4218   FastAssign(rpcGetItemData(aItemType, FMTimeStamp, Patient.DFN), lstScratchLab.Items);
    4219   for i := 0 to lstScratchLab.Items.Count - 1 do
    4220   begin
    4221     datastring := lstScratchLab.Items[i];
    4222     checkstring := Pieces(datastring, '^', 1, 2) + '^' + Pieces(datastring, '^', 7, 8);
    4223     if length(spec1) = 0  then
    4224     begin
    4225       spec1 := checkstring;
    4226       lstSpec1.Items.Add(datastring)
    4227     end
    4228     else if spec1 = checkstring then
    4229       lstSpec1.Items.Add(datastring)
    4230     else if length(spec2) = 0 then
    4231     begin
    4232       singlespec := false;
    4233       spec2 := checkstring;
    4234       lstSpec2.Items.Add(datastring)
    4235     end
    4236     else if spec2 = checkstring then
    4237       lstSpec2.Items.Add(datastring)
    4238     else if length(spec3) = 0 then
    4239     begin
    4240       spec3 := checkstring;
    4241       lstSpec3.Items.Add(datastring)
    4242     end
    4243     else if spec3 = checkstring then
    4244       lstSpec3.Items.Add(datastring)
    4245     else
    4246     begin
    4247       spec4 := checkstring;
    4248       lstSpec4.Items.Add(datastring)
    4249     end;
    4250   end;
     5337  aListItem := aListView.Items.Insert(oldlisting);
     5338  aListItem.Caption := Piece(GtslMultiSpec[aIndex], '^', 4);
     5339  aListItem.SubItems.Add(filename);
     5340  aListItem.SubItems.Add('');
     5341  aListItem.SubItems.Add('');
     5342  aGraphItem := TGraphItem.Create;
     5343  aGraphItem.Values := GtslMultiSpec[aIndex];
     5344  aListItem.SubItems.AddObject('', aGraphItem);
     5345  if selectlab then
     5346    if not FFastLabs then
     5347      aListView.Items[oldlisting].Selected := true;
     5348end;
     5349
     5350procedure TfrmGraphs.LabCheck(aListView: TListView; aItemType: string; var oldlisting: integer);
     5351var
     5352  i: integer;
     5353  checkitem: string;
     5354  aGraphItem: TGraphItem;
     5355begin
     5356  oldlisting := 0;
     5357  aListView.SortType := stNone;    // avoids out of bounds error
     5358  for i := 0 to aListView.Items.Count - 1 do
     5359  begin
     5360    aGraphItem := TGraphItem(aListView.Items.Item[i].SubItems.Objects[3]);   //get file^ien match
     5361    checkitem := Pieces(aGraphItem.Values, '^', 1, 2);
     5362    if aItemType = checkitem then
     5363    begin
     5364      oldlisting := i;
     5365      aListView.Items.Delete(i);
     5366      break;
     5367    end;
     5368  end;
     5369end;
     5370
     5371procedure TfrmGraphs.LabData(aItemType, aItemName, aSection: string; getdata: boolean);
     5372var
     5373  singlespec, selectlab: boolean;
     5374  i, oldlisting: integer;
     5375  filename: string;
     5376  spec1, spec2, spec3, spec4: string;
     5377begin
     5378  if getdata then
     5379    FastAssign(rpcGetItemData(aItemType, FMTimeStamp, Patient.DFN), GtslScratchLab);
     5380  SpecCheck(spec1, spec2, spec3, spec4, singlespec);
    42515381  if singlespec then
    4252     lstData.Items.AddStrings(lstScratchLab.Items)
     5382    FastAddStrings(GtslScratchLab, GtslData)
    42535383  else
    42545384  begin
    4255     lstMultiSpec.Items.Clear;
    4256     itemnum := Piece(aItemType, '^', 2);
    4257     if length(spec1) > 0 then
    4258     begin
    4259       newitemnum := itemnum + '.1';
    4260       newitemname := aItemName + ' (' + LowerCase(Piece(spec1, '^', 4)) + ')';
    4261       for i := 0 to lstItems.Items.Count - 1 do
    4262       if aItemType = Pieces(lstItems.Items[i], '^', 1, 2) then
    4263       begin
    4264         newstring := lstItems.Items[i];
    4265         lstItems.Items.Delete(i);
    4266         break;
    4267       end;
    4268       for i := 0 to lstData.Items.Count - 1 do
    4269       if aItemType = Pieces(lstData.Items[i], '^', 1, 2) then
    4270         lstData.Items.Delete(i);
    4271       ResetSpec(lstSpec1, itemnum, newitemnum, newitemname, newstring);
    4272     end;
    4273     if length(spec2) > 0 then
    4274     begin
    4275       newitemnum := itemnum + '.2';
    4276       newitemname := aItemName + ' (' + LowerCase(Piece(spec2, '^', 4)) + ')';
    4277       ResetSpec(lstSpec2, itemnum, newitemnum, newitemname, newstring);
    4278     end;
    4279     if length(spec3) > 0 then
    4280     begin
    4281       newitemnum := itemnum + '.3';
    4282       newitemname := aItemName + ' (' + LowerCase(Piece(spec3, '^', 4)) + ')';
    4283       ResetSpec(lstSpec3, itemnum, newitemnum, newitemname, newstring);
    4284     end;
    4285     if length(spec4) > 0 then
    4286     begin
    4287       newitemnum := itemnum + '.4';
    4288       newitemname := aItemName + ' (other)';     // not specific after 3 specimens (from same time)
    4289       ResetSpec(lstSpec4, itemnum, newitemnum, newitemname, newstring);
    4290     end;
    4291     oldlisting := 0;
    4292     lvwItemsTop.SortType := stNone;    // avoids out of bounds error
    4293     for i := 0 to lvwItemsTop.Items.Count - 1 do
    4294     begin
    4295       aGraphItem := TGraphItem(lvwItemsTop.Items.Item[i].SubItems.Objects[3]);   //get file^ien match
    4296       checkitem := Pieces(aGraphItem.Values, '^', 1, 2);
    4297       if aItemType = checkitem then
    4298       begin
    4299         oldlisting := i;
    4300         lvwItemsTop.Items.Delete(i);
    4301         break;
    4302       end;
    4303     end;
     5385    SpecSet(spec1, spec2, spec3, spec4, aItemType, aItemName);
    43045386    filename := FileNameX('63');
    4305     for i := 0 to lstMultiSpec.Items.Count - 1 do
    4306     begin
    4307       lstCheck.Items.Add(UpperCase(Pieces(lstMultiSpec.Items[i], '^', 1, 2)));
    4308       if (FGraphSetting.FMStartDate = FM_START_DATE)
    4309         or DateRangeMultiItems(FGraphSetting.FMStartDate, FGraphSetting.FMStopDate, Piece(lstMultiSpec.Items[i], '^', 2)) then
    4310       begin
    4311       with lvwItemsTop do
    4312         aListItem := Items.Insert(oldlisting);
    4313         aListItem.Caption := Piece(lstMultiSpec.Items[i], '^', 4);
    4314         aListItem.SubItems.Add(filename);
    4315         aListItem.SubItems.Add('');
    4316         aListItem.SubItems.Add('');
    4317         aGraphItem := TGraphItem.Create;
    4318         aGraphItem.Values := lstMultiSpec.Items[i];
    4319         aListItem.SubItems.AddObject('info object', aGraphItem);
    4320         if aSection = 'top' then lvwItemsTop.Items[oldlisting].Selected := true;
    4321       end;
     5387
     5388    LabCheck(lvwItemsTop, aItemType, oldlisting);
     5389    selectlab := aSection = 'top';
     5390    lvwItemsTop.Items.BeginUpdate;
     5391    for i := 0 to GtslMultiSpec.Count - 1 do
     5392    begin
     5393      GtslCheck.Add(UpperCase(Pieces(GtslMultiSpec[i], '^', 1, 2)));
     5394      if (FGraphSetting.FMStartDate = FM_START_DATE) or
     5395          DateRangeMultiItems(FGraphSetting.FMStartDate, FGraphSetting.FMStopDate, Piece(GtslMultiSpec[i], '^', 2)) then
     5396        LabAdd(lvwItemsTop, filename, i, oldlisting, selectlab);
    43225397    end;
    43235398    lvwItemsTop.SortType := stBoth;
    4324     oldlisting := 0;
    4325     lvwItemsBottom.SortType := stNone;    // avoids out of bounds error
    4326     for i := 0 to lvwItemsBottom.Items.Count - 1 do
    4327     begin
    4328       aGraphItem := TGraphItem(lvwItemsBottom.Items.Item[i].SubItems.Objects[3]);   //get file^ien match
    4329       checkitem := Pieces(aGraphItem.Values, '^', 1, 2);
    4330       if aItemType = checkitem then
    4331       begin
    4332         oldlisting := i;
    4333         lvwItemsBottom.Items.Delete(i);
    4334         break;
    4335       end;
    4336     end;
    4337     for i := 0 to lstMultiSpec.Items.Count - 1 do
    4338     begin
    4339       aListItem := lvwItemsBottom.Items.Insert(oldlisting);
    4340       aListItem.Caption := Piece(lstMultiSpec.Items[i], '^', 4);
    4341       aListItem.SubItems.Add(filename);
    4342       aListItem.SubItems.Add('');
    4343       aListItem.SubItems.Add('');
    4344       aGraphItem := TGraphItem.Create;
    4345       aGraphItem.Values := lstMultiSpec.Items[i];
    4346       aListItem.SubItems.AddObject('info object', aGraphItem);
    4347       if aSection = 'bottom' then lvwItemsBottom.Items[oldlisting].Selected := true;
    4348     end;
     5399    lvwItemsTop.Items.EndUpdate;
     5400
     5401    LabCheck(lvwItemsBottom, aItemType, oldlisting);
     5402    selectlab := aSection = 'bottom';
     5403    lvwItemsBottom.Items.BeginUpdate;
     5404    for i := 0 to GtslMultiSpec.Count - 1 do
     5405      LabAdd(lvwItemsBottom, filename, i, oldlisting, selectlab);
    43495406    lvwItemsBottom.SortType := stBoth;
     5407    lvwItemsBottom.Items.EndUpdate;
    43505408  end;
    43515409end;
     
    43645422  end;
    43655423  itemspec := aItem + '^' + aSpec;
    4366   for i := 0 to lstTestSpec.Items.Count - 1 do
    4367   if itemspec = Pieces(lstTestSpec.Items[i], '^', 1, 2) then
    4368   begin
    4369     specstring := lstTestSpec.Items[i];
     5424  for i := 0 to GtslTestSpec.Count - 1 do
     5425  if itemspec = Pieces(GtslTestSpec[i], '^', 1, 2) then
     5426  begin
     5427    specstring := GtslTestSpec[i];
    43705428    low :=   Piece(specstring, '^', 3);
    43715429    high :=  Piece(specstring, '^', 4);
     
    44425500end;
    44435501
    4444 procedure TfrmGraphs.ResetSpec(aListBox: TListBox; aItemNum, aNewItemNum, aNewItemName, aNewString: string);
     5502procedure TfrmGraphs.ResetSpec(aList: TStrings; aItemNum, aNewItemNum, aNewItemName, aNewString: string);
    44455503var                                             //also add itemx
    44465504  i: integer;
     
    44485506  newestdate, newstring: string;
    44495507begin
    4450   lstTemp.Items.Clear;
     5508  GtslTemp.Clear;
    44515509  newdate := 0;
    4452   for i := 0 to aListBox.Items.Count - 1 do
    4453   begin
    4454     newstring := aListBox.Items[i];
     5510  for i := 0 to aList.Count - 1 do
     5511  begin
     5512    newstring := aList[i];
    44555513    newestdate := FMCorrectedDate(Piece(newstring, '^', 3));
    44565514    checkdate := strtofloatdef(newestdate, -BIG_NUMBER);
    44575515    if checkdate > newdate then newdate := checkdate;
    44585516    SetPiece(newstring, '^', 2, aNewItemNum);
    4459     lstTemp.Items.Add(newstring);
    4460   end;
    4461   lstData.Items.AddStrings(lstTemp.Items);
     5517    GtslTemp.Add(newstring);
     5518  end;
     5519  FastAddStrings(GtslTemp, GtslData);
    44625520  newestdate := floattostr(newdate);
    44635521  SetPiece(aNewString, '^', 2, aNewItemNum);
    44645522  SetPiece(aNewString, '^', 4, aNewItemName);
    44655523  SetPiece(aNewString, '^', 6, newestdate);
    4466   lstItems.Items.Add(aNewString);
    4467   lstMultiSpec.Items.Add(aNewString);
     5524  GtslItems.Add(aNewString);
     5525  GtslMultiSpec.Add(aNewString);
    44685526end;
    44695527
     
    44925550        mnuPopGraphRemove.Caption := 'Remove - ' + seriestitle;
    44935551        mnuPopGraphDetails.Caption := 'Details - ' + seriestitle;
     5552        mnuPopGraphValueMarks.Caption := 'Values - ';
     5553        mnuPopGraphValueMarks.Enabled := false;
    44945554      end
    44955555      else
     
    45115571        mnuPopGraphRemove.Caption := 'Remove - ' + seriestitle;
    45125572        mnuPopGraphDetails.Caption := 'Details - ' + seriestitle;
     5573        mnuPopGraphValueMarks.Caption := 'Values - ';
     5574        mnuPopGraphValueMarks.Enabled := false;
    45135575      end
    45145576      else
     
    45305592  fmdatetime := datetimetofmdatetime(aDateTime);
    45315593  fmstring := floattostr(fmdatetime);
    4532   for i := 0 to lstData.Items.Count - 1 do
    4533   begin
    4534     datastring := lstData.Items[i];
     5594  for i := 0 to GtslData.Count - 1 do
     5595  begin
     5596    datastring := GtslData[i];
    45355597    if Pieces(datastring, '^', 1, 2) = '120.5^1' then   //********** get item # for bp instead of 1
    45365598    begin
     
    45475609end;
    45485610
    4549 procedure TfrmGraphs.mnuMedsasganttClick(Sender: TObject);
    4550 begin
    4551   (Sender as TMenuItem).Checked := true;
    4552   lvwItemsTopClick(self);
    4553   lvwItemsBottomClick(self);
     5611procedure TfrmGraphs.mnuCustomClick(Sender: TObject);
     5612begin
     5613  mnuCustom.Checked := not mnuCustom.Checked;
     5614  tsTopCustom.TabVisible := mnuCustom.Checked;
     5615  tsBottomCustom.TabVisible := mnuCustom.Checked;
     5616end;
     5617
     5618procedure TfrmGraphs.mnuGraphDataClick(Sender: TObject);
     5619begin
     5620  frmGraphData.Show;
     5621end;
     5622
     5623procedure TfrmGraphs.mnuMHasNumeric1Click(Sender: TObject);
     5624begin
     5625  DialogGraphOthers(1);
    45545626end;
    45555627
     
    45575629begin
    45585630  FFirstClick := true;
    4559   lstZoomHistory.Items.Clear;
     5631  GtslZoomHistoryFloat.Clear;
    45605632  FRetainZoom := false;
    45615633  mnuPopGraphZoomBack.Enabled := false;
     
    45665638  ValueIndex: Integer; var MarkText: String);
    45675639var
    4568   cnt, i: integer;
    4569   checktag, nonstring: string;
    4570 begin    // ********* listing one series' values is ok but no multiple ???
     5640  i: integer;
     5641  checktag, checkindex, checkseries, firstdatecheck, firsttext, nonstring: string;
     5642begin
     5643  firsttext := MarkText;
    45715644  MarkText := Sender.Title;
    4572   if Copy(MarkText, 1, 4) = 'Ref ' then
    4573     MarkText := '';
    4574   if Sender.Title = '(non-numeric)' then
     5645  if Copy(MarkText, 1, 4) = 'Ref ' then MarkText := ''
     5646  else if Piece(Sender.Title, '^', 1) = '(non-numeric)' then
    45755647  begin
    45765648    if Sender.Tag > 0 then
    45775649    begin
    4578       checktag := inttostr(Sender.Tag);
    4579       cnt := -1;
    4580       for i := 0 to lstNonNumeric.Items.Count - 1 do
     5650      checkseries := inttostr(Sender.Tag - BIG_NUMBER);
     5651      firstdatecheck := floattostr(sender.XValue[ValueIndex]);
     5652      checktag := inttostr(Sender.ParentChart.Tag);
     5653      checkindex := inttostr(ValueIndex + 1);
     5654      for i := 0 to GtslNonNum.Count - 1 do
    45815655      begin
    4582         nonstring := lstNonNumeric.Items[i];
    4583         if  checktag = Piece(nonstring, '^', 3) then
     5656        nonstring := GtslNonNum[i];
     5657        if checktag = '0' then
    45845658        begin
    4585           cnt := cnt + 1;
    4586           if  cnt = ValueIndex then
     5659          if checkseries = Piece(nonstring, '^', 3) then
     5660            if Piece(nonstring, '^', 4) = checkindex then
     5661            begin
     5662              MarkText := Piece(nonstring, '^', 13);
     5663            end;
     5664        end
     5665        else if checktag = Piece(nonstring, '^', 2) then
     5666        begin
     5667          if checkseries = Piece(nonstring, '^', 3) then
     5668          if Piece(nonstring, '^', 4) = checkindex then
    45875669          begin
    4588             MarkText := Piece(nonstring, '^', 2);
     5670            MarkText := Piece(nonstring, '^', 13);
    45895671            break;
    45905672          end;
    45915673        end;
    45925674      end;
    4593       if MarkText = '(non-numeric)' then
    4594         beep;
    4595     end;
    4596   end;
     5675    end;
     5676  end
     5677  else if Sender is TLineSeries then
     5678    MarkText := firsttext;   
    45975679end;
    45985680
    45995681procedure TfrmGraphs.mnuPopGraphRemoveClick(Sender: TObject);
    46005682var
    4601   i, selnum: integer;
     5683  selnum: integer;
    46025684  aSection, typeitem: string;
    4603   aComboBox: TORComboBox;
     5685  aListBox: TORListBox;
    46045686  aListView: TListView;
    46055687begin
     
    46075689  if pnlTop.Tag = 1 then
    46085690  begin
    4609     aComboBox := cboViewsTop;
     5691    aListBox := lstViewsTop;
    46105692    aListView := lvwItemsTop;
    46115693    aSection := 'top';
     
    46135695  else
    46145696  begin
    4615     aComboBox := cboViewsBottom;
     5697    aListBox := lstViewsBottom;
    46165698    aListView := lvwItemsBottom;
    46175699    aSection := 'bottom';
    46185700  end;
    4619   aComboBox.ItemIndex := -1;
    4620   aComboBox.Text := '';
     5701  aListBox.ItemIndex := -1;
    46215702  if aListView.SelCount = 0 then exit;
    46225703  if StripHotKey(mnuPopGraphRemove.Caption) = ('Remove all selections from ' + aSection) then
    4623   begin
    4624     with aListView do
    4625     for i := 0 to Items.Count - 1 do
    4626       if Items[i].Selected then
    4627       begin
    4628         Items[i].Selected := false;
    4629       end;
    4630     DisplayData('top');
    4631     DisplayData('bottom');
    4632   end
     5704    aListView.Selected := nil
    46335705  else
    46345706  begin
     
    46365708    if selnum = -1 then exit;
    46375709    aListView.Items[selnum].Selected := false;
    4638     DisplayData('top');
    4639     DisplayData('bottom');
    4640   end;
     5710  end;
     5711  DisplayData('top');
     5712  DisplayData('bottom');
    46415713  mnuPopGraphRemove.Enabled := false;
    46425714  mnuPopGraphResetClick(self);
     
    46565728  displayheight, displaynum, i: integer;
    46575729begin
     5730  if Not Assigned(FGraphSetting) then Exit;
    46585731  ChartOnZoom(chartDatelineTop);
    46595732  with aScrollBox do
     
    48165889end;
    48175890
     5891procedure TfrmGraphs.BorderValue(var bordervalue: double; value: double);
     5892begin
     5893  if FGraphSetting.FixedDateRange then
     5894    if bordervalue = -BIG_NUMBER then
     5895      bordervalue := value;
     5896end;
     5897
     5898procedure TfrmGraphs.BPAdd(itemvalue: string; adatetime: TDateTime; var fixeddatevalue: double; serLine, serBPDiastolic, serBPMean: TLineSeries);
     5899var
     5900  value: double;
     5901  valueD, valueM, valueS: string;
     5902begin
     5903  valueS := Piece(itemvalue, '/', 1);
     5904  valueD := Piece(itemvalue, '/', 2);
     5905  valueM := Piece(itemvalue, '/', 3);
     5906  value := strtofloatdef(valueS, -BIG_NUMBER);
     5907  if value <> -BIG_NUMBER then
     5908    serLine.AddXY(adatetime, value, '', clTeeColor);
     5909  value := strtofloatdef(valueD, -BIG_NUMBER);
     5910  if value <> -BIG_NUMBER then
     5911    serBPDiastolic.AddXY(adatetime, value, '', clTeeColor);
     5912  value := strtofloatdef(valueM, -BIG_NUMBER);
     5913  if value <> -BIG_NUMBER then
     5914  begin
     5915    serBPMean.AddXY(adatetime, value, '', clTeeColor);
     5916    serBPMean.Active := true;
     5917  end;
     5918  BorderValue(fixeddatevalue, 100);
     5919end;
     5920
     5921procedure TfrmGraphs.BPCheck(aChart: TChart; aFileType: string; serLine, serBPDiastolic, serBPMean: TLineSeries);
     5922begin
     5923  MakeSeriesBP(aChart, serLine, serBPDiastolic, aFileType);
     5924  MakeSeriesBP(aChart, serLine, serBPMean, aFileType);
     5925  serBPDiastolic.Active := true;
     5926  serBPMean.Active := false;
     5927end;
     5928
     5929procedure TfrmGraphs.PainAdd(serBlank: TPointSeries);
     5930begin
     5931  begin
     5932    serBlank.Active := true;
     5933    serBlank.Pointer.Pen.Visible := false;
     5934    serBlank.AddXY(IncDay(FGraphSetting.LowTime, -1), 0, '', pnlScrollTopBase.Color);
     5935    serBlank.AddXY(IncDay(FGraphSetting.LowTime, -1), 10, '', pnlScrollTopBase.Color);
     5936  end;
     5937end;
     5938
     5939procedure TfrmGraphs.NumAdd(serLine: TLineSeries; value: double; adatetime: TDateTime;
     5940  var fixeddatevalue, hi, lo: double; var high, low: string);
     5941begin
     5942  if (btnChangeSettings.Tag = 1) and (hi <> -BIG_NUMBER) and (lo <> -BIG_NUMBER) then
     5943  begin      // standard deviation
     5944    value := StdDev(value, hi, lo);
     5945    serLine.AddXY(adatetime, value, '', clTeeColor);
     5946    high := '2'; low := '-2';
     5947    BorderValue(fixeddatevalue, 0);
     5948    //splGraphs.Tag := 1;   // show ref range
     5949  end        // inverse value
     5950  else if btnChangeSettings.Tag = 2 then
     5951  begin
     5952    value := InvVal(value);
     5953    serLine.AddXY(adatetime, value, '', clTeeColor);
     5954    high := '2'; low := '0';
     5955    BorderValue(fixeddatevalue, 0);
     5956    splGraphs.Tag := 0;  // do not show ref range
     5957  end
     5958  else
     5959  begin       // numeric value
     5960    serLine.AddXY(adatetime, value, '', clTeeColor);
     5961    BorderValue(fixeddatevalue, value);
     5962  end;
     5963end;
     5964
     5965procedure TfrmGraphs.NonNumSave(aChart: TChart; aTitle, aSection: string; adatetime: TDateTime;
     5966  var noncnt: integer; newcnt, aIndex: integer);
     5967var
     5968  astring: string;
     5969begin
     5970  noncnt := noncnt + 1;
     5971  astring := floattostr(adatetime) + '^' + inttostr(aChart.Tag) + '^'
     5972           + inttostr(newcnt) + '^' + inttostr(noncnt) + '^^' + aTitle + '^'
     5973           + aSection + '^^' + GtslTemp[aIndex];
     5974  GtslNonNum.Add(astring);
     5975end;
     5976
    48185977//****************************************************************************
    48195978
    4820 procedure TfrmGraphs.MakeLineSeries(aChart: TChart; aTitle, aFileType: string; var aSerCnt, aNonCnt: integer; multiline: boolean);
    4821 
    4822   procedure BorderValue(var bordervalue: double; value: double);
    4823   begin
    4824     if FGraphSetting.FixedDateRange then
    4825       if bordervalue = -BIG_NUMBER then
    4826         bordervalue := value;
    4827   end;
    4828 
    4829 var
    4830   estimate, firstcnt, i, noncnt: integer;
    4831   value, fixeddatevalue, hi, highestvalue, highvalue, lo, nonvalue: double;
    4832   checkdata, fmtime, itemvalue, valueD, valueM, valueS: string;
    4833   high, low, specimen: string;
     5979procedure TfrmGraphs.MakeLineSeries(aChart: TChart; aTitle, aFileType, section: string;
     5980  var aSerCnt, aNonCnt: integer; multiline: boolean);
     5981var
     5982  i, noncnt, newcnt: integer;
     5983  value, fixeddatevalue, hi, lo: double;
     5984  checkdata, fmtime, itemvalue: string;
     5985  high, low, specimen, comments: string;
    48345986  adatetime, adatetime1: TDateTime;
    48355987  afixeddate, afixeddate1: TDateTime;
    4836   ser1, ser2, ser3, serLow, serHigh: TLineSeries;
    4837   serBlank, serPoint: TPointSeries;
     5988  serLine, serBPDiastolic, serBPMean, serLow, serHigh: TLineSeries;
     5989  serBlank: TPointSeries;
    48385990begin
    48395991  fixeddatevalue := -BIG_NUMBER;
    4840   highestvalue := aChart.MaxYValue(aChart.LeftAxis);
    4841   if highestvalue < 1 then highestvalue := 1;
    4842   firstcnt := lstNonNumeric.Items.Count;
    4843   noncnt := firstcnt;
     5992  noncnt := 0; //GtslNonNum.Count;
    48445993  aChart.LeftAxis.LabelsFont.Color := aChart.BottomAxis.LabelsFont.Color;
    48455994  aSerCnt := aSerCnt + 1;
    4846   ser1 := TLineSeries.Create(aChart);
    4847   ser2 := TLineSeries.Create(aChart);
    4848   ser3 := TLineSeries.Create(aChart);
    4849   serPoint := TPointSeries.Create(aChart);
    4850   serBlank := TPointSeries.Create(aChart);
    4851   serLow := TLineSeries.Create(aChart);
    4852   serHigh := TLineSeries.Create(aChart);
    48535995  specimen := LowerCase(Piece(aTitle, '^', 4));
    4854   low := Piece(aTitle, '^', 5);                   // collect non numeric - graph as events
     5996  low := Piece(aTitle, '^', 5);
    48555997  high := Piece(aTitle, '^', 6);
    48565998  lo := strtofloatdef(low, -BIG_NUMBER);
    48575999  hi := strtofloatdef(high, -BIG_NUMBER);
     6000  serLine := TLineSeries.Create(aChart);
     6001  newcnt := aChart.SeriesCount;
     6002  serBPDiastolic := TLineSeries.Create(aChart);
     6003  serBPMean := TLineSeries.Create(aChart);
     6004  serLow := TLineSeries.Create(aChart);
    48586005  serLow.Active := false;
     6006  serHigh := TLineSeries.Create(aChart);
    48596007  serHigh.Active := false;
    4860   serPoint.Active := false;
     6008  serBlank := TPointSeries.Create(aChart);
    48616009  serBlank.Active := false;
    4862   with ser1 do
    4863   begin
     6010  with serLine do
     6011  begin
     6012    MakeSeriesInfo(aChart, serLine, aTitle, aFileType, aSerCnt);
    48646013    LinePen.Visible := FGraphSetting.Lines;
    4865     ParentChart := aChart;
    4866     Title := Piece(aTitle, '^', 3);
    48676014    if (length(specimen) > 0) and (not ansicontainsstr(Title, specimen)) then
    48686015      Title := Title + ' (' + specimen + ')';
    4869     XValues.DateTime := True;
    4870     NextPointerStyle(ser1, aSerCnt);
    4871     Identifier := aFileType;
    48726016    Pointer.Visible := true;
    48736017    Pointer.InflateMargins := true;
    4874     GetData(aTitle);
    4875     ColorEachPoint := false;
    4876     SeriesColor := NextColor(aSerCnt);
    4877     Marks.BackColor := clInfoBk;
    4878     if ser1.Title = 'Blood Pressure' then
    4879     begin
    4880       ser1.Title := 'Blood Pressure';
    4881       with ser2 do
     6018    NextPointerStyle(serLine, aSerCnt);
     6019    Tag := newcnt;
     6020  end;
     6021  if serLine.Title = 'Blood Pressure' then
     6022    BPCheck(aChart, aFileType, serLine, serBPDiastolic, serBPMean);
     6023  for i:= 0 to GtslTemp.Count - 1 do
     6024  begin
     6025    checkdata := GtslTemp[i];
     6026    fmtime := FMCorrectedDate(Piece(checkdata, '^', 3));
     6027    if IsFMDateTime(fmtime) then
     6028    begin
     6029      HighLow(fmtime, '', aChart, adatetime, adatetime1);
     6030      comments := Piece(checkdata, '^', 9);
     6031      if strtointdef(comments, -1) > 0  then aChart.Hint := comments;  // for any occurrence
     6032      itemvalue := Piece(checkdata, '^', 5);
     6033      itemvalue := trim(itemvalue);
     6034      itemvalue := StringReplace(itemvalue, ',', '', [rfReplaceAll]);
     6035      if serLine.Title = 'Blood Pressure' then
     6036        BPAdd(itemvalue, adatetime, fixeddatevalue, serLine, serBPDiastolic, serBPMean)
     6037      else
    48826038      begin
    4883         ParentChart := aChart;
    4884         Title := 'Blood Pressure';
    4885         XValues.DateTime := true;
    4886         Pointer.Style := ser1.Pointer.Style;
    4887         ShowInLegend := false;    //****
    4888         Identifier := aFileType;
    4889         Pointer.Visible := true;
    4890         Pointer.InflateMargins := true;
    4891         ColorEachPoint := false;
    4892         SeriesColor := ser1.SeriesColor;
    4893         Marks.BackColor := clInfoBk;
    4894         Active := true;
     6039        value := strtofloatdef(itemvalue, -BIG_NUMBER);
     6040        if value <> -BIG_NUMBER then
     6041          NumAdd(serLine, value, adatetime, fixeddatevalue, hi, lo, high, low)
     6042        else
     6043          NonNumSave(aChart, serLine.Title, section, adatetime, noncnt, newcnt, i);
    48956044      end;
    4896       with ser3 do
    4897       begin
    4898         ParentChart := aChart;
    4899         Title := 'Blood Pressure';
    4900         XValues.DateTime := true;
    4901         Pointer.Style := ser1.Pointer.Style;
    4902         ShowInLegend := false;   //****
    4903         Identifier := aFileType;
    4904         Pointer.Visible := true;
    4905         Pointer.InflateMargins := true;
    4906         ColorEachPoint := false;
    4907         SeriesColor := ser1.SeriesColor;
    4908         Marks.BackColor := clInfoBk;
    4909         Active := false;
    4910       end;
    4911     end
    4912     else
    4913     begin
    4914       ser2.Active := false;
    4915       ser3.Active := false;
    4916     end;
    4917     highvalue := 0;
    4918     with lstTemp do
    4919     for i:= 0 to Items.Count - 1 do
    4920     begin
    4921       checkdata := lstTemp.Items[i];
    4922       fmtime := FMCorrectedDate(Piece(Items[i], '^', 3));
    4923       if IsFMDateTime(fmtime) then
    4924       begin
    4925         HighLow(fmtime, '', aChart, adatetime, adatetime1);
    4926         itemvalue := Piece(Items[i], '^', 5);
    4927         itemvalue := trim(itemvalue);
    4928         itemvalue := StringReplace(itemvalue, ',', '', [rfReplaceAll]);
    4929         if ser1.Title = 'Blood Pressure' then
    4930         begin
    4931           valueS := Piece(itemvalue, '/', 1);
    4932           valueD := Piece(itemvalue, '/', 2);
    4933           valueM := Piece(itemvalue, '/', 3);
    4934           value := strtofloatdef(valueS, -BIG_NUMBER);
    4935           if value <> -BIG_NUMBER then
    4936             ser1.AddXY(adatetime, value, '', clTeeColor);
    4937           value := strtofloatdef(valueD, -BIG_NUMBER);
    4938           if value <> -BIG_NUMBER then
    4939             ser2.AddXY(adatetime, value, '', clTeeColor);
    4940           value := strtofloatdef(valueM, -BIG_NUMBER);
    4941           if value <> -BIG_NUMBER then
    4942           begin
    4943             ser3.AddXY(adatetime, value, '', clTeeColor);
    4944             ser3.Active := true;
    4945           end;
    4946           BorderValue(fixeddatevalue, 100);
    4947         end
    4948         else
    4949         begin
    4950           value := strtofloatdef(itemvalue, -BIG_NUMBER);
    4951           if value <> -BIG_NUMBER then
    4952           begin
    4953             if (btnChangeSettings.Tag = 1) and (hi <> -BIG_NUMBER) and (lo <> -BIG_NUMBER) then
    4954             begin
    4955               value := StdDev(value, hi, lo);
    4956               ser1.AddXY(adatetime, value, '', clTeeColor);
    4957               high := '2'; low := '-2';
    4958               BorderValue(fixeddatevalue, 0);
    4959               //splGraphs.Tag := 1;   // show ref range
    4960             end
    4961             else if btnChangeSettings.Tag = 2 then
    4962             begin
    4963               value := InvVal(value);
    4964               ser1.AddXY(adatetime, value, '', clTeeColor);
    4965               high := '2'; low := '0';
    4966               BorderValue(fixeddatevalue, 0);
    4967               splGraphs.Tag := 0;  // do not show ref range
    4968             end
    4969             else
    4970             begin
    4971               ser1.AddXY(adatetime, value, '', clTeeColor);
    4972               if value > highvalue then
    4973                 highvalue := value;
    4974               BorderValue(fixeddatevalue, value);
    4975             end;
    4976           end
    4977           else
    4978           begin
    4979             noncnt := noncnt + 1;
    4980             lstNonNumeric.Items.Add(floattostr(adatetime) + '^' +
    4981               itemvalue + '^' + inttostr(aNonCnt + 1));
    4982           end;
    4983         end;
    4984       end;
    4985     end;
    4986     if (length(low) > 0) and (splGraphs.Tag = 1) then
    4987     begin
    4988       with serLow do
    4989       begin
    4990         Active := true;
    4991         ParentChart := aChart;
    4992         XValues.DateTime := True;
    4993         Pointer.Visible := false;
    4994         Pointer.InflateMargins := true;
    4995         OnGetMarkText := serDatelineTop.OnGetMarkText;
    4996         ColorEachPoint := false;
    4997         Title := 'Ref Low ' + low;
    4998         Pointer.Style := psCircle;
    4999         SeriesColor := ser1.SeriesColor; //clBtnShadow ; //clTeeColor;
    5000         Marks.Visible := false;
    5001         LinePen.Visible := true;
    5002         LinePen.Width := 2;
    5003         LinePen.Style := psDash;  //does not show when width <> 1
    5004       end;
    5005       value := strtofloatdef(low, -BIG_NUMBER);
    5006       if value <> -BIG_NUMBER then
    5007       begin
    5008         serLow.AddXY(IncDay(FGraphSetting.LowTime, -1), value, '', clTeeColor);
    5009         serLow.AddXY(IncDay(FGraphSetting.HighTime, 1), value, '', clTeeColor);
    5010         BorderValue(fixeddatevalue, value);
    5011       end;
    5012     end;
    5013     if (length(high) > 0) and (splGraphs.Tag = 1) then
    5014     begin
    5015       with serHigh do
    5016       begin
    5017         Active := true;
    5018         ParentChart := aChart;
    5019         XValues.DateTime := True;
    5020         Pointer.Visible := false;
    5021         Pointer.InflateMargins := true;
    5022         OnGetMarkText := serDatelineTop.OnGetMarkText;
    5023         ColorEachPoint := false;
    5024         Title := 'Ref High ' + high;
    5025         Pointer.Style := psCircle;
    5026         SeriesColor := ser1.SeriesColor; // clBtnShadow; //clTeeColor;
    5027         Marks.Visible := false;
    5028         LinePen.Visible := true;
    5029         LinePen.Width := 2;
    5030         LinePen.Style := psDash;  //does not show when width <> 1
    5031       end;
    5032       value := strtofloatdef(high, -BIG_NUMBER);
    5033       if value <> -BIG_NUMBER then
    5034       begin
    5035         serHigh.AddXY(IncDay(FGraphSetting.LowTime, -1), value, '', clTeeColor);
    5036         serHigh.AddXY(IncDay(FGraphSetting.HighTime, 1), value, '', clTeeColor);
    5037         BorderValue(fixeddatevalue, value);
    5038       end;
    5039     end;
    5040     splGraphs.Tag := 0;
    5041     if noncnt > firstcnt then
    5042     begin
    5043       if aChart.Height < 10 then estimate := pnlMain.Height div 2
    5044       else estimate := aChart.Height;
    5045       aNonCnt := aNonCnt + 1;  // use nonnumeric count to offset position
    5046       nonvalue := (aNonCnt * (10 / (estimate + 1)) * highestvalue);
    5047       with serBlank do
    5048       begin
    5049         Active := true;
    5050         ParentChart := aChart;
    5051         XValues.DateTime := True;
    5052         Pointer.Visible := true;
    5053         Pointer.InflateMargins := true;
    5054         OnGetMarkText := serDatelineTop.OnGetMarkText;
    5055         ColorEachPoint := false;
    5056         Title := '';
    5057         Pointer.Style := psSmallDot;
    5058         SeriesColor := aChart.Color;
    5059         Marks.Visible := false;
    5060         ShowInLegend := false;
    5061       end;
    5062       with serPoint do
    5063       begin
    5064         Active := true;
    5065         ParentChart := aChart;
    5066         XValues.DateTime := True;
    5067         Pointer.Visible := true;
    5068         Pointer.InflateMargins := true;
    5069         OnGetMarkText := serDatelineTop.OnGetMarkText;
    5070         ColorEachPoint := false;
    5071         Title := '(non-numeric)';
    5072         Hint := aTitle;
    5073         Tag := aNonCnt;
    5074         Pointer.Style := ser1.Pointer.Style;
    5075         SeriesColor := ser1.SeriesColor;
    5076         Marks.BackColor := clInfoBk;
    5077         ShowInLegend := false;
    5078       end;
    5079       for i := 0 to lstNonNumeric.Items.Count - 1 do
    5080       begin
    5081         if Piece(lstNonNumeric.Items[i], '^',3) = inttostr(aNonCnt) then
    5082         if highvalue = 0 then
    5083         begin
    5084           adatetime := strtofloatdef(Piece(lstNonNumeric.Items[i], '^', 1), -BIG_NUMBER);
    5085           if adatetime <> -BIG_NUMBER then
    5086           begin
    5087             serBlank.Pointer.Pen.Visible := false;
    5088             serBlank.AddXY(adatetime, 1, '', pnlScrollTopBase.Color);
    5089             break;
    5090           end;
    5091         end;
    5092       end;
    5093       for i := 0 to lstNonNumeric.Items.Count - 1 do
    5094       if Piece(lstNonNumeric.Items[i], '^',3) = inttostr(aNonCnt) then
    5095       begin
    5096         adatetime := strtofloatdef(Piece(lstNonNumeric.Items[i], '^', 1), -BIG_NUMBER);
    5097         if adatetime <> -BIG_NUMBER then
    5098         begin
    5099           serPoint.Pointer.Pen.Visible := true;
    5100           serPoint.AddXY(adatetime, nonvalue, '', ser1.SeriesColor);
    5101           BorderValue(fixeddatevalue, nonvalue);
    5102         end;
    5103       end;
    5104       if highvalue = 0 then
    5105       begin
    5106         aChart.LeftAxis.LabelsFont.Color := pnlScrollTopBase.Color;
    5107         FNonNumerics := true;
    5108       end;
    5109     end;
    5110     if ser1.Title = 'Pain' then
    5111     begin
    5112       if not serBlank.Active then
    5113       with serBlank do
    5114       begin
    5115         Active := true;
    5116         ParentChart := aChart;
    5117         XValues.DateTime := True;
    5118         Pointer.Visible := true;
    5119         Pointer.InflateMargins := true;
    5120         OnGetMarkText := serDatelineTop.OnGetMarkText;
    5121         ColorEachPoint := false;
    5122         Title := '';
    5123         Pointer.Style := psSmallDot;
    5124         SeriesColor := aChart.Color;
    5125         Marks.Visible := false;
    5126         ShowInLegend := false;
    5127       end;
    5128       serBlank.Pointer.Pen.Visible := false;
    5129       serBlank.AddXY(IncDay(FGraphSetting.LowTime, -1), 0, '', pnlScrollTopBase.Color);
    5130       serBlank.AddXY(IncDay(FGraphSetting.LowTime, -1), 10, '', pnlScrollTopBase.Color);
    5131     end;
    5132     if multiline then
    5133     begin
    5134       // do nothing for now
    5135     end;
    5136     if fixeddatevalue <> -BIG_NUMBER then
    5137     begin
    5138       if not serBlank.Active then
    5139       with serBlank do
    5140       begin
    5141         Active := true;
    5142         ParentChart := aChart;
    5143         XValues.DateTime := True;
    5144         Pointer.Visible := true;
    5145         Pointer.InflateMargins := true;
    5146         OnGetMarkText := serDatelineTop.OnGetMarkText;
    5147         ColorEachPoint := false;
    5148         Title := '';
    5149         Pointer.Style := psSmallDot;
    5150         SeriesColor := aChart.Color;
    5151         Marks.Visible := false;
    5152         ShowInLegend := false;
    5153       end;
    5154       FixedDates(afixeddate, afixeddate1);
    5155       serBlank.Pointer.Pen.Visible := false;
    5156       serBlank.AddXY(afixeddate, fixeddatevalue, '', aChart.Color);
    5157       serBlank.AddXY(afixeddate1, fixeddatevalue, '', aChart.Color);
    5158     end;
    5159     GetHorizAxis.ExactDateTime := True;
    5160     GetHorizAxis.Increment := DateTimeStep[dtOneMinute];
     6045    end;
     6046  end;
     6047  if (length(low) > 0) and (splGraphs.Tag = 1) then
     6048    MakeSeriesRef(aChart, serLine, serLow, 'Ref Low ', low, fixeddatevalue);
     6049  if (length(high) > 0) and (splGraphs.Tag = 1) then
     6050    MakeSeriesRef(aChart, serLine, serHigh, 'Ref High ', high, fixeddatevalue);
     6051  splGraphs.Tag := 0;
     6052  MakeSeriesPoint(aChart, serBlank);
     6053  if serLine.Title = 'Pain' then
     6054    PainAdd(serBlank);
     6055  if multiline then
     6056  begin
     6057    // do nothing for now
     6058  end;
     6059  if fixeddatevalue <> -BIG_NUMBER then
     6060  begin
     6061    serBlank.Active := true;
     6062    serBlank.Pointer.Pen.Visible := false;
     6063    FixedDates(afixeddate, afixeddate1);
     6064    serBlank.AddXY(afixeddate, fixeddatevalue, '', aChart.Color);
     6065    serBlank.AddXY(afixeddate1, fixeddatevalue, '', aChart.Color);
    51616066  end;
    51626067end;
     
    51686073  fmtime: string;
    51696074  adatetime, adatetime1: TDateTime;
    5170   ser1: TPointSeries;
     6075  serPoint: TPointSeries;
    51716076begin
    51726077  aSerCnt := aSerCnt + 1;
    5173   ser1 := TPointSeries.Create(aChart);
    5174   with ser1 do
    5175   begin
    5176     ParentChart := aChart;
    5177     Title := Piece(aTitle, '^', 3);
    5178     OnGetMarkText := serDatelineTop.OnGetMarkText;
    5179     XValues.DateTime := True;
    5180     NextPointerStyle(ser1, aSerCnt);
     6078  serPoint := TPointSeries.Create(aChart);
     6079  MakeSeriesInfo(aChart, serPoint, aTitle, aFileType, aSerCnt);
     6080  with serPoint do
     6081  begin
     6082    NextPointerStyle(serPoint, aSerCnt);
     6083    Pointer.Visible := true;
     6084    Pointer.InflateMargins := true;
     6085    Pointer.Style := psSmallDot;
     6086    Pointer.Pen.Visible := true;
    51816087    Pointer.VertSize := 10;
    51826088    Pointer.HorizSize := 2;
    5183     Identifier := aFileType;
    5184     Pointer.Visible := true;
    5185     GetData(aTitle);
    5186     ColorEachPoint := false;
    5187     SeriesColor := NextColor(aSerCnt);
    5188     Marks.BackColor := clInfoBk;
    5189     with lstTemp do
    5190     for i := 0 to lstTemp.Items.Count - 1 do
    5191     begin
    5192       fmtime := FMCorrectedDate(Piece(Items[i], '^', 3));
     6089    for i := 0 to GtslTemp.Count - 1 do
     6090    begin
     6091      fmtime := FMCorrectedDate(Piece(GtslTemp[i], '^', 3));
    51936092      if IsFMDateTime(fmtime) then
    51946093      begin
    51956094        HighLow(fmtime, '', aChart, adatetime, adatetime1);
    5196         value := strtofloatdef(Piece(Items[i], '^', 5), -BIG_NUMBER);
     6095        value := strtofloatdef(Piece(GtslTemp[i], '^', 5), -BIG_NUMBER);
    51976096        if value = -BIG_NUMBER then
    51986097        begin
    51996098          value := aSerCnt;
    5200           TempCheck(Pieces(Items[i], '^', 1, 2), value);
     6099          TempCheck(Pieces(GtslTemp[i], '^', 1, 2), value);
    52016100        end;
    5202         ser1.AddXY(adatetime, value, '', clTeeColor);
     6101        serPoint.AddXY(adatetime, value, '', clTeeColor);
    52036102      end;
    52046103    end;
    5205     GetHorizAxis.ExactDateTime := True;
    5206     GetHorizAxis.Increment := DateTimeStep[dtOneMinute];
    52076104  end;
    52086105end;
     
    52156112  adatetime, adatetime1: TDateTime;
    52166113  afixeddate, afixeddate1: TDateTime;
    5217   ser1: TBarSeries;
     6114  serBar: TBarSeries;
    52186115  serBlank: TPointSeries;
    52196116begin
    52206117  aSerCnt := aSerCnt + 1;
    5221   ser1 := TBarSeries.Create(aChart);
    52226118  serBlank := TPointSeries.Create(aChart);
    5223   with serBlank do
    5224   begin
    5225     Active := true;
    5226     ParentChart := aChart;
    5227     XValues.DateTime := True;
    5228     Pointer.Visible := true;
    5229     Pointer.InflateMargins := false;
    5230     ColorEachPoint := false;
    5231     Title := '';
    5232     Pointer.Style := psSmallDot;
    5233     OnGetMarkText := serDatelineTop.OnGetMarkText;
    5234     SeriesColor := aChart.Color;
    5235     Marks.BackColor := clInfoBk;
    5236     ShowInLegend := false;
    5237   end;
    5238   with ser1 do
    5239   begin
    5240     ParentChart := aChart;
    5241     Title := Piece(aTitle, '^', 3);
    5242     XValues.DateTime := True;
     6119  MakeSeriesPoint(aChart, serBlank);
     6120  serBar := TBarSeries.Create(aChart);
     6121  MakeSeriesInfo(aChart, serBar, aTitle, aFileType, aSerCnt);
     6122  with serBar do
     6123  begin
    52436124    YOrigin := 0;
    5244     Identifier := aFileType;
    5245     Marks.Visible := false;
    5246     OnGetMarkText := serDatelineTop.OnGetMarkText;
    52476125    CustomBarWidth := 7;
    5248     Marks.Style := smsLabel;
    5249     GetData(aTitle);
    5250     ColorEachPoint := false;
    5251     SeriesColor := NextColor(aSerCnt);
    5252     Marks.BackColor := clInfoBk;
    5253     NextPointerStyle(ser1, aSerCnt);
    5254     with lstTemp do
    5255     for i:= 0 to Items.Count - 1 do
    5256     begin
    5257       fmtime := FMCorrectedDate(Piece(Items[i], '^', 3));
     6126    NextPointerStyle(serBar, aSerCnt);
     6127    for i:= 0 to GtslTemp.Count - 1 do
     6128    begin
     6129      fmtime := FMCorrectedDate(Piece(GtslTemp[i], '^', 3));
    52586130      if IsFMDateTime(fmtime) then
    52596131      begin
     
    52636135          if copy((FPrevEvent + '00'), 1, 12) = copy(fmtime, 1, 12) then  // same time occurrence
    52646136          begin
    5265             pnlInfo.Caption := TXT_WARNING_SAME_TIME;
    5266             pnlInfo.Color := COLOR_WARNING;
    5267             pnlInfo.Visible := true;
     6137            InfoMessage(TXT_WARNING_SAME_TIME, COLOR_WARNING, true);
    52686138            pnlHeader.Visible := true;
    52696139            FWarning := true;
    52706140          end;
    52716141        if value <> -BIG_NUMBER then
    5272           ser1.AddXY(adatetime, value, '', clTeeColor);
     6142          serBar.AddXY(adatetime, value, '', clTeeColor);
    52736143        FPrevEvent := copy(fmtime, 1, 10);
    52746144        if i = 0 then
     
    52856155      end;
    52866156    end;
    5287     GetHorizAxis.ExactDateTime := True;
    5288     GetHorizAxis.Increment := DateTimeStep[dtOneMinute];
    5289   end;
    5290 end;
    5291 
    5292 procedure TfrmGraphs.MakeManyGanttSeries(aChart: TChart; aTitle, aFileType: string; var aSerCnt: integer);
     6157  end;
     6158end;
     6159
     6160procedure TfrmGraphs.MakeGanttSeries(aChart: TChart; aTitle, aFileType: string; var aSerCnt: integer);
    52936161var
    52946162  i, value: integer;
     
    52966164  adatetime, adatetime1: TDateTime;
    52976165  afixeddate, afixeddate1: TDateTime;
    5298   gantt: TGanttSeries;
     6166  serGantt: TGanttSeries;
    52996167  serBlank: TPointSeries;
    53006168begin
    53016169  aSerCnt := aSerCnt + 1;
    5302   gantt := TGanttSeries.Create(aChart);
    53036170  serBlank := TPointSeries.Create(aChart);
    5304   with serBlank do
    5305   begin
    5306     Active := true;
    5307     ParentChart := aChart;
    5308     XValues.DateTime := True;
    5309     Pointer.Visible := true;
    5310     Pointer.InflateMargins := false;
    5311     ColorEachPoint := false;
    5312     Title := '';
    5313     Pointer.Style := psSmallDot;
    5314     OnGetMarkText := serDatelineTop.OnGetMarkText;
    5315     SeriesColor := aChart.Color;
    5316     Marks.BackColor := clInfoBk;
    5317     ShowInLegend := false;
    5318   end;
    5319   with gantt do
    5320   begin
    5321     ParentChart := aChart;
    5322     Title := Piece(aTitle, '^', 3);
    5323     Marks.Style := smsLabel;
    5324     OnGetMarkText := serDatelineTop.OnGetMarkText;
     6171  MakeSeriesPoint(aChart, serBlank);
     6172  serGantt := TGanttSeries.Create(aChart);
     6173  MakeSeriesInfo(aChart, serGantt, aTitle, aFileType, aSerCnt);
     6174  with serGantt do
     6175  begin
    53256176    if Piece(aTitle, '^', 1) = '55' then       // make inpatient meds smaller to identify
    53266177      Pointer.VertSize := RX_HEIGHT_IN
     
    53316182    else
    53326183      Pointer.VertSize := RX_HEIGHT_OUT;
    5333     GetData(aTitle);
    5334     ColorEachPoint := false;
    5335     SeriesColor := NextColor(aSerCnt);
    5336     Identifier := aFileType;
    5337     Marks.BackColor := clInfoBk;
    53386184    value := round(((aSerCnt mod NUM_COLORS) / NUM_COLORS) * 80) + 20 + aSerCnt;
    53396185    if aFileType <> '9999911' then
    53406186      if aChart <> chartDatelineTop then
    53416187        if aChart <> chartDatelineBottom then
    5342       value := value - 26;
    5343     with lstTemp do
    5344     for i := 0 to lstTemp.Items.Count - 1 do
    5345     begin
    5346       fmtime := FMCorrectedDate(Piece(Items[i], '^', 3));
    5347       fmtime1 := FMCorrectedDate(Piece(Items[i], '^', 4));
     6188          value := value - 26;
     6189    for i := 0 to GtslTemp.Count - 1 do
     6190    begin
     6191      fmtime := FMCorrectedDate(Piece(GtslTemp[i], '^', 3));
     6192      fmtime1 := FMCorrectedDate(Piece(GtslTemp[i], '^', 4));
    53486193      if IsFMDateTime(fmtime) and IsFMDateTime(fmtime1) then
    53496194      begin
     
    53656210      end;
    53666211    end;
    5367     GetHorizAxis.ExactDateTime := True;
    5368     GetHorizAxis.Increment := DateTimeStep[dtOneMinute];
    53696212  end;
    53706213end;
     
    53776220  adatetime, adatetime1: TDateTime;
    53786221  afixeddate, afixeddate1: TDateTime;
    5379   gantt: TGanttSeries;
     6222  serGantt: TGanttSeries;
    53806223  serBlank: TPointSeries;
    53816224begin
    53826225  aSerCnt := aSerCnt + 1;
    5383   gantt := TGanttSeries.Create(aChart);
    53846226  serBlank := TPointSeries.Create(aChart);
    5385   with serBlank do
    5386   begin
    5387     Active := true;
    5388     ParentChart := aChart;
    5389     XValues.DateTime := True;
    5390     Pointer.Visible := true;
    5391     Pointer.InflateMargins := false;
    5392     ColorEachPoint := false;
    5393     Title := '';
    5394     Pointer.Style := psSmallDot;
    5395     OnGetMarkText := serDatelineTop.OnGetMarkText;
    5396     SeriesColor := aChart.Color;
    5397     Marks.Visible := false;
    5398     ShowInLegend := false;
    5399   end;
    5400   with gantt do
    5401   begin
    5402     ParentChart := aChart;
    5403     Title := Piece(aTitle, '^', 3);
    5404     Marks.Style := smsLabel;
    5405     OnGetMarkText := serDatelineTop.OnGetMarkText;
     6227  MakeSeriesPoint(aChart, serBlank);
     6228  serGantt := TGanttSeries.Create(aChart);
     6229  MakeSeriesInfo(aChart, serGantt, aTitle, aFileType, aSerCnt);
     6230  with serGantt do
     6231  begin
    54066232    if Piece(aTitle, '^', 1) = '405' then  // make admit smaller to identify
    54076233      Pointer.VertSize := NUM_COLORS + 3
     
    54106236    else
    54116237      Pointer.VertSize := NUM_COLORS + (aSerCnt mod NUM_COLORS) + 10;
    5412     GetData(aTitle);
    5413     ColorEachPoint := false;
    5414     SeriesColor := NextColor(aSerCnt);
    5415     Identifier := aFileType;
    5416     Marks.BackColor := clInfoBk;
    54176238    value := aSerCnt div NUM_COLORS;
    5418     with lstTemp do
    5419     for i:= 0 to Items.Count - 1 do
    5420     begin
    5421       fmtime := FMCorrectedDate(Piece(Items[i], '^', 3));
    5422       fmtime1 := FMCorrectedDate(Piece(Items[i], '^', 4));
     6239    for i:= 0 to GtslTemp.Count - 1 do
     6240    begin
     6241      fmtime := FMCorrectedDate(Piece(GtslTemp[i], '^', 3));
     6242      fmtime1 := FMCorrectedDate(Piece(GtslTemp[i], '^', 4));
    54236243      if IsFMDateTime(fmtime) and IsFMDateTime(fmtime1) then
    54246244      begin
     
    54386258      end;
    54396259    end;
    5440     GetHorizAxis.ExactDateTime := True;
    5441     GetHorizAxis.Increment := DateTimeStep[dtOneMinute];
    5442   end;
    5443 end;
    5444 
    5445 procedure TfrmGraphs.MakeWeightedGanttSeries(aChart: TChart; aTitle, aFileType: string; var aSerCnt: integer);
    5446 var
    5447   i: integer;
    5448   value: double;
    5449   fmtime, fmtime1: string;
    5450   gantt: TGanttSeries;
    5451   adatetime, adatetime1: TDateTime;
    5452 begin
    5453   aSerCnt := aSerCnt + 1;
    5454   gantt := TGanttSeries.Create(aChart);
    5455   with gantt do
    5456   begin
    5457     ParentChart := aChart;
    5458     Title := Piece(aTitle, '^', 3);
    5459     Marks.Style := smsLabel;
    5460     OnGetMarkText := serDatelineTop.OnGetMarkText;
    5461     value := NUM_COLORS;
    5462     GetData(aTitle);
    5463     ColorEachPoint := false;
    5464     SeriesColor := NextColor(aSerCnt);
    5465     Identifier := aFileType;
    5466     Marks.BackColor := clInfoBk;
    5467     with lstTemp do
    5468     for i:= 0 to Items.Count - 1 do
    5469     begin
    5470       fmtime := FMCorrectedDate(Piece(Items[i], '^', 3));
    5471       fmtime1 := FMCorrectedDate(Piece(Items[i], '^', 4));
    5472       if IsFMDateTime(fmtime) and IsFMDateTime(fmtime1) then
    5473       begin
    5474         HighLow(fmtime, fmtime1, aChart, adatetime, adatetime1);
    5475         value := Vfactor(Piece(aTitle, '^', 3));
    5476         AddGantt(adatetime, adatetime1, 1, '');
    5477         value := value + (value / 2);
    5478       end;
    5479     end;
    5480     Pointer.VertSize := round(value);
    5481     GetHorizAxis.ExactDateTime := True;
    5482     GetHorizAxis.Increment := DateTimeStep[dtOneMinute];
    5483   end;
    5484 end;
    5485 
    5486 procedure TfrmGraphs.MakeArrowSeries(aChart: TChart; aTitle, aFileType: string; var aSerCnt: integer);
    5487 var
    5488   i: integer;
    5489   value: double;
    5490   fmtime, fmtime1: string;
    5491   arrows: TArrowSeries;
    5492   adatetime, adatetime1: TDateTime;
    5493 begin
    5494   aSerCnt := aSerCnt + 1;
    5495   arrows := TArrowSeries.Create(aChart);
    5496   with arrows do
    5497   begin
    5498     ParentChart := aChart;
    5499     Title := Piece(aTitle, '^', 3);
    5500     Clear;
    5501     ArrowWidth := 12;
    5502     ArrowHeight := 9;
    5503     StartXValues.DateTime := true;
    5504     EndXValues.DateTime := true;
    5505     Marks.Style := smsLabel;
    5506     OnGetMarkText := serDatelineTop.OnGetMarkText;
    5507     Pointer.Visible := false;
    5508     Pointer.VertSize := 17; //pnlTop.Height;        //******* for meds
    5509     Pointer.HorizSize := 24;
    5510     Pointer.InflateMargins := true;
    5511     GetData(aTitle);
    5512     ColorEachPoint := false;
    5513     SeriesColor := NextColor(aSerCnt);
    5514     Identifier := aFileType;
    5515     Marks.BackColor := clInfoBk;
    5516     with lstTemp do
    5517     for i:= 0 to Items.Count - 1 do
    5518     begin
    5519       fmtime := FMCorrectedDate(Piece(Items[i], '^', 3));
    5520       fmtime1 := FMCorrectedDate(Piece(Items[i], '^', 4));
    5521       if IsFMDateTime(fmtime) and IsFMDateTime(fmtime1) then
    5522       begin
    5523         HighLow(fmtime, fmtime1, aChart, adatetime, adatetime1);
    5524         value := strtofloatdef(Piece(Items[i], '^', 5), -BIG_NUMBER);
    5525         if value = -BIG_NUMBER then
    5526           TempCheck(Pieces(Items[i], '^', 1, 2), value);
    5527         AddArrow(adatetime, value, adatetime1, value, '', SeriesColor);
    5528       end;
    5529     end;
    5530     GetHorizAxis.ExactDateTime := True;
    5531     GetHorizAxis.Increment := DateTimeStep[dtOneMinute];
    5532   end;
    5533 end;
    5534 
    5535 procedure TfrmGraphs.MakeWeightedArrowSeries(aChart: TChart; aTitle, aFileType: string; var aSerCnt: integer);
    5536 var
    5537   i: integer;
    5538   value: double;
    5539   fmtime, fmtime1: string;
    5540   adatetime, adatetime1: TDateTime;
    5541   arrows: TArrowSeries;
    5542 begin
    5543   aSerCnt := aSerCnt + 1;
    5544   arrows := TArrowSeries.Create(aChart);
    5545   with arrows do
    5546   begin
    5547     ParentChart := aChart;
    5548     Title := Piece(aTitle, '^', 3);
    5549     Clear;
    5550     ArrowWidth := 12;
    5551     ArrowHeight := 9;
    5552     StartXValues.DateTime := true;
    5553     EndXValues.DateTime := true;
    5554     Marks.Style := smsLabel;
    5555     OnGetMarkText := serDatelineTop.OnGetMarkText;
    5556     Pointer.Visible := false;
    5557     Pointer.VertSize := 17; //pnlTop.Height;        //******* for meds
    5558     Pointer.HorizSize := 24;
    5559     Pointer.InflateMargins := true;
    5560     GetData(aTitle);
    5561     ColorEachPoint := false;
    5562     SeriesColor := NextColor(aSerCnt);
    5563     Identifier := aFileType;
    5564     Marks.BackColor := clInfoBk;
    5565     with lstTemp do
    5566     for i:= 0 to Items.Count - 1 do
    5567     begin
    5568       fmtime := FMCorrectedDate(Piece(Items[i], '^', 3));
    5569       fmtime1 := FMCorrectedDate(Piece(Items[i], '^', 4));
    5570       if IsFMDateTime(fmtime) and IsFMDateTime(fmtime1) then
    5571       begin
    5572         HighLow(fmtime, fmtime1, aChart, adatetime, adatetime1);
    5573         value := strtofloatdef(Piece(Items[i], '^', 5), -BIG_NUMBER);
    5574         if value = -BIG_NUMBER then
    5575           TempCheck(Pieces(Items[i], '^', 1, 2), value);
    5576         AddArrow(adatetime, value, adatetime1, value, '', SeriesColor);
    5577       end;
    5578     end;
    5579     value := Vfactor(Piece(aTitle, '^', 3));
    5580     if value < 1 then value := 1;
    5581     Pointer.HorizSize := round(value);
    5582     GetHorizAxis.ExactDateTime := True;
    5583     GetHorizAxis.Increment := DateTimeStep[dtOneMinute];
    5584   end;
    5585 end;
    5586 
    5587 procedure TfrmGraphs.MakeGanttSeries(aChart: TChart; aTitle, aFileType: string; var aSerCnt: integer);
    5588 var
    5589   i: integer;
    5590   value: double;
    5591   fmtime, fmtime1: string;
    5592   adatetime, adatetime1: TDateTime;
    5593   gantt: TGanttSeries;
    5594 begin
    5595   aSerCnt := aSerCnt + 1;
    5596   gantt := TGanttSeries.Create(aChart);
    5597   with gantt do
    5598   begin
    5599     ParentChart := aChart;
    5600     Title := Piece(aTitle, '^', 3);
    5601     Marks.Style := smsLabel;
    5602     OnGetMarkText := serDatelineTop.OnGetMarkText;
    5603     Pointer.VertSize := pnlTop.Height;        //******* like vertical bars
    5604     GetData(aTitle);
    5605     ColorEachPoint := false;
    5606     SeriesColor := NextColor(aSerCnt);
    5607     Identifier := aFileType;
    5608     Marks.BackColor := clInfoBk;
    5609     with lstTemp do
    5610     for i:= 0 to Items.Count - 1 do
    5611     begin
    5612       fmtime := FMCorrectedDate(Piece(Items[i], '^', 3));
    5613       fmtime1 := FMCorrectedDate(Piece(Items[i], '^', 4));
    5614       if IsFMDateTime(fmtime) and IsFMDateTime(fmtime1) then
    5615       begin
    5616         HighLow(fmtime, fmtime1, aChart, adatetime, adatetime1);
    5617         value := strtofloatdef(Piece(Items[i], '^', 5), -BIG_NUMBER);
    5618         if value = -BIG_NUMBER then
    5619           TempCheck(Pieces(Items[i], '^', 1, 2), value);
    5620         AddGantt(adatetime, adatetime1, 1, '');
    5621       end;
    5622     end;
    5623     GetHorizAxis.ExactDateTime := True;
    5624     GetHorizAxis.Increment := DateTimeStep[dtOneMinute];
    5625   end;
    5626 end;
    5627 
    5628 procedure TfrmGraphs.MakeAGanttSeries(aChart: TChart; aTitle, aFileType: string; var aSerCnt: integer);
    5629 var
    5630   i: integer;
    5631   value: double;
    5632   fmtime, fmtime1: string;
    5633   gantt: TGanttSeries;
    5634   adatetime, adatetime1: TDateTime;
    5635 begin
    5636   aSerCnt := aSerCnt + 1;
    5637   if aChart = chartDatelineTop then
    5638     gantt := serDatelineTop
    5639   else
    5640     gantt := serDatelineBottom;
    5641   with gantt do
    5642   begin
    5643     ParentChart := aChart;
    5644     Active := true;
    5645     Title := Piece(aTitle, '^', 3);
    5646     Marks.Style := smsLabel;
    5647     OnGetMarkText := serDatelineTop.OnGetMarkText;
    5648     //Pointer.VertSize := pnlTop.Height;        //******* for meds
    5649     GetData(aTitle);
    5650     Identifier := aFileType;
    5651     ColorEachPoint := True;
    5652     with lstTemp do
    5653     for i:= 0 to Items.Count - 1 do
    5654     begin
    5655       fmtime := FMCorrectedDate(Piece(Items[i], '^', 3));
    5656       fmtime1 := FMCorrectedDate(Piece(Items[i], '^', 4));
    5657       if IsFMDateTime(fmtime) and IsFMDateTime(fmtime1) then
    5658       begin
    5659         HighLow(fmtime, fmtime1, aChart, adatetime, adatetime1);
    5660         value := strtofloatdef(Piece(Items[i], '^', 5), -BIG_NUMBER);
    5661         if value = -BIG_NUMBER then
    5662           TempCheck(Pieces(Items[i], '^', 1, 2), value);
    5663         AddGantt(adatetime, adatetime1, aSerCnt, '');
    5664       end;
    5665     end;
    5666     GetHorizAxis.ExactDateTime := True;
    5667     GetHorizAxis.Increment := DateTimeStep[dtOneMinute];
    56686260  end;
    56696261end;
     
    56756267end;
    56766268
    5677 function TfrmGraphs.ValueText(Sender: TCustomChart; Series: TChartSeries; ValueIndex: Integer): string;
     6269function TfrmGraphs.NonNumText(listnum , seriesnum, valueindex: integer): string;
     6270var
     6271  ok: boolean;
     6272  i: integer;
     6273  nonvalue, date1, resultdate, otherdate: string;
     6274  datestart: double;
     6275  charttag, filename, typeitemname, filenum, itemnum, specimen, seriescheck, value: string;
     6276begin
     6277  ok := false;
     6278  seriescheck := inttostr(seriesnum - BIG_NUMBER);
     6279  charttag := inttostr(listnum);
     6280  for i := 0 to GtslNonNum.Count - 1 do
     6281  begin
     6282    nonvalue := GtslNonNum[i];
     6283    if Piece(nonvalue, '^', 2) = charttag then
     6284      if Piece(nonvalue, '^', 3) = seriescheck then
     6285        if Piece(nonvalue, '^', 4) = inttostr(valueindex + 1) then
     6286      begin
     6287        ok := true;
     6288        break;
     6289      end;
     6290  end;
     6291  if not ok then
     6292  begin
     6293    Result := '';
     6294    exit;
     6295  end;
     6296  date1    := Piece(nonvalue, '^', 1);
     6297  filenum  := Piece(nonvalue, '^', 9);
     6298  itemnum  := Piece(nonvalue, '^', 10);
     6299  value    := Piece(nonvalue, '^', 13);
     6300  specimen := Piece(nonvalue, '^', 16);
     6301  filename := FileNameX(filenum);
     6302  typeitemname := MixedCase(ItemName(filenum, itemnum));
     6303  if length(specimen) > 0 then
     6304    typeitemname := typeitemname + ' (' + LowerCase(specimen) + ')';
     6305  datestart := strtofloat(date1);
     6306  resultdate := FormatDateTime('mmm d, yyyy  h:nn am/pm', datestart);
     6307  otherdate := FormatDateTime('mm/dd/yy hh:nn', datestart);
     6308  Result := filenum + '^' +filename + '^' + resultdate + '^'
     6309          + typeitemname + '^' + value + '^' + otherdate;
     6310end;
     6311
     6312function TfrmGraphs.ValueText(Sender: TCustomChart; aSeries: TChartSeries; ValueIndex: Integer): string;
    56786313var      // type#^typename^formatdate^itemname^result^date
    5679   i, offset, SeriesNum, selnum: integer;
    5680   dateend, datestart: double;
    5681   astring, datecheck, filetype, fmdatecheck, item, otherdate, partitem: string;
    5682   resultdate, results, seriestitle, typeitem, typename, typenum: string;
    5683 begin
     6314  OKToUse: boolean;
     6315  i, SeriesNum, selnum, chartnum: integer;
     6316  filetype, otherdate: string;
     6317  resultdate, resultstring, seriestitle, typeitem, typename, typenum: string;
     6318begin
     6319  Result := '';
    56846320  SeriesNum := -1;
    5685   for i := 0 to Sender.SeriesCount -1 do
    5686   if Sender.Series[i] = Series then
    5687   begin
    5688     SeriesNum := i;
    5689     filetype := Sender.Series[i].Identifier;
    5690     break;
    5691   end;
    5692   seriestitle := Sender.Series[SeriesNum].Title;
    5693   if (seriestitle = '') and (SeriesNum < (Series.Count - 1)) then
    5694     if Sender.Series[SeriesNum + 1].Title = '(non-numeric)' then
    5695     begin
    5696       SeriesNum := SeriesNum + 1;
    5697       seriestitle := '(non-numeric)';
    5698     end;
    5699   Result := '';
    5700   if seriestitle <> '(non-numeric)' then
    5701   begin
    5702     ItemCheck(lvwItemsTop, seriestitle, selnum, typeitem);
    5703     typeitem := UpperCase(typeitem);
    5704   end
    5705   else
    5706   begin
    5707     selnum := 1;
    5708     typeitem := '63';
    5709     offset := 2; // 2 series before
    5710     if (copy(Sender.Series[SeriesNum - offset].Title, 1, 4) = 'Ref ') then
    5711       if SeriesNum - 4 > -1 then
    5712         offset := 4 // if ref ranges
    5713       else if SeriesNum - 3 > -1 then
    5714         offset := 3; // if ref ranges
    5715     seriestitle := Sender.Series[SeriesNum - offset].Title + ' ' + seriestitle;
    5716   end;
     6321  for i := 0 to Sender.SeriesCount - 1 do
     6322    if Sender.Series[i] = aSeries then
     6323    begin
     6324      SeriesNum := i;
     6325      filetype := Sender.Series[i].Identifier;
     6326      break;
     6327    end;
     6328  if SeriesNum = -1 then
     6329  begin
     6330    Result := '';
     6331    exit;
     6332  end;
     6333  chartnum := Sender.Tag;
     6334  seriestitle := Piece(Sender.Series[SeriesNum].Title, '^', 1);
     6335  if seriestitle = '(non-numeric)' then
     6336  begin
     6337    Result := NonNumText(chartnum, (aSeries as TChartSeries).Tag, ValueIndex);
     6338    exit;
     6339  end;
     6340  ItemCheck(lvwItemsTop, seriestitle, selnum, typeitem);
     6341  typeitem := UpperCase(typeitem);
    57176342  if selnum < 0 then
    57186343  begin
     
    57266351    typeitem := typenum + '^' + Piece(typeitem, '^', 2);
    57276352  end;
    5728   if typenum = '55' then
    5729   begin
    5730     if Series is TGanttSeries then
    5731       if (Series as TGanttSeries).Pointer.VertSize <> RX_HEIGHT_IN then
    5732       if (Series as TGanttSeries).Pointer.VertSize <> RX_HEIGHT_NVA then
    5733         typenum := '52'
    5734       else typenum := '55NVA';
    5735   end
    5736   else if typenum = '55NVA' then
    5737   begin
    5738     if Series is TGanttSeries then
    5739       if (Series as TGanttSeries).Pointer.VertSize <> RX_HEIGHT_NVA then
    5740       if (Series as TGanttSeries).Pointer.VertSize <> RX_HEIGHT_OUT then
    5741         typenum := '55'
    5742       else typenum := '52';
    5743   end
    5744   else if typenum = '52' then
    5745   begin
    5746     if Series is TGanttSeries then
    5747       if (Series as TGanttSeries).Pointer.VertSize <> RX_HEIGHT_OUT then
    5748       if (Series as TGanttSeries).Pointer.VertSize <> RX_HEIGHT_NVA then
    5749         typenum := '55'
    5750       else typenum := '55NVA';
    5751   end;
     6353  CheckMedNum(typenum, aSeries);
    57526354  typename := FileNameX(typenum);
    57536355  if ValueIndex < 0 then
     
    57606362  else if Copy(typename, length(typename), 1) = 's' then
    57616363    typename := Copy(typename, 1, length(typename) - 1);
    5762   if (Series is TGanttSeries) then
    5763   begin
    5764     datestart := (Series as TGanttSeries).StartValues[ValueIndex];
    5765     dateend := (Series as TGanttSeries).EndValues[ValueIndex];
     6364  ValueDates(aSeries, ValueIndex, resultdate, otherdate);
     6365  ResultValue(resultstring, seriestitle, typenum, typeitem, Sender, aSeries, ValueIndex, SeriesNum, OKToUse);
     6366  if not OKToUse then
     6367    Result := ''
     6368  else
     6369    Result := typenum + '  ^' + typename + '^' + resultdate + '^' +
     6370      seriestitle + '^' + resultstring + '^' + otherdate;
     6371end;
     6372
     6373procedure TfrmGraphs.ValueDates(aSeries: TChartSeries; ValueIndex: Integer; var resultdate, otherdate: string);
     6374var
     6375  dateend, datestart: double;
     6376begin
     6377  if (aSeries is TGanttSeries) then
     6378  begin
     6379    datestart := (aSeries as TGanttSeries).StartValues[ValueIndex];
     6380    dateend := (aSeries as TGanttSeries).EndValues[ValueIndex];
    57666381  end
    57676382  else
    57686383  begin
    5769     datestart := Series.XValue[ValueIndex];
     6384    datestart := aSeries.XValue[ValueIndex];
    57706385    dateend := datestart;
    57716386  end;
     
    57826397    otherdate := FormatDateTime('mm/dd/yy hh:nn', datestart);
    57836398  end;
    5784   results := '';
     6399end;
     6400
     6401procedure TfrmGraphs.CheckMedNum(var typenum: string; aSeries: TChartSeries);
     6402begin
     6403  if typenum = '55' then
     6404  begin
     6405    if aSeries is TGanttSeries then
     6406    if (aSeries as TGanttSeries).Pointer.VertSize <> RX_HEIGHT_IN then
     6407    if (aSeries as TGanttSeries).Pointer.VertSize <> RX_HEIGHT_NVA then
     6408      typenum := '52'
     6409    else typenum := '55NVA';
     6410  end
     6411  else if typenum = '55NVA' then
     6412  begin
     6413    if aSeries is TGanttSeries then
     6414    if (aSeries as TGanttSeries).Pointer.VertSize <> RX_HEIGHT_NVA then
     6415    if (aSeries as TGanttSeries).Pointer.VertSize <> RX_HEIGHT_OUT then
     6416      typenum := '55'
     6417    else typenum := '52';
     6418  end
     6419  else if typenum = '52' then
     6420  begin
     6421    if aSeries is TGanttSeries then
     6422    if (aSeries as TGanttSeries).Pointer.VertSize <> RX_HEIGHT_OUT then
     6423    if (aSeries as TGanttSeries).Pointer.VertSize <> RX_HEIGHT_NVA then
     6424      typenum := '55'
     6425    else typenum := '55NVA';
     6426  end;
     6427end;
     6428
     6429procedure TfrmGraphs.ResultValue(var resultstring, seriestitle: string; typenum, typeitem: string;
     6430  Sender: TCustomChart; aSeries: TChartSeries; ValueIndex, SeriesNum: Integer; var OKToUse: boolean);
     6431var
     6432  i: integer;
     6433  item, partitem, fmdatecheck, astring, datecheck: string;
     6434begin
     6435  resultstring := '';
     6436  OKToUse := true;
    57856437  if typenum = '63' then
    57866438  begin
    5787     if Series is TLineSeries then
    5788       if (Series as TLineSeries).LinePen.Style = psDash then
    5789         exit;          // serHigh or serLow
    5790     if Series is TPointSeries then
    5791       if (Series as TPointSeries).Pointer.Style = psSmallDot then
    5792         exit;         // serBlank
     6439    if aSeries is TLineSeries then
     6440      if (aSeries as TLineSeries).LinePen.Style = psDash then
     6441      begin
     6442        OKToUse := false;
     6443        exit;    // serHigh or serLow
     6444      end;
     6445    if aSeries is TPointSeries then
     6446      if (aSeries as TPointSeries).Pointer.Style = psSmallDot then
     6447      begin
     6448        OKToUse := false;
     6449        exit;    // serBlank
     6450      end;
    57936451    if copy(seriestitle, length(seriestitle) - 12, length(seriestitle)) = '(non-numeric)' then
    57946452    begin
    57956453      seriestitle := copy(seriestitle, 1, length(seriestitle) - 13);
    5796       serDatelineTopGetMarkText(Sender.Series[SeriesNum], ValueIndex, results);
     6454      serDatelineTopGetMarkText(Sender.Series[SeriesNum], ValueIndex, resultstring);
    57976455    end
    57986456    else
    5799       results := floattostr(Series.YValue[ValueIndex]);
     6457      resultstring := floattostr(aSeries.YValue[ValueIndex]);
    58006458  end
    58016459  else if typenum <> '120.5' then
     
    58056463    //if (partitem = 'M;A;') then     //or (partitem = 'M;T;') then   tb antibiotic on 1st piece
    58066464    begin
    5807       fmdatecheck := floattostr(DateTimeToFMDateTime(Series.XValue[ValueIndex]));
    5808       for i := 0 to lstData.Items.Count - 1 do
     6465      fmdatecheck := floattostr(DateTimeToFMDateTime(aSeries.XValue[ValueIndex]));
     6466      for i := 0 to GtslData.Count - 1 do
    58096467      begin
    5810         astring := lstData.Items[i];
     6468        astring := GtslData[i];
    58116469        if item = Piece(astring, '^', 2) then
    58126470        begin
     
    58166474          if datecheck = fmdatecheck then
    58176475          begin
    5818             results := MixedCase(Piece(astring, '^', 5));
     6476            resultstring := MixedCase(Pieces(astring, '^', 5, 6)) + '^' + Piece(astring, '^', 7);
    58196477            break;
    58206478          end;
     
    58266484  begin
    58276485    if seriestitle = 'Blood Pressure' then
    5828       results := BPValue(Series.XValue[ValueIndex])
     6486      resultstring := BPValue(aSeries.XValue[ValueIndex])
    58296487    else
    5830       results := floattostr(Series.YValue[ValueIndex]);
    5831   end;
    5832   Result := typenum + '  ^' + typename + '^' + resultdate + '^' +
    5833     seriestitle + '^' + results + '^' + otherdate;
     6488      resultstring := floattostr(aSeries.YValue[ValueIndex]);
     6489  end;
    58346490end;
    58356491
    58366492procedure TfrmGraphs.chartBaseMouseMove(Sender: TObject; Shift: TShiftState; X, Y: Integer);
    58376493var
    5838   ClickedLegend, ClickedValue, j: Integer;
     6494  ClickedLegend, ClickedMark, ClickedValue, j: Integer;
    58396495  itemname: string;
    58406496  NewPt: TPoint;
     
    58456501  FActiveGraph := (Sender as TChart);
    58466502  NewPt := Mouse.CursorPos;
    5847   ClickedValue := -1;
    58486503  ClickedLegend := -1;
     6504  ClickedMark   := -1;
     6505  ClickedValue  := -1;
    58496506  if FHintWinActive then exit;
    58506507  with FActiveGraph do
     
    58586515        ClickedValue := Clicked(FX, FY);
    58596516        if ClickedValue > -1 then break;
     6517        ClickedMark := Marks.Clicked(FX, FY);
     6518        if ClickedMark > -1 then break;
    58606519        ClickedLegend := Legend.Clicked(FX, FY);
    58616520        if ClickedLegend > -1 then break;
    58626521      end;
    58636522    end;
    5864     if ClickedValue > -1 then
     6523    if (ClickedValue > -1) or (ClickedMark > -1) then
    58656524    begin
    58666525      FHintStop := false;
     
    58836542end;
    58846543
     6544procedure TfrmGraphs.chartBaseMouseUp(Sender: TObject; Button: TMouseButton;
     6545  Shift: TShiftState; X, Y: Integer);
     6546begin
     6547  (Sender as TChart).AllowZoom := FGraphSetting.HorizontalZoom;      // avoids cursor rectangle from appearing
     6548end;
     6549
     6550procedure TfrmGraphs.FormatHint(var astring: string);
     6551var
     6552  i, j: integer;
     6553  titlename, dttm, itemname, info, slice, text, value, newinfo, hintslice, hintformat: string;
     6554begin
     6555  // hint format: slice|slice|slice| ...
     6556  // where | is linebreak and slice is [text] value~[text] value~[text] value~ ...
     6557  hintformat := Piece(TypeString(Piece(Piece(astring, '^', 1), ' ', 1)), '^', 9);
     6558  titlename := Piece(astring, '^', 2);
     6559  dttm := Piece(astring, '^', 3);
     6560  if copy(astring, length(astring) - 5, length(astring)) = ' 00:00' then
     6561    dttm := Pieces(dttm, ' ', 1, 3);
     6562  itemname := Piece(astring, '^', 4);
     6563  info := itemname + '~' + Piece(astring, '^', 5) + '~';
     6564  newinfo := '';
     6565  for i := 1 to BIG_NUMBER do
     6566  begin
     6567    hintslice := Piece(hintformat, '|', i);
     6568    slice := Piece(info, '|', i);
     6569    for j := 1 to BIG_NUMBER do
     6570    begin
     6571      text := Piece(hintslice, '~', j);
     6572      value := Piece(info, '~', j);
     6573      newinfo := newinfo + text + ' ' + value;
     6574      //if Piece(hintslice, '~', j + 1) = '' then
     6575      //  break;                                                   .
     6576
     6577      if Pos('~', hintslice) = length(hintslice) then
     6578        break;
     6579      if Piece(slice, '~', j + 1) = '' then
     6580        break;
     6581    end;
     6582    if Piece(hintslice, '|', i + 1) = '' then
     6583      break;
     6584    if length(Piece(hintformat, '|', i + 1)) > 0 then
     6585      newinfo := newinfo + #13;
     6586    if Piece(hintformat, '|', i + 1) = '' then
     6587      break;
     6588  end;
     6589  astring := titlename + '  ' + dttm + #13 + newinfo; //itemname + '  ' + newinfo;
     6590end;
     6591
    58856592procedure TfrmGraphs.timHintPauseTimer(Sender: TObject);
     6593
     6594  function TitleOK(aTitle: string): boolean;
     6595  begin
     6596    Result := false;
     6597    if Copy(aTitle, 1, 7)= 'Ref Low' then exit
     6598    else if Copy(aTitle, 1, 8)= 'Ref High' then exit
     6599    else if aTitle = TXT_COMMENTS then exit
     6600    else if aTitle = TXT_NONNUMERICS then exit;
     6601    Result := true;
     6602  end;
     6603
    58866604var
    58876605  ClickedValue, j: Integer;
    5888   dttm, itemname, textvalue: string;
     6606  textvalue: string;
    58896607  Rct: TRect;
    58906608begin
     
    58976615      if FHintStop then break;
    58986616      ClickedValue := Clicked(FX, FY);
     6617      if ClickedValue = -1 then ClickedValue := Marks.Clicked(FX, FY);
    58996618      if ClickedValue > -1 then break;
    59006619    end;
     
    59106629      if FHintWinActive then
    59116630        InactivateHint;
    5912       itemname := Series[j].Title;
    5913       if Copy(itemname, 1, 7)= 'Ref Low' then exit;
    5914       if Copy(itemname, 1, 8)= 'Ref High' then exit;
     6631      if not TitleOK(Series[j].Title) then
     6632        exit;
    59156633      FOnSeries := j;
    59166634      FOnValue := ClickedValue;
    59176635      textvalue := ValueText(FActiveGraph, Series[j], ClickedValue);
    5918       dttm := Piece(textvalue, '^', 3);
    5919       //if copy(textvalue, length(textvalue) - 5, length(textvalue)) = ' 00:00' then
    5920       //  dttm := Pieces(dttm, ' ', 1, 3);
    5921       textvalue := Piece(textvalue, '^', 2) + '  ' + dttm +
    5922         #13 + Piece(textvalue, '^', 4) + '  ' + Piece(textvalue, '^', 5);
     6636      FormatHint(textvalue);
    59236637      Rct := FHintWin.CalcHintRect(Screen.Width, textvalue, nil);
    59246638      OffsetRect(Rct, FX, FY + 20);
     
    60056719end;
    60066720
     6721procedure TfrmGraphs.InfoMessage(aCaption: string; aColor: TColor; aVisible: boolean);
     6722begin
     6723  pnlInfo.Caption := aCaption;
     6724  pnlInfo.Color := aColor;
     6725  pnlInfo.Visible := aVisible;
     6726end;
     6727
    60076728procedure TfrmGraphs.mnuPopGraphZoomBackClick(Sender: TObject);
    60086729begin
    60096730  FFirstClick := true;
    6010   with lstZoomHistory do
    6011   begin
    6012     Items.Delete(Count - 1);
    6013     if Count = 0 then mnuPopGraphResetClick(self)
    6014     else ZoomUpdate;
    6015   end;
     6731  GtslZoomHistoryFloat.Delete(GtslZoomHistoryFloat.Count - 1);
     6732  if GtslZoomHistoryFloat.Count = 0 then mnuPopGraphResetClick(self)
     6733  else ZoomUpdate;
    60166734end;
    60176735
     
    60216739  BigTime, SmallTime: TDateTime;
    60226740begin
    6023   lastzoom := lstZoomHistory.Items[lstZoomHistory.Count - 1];
     6741  lastzoom := GtslZoomHistoryFloat[GtslZoomHistoryFloat.Count - 1];
    60246742  SmallTime := StrToFloat(Piece(lastzoom, '^', 1));
    60256743  BigTime := StrToFloat(Piece(lastzoom, '^', 2));
     
    60296747
    60306748procedure TfrmGraphs.ZoomUpdateInfo(SmallTime, BigTime: TDateTime);
    6031 begin
    6032   pnlInfo.Caption := TXT_ZOOMED;
    6033   pnlInfo.Color := COLOR_ZOOM;
    6034   pnlInfo.Caption := pnlInfo.Caption + FormatDateTime('mmm d, yyyy  h:nn am/pm', SmallTime);
    6035   pnlInfo.Caption := pnlInfo.Caption + ' to ' + FormatDateTime('mmm d, yyyy  h:nn am/pm', BigTime) + '.';
    6036   pnlInfo.Visible := true;
     6749var
     6750  aString: string;
     6751begin
     6752  aString := TXT_ZOOMED
     6753           + FormatDateTime('mmm d, yyyy  h:nn am/pm', SmallTime)
     6754           + ' to ' + FormatDateTime('mmm d, yyyy  h:nn am/pm', BigTime) + '.';
     6755  InfoMessage(aString, COLOR_ZOOM, true);
    60376756  pnlHeader.Visible := true;
    60386757end;
     
    60616780  topflag: boolean;
    60626781  i, count: integer;
    6063   StrForFooter, StrForHeader, aTitle, aWarning, aDateRange: String;
     6782  StrForFooter, StrForHeader, aTitle, aWarning, aDateRange, aAction: String;
    60646783  aHeader: TStringList;
    60656784  wrdApp, wrdDoc, wrdPrintDlg: Variant;
    60666785  ChildControl: TControl;
    60676786begin
    6068   topflag := mnuPopGraphStayOnTop.Checked and mnuPopGraphStayOnTop.Enabled;
    60696787  try
    60706788    wrdApp := CreateOleObject('Word.Application');
     
    60726790    raise Exception.Create('Cannot start MS Word!');
    60736791  end;
     6792  if Sender = mnuPopGraphPrint then
     6793    aAction := 'PRINT'
     6794  else
     6795    aAction := 'COPY';
     6796  topflag := mnuPopGraphStayOnTop.Checked and mnuPopGraphStayOnTop.Enabled;
    60746797  Screen.Cursor := crDefault;
    60756798  aTitle := 'CPRS Graphing';
     
    61006823  wrdDoc.PageNumbers.Add;
    61016824  wrdDoc := wrdApp.Documents.Item(1);
     6825  if aAction = 'COPY' then
     6826  begin
     6827    wrdDoc.Range.Font.Name := 'Courier New';
     6828    wrdDoc.Range.Font.Size := 9;
     6829    wrdDoc.Range.Text := StrForHeader;
     6830  end;
    61026831  wrdDoc.Range.InsertParagraphAfter;
    61036832  for i := 0 to scrlTop.ControlCount - 1 do           // goes from top to bottom
     
    61366865    wrdDoc.Paragraphs.Last.Range.Paste;
    61376866  end;
    6138   wrdPrintDlg := wrdApp.Dialogs.item(wdDialogFilePrint);
    6139   Screen.Cursor := crDefault;
    6140   Application.ProcessMessages;
    6141   if topflag then
    6142     mnuPopGraphStayOnTopClick(self);
    6143   wrdPrintDlg.Show;
    6144   wrdApp.Visible := false;
    6145   Screen.Cursor := crHourGlass;
    6146   Application.ProcessMessages;
    6147   Sleep(5000);
    6148   count := 0;
    6149   while (wrdApp.Application.BackgroundPrintingStatus > 0) do
    6150   begin
    6151     Sleep(1000);
     6867  if aAction = 'PRINT' then
     6868  begin
     6869    wrdPrintDlg := wrdApp.Dialogs.item(wdDialogFilePrint);
     6870    Screen.Cursor := crDefault;
    61526871    Application.ProcessMessages;
    6153     count := count + 1;
    6154     if count > 3 then break;
     6872    if topflag then
     6873      mnuPopGraphStayOnTopClick(self);
     6874    wrdPrintDlg.Show;
     6875    wrdApp.Visible := false;
     6876    Screen.Cursor := crHourGlass;
     6877    Application.ProcessMessages;
     6878    Sleep(5000);
     6879    count := 0;
     6880    while (wrdApp.Application.BackgroundPrintingStatus > 0) do
     6881    begin
     6882      Sleep(1000);
     6883      Application.ProcessMessages;
     6884      count := count + 1;
     6885      if count > 3 then break;
     6886    end;
     6887  end;
     6888  if aAction = 'COPY' then
     6889  begin
     6890    wrdDoc.Range.WholeStory;
     6891    wrdDoc.Range.Copy;
    61556892  end;
    61566893  wrdApp.DisplayAlerts := false;
     
    61616898  Application.ProcessMessages;
    61626899  if topflag then
    6163     mnuPopGraphStayOnTopClick(self);
     6900    if aAction = 'PRINT' then
     6901      mnuPopGraphStayOnTopClick(self);
    61646902  Screen.Cursor := crDefault;
     6903end;
     6904
     6905procedure TfrmGraphs.lstViewsTopChange(Sender: TObject);
     6906begin
     6907  Screen.Cursor := crHourGlass;
     6908  ViewsChange(lvwItemsTop, lstViewsTop, 'top');
     6909  Screen.Cursor := crDefault;
     6910end;
     6911
     6912procedure TfrmGraphs.lstViewsTopEnter(Sender: TObject);
     6913begin
     6914  if Sender = lstViewsTop then
     6915    lstViewsTop.Tag := 0;                     // reset
     6916end;
     6917
     6918procedure TfrmGraphs.lstViewsTopMouseDown(Sender: TObject; Button: TMouseButton;
     6919  Shift: TShiftState; X, Y: Integer);
     6920begin
     6921  //  for right mouse click make arrangements for view definition ****************
     6922end;
     6923
     6924procedure TfrmGraphs.lstViewsBottomChange(Sender: TObject);
     6925begin
     6926  Screen.Cursor := crHourGlass;
     6927  ViewsChange(lvwItemsBottom, lstViewsBottom, 'bottom');
     6928  Screen.Cursor := crDefault;
     6929end;
     6930
     6931procedure TfrmGraphs.lstViewsBottomEnter(Sender: TObject);
     6932begin
     6933  if Sender = lstViewsBottom then
     6934    lstViewsBottom.Tag := 0;                     // reset
     6935end;
     6936
     6937procedure TfrmGraphs.lstViewsBottomMouseDown(Sender: TObject;
     6938  Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
     6939begin
     6940  //  for right mouse click make arrangements for view definition ****************
     6941end;
     6942
     6943procedure TfrmGraphs.lvwItemsBottomChange(Sender: TObject; Item: TListItem;
     6944  Change: TItemChange);
     6945begin
     6946  if FArrowKeys then
     6947    if lvwItemsBottom.SelCount > 0 then
     6948    begin
     6949      if pnlItemsBottomInfo.Tag <> 1 then
     6950        lvwItemsBottomClick(self);
     6951      FArrowKeys := false;
     6952    end;
    61656953end;
    61666954
     
    61686956  Change: TItemChange);
    61696957begin
    6170   if FArrowKeys and (lvwItemsTop.SelCount > 0) then
    6171   begin
    6172     if pnlItemsTopInfo.Tag <> 1 then
    6173       lvwItemsTopClick(self);
    6174     FArrowKeys := false;
    6175   end;
    6176 end;
    6177 
    6178 procedure TfrmGraphs.lvwItemsBottomChange(Sender: TObject; Item: TListItem;
    6179   Change: TItemChange);
    6180 begin
    6181   if FArrowKeys and (lvwItemsBottom.SelCount > 0) then
    6182   begin
    6183     if pnlItemsBottomInfo.Tag <> 1 then
    6184       lvwItemsBottomClick(self);
    6185     FArrowKeys := false;
    6186   end;
     6958  if FArrowKeys then
     6959    if lvwItemsTop.SelCount > 0 then
     6960    begin
     6961      if pnlItemsTopInfo.Tag <> 1 then
     6962        lvwItemsTopClick(self);
     6963      FArrowKeys := false;
     6964    end;
     6965end;
     6966
     6967procedure TfrmGraphs.lvwItemsTopClick(Sender: TObject);
     6968var
     6969  i: integer;
     6970begin
     6971  FFirstClick := true;
     6972  if not FFastTrack then
     6973    if GraphTurboOn then
     6974      Switch;
     6975  if lvwItemsTop.SelCount > FGraphSetting.MaxSelect then
     6976  begin
     6977    pnlItemsTopInfo.Tag := 1;
     6978    lvwItemsTop.ClearSelection;
     6979    if FTooManyItems then FTooManyItems := false
     6980    else
     6981    begin
     6982      ShowMsg('Too many items to graph');
     6983      FTooManyItems := true;  // flag so that warning will not be displayed twice
     6984    end;
     6985    for i := 0 to GtslSelPrevTopFloat.Count - 1 do
     6986      lvwItemsTop.Items[strtoint(GtslSelPrevTopFloat[i])].Selected := true;
     6987    pnlItemsTopInfo.Tag := 0;
     6988  end
     6989  else
     6990  begin
     6991    GtslSelPrevTopFloat.Clear;
     6992    for i := 0 to lvwItemsTop.Items.Count - 1 do
     6993    if lvwItemsTop.Items[i].Selected then
     6994      GtslSelPrevTopFloat.Add(inttostr(i));
     6995    ItemsClick(Sender, lvwItemsTop, lvwItemsBottom, chkItemsTop, lstViewsTop, GtslSelCopyTop, 'top');
     6996  end;
     6997end;
     6998
     6999procedure TfrmGraphs.lvwItemsTopEnter(Sender: TObject);
     7000begin
     7001  if lvwItemsTop.SelCount = 0 then
     7002    if lvwItemsTop.Items.Count > 0 then
     7003      lvwItemsTop.Items[0].Focused := true;
    61877004end;
    61887005
     
    61927009  if Key in [VK_PRIOR, VK_NEXT, VK_UP, VK_DOWN] then
    61937010    FArrowKeys := true;
    6194 end;
    6195 
    6196 procedure TfrmGraphs.testcount1Click(Sender: TObject);
    6197 
    6198  function boxcount(aListBox: TListBox): string;
    6199  var
    6200    i, ccnt: integer;
    6201  begin
    6202    Result := '';
    6203    ccnt := 0;
    6204    for i := 0 to aListBox.Items.Count - 1 do
    6205      ccnt := ccnt + length(aListBox.Items[i]);
    6206    Result := inttostr(aListBox.Items.Count) + ';' + inttostr(ccnt);
    6207  end;
    6208 
    6209 var
    6210   i, lines, total: integer;
    6211   aString: string;
    6212 begin
    6213   lines := 0;
    6214   total := 0;
    6215   with pnlData do
    6216   for i:= 0 to pnlData.ControlCount - 1 do
    6217     if Controls[i] is TListBox then
    6218     begin
    6219       aString := boxcount(Controls[i] as TListBox);
    6220       lines := lines + strtointdef(Piece(aString, ';', 1), 0);
    6221       total := total + strtointdef(Piece(aString, ';', 2), 0);
    6222     end;
    6223   aString := boxcount(lstTypes) + '^' + boxcount(lstItems) + '^' + boxcount(lstData)
    6224              + '  lines: ' + inttostr(lines) + '   total: ' + inttostr(total);
    6225   showmessage(aString);
    62267011end;
    62277012
     
    62387023  with FGraphSetting do FixedDateRange := not FixedDateRange;
    62397024  ChangeStyle;
    6240 end;
    6241 
    6242 //***************** these are used to fix dropdown when large fonts
    6243 
    6244 procedure TfrmGraphs.cboViewsTopDropDown(Sender: TObject);
    6245 begin
    6246   cboViewsTop.Align := alNone;
    6247 end;
    6248 
    6249 procedure TfrmGraphs.cboViewsTopDropDownClose(Sender: TObject);
    6250 begin
    6251   cboViewsTop.Align := alClient;
    6252 end;
    6253 
    6254 procedure TfrmGraphs.cboViewsBottomDropDown(Sender: TObject);
    6255 begin
    6256   cboViewsBottom.Align := alNone;
    6257 end;
    6258 
    6259 procedure TfrmGraphs.cboViewsBottomDropDownClose(Sender: TObject);
    6260 begin
    6261   cboViewsBottom.Align := alClient;
    62627025end;
    62637026
     
    62897052end;
    62907053
    6291 procedure TfrmGraphs.lvwItemsTopEnter(Sender: TObject);
    6292 begin
    6293   if lvwItemsTop.SelCount = 0 then
    6294     if lvwItemsTop.Items.Count > 0 then
    6295       lvwItemsTop.Items[0].Focused := true;
    6296 end;
    6297 
    62987054procedure TfrmGraphs.chkItemsBottomEnter(Sender: TObject);
    62997055begin
     
    63057061end;
    63067062
    6307 procedure TfrmGraphs.cboViewsBottomEnter(Sender: TObject);
    6308 begin
    6309   if not chkDualViews.Checked then
    6310     SelectNext(ActiveControl as TWinControl, True, True);
    6311 end;
    6312 
    63137063procedure TfrmGraphs.lvwItemsBottomEnter(Sender: TObject);
    63147064begin
     
    63207070end;
    63217071
     7072procedure TfrmGraphs.UpdateAccessabilityActions(var Actions: TAccessibilityActions);
     7073begin
     7074  Actions := Actions - [aaColorConversion];
     7075end;
     7076
     7077procedure TfrmGraphs.memTopEnter(Sender: TObject);
     7078begin
     7079  memTop.Color := clBtnShadow;
     7080end;
     7081
     7082procedure TfrmGraphs.memTopExit(Sender: TObject);
     7083begin
     7084  memTop.Color := clBtnFace;
     7085end;
     7086
     7087procedure TfrmGraphs.memBottomEnter(Sender: TObject);
     7088begin
     7089  memBottom.Color := clBtnShadow;
     7090end;
     7091
     7092procedure TfrmGraphs.memBottomExit(Sender: TObject);
     7093begin
     7094  memBottom.Color := clBtnFace;
     7095end;
     7096
     7097procedure TfrmGraphs.memTopKeyDown(Sender: TObject; var Key: Word;
     7098  Shift: TShiftState);
     7099begin
     7100  case Key of
     7101    VK_UP:      SendMessage(scrlTop.Handle, WM_VSCROLL, SB_LINEUP,   0);
     7102    VK_PRIOR:   SendMessage(scrlTop.Handle, WM_VSCROLL, SB_PAGEUP,   0);
     7103    VK_NEXT:    SendMessage(scrlTop.Handle, WM_VSCROLL, SB_PAGEDOWN, 0);
     7104    VK_DOWN:    SendMessage(scrlTop.Handle, WM_VSCROLL, SB_LINEDOWN, 0);
     7105    VK_HOME:    SendMessage(scrlTop.Handle, WM_VSCROLL, SB_TOP,      0);
     7106    VK_END:     SendMessage(scrlTop.Handle, WM_VSCROLL, SB_BOTTOM,   0);
     7107  end;
     7108end;
     7109
     7110procedure TfrmGraphs.memBottomKeyDown(Sender: TObject; var Key: Word;
     7111  Shift: TShiftState);
     7112begin
     7113  case Key of
     7114    VK_UP:      SendMessage(scrlBottom.Handle, WM_VSCROLL, SB_LINEUP,   0);
     7115    VK_PRIOR:   SendMessage(scrlBottom.Handle, WM_VSCROLL, SB_PAGEUP,   0);
     7116    VK_NEXT:    SendMessage(scrlBottom.Handle, WM_VSCROLL, SB_PAGEDOWN, 0);
     7117    VK_DOWN:    SendMessage(scrlBottom.Handle, WM_VSCROLL, SB_LINEDOWN, 0);
     7118    VK_HOME:    SendMessage(scrlBottom.Handle, WM_VSCROLL, SB_TOP,      0);
     7119    VK_END:     SendMessage(scrlBottom.Handle, WM_VSCROLL, SB_BOTTOM,   0);
     7120  end;
     7121end;
     7122
    63227123initialization
    63237124  CoInitialize (nil);
Note: See TracChangeset for help on using the changeset viewer.