Index: cprs/trunk/CPRS-Chart/Orders/fODBBank.pas
===================================================================
--- cprs/trunk/CPRS-Chart/Orders/fODBBank.pas	(revision 456)
+++ cprs/trunk/CPRS-Chart/Orders/fODBBank.pas	(revision 829)
@@ -1,4 +1,3 @@
 unit fODBBank;
-
 interface
 
@@ -6,58 +5,57 @@
   SysUtils, WinTypes, WinProcs, Messages, Classes, Graphics, Controls,
   Forms, Dialogs, StdCtrls, ORCtrls, ORfn, fODBase, ExtCtrls, ComCtrls, uConst,
-  ORDtTm, Buttons, Menus, ImgList;
+  ORDtTm, Buttons, Menus, ImgList, VA508AccessibilityManager, VAUtils;
 
 type
   TfrmODBBank = class(TfrmODBase)
-    pnlBB: TPanel;
-    pnlFull: TPanel;
+    dlgLabCollTime: TORDateTimeDlg;
+    ORWanted: TORDateTimeDlg;
+    pnlComments: TPanel;
+    btnUpdateComments: TButton;
+    btnCancelComment: TButton;
+    lblOrdComment: TLabel;
     pgeProduct: TPageControl;
-    tabInfo: TTabSheet;
+    TabInfo: TTabSheet;
     edtInfo: TCaptionRichEdit;
     TabDiag: TTabSheet;
     lblReqComment: TOROffsetLabel;
+    TabResults: TTabSheet;
+    edtResults: TCaptionRichEdit;
     pnlFields: TPanel;
-    dlgLabCollTime: TORDateTimeDlg;
-    ORWanted: TORDateTimeDlg;
     lblDiagComment: TOROffsetLabel;
-    txtDiagComment: TCaptionEdit;
-    pnlSelectedTests: TGroupBox;
-    lvSelectionList: TCaptionListView;
     lblUrgency: TLabel;
+    lblReason: TLabel;
+    lblSurgery: TLabel;
     cboUrgency: TORComboBox;
-    lblCollType: TLabel;
-    cboCollType: TORComboBox;
     chkConsent: TCheckBox;
-    lblPreparation: TLabel;
-    calWantTime: TORDateBox;
-    lblWanted: TLabel;
-    tReason: TEdit;
-    lblReason: TLabel;
     cboSurgery: TORComboBox;
-    lblSurgery: TLabel;
-    txtImmedColl: TCaptionEdit;
-    cboCollTime: TORComboBox;
-    lblCollTime: TLabel;
-    cmdImmedColl: TSpeedButton;
-    pnlCollTimeButton: TKeyClickPanel;
-    calCollTime: TORDateBox;
-    cboPreparation: TORComboBox;
-    btnRemove: TButton;
-    btnRemoveAll: TButton;
-    pnlTop: TPanel;
     pnlSelect: TPanel;
-    pnlDiagTests: TGroupBox;
+    pnlDiagnosticTests: TGroupBox;
     cboAvailTest: TORComboBox;
     pnlBloodComponents: TGroupBox;
     lblQuantity: TLabel;
+    lblModifiers: TLabel;
     cboAvailComp: TORComboBox;
     tQuantity: TEdit;
-    upQuantity: TUpDown;
-    TabResults: TTabSheet;
-    edtResults: TCaptionRichEdit;
-    btnAddTests: TORAlignSpeedButton;
-    ImageList1: TImageList;
-    lblModifiers: TLabel;
     cboModifiers: TORComboBox;
+    GroupBox1: TGroupBox;
+    cboQuick: TORComboBox;
+    pnlSelectedTests: TGroupBox;
+    lvSelectionList: TCaptionListView;
+    btnRemove: TButton;
+    btnRemoveAll: TButton;
+    cboReasons: TORComboBox;
+    lblRequiredField: TLabel;
+    memDiagComment: TRichEdit;
+    lblCollType: TLabel;
+    cboCollType: TORComboBox;
+    lblCollTime: TLabel;
+    cboCollTime: TORComboBox;
+    calWantTime: TORDateBox;
+    lblWanted: TLabel;
+    calCollTime: TORDateBox;
+    txtImmedColl: TCaptionEdit;
+    pnlCollTimeButton: TKeyClickPanel;
+    cmdImmedColl: TSpeedButton;
     lblTNS: TLabel;
     procedure FormCreate(Sender: TObject);
@@ -78,5 +76,4 @@
     procedure pgeProductChange(Sender: TObject);
     procedure cboCollTypeChange(Sender: TObject);
-    procedure btnAddTestsClick(Sender: TObject);
     procedure FormDestroy(Sender: TObject);
     procedure btnRemoveClick(Sender: TObject);
@@ -86,9 +83,22 @@
     procedure chkConsentClick(Sender: TObject);
     procedure cboUrgencyChange(Sender: TObject);
-    procedure txtDiagCommentChange(Sender: TObject);
-    procedure cboPreparationChange(Sender: TObject);
     procedure cboSurgeryChange(Sender: TObject);
-    procedure tReasonChange(Sender: TObject);
     procedure calCollTimeChange(Sender: TObject);
+    procedure cboQuickClick(Sender: TObject);
+    procedure tQuantityEnter(Sender: TObject);
+    procedure btnUpdateCommentsClick(Sender: TObject);
+    procedure btnCancelCommentClick(Sender: TObject);
+    procedure cboSurgeryClick(Sender: TObject);
+    procedure cboReasonsEnter(Sender: TObject);
+    procedure cboReasonsExit(Sender: TObject);
+    procedure tQuantityClick(Sender: TObject);
+    procedure tQuantityChange(Sender: TObject);
+    procedure cboReasonsChange(Sender: TObject);
+    procedure cboModifiersChange(Sender: TObject);
+    procedure lvSelectionListClick(Sender: TObject);
+    procedure cboAvailCompChange(Sender: TObject);
+    procedure cboCollTimeChange(Sender: TObject);
+    procedure memDiagCommentChange(Sender: TObject);
+    procedure cboUrgencyExit(Sender: TObject);
   protected
     FCmtTypes: TStringList ;
@@ -106,7 +116,10 @@
     procedure ExtractSurgeries(OutList:TStrings; AList:TStrings);
     procedure ExtractUrgencies(OutList:TStrings; AList:TStrings);
+    procedure ExtractTNSOrders(OutList:TStrings; AList:TStrings);
     procedure ExtractModifiers(OutList:TStrings; AList:TStrings);
+    procedure ExtractReasons(OutList:TStrings; AList:TStrings);
     procedure ExtractSpecimens(OutList:TStrings; AList:TStrings);
     procedure ExtractTypeScreen(OutList:TStrings; AList:TStrings);
+    procedure ExtractOther(OutList:TStrings; AList:TStrings);
     procedure ExtractPatientInfo(OutList:TStrings; AList:TStrings);
     procedure ExtractSpecimen(OutList:TStrings; AList:TStrings);
@@ -114,4 +127,6 @@
     procedure LoadUrgencies(AComboBox:TORComboBox);
     procedure LoadModifiers(AComboBox:TORComboBox);
+    procedure LoadReasons(AComboBox:TORComboBox);
+
   private
     FLastCollType: string;
@@ -123,5 +138,9 @@
     FEvtDivision: integer;
     FVbecLookup: string;
+    FQuickList:  Integer;
+    FQuickItems: TStringList;
+    FOrderAction: Integer;
     procedure ReadServerVariables;
+    procedure SetOnQuickOrder;
   public
     procedure SetupDialog(OrderAction: Integer; const ID: string); override;
@@ -153,4 +172,5 @@
     CollSamp: Integer;                    { index into CollSampList }
     Specimen: Integer;                    { IEN of specimen }
+    Urgency: Integer;                     { IEN of urgency }
     Comment: TStringList;                 { text of comment }
     TestReqComment: string;               { Name of required comment }
@@ -162,4 +182,6 @@
     SpecimenList: TStringList;            { Strings: IEN^Specimen Name }
     SpecListCount: integer;               { count of original contents of SpecimenList}
+    UrgencyList: TStringList;             { Strings: IEN^Urgency Name }
+    ForceUrgency: Boolean;                { true if not prompt Urgency }
     SurgeryList: TStringList;             { Strings: Surgeries}
     PatientInfo: TStringList;             { Text of Patient Information}
@@ -179,9 +201,13 @@
     procedure LoadCollSamp(AComboBox: TORComboBox);
     procedure LoadSpecimen(AComboBox: TORComboBox);
+    procedure LoadUrgency(CollType: string; AComboBox:TORComboBox);
     function  NameOfCollSamp: string;
     function  NameOfSpecimen: string;
+    function  NameOfUrgency: string;
     function  ObtainCollSamp: Boolean;
     function  ObtainSpecimen: Boolean;
+    function  ObtainUrgency: Boolean;
     function  ObtainComment: Boolean;
+
   end;
 
@@ -202,14 +228,18 @@
 var
   uSelectedItems: TStringList;   //Selected Items in ListView- if TestYes =1 then test else component
-                                 //TestYes(1)^Test-Component(2)^Qty(3)^Sample(4,5)^Specimen(6,7)^Modifier(8)
+                                 //TestYes(1)^Test-Component(2)^Qty(3)^Modifier(4)^Specimen(5,6)^CollTime(7)^CollType(8)
   uVBECList: TStringList;        //List of items from VBEC api
   uTestsForResults: TStringList; //List of tests to show results
   uUrgencyList: TStringList;     //List of Urgencies
+  uTNSOrders: TStringList;       //List of Current orders for Type & Screen
   uModifierList: TStringList;    //List of Modifiers
+  uReasonsList: TStringList;     //List of Reasons for Request
   uRaw: TStringList;             //Results Array
   uTestSelected, uComponentSelected: Boolean;  //Used on Validate
-  uDfltUrgency: Integer;
+  uDfltUrgency: Integer;         //Default Urgency
+  uSelUrgency: String;          //Previously Selected Urgency - Used when components have been added for specific urgency
+  uSelSurgery: Integer;          //Selected Surgery for Blood order
   uSpecimen, uGetTnS: Integer;            //Set to 1 if a specimen for test is already in lab... no need to collect
-  uDfltCollType: string;
+  uDfltCollType, uReason: string;
   ALabTest: TLabTest;
   UserHasLRLABKey: boolean;
@@ -228,5 +258,5 @@
 
   TI_INFO = 0;    //Corresponds with pgeProduct TabIndex
-  TI_ORDER = 1;
+  TI_COMPONENT = 1;
   TI_RESULTS = 2;
 
@@ -239,4 +269,6 @@
   i: integer;
   AList, ATests: TStringList;
+  ListCount: Integer;
+  x: string;
 begin
   AutoSizeDisabled := True;
@@ -248,12 +280,20 @@
   uTestsForResults := TStringList.Create;
   uUrgencyList := TStringList.Create;
+  uTNSOrders := TStringList.Create;
   uModifierList := TStringList.Create;
+  uReasonsList := TStringList.Create;
   uRaw := TStringList.Create;
   uSpecimen := 0;
   uGetTnS := 0;
+  uReason := '';
   lblTNS.Caption := '';
   lblTNS.Visible := false;
+  pnlMessage.Visible := false;
   uDfltUrgency := 9;
-  TabResults.ImageIndex := 0;
+  uSelUrgency := '';
+  uSelSurgery := 0;
+  TabResults.Caption := 'Lab Results';
+  edtResults.Lines.Clear;
+  edtResults.Lines.Add('Lab results are ONLY available after selecting/adding a component on the Blood Bank Orders tab that has been designated for results retrieval.');
   Responses.Clear;
   try
@@ -265,6 +305,4 @@
     LRFSCH   := '';
     LRORDERMODE := TORDER_MODE_INFO;
-    DisableComponentControls;
-    DisableDiagTestControls;
     FLastColltime := '';
     FLastLabCollTime := '';
@@ -277,7 +315,4 @@
     AllowQuickOrder := True;
     StatusText('Loading Dialog Definition');
-    lblReqComment.Visible := False ;
-    lblModifiers.Enabled := False;
-    cboModifiers.Enabled := False;
     FCmtTypes := TStringList.Create;
     for i := 0 to 6 do FCmtTypes.Add(CmtType[i]) ;
@@ -289,11 +324,12 @@
       EvtDivision := StrToIntDef(GetEventDiv1(IntToStr(Self.EvtID)),0);
       if EvtDelayLoc>0 then
-        AList.Assign(ODForLab(EvtDelayLoc,EvtDivision))
+        FastAssign(ODForLab(EvtDelayLoc,EvtDivision), AList)
       else
-        AList.Assign(ODForLab(Encounter.Location,EvtDivision));
+        FastAssign(ODForLab(Encounter.Location,EvtDivision), AList);
     end else
-      AList.Assign(ODForLab(Encounter.Location)); // ODForLab returns TStrings with defaults
+      FastAssign(ODForLab(Encounter.Location), AList); // ODForLab returns TStrings with defaults
     CtrlInits.LoadDefaults(AList);
     InitDialog;
+    GroupBox1.Visible := True;
     with CtrlInits do
     begin
@@ -309,5 +345,5 @@
       StatusText('Initializing List of Tests');
       FVbecLookup := 'S.VBT';
-      cboAvailTest.InitLongList('');
+      cboAvailTest.InitLongList('');      //Populates cboAvailTest control based on S.VBT xref
     end;
     cboAvailComp.Clear;
@@ -329,25 +365,37 @@
     AList.Clear;
     ExtractUrgencies(uUrgencyList, uVBECList);
+    ExtractTNSOrders(uTNSOrders, uVBECList);
     LoadUrgencies(cboUrgency);
-    cboUrgency.SelectByID(IntToStr(uDfltUrgency));
     ExtractModifiers(uModifierList, uVBECList);
+    ExtractReasons(uReasonsList, uVBECList);
     LoadModifiers(cboModifiers);
-    calWantTime.Text := FormatFMDateTime('mmm dd,yyyy@hh:nn',DateTimeToFMDateTime(Now));
-    //cboPreparation.SelectByID('I');
-    memMessage.Visible := false;
-    memOrder.Visible := false;
-    cmdAccept.Visible := false;
+    LoadReasons(cboReasons);
+    calWantTime.Text := 'NOW'; //FormatFMDateTime('mmm dd,yyyy@hh:nn',DateTimeToFMDateTime(Now));
     pgeProduct.TabIndex := TI_INFO;
-    lvSelectionList.Column[0].Width := 200;
-    lvSelectionList.Column[1].Width := 40;
+    lvSelectionList.Column[0].Width := 240;
+    lvSelectionList.Column[1].Width := 30;
+    lvSelectionList.Column[2].Width := 100;
+    DisableComponentControls;
+    DisableDiagTestControls;
     pgeProduct.ActivePageIndex := TI_INFO;
-    PreserveControl(cboAvailTest);
-    PreserveControl(cboAvailComp);
-    PreserveControl(cboCollType);
-    PreserveControl(cboCollTime);
-    PreserveControl(calCollTime);
-    PreserveControl(calWantTime);
     StatusText('');
-
+    x := 'VBEC';
+    FQuickItems := TStringList.Create;
+    ListForQuickOrders(FQuickList, ListCount, x);
+    if ListCount > 0 then
+      begin
+        SubsetOfQuickOrders(FQuickItems, FQuickList, 0, 0);
+      end else
+      begin
+        ListCount := 1;
+        FQuickItems.Add('0^(No quick orders available)');
+      end;
+
+    FastAssign(FQuickItems, cboQuick.Items);
+    if lvSelectionList.Items.Count > 0 then
+      begin
+        memOrder.Visible := true;
+        cmdAccept.Visible := true;
+      end;
   finally
     AList.Free;
@@ -375,31 +423,1023 @@
 procedure TfrmODBBank.SetupDialog(OrderAction: Integer; const ID: string);
 var
-  tmpResp: TResponse;
+  AnInstance, CurAdd: Integer;
+  AResponse: TResponse;
+  i, j, k, aTNS, aTNSDays, getTest, TestAdded: integer;
+  aStr, aTestYes, aName, aTypeScreen, aSpecimen, aModifier, sub, sub1, x, aTNSString: string;
+  ListItem: TListItem;
+  aList: TStringList;
+  aTests: TStringList;
+begin
+  inherited;
+  aList := TStringList.Create;
+  aTests:= TStringList.Create;
+  try
+  FOrderAction := OrderAction;
+  ReadServerVariables;
+  sub1 := '';
+  aTypeScreen := '';
+  aSpecimen := '^';
+  aModifier := '';
+  if OrderAction in [ORDER_COPY, ORDER_EDIT, ORDER_QUICK] then with Responses, ALabTest do
+    begin
+      AnInstance := NextInstance('ORDERABLE', 0);
+      while AnInstance > 0 do
+        begin
+          AResponse := FindResponseByName('ORDERABLE', AnInstance);
+          if AResponse <> nil then
+            begin
+              sub := GetSubtype(AResponse.EValue);
+              if sub = 't' then
+                begin
+                  SetControl(cboAvailTest,        'ORDERABLE', AnInstance);
+                  ALabTest := TLabTest.Create(cboAvailTest.ItemID, Responses);
+                end
+              else
+                begin
+                  SetControl(cboAvailComp,        'ORDERABLE', AnInstance);
+                  ALabTest := TLabTest.Create(cboAvailComp.ItemID, Responses);
+                end;
+              if ALabTest = nil then Exit;  // Causes access violation
+              if AnInstance = 1 then
+                begin
+                  SetControl(cboReasons,         'REASON' , AnInstance);
+                  SetControl(calWantTime,        'DATETIME', AnInstance);
+                  SetControl(memDiagComment,     'COMMENT', AnInstance);
+                  SetControl(chkConsent,         'YN', AnInstance);
+                  //DetermineCollectionDefaults(Responses);
+                  SetControl(cboCollType,        'COLLECT', AnInstance);
+                  SetControl(cboCollTime,        'START', AnInstance);
+                  SetupCollTimes(cboCollType.ItemID);
+                  SetControl(cboUrgency,         'URGENCY', AnInstance);
+                  SetControl(cboSurgery,         'MISC', AnInstance);
+                  Urgency := cboUrgency.ItemIEN;
+                  if (Urgency = 0) and (cboUrgency.Items.Count = 1) then
+                    begin
+                      cboUrgency.ItemIndex := 0;
+                      Urgency := cboUrgency.ItemIEN;
+                    end;
+                  i := 1 ;
+                  AResponse := Responses.FindResponseByName('COMMENT',i);
+                  while AResponse <> nil do
+                    begin
+                      Comment.Add(AResponse.EValue);
+                      Inc(i);
+                      AResponse := Responses.FindResponseByName('COMMENT',i);
+                    end ;
+                end;
+              if sub = 't' then with ALabTest do      //DIAGNOSTIC TEST
+                begin
+                  Changing := True;
+                  DisableComponentControls;
+                  EnableDiagTestControls;
+                  LRORDERMODE := TORDER_MODE_DIAG;
+                  aList.Clear;
+                  aTestYes := '1';
+                  ExtractTypeScreen(aList, uVBECList);
+                  if aList.Count > 0 then aTypeScreen := aList[0];
+                  aList.Clear;
+                  with lvSelectionList do
+                    begin
+                      ListItem := Items.Add;
+                      ListItem.Caption := piece(cboAvailTest.Items[cboAvailTest.ItemIndex],'^',2);
+                      ListItem.SubItems.Add('');
+                      ListItem.SubItems.Add('');
+                      ListItem.SubItems.Add('');
+                      ListItem.SubItems.Add(piece(cboAvailTest.Items[cboAvailTest.ItemIndex],'^',1));
+                      if piece(cboAvailTest.Items[cboAvailTest.ItemIndex],'^',1) = aTypeScreen then
+                        begin
+                          lblTNS.Caption := '';
+                          lblTNS.Visible := false;
+                          memMessage.Text := '';
+                          pnlMessage.Visible := false;
+                          uGetTnS := 0;
+                          pnlDiagnosticTests.Caption := 'Diagnostic Tests';
+                        end;
+                    end;
+                  aStr := aTestYes + '^' + IntToStr(aLabTest.TestID) + '^' + tQuantity.Text + '^' + aModifier + '^' + aSpecimen + '^' + IntToStr(aLabTest.ItemID);  //aSpecimen has 2 pieces additional pieces added for Tests
+                  uSelectedItems.Add(aStr);
+                  if Length(calWantTime.Text) > 0 then Responses.Update('DATETIME',1,ValidCollTime(calWantTime.Text),calWantTime.Text);
+                  {with cboCollType do if Length(ItemID) > 0 then
+                    begin
+                      Responses.Update('COLLECT', 1, ItemID, ItemID) ;
+                      FLastCollType := ItemID;
+                    end;  }
+                  if Length(cboUrgency.Text) > 0 then Responses.Update('URGENCY',1,cboUrgency.ItemID,cboUrgency.Text);
+                  if Length(memDiagComment.Text) > 0 then Responses.Update('COMMENT',1,memDiagComment.Text,memDiagComment.Text);
+                  if Length(cboReasons.Text) > 0 then Responses.Update('REASON',1,cboReasons.Text,cboReasons.Text);
+                  LoadCollType(cboCollType);
+                  if (cboCollType.ItemID = 'LC') or (cboCollType.ItemID = 'I') then
+                    if not(ALabTest.LabCanCollect) and OrderForInpatient then
+                      cboCollType.SelectByID('WC')
+                    else if not(ALabTest.LabCanCollect) then
+                      cboCollType.SelectByID('SP');
+                  SetupCollTimes(cboCollType.ItemID);
+                  if cboCollType.ItemID = 'LC' then
+                    begin
+                      with cboCollTime do
+                        if Length(ItemID) > 0 then
+                          begin
+                            Responses.Update('START', 1, Copy(ItemID, 2, 999), Copy(ItemID, 2, 999));
+                            FLastLabCollTime := ItemID + U + Text;
+                          end
+                        else if Length(Text) > 0 then
+                          begin
+                            Responses.Update('START', 1, ValidCollTime(Text), Text) ;
+                            FLastLabCollTime := ValidCollTime(Text);
+                          end;
+                    end
+                  else
+                    begin
+                      with calCollTime do
+                        if FMDateTime > 0 then
+                          begin
+                            Responses.Update('START', 1, ValidCollTime(Text), Text);
+                            FLastColltime := ValidCollTime(Text);
+                          end
+                        else
+                          begin
+                            Responses.Update('START', 1, '', '') ;
+                            FLastCollTime := '';
+                          end;
+                    end;
+                  with cboCollType do if Length(ItemID) > 0 then
+                    begin
+                      Responses.Update('COLLECT', 1, ItemID, ItemID) ;
+                      FLastCollType := ItemID;
+                    end;
+                  //if Length(cboCollType.Text) > 0 then Responses.Update('COLLECT',1,cboCollType.ItemID,cboCollType.ItemID);
+                  memOrder.Text := Responses.OrderText;
+                  Changing := False;
+                  if ObtainCollSamp then
+                    begin
+                      //For BloodBank orders, this condition should never occur
+                    end
+                  else
+                    begin
+                      with ALabTest do
+                        with TCollSamp(CollSampList.Items[IndexOfCollSamp(CollSamp)]) do
+                          begin
+                            x := '' ;
+                            for i := 0 to WardComment.Count-1 do
+                            x := x + WardComment.strings[i]+#13#10 ;
+                            pnlMessage.TabOrder := cboAvailTest.TabOrder + 1;
+                            OrderMessage(x) ;
+                          end ;
+                    end;
+                end;
+              if sub = 'c' then with ALabTest do  //COMPONENT
+                begin
+                  Changing := True;
+                  DisableDiagTestControls;
+                  EnableComponentControls;
+                  aTestYes := '0';
+                  LRORDERMODE := TORDER_MODE_COMP;
+                  SetControl(cboModifiers,       'MODIFIER', AnInstance);
+                  SetControl(tQuantity,          'QTY', AnInstance);
+                  uComponentSelected := true;
+                  aList.Clear;
+                  TestAdded := 0;
+                  getTest := 0;
+                  ExtractTests(aList, uVBECList);   //Get Results associated with ordered components
+                    for j := 0 to aList.Count - 1 do
+                      begin
+                        if StrToInt(piece(aList[j],'^',1)) = aLabTest.ItemID then
+                          begin
+                            if uTestsForResults.Count < 1 then getTest := 1;
+                            for k := 0 to uTestsForResults.Count - 1 do
+                              begin
+                                if piece(uTestsForResults[k],'^',1) = piece(aList[j],'^',3) then
+                                  begin
+                                    getTest := 0;
+                                    break;
+                                  end
+                                else getTest := 1;
+                              end;
+                            if getTest = 1 then
+                              begin
+                                uTestsForResults.Add(piece(aList[j],'^',3));
+                                TestAdded := 1;
+                              end;
+                          end;
+                      end;
+                    if TestAdded = 1 then
+                      begin
+                        edtResults.Clear;
+                        aTests.Clear;
+                        GetPatientBloodResults(aTests, Patient.DFN, uTestsForResults);
+                        QuickCopy(ATests,edtResults);
+                        if edtResults.Lines.Count > 0 then TabResults.Caption := 'Lab Results Available'; //TabResults.ImageIndex := 1;
+                        uRaw.Clear;
+                        GetPatientBloodResultsRaw(uRaw, Patient.DFN, uTestsForResults);
+                      end;
+                    CurAdd := 1;
+                    if uRaw.Count > 0 then
+                    for j := 0 to uRaw.Count - 1 do
+                      begin
+                        if Length(uRaw[j]) > 0 then Responses.Update('RESULTS', CurAdd, uRaw[j], piece(uRaw[j],'^',1));
+                        Inc(CurAdd);
+                      end;
+                  with lvSelectionList do
+                    begin
+                      ListItem := Items.Add;
+                      ListItem.Caption := piece(cboAvailComp.Items[cboAvailComp.ItemIndex],'^',2);
+                      ListItem.SubItems.Add(tQuantity.Text);
+                      if length(cboModifiers.ItemID) > 0 then
+                        begin
+                          ListItem.SubItems.Add(cboModifiers.Items[cboModifiers.ItemIndex]);
+                          ListItem.SubItems.Add(IntToStr(cboModifiers.ItemIndex));
+                        end
+                        else
+                          begin
+                            ListItem.SubItems.Add('');
+                            ListItem.SubItems.Add('');
+                          end;
+                      ListItem.SubItems.Add(piece(cboAvailComp.Items[cboAvailComp.ItemIndex],'^',1));
+                    end;
+                  aStr := aTestYes + '^' + IntToStr(aLabTest.TestID) + '^' + tQuantity.Text + '^' + aModifier + '^' + aSpecimen + '^' + IntToStr(aLabTest.ItemID);  //aSpecimen has 2 pieces additional pieces added for Tests
+                  uSelectedItems.Add(aStr);
+                  memOrder.Text := Responses.OrderText;
+                  Changing := False;
+                end;
+            end;
+          StatusText('');
+          AnInstance := NextInstance('ORDERABLE', AnInstance);
+        end;  //while AnInstance - ORDERABLE
+      DisableComponentControls;
+      DisableDiagTestControls;
+    end;
+    CurAdd := 1;
+    for i := 0 to uSelectedItems.Count - 1 do
+      begin
+        aName := lvSelectionList.Items[i].Caption;
+        x := uSelectedItems[i];
+        if piece(x,'^',1) = '1' then    //Diagnostic Test related fields
+          begin
+            if Length(piece(x,'^',2)) > 0 then Responses.Update('ORDERABLE', CurAdd, piece(x,'^',2), aName);
+          end
+        else
+          begin
+            if Length(piece(x,'^',2)) > 0 then Responses.Update('ORDERABLE', CurAdd, piece(x,'^',2), aName);
+            if Length(piece(x,'^',3)) > 0 then Responses.Update('QTY', CurAdd, piece(x,'^',3), piece(x,'^',3));
+            if Length(piece(x,'^',4)) > 0 then Responses.Update('MODIFIER', CurAdd, piece(x,'^',4), piece(x,'^',4));
+            if Length(piece(x,'^',5)) > 0 then Responses.Update('SPECSTS', CurAdd, pieces(x,'^',5,7), piece(x,'^',5));
+            if Length(cboSurgery.Text) > 0 then Responses.Update('MISC',1,cboSurgery.Text,cboSurgery.Text);
+            if Length(calWantTime.Text) > 0 then Responses.Update('DATETIME',1,ValidCollTime(calWantTime.Text),calWantTime.Text);
+            if Length(cboUrgency.Text) > 0 then Responses.Update('URGENCY',1,cboUrgency.ItemID,cboUrgency.Text)
+              else
+                begin
+                  cboUrgency.ItemIndex := 1;
+                  Responses.Update('URGENCY',1,cboUrgency.ItemID,cboUrgency.Text);
+                  cboUrgencyChange(self);
+                end;
+          end;
+        Inc(CurAdd);
+      end;
+    for i := 0 to lvSelectionList.Items.Count - 1 do
+      begin
+        if lvSelectionList.Items[i].SubItems[3] = aTypeScreen then
+          begin
+            if uTNSOrders.Count > 0 then
+              begin
+                for j := 0 to uTNSOrders.Count - 1 do
+                  aTNSString := aTNSString + CRLF + uTNSOrders[j];
+                with Application do
+                  begin
+                    NormalizeTopMosts;
+                    aTNSDays := TNSDaysBack;
+                    aTNS :=
+                      MessageBox(PChar(aTNSString + CRLF + CRLF +
+                                 'Do you wish to continue with this request for Type & Screen?'),
+                                 PChar('Type & Screen Entered in Past ' + IntToStr(TNSDaysBack) + ' Days'),
+                                 MB_YESNO);
+                    RestoreTopMosts;
+                    if aTNS = 7 then
+                      begin
+                        lvSelectionList.ItemIndex := i;
+                        lvSelectionListClick(self);
+                        btnRemoveClick(self);
+                        break;
+                      end;
+                  end;
+              end;
+            break;
+          end;
+      end;
+  {if OrderAction in [ORDER_COPY, ORDER_EDIT, ORDER_QUICK] then with Responses, ALabTest do
+    begin
+      if OrderAction in [ORDER_QUICK, ORDER_EDIT] then uQuickInProcess := 1;
+      AnInstance := NextInstance('ORDERABLE', 0);
+      while AnInstance > 0 do
+        begin
+          AResponse := FindResponseByName('ORDERABLE', AnInstance);
+          if AResponse <> nil then
+            begin
+              sub := GetSubtype(AResponse.EValue);
+              if sub = 't' then
+                begin
+                  SetControl(cboAvailTest,        'ORDERABLE', AnInstance);
+                  ALabTest := TLabTest.Create(cboAvailTest.ItemID, Responses);
+                end
+              else
+                begin
+                  SetControl(cboAvailComp,        'ORDERABLE', AnInstance);
+                  ALabTest := TLabTest.Create(cboAvailComp.ItemID, Responses);
+                end;
+              //SetControl(cboTests,           'ORDERABLE', AnInstance);
+              //ALabTest := TLabTest.Create(cboTests.ItemID, Responses);
+              if ALabTest = nil then Exit;  // Causes access violation
+              //sub := GetSubtype(ALabTest.TestName);
+              if AnInstance = 1 then
+                begin
+                  DetermineCollectionDefaults(Responses);
+                  SetControl(cboReasons,         'REASON', AnInstance);
+                  SetControl(chkConsent,         'YN', AnInstance);
+                  SetControl(cboSurgery,         'MISC', AnInstance);
+                  //SetControl(cboCollType,        'COLLECT', AnInstance);
+                  //SetControl(cboCollTime,        'START', AnInstance);
+                  SetControl(calWantTime,        'DATETIME', AnInstance);
+                  //LoadUrgency(cboCollType.ItemID, cboUrgency);
+                  SetControl(cboUrgency,         'URGENCY', AnInstance);
+                  Urgency := cboUrgency.ItemIEN;
+                  if (Urgency = 0) and (cboUrgency.Items.Count = AnInstance) then
+                    begin
+                      cboUrgency.ItemIndex := 0;
+                      Urgency := cboUrgency.ItemIEN;
+                    end;
+                  i := 1 ;
+                  AResponse := Responses.FindResponseByName('COMMENT',i);
+                  while AResponse <> nil do
+                      begin
+                        if Length(AResponse.Evalue) > 0 then
+                          Comment.Add(AResponse.EValue);
+                        Inc(i);
+                        AResponse := Responses.FindResponseByName('COMMENT',i);
+                      end ;
+                end;
+              if sub = 't' then with ALabTest do      //DIAGNOSTIC TEST
+                begin
+                  Changing := True;
+                  DisableComponentControls;
+                  EnableDiagTestControls;
+                  LRORDERMODE := TORDER_MODE_DIAG;
+                  with Responses do
+                    begin
+                      StatusText('Initializing Order');
+                      AResponse := FindResponseByName('ORDERABLE', AnInstance);
+                      if AResponse <> nil then
+                        sub1 := GetSubtype(AResponse.EValue);
+                      if sub1 = 't' then
+                        begin
+                          SetControl(cboAvailTest,       'ORDERABLE', AnInstance);
+                          //SetControl(cboTests,           'ORDERABLE', AnInstance);
+                          //DetermineCollectionDefaults(Responses);   //cboCollType = COLLECT , calCollTime = START
+                          cboAvailTestSelect(self);
+                        end;
+                    end;
+                  Changing := False;
+                  if ObtainCollSamp then
+                    begin
+                      //For BloodBank orders, this condition should never occur
+                    end
+                  else
+                    begin
+                      with ALabTest do
+                        with TCollSamp(CollSampList.Items[IndexOfCollSamp(CollSamp)]) do
+                          begin
+                            x := '' ;
+                            for i := 0 to WardComment.Count-1 do
+                            x := x + WardComment.strings[i]+#13#10 ;
+                            pnlMessage.TabOrder := cboAvailTest.TabOrder + 1;
+                            OrderMessage(x) ;
+                          end ;
+                    end;
+                end;
+              if sub = 'c' then with ALabTest do  //COMPONENT
+                begin
+                  Changing := True;
+                  DisableDiagTestControls;
+                  EnableComponentControls;
+                  LRORDERMODE := TORDER_MODE_COMP;
+                  with Responses do
+                    begin
+                      StatusText('Initializing Order');
+                      AResponse := FindResponseByName('ORDERABLE', AnInstance);
+                      if AResponse <> nil then
+                        sub1 := GetSubtype(AResponse.EValue);
+                      if sub1 = 'c' then
+                        begin
+                          SetControl(cboAvailComp,       'ORDERABLE', AnInstance);
+                          //SetControl(cboTests,           'ORDERABLE', AnInstance);
+                          SetControl(cboModifiers,       'MODIFIER', AnInstance);
+                          SetControl(tQuantity,          'QTY', AnInstance);
+                          //DetermineCollectionDefaults(Responses);
+                          cboAvailCompSelect(self);
+                        end;
+                    end;
+                  Changing := False;
+                end;
+              with ALabTest do
+                begin
+                  if ObtainComment then
+                    LoadRequiredComment(FCmtTypes.IndexOf(CurReqComment))
+                  else
+                    DisableCommentPanels;
+                  x := '' ;
+                  for i := 0 to CurWardComment.Count-1 do
+                    x := x + CurWardComment.strings[i]+#13#10 ;
+                  i :=  IndexOfCollSamp(CollSamp);
+                  if i > -1 then with TCollSamp(CollSampList.Items[IndexOfCollSamp(CollSamp)]) do
+                    for i := 0 to WardComment.Count-1 do
+                      x := x + WardComment.strings[i]+#13#10 ;
+                  pnlMessage.TabOrder := cboAvailTest.TabOrder + 1;
+                  if Length(x) > 0 then
+                    begin
+                      OrderMessage(x) ;
+                    end;
+                end;
+              StatusText('');
+              Changing := True;
+              //if not(FOrderAction = ORDER_EDIT) then DetermineCollectionDefaults(Responses);
+              Changing := False;
+            end;
+          AnInstance := NextInstance('ORDERABLE', AnInstance);
+        end; //while AnInstance - ORDERABLE
+      DisableComponentControls;
+      DisableDiagTestControls;
+      uQuickInProcess := 0;
+    end;  }
+  finally
+    aList.Free;
+    aTests.Free;
+  end;
+  edtResults.Height := 247;
+  edtInfo.Height := 247;
+  if lvSelectionList.Items.Count > 0 then
+    begin
+      pnlSelectedTests.Visible := True;
+      cmdAccept.Visible := True;
+      memOrder.Visible := True;
+      GroupBox1.Visible := False;
+    end;
+end;
+
+procedure TfrmODBBank.SetOnQuickOrder;
+  var
+  AnInstance: Integer;
+  AResponse: TResponse;
   i: integer;
+  x,sub,sub1,aTNSString: string;
+  aList: TStringList;
+  aGotIt: boolean;
+  aTests: TStringList;
+  ListItem: TListItem;
+  aName, aMsg, aStr, aModifier, aReason, aSurgery, aCollTime, aTestYes, aSpecimen, aTypeScreen: String;
+  CurAdd, j, k, getTest, TestAdded, aMSBOS, aMSBOSContinue, aTNS, aTNSDays: Integer;
 begin
   inherited;
-  ReadServerVariables;
-  if LRFZX <> '' then
-    begin
-      cboCollType.SelectByID(LRFZX);
-      if cboCollType.ItemIndex > -1 then SetupCollTimes(LRFZX);
-    end;
-  if OrderAction in [ORDER_COPY, ORDER_EDIT, ORDER_QUICK] then with Responses, ALabTest do
-   begin
-      SetControl(cboAvailTest,       'ORDERABLE', 1);
-      cboAvailTestSelect(Self);
-      if ALabTest = nil then Exit;  // Causes access violation in FillCollSampleList
-      Changing := True;
-      DetermineCollectionDefaults(Responses);
-      i := 1 ;
-      tmpResp := Responses.FindResponseByName('COMMENT',i);
-      while tmpResp <> nil do
-        begin
-          Comment.Add(tmpResp.EValue);
-          Inc(i);
-          tmpResp := Responses.FindResponseByName('COMMENT',i);
-        end ;
-      Changing := False;
-   end;
+  aList := TStringList.Create;
+  aTests := TStringList.Create;
+  try
+    aModifier := '';
+    aReason := '';
+    aSurgery := '';
+    aCollTime := '';
+    aTestYes := '0';
+    aTypeScreen := '';
+    aSpecimen := '';
+    sub1 := '';
+    ExtractTypeScreen(aList, uVBECList);
+    if aList.Count > 0 then aTypeScreen := aList[0];
+    aList.Clear;
+    Extractspecimen(aList, uVBECList);
+    if aList.Count > 0 then aSpecimen := aList[0];
+    with Responses, ALabTest do
+      begin
+        Changing := True;
+        aGotIt := False;
+        FLastItemID := cboQuick.ItemID;
+        QuickOrder := ExtractInteger(cboQuick.ItemID);
+        with Responses do
+          begin
+            StatusText('Initializing Quick Order');
+            AnInstance := NextInstance('ORDERABLE', 0);
+            while AnInstance > 0 do
+              begin
+                AResponse := FindResponseByName('ORDERABLE', AnInstance);
+                sub := GetSubtype(AResponse.EValue);
+                if sub = 't' then
+                  begin
+                    SetControl(cboAvailTest,        'ORDERABLE', AnInstance);
+                    ALabTest := TLabTest.Create(cboAvailTest.ItemID, Responses);
+                  end
+                else
+                  begin
+                    SetControl(cboAvailComp,        'ORDERABLE', AnInstance);
+                    ALabTest := TLabTest.Create(cboAvailComp.ItemID, Responses);
+                  end;
+                for i := 0 to aList.Count - 1 do
+                  if aList[i] = ALabTest.TestName then
+                    begin
+                      aGotIt := true;
+                      break;
+                    end;
+                if aGotIt = true then
+                  begin
+                    aGotIt := false;
+                    AnInstance := NextInstance('ORDERABLE', AnInstance);
+                    Continue;
+                  end
+                  else
+                    begin
+                      aList.Add(ALabTest.TestName);
+                    end;
+                if AResponse <> nil then
+                  sub1 := GetSubtype(AResponse.EValue);
+                if AnInstance = 1 then
+                  begin
+                    SetControl(cboReasons,         'REASON', AnInstance);
+                    SetControl(calWantTime,        'DATETIME', AnInstance);
+                    SetControl(memDiagComment,     'COMMENT', AnInstance);
+                    SetControl(chkConsent,         'YN', AnInstance);
+                    //DetermineCollectionDefaults(Responses);
+                    SetControl(cboCollType,        'COLLECT', AnInstance);
+                    SetupCollTimes(cboCollType.ItemID);
+                    //SetControl(cboCollTime,        'START', AnInstance);
+                    //LoadUrgency(cboCollType.ItemID, cboUrgency);
+                    SetControl(cboUrgency,         'URGENCY', AnInstance);
+                    Urgency := cboUrgency.ItemIEN;
+                    if (Urgency = 0) and (cboUrgency.Items.Count = AnInstance) then
+                      begin
+                        cboUrgency.ItemIndex := 0;
+                        Urgency := cboUrgency.ItemIEN;
+                        cboUrgencyChange(self);
+                      end;
+                    SetControl(cboSurgery,         'MISC', AnInstance);
+                    if not(ALabTest = nil) then
+                      begin
+                        Urgency := cboUrgency.ItemIEN;
+                        if (Urgency = 0) and (cboUrgency.Items.Count = 1) then
+                          begin
+                            cboUrgency.ItemIndex := 0;
+                            Urgency := cboUrgency.ItemIEN;
+                          end;
+                        i := 1 ;
+                        AResponse := Responses.FindResponseByName('COMMENT',i);
+                        while AResponse <> nil do
+                          begin
+                            Comment.Add(AResponse.EValue);
+                            Inc(i);
+                            AResponse := Responses.FindResponseByName('COMMENT',i);
+                          end ;
+                      end;
+                    if not(cboCollType.ItemID = 'LC') then
+                      begin
+                        if Length(cboCollTime.Text) > 0 then
+                          begin
+                            calCollTime.FMDateTime := StrToFMDateTime(cboCollTime.Text);
+                            FLastCollTime := cboCollTime.Text;
+                          end
+                        else
+                          begin
+                            FLastCollTime := '';
+                          end;
+                      end;
+                  end;
+                if sub1 = 'c' then
+                  begin
+                    DisableDiagTestControls;
+                    EnableComponentControls;
+                    LRORDERMODE := TORDER_MODE_COMP;
+                    SetControl(cboAvailComp,       'ORDERABLE', AnInstance);
+                    SetControl(cboModifiers,       'MODIFIER', AnInstance);
+                    SetControl(tQuantity,          'QTY', AnInstance);
+                    //DetermineCollectionDefaults(Responses);
+                    //Check for and display any associated Lab Results
+                    aList.Clear;
+                    TestAdded := 0;
+                    getTest := 0;
+                    ExtractTests(aList, uVBECList);   //Get Results associated with ordered components
+                      for j := 0 to aList.Count - 1 do
+                        begin
+                          if StrToInt(piece(aList[j],'^',1)) = aLabTest.ItemID then
+                            begin
+                              if uTestsForResults.Count < 1 then getTest := 1;
+                              for k := 0 to uTestsForResults.Count - 1 do
+                                begin
+                                  if piece(uTestsForResults[k],'^',1) = piece(aList[j],'^',3) then
+                                    begin
+                                      getTest := 0;
+                                      break;
+                                    end
+                                  else getTest := 1;
+                                end;
+                              if getTest = 1 then
+                                begin
+                                  uTestsForResults.Add(piece(aList[j],'^',3));
+                                  TestAdded := 1;
+                                end;
+                            end;
+                        end;
+                      if TestAdded = 1 then
+                        begin
+                          edtResults.Clear;
+                          aTests.Clear;
+                          GetPatientBloodResults(aTests, Patient.DFN, uTestsForResults);
+                          QuickCopy(ATests,edtResults);
+                          if edtResults.Lines.Count > 0 then TabResults.Caption := 'Lab Results Available'; //TabResults.ImageIndex := 1;
+                          uRaw.Clear;
+                          GetPatientBloodResultsRaw(uRaw, Patient.DFN, uTestsForResults);
+                        end;
+                      CurAdd := 1;
+                      if uRaw.Count > 0 then
+                      for j := 0 to uRaw.Count - 1 do
+                        begin
+                          if Length(uRaw[j]) > 0 then Responses.Update('RESULTS', CurAdd, uRaw[j], piece(uRaw[j],'^',1));
+                          Inc(CurAdd);
+                        end;
+                    aSpecimen := '^';
+                    aTestYes := '0';
+                    aReason := '';
+                    aSurgery := '';
+                    aCollTime := '';
+                    ExtractSpecimen(aList, uVBECList);
+                    if aList.Count > 0 then aSpecimen := aList[0];
+                    if length(cboModifiers.ItemID) > 0 then aModifier := cboModifiers.Items[cboModifiers.ItemIndex];
+                    if length(cboReasons.ItemID) > 0 then aReason := cboReasons.Items[cboReasons.ItemIndex];
+                    if length(cboSurgery.ItemID) > 0 then aSurgery := cboSurgery.Items[cboSurgery.ItemIndex];
+                    if length(cboCollTime.ItemID) > 0 then aCollTime := cboCollTime.Items[cboCollTime.ItemIndex];
+                    if Length(cboSurgery.ItemID) > 0 then
+                      begin
+                        aList.Clear;
+                        ExtractMSBOS(aList, uVBECList);    //Get maximum units for selected Surgey
+                        for i := 0 to aList.Count - 1 do
+                          begin
+                            if (StrToInt(piece(aList[i],'^',1)) = aLabTest.ItemID)
+                             and (piece(aList[i],'^',3) = cboSurgery.Text) then
+                              begin
+                                aMSBOS := StrToInt(piece(aList[i],'^',4));
+                                if (aMSBOS > 0) and (StrToInt(tQuantity.Text) > aMSBOS) then
+                                  begin
+                                    with Application do
+                                    begin
+                                      NormalizeTopMosts;
+                                      aMSBOSContinue :=
+                                        MessageBox(PChar('The number of units ordered (' + tQuantity.Text +
+                                                   ') for ' + aLabTest.TestName + ' exceeds the maximum number of units ('
+                                                   + IntToStr(aMSBOS) +
+                                                   ') for the ' + cboSurgery.text +
+                                                   ' surgical procedure selected.' + CRLF + CRLF + 'Do you wish to continue?'),
+                                                   PChar('Maximum Number of Units Exceeded'),
+                                                   MB_YESNO);
+                                      RestoreTopMosts;
+                                    end;
+                                    if aMSBOSContinue = 7 then
+                                      begin
+                                        ShowMsg(cboAvailComp.Text + ' has NOT been added to this request.');
+                                        exit;
+                                      end;
+                                  end;
+                              end;
+                          end;
+                      end;
+                    if (uTNSOrders.Count < 1) then //SpecimenNeeded(aList, uVBECList, aLabTest.ItemID) then  //check to see if type and screen is needed
+                      begin
+                        uGetTnS := 1;
+                      end;
+                    aList.Clear;
+                    ExtractSpecimens(aList, uVBECList);    //Get specimen values to pass back to Server
+                    for i := 0 to aList.Count - 1 do
+                      begin
+                        if (StrToInt(piece(aList[i],'^',1)) = aLabTest.ItemID) then
+                          begin
+                            aSpecimen := piece(aList[i],'^',2) + '^' + aSpecimen;
+                            break;
+                          end;
+                      end;
+                    uComponentSelected := true;
+                    with lvSelectionList do
+                      begin
+                        ListItem := Items.Add;
+                        ListItem.Caption := piece(cboAvailComp.Items[cboAvailComp.ItemIndex],'^',2);
+                        ListItem.SubItems.Add(tQuantity.Text);
+                        if length(cboModifiers.ItemID) > 0 then
+                          begin
+                            ListItem.SubItems.Add(cboModifiers.Items[cboModifiers.ItemIndex]);
+                            ListItem.SubItems.Add(IntToStr(cboModifiers.ItemIndex));
+                          end
+                          else
+                            begin
+                              ListItem.SubItems.Add('');
+                              ListItem.SubItems.Add('');
+                            end;
+                        ListItem.SubItems.Add(piece(cboAvailComp.Items[cboAvailComp.ItemIndex],'^',1));
+                      end;
+                    CurAdd := 1;
+                    aStr := aTestYes + '^' + IntToStr(aLabTest.TestID) + '^' + tQuantity.Text + '^' + aModifier + '^' + aSpecimen + '^' + IntToStr(aLabTest.ItemID);  //aSpecimen has 2 pieces additional pieces added for Tests
+                    uSelectedItems.Add(aStr);
+                    for i := 0 to uSelectedItems.Count - 1 do
+                      begin
+                        aName := lvSelectionList.Items[i].Caption;
+                        x := uSelectedItems[i];
+                        if piece(x,'^',1) = '1' then    //Diagnostic Test related fields
+                          begin
+                            if Length(piece(x,'^',2)) > 0 then Responses.Update('ORDERABLE', CurAdd, piece(x,'^',2), aName);
+                          end
+                        else
+                          begin
+                            if Length(piece(x,'^',2)) > 0 then Responses.Update('ORDERABLE', CurAdd, piece(x,'^',2), aName);
+                            if Length(piece(x,'^',3)) > 0 then Responses.Update('QTY', CurAdd, piece(x,'^',3), piece(x,'^',3));
+                            if Length(piece(x,'^',4)) > 0 then Responses.Update('MODIFIER', CurAdd, piece(x,'^',4), aModifier);
+                            if Length(piece(x,'^',5)) > 0 then Responses.Update('SPECSTS', CurAdd, pieces(x,'^',5,7), piece(x,'^',5));
+                            if Length(cboSurgery.Text) > 0 then Responses.Update('MISC',1,cboSurgery.Text,cboSurgery.Text);
+                          end;
+                        Inc(CurAdd);
+                      end;
+                    memOrder.Text := Responses.OrderText;
+                    GroupBox1.Visible := False;
+                  aMsg := '';
+                  LRORDERMODE := TORDER_MODE_INFO;
+                  {if uGetTnS = 1 then
+                    begin
+                      lblTNS.Caption := 'TYPE + SCREEN must be added to order';
+                      lblTNS.Visible := true;
+                      memMessage.Text := 'TYPE + SCREEN must be added to order';
+                      memMessage.Visible := false;
+                      pnlMessage.Visible := true;
+                      pnlDiagnosticTests.Caption := 'Diagnostic Tests*';
+                    end;  }
+                  {if uGetTnS = 1 then
+                    begin
+                      if responses.QuickOrder < 1 then
+                        begin
+                          for i := 1 to cboAvailTest.Items.Count - 1 do
+                            begin
+                              if piece(cboAvailTest.Items[i],'^',1) = aTypeScreen then
+                                begin
+                                  if piece(aSpecimen,'^',1) = '1' then
+                                    begin
+                                      cboCollTime.Text := calWantTime.Text;
+                                      aCollSave := cboCollTime.Text + '^' + cboCollTime.ItemID + '^' + cboCollType.Text + '^' + cboCollType.ItemID;
+                                      cboCollTime.Text := '';
+                                      cboCollType.Text := '';
+                                      uSpecimen := 1;
+                                    end;
+                                  cboModifiers.Text := '';
+                                  cboAvailTest.SelectByID(aTypeScreen);
+                                  cboTests.SelectByID(aTypeScreen);
+                                  cboTestsClick(self);
+                                  //cboAvailTestSelect(Self);
+                                  uSpecimen := 0;
+                                  cboCollTime.Text := piece(aCollSave,'^',1);
+                                  cboCollType.Text := piece(aCollSave,'^',3);
+                                  aCollSave := '';
+                                  break;
+                                end;
+                            end;
+                          aMsg := 'An order for Type and Screen has been added to this request' + '.';
+                        end
+                        else
+                          begin
+                            lblTNS.Caption := 'TYPE + SCREEN must be added to order';
+                            lblTNS.Visible := true;
+                            memMessage.Text := 'TYPE + SCREEN must be added to order';
+                            memMessage.Visible := false;
+                            pnlMessage.Visible := true;
+                          end;
+                    end;
+                  if (uGetTnS = 1) then
+                    begin
+                      if length(aMsg) > 0 then aMsg := aMsg + crlf + crlf;
+                      ShowMsg(aMsg);
+                    end;  }
+
+                  //cboModifiers.Text := '';
+                  edtResults.Height := 247;
+                  edtInfo.Height := 247;
+                  if lvSelectionList.Items.Count > 0 then
+                    begin
+                      pnlSelectedTests.Visible := True;
+                      cmdAccept.Visible := True;
+                      memOrder.Visible := True;
+                      GroupBox1.Visible := False;
+                    end;
+                  end
+                  else
+                    begin
+                      if sub1 = 't' then
+                      begin
+                        DisableComponentControls;
+                        EnableDiagTestControls;
+                        LRORDERMODE := TORDER_MODE_DIAG;
+                        aTestYes := '1';
+                        SetControl(cboAvailTest,       'ORDERABLE', AnInstance);
+                        //DetermineCollectionDefaults(Responses);   //cboCollType = COLLECT , calCollTime = START
+                        i := 1 ;
+                        AResponse := Responses.FindResponseByName('COMMENT',i);
+                        while AResponse <> nil do
+                          begin
+                            Comment.Add(AResponse.EValue);
+                            Inc(i);
+                            AResponse := Responses.FindResponseByName('COMMENT',i);
+                          end ;
+                        if ObtainCollSamp then
+                          begin
+                          //For BloodBank orders, this condition should never occur
+                          end
+                        else
+                          begin
+                            with ALabTest do
+                              with TCollSamp(CollSampList.Items[IndexOfCollSamp(CollSamp)]) do
+                                begin
+                                  x := '' ;
+                                  for i := 0 to WardComment.Count-1 do
+                                  x := x + WardComment.strings[i]+#13#10 ;
+                                  pnlMessage.TabOrder := cboAvailTest.TabOrder + 1;
+                                  OrderMessage(x) ;
+                                end ;
+                          end;
+                        if Length(calWantTime.Text) > 0 then Responses.Update('DATETIME',1,ValidCollTime(calWantTime.Text),calWantTime.Text);
+                        with cboCollType do if Length(ItemID) > 0 then
+                          begin
+                            Responses.Update('COLLECT', 1, ItemID, ItemID) ;
+                            FLastCollType := ItemID;
+                          end;
+                        if Length(cboUrgency.Text) > 0 then Responses.Update('URGENCY',1,cboUrgency.ItemID,cboUrgency.Text)
+                          else
+                            begin
+                              cboUrgency.ItemIndex := 1;
+                              Responses.Update('URGENCY',1,cboUrgency.ItemID,cboUrgency.Text);
+                              cboUrgencyChange(self);
+                            end;
+                        if Length(memDiagComment.Text) > 0 then Responses.Update('COMMENT',1,memDiagComment.Text,memDiagComment.Text);
+                        if Length(cboReasons.Text) > 0 then Responses.Update('REASON',1,cboReasons.Text,cboReasons.Text);
+                        LoadCollType(cboCollType);
+                        if (cboCollType.ItemID = 'LC') or (cboCollType.ItemID = 'I') then
+                          if not(ALabTest.LabCanCollect) and OrderForInpatient then
+                            cboCollType.SelectByID('WC')
+                          else if not(ALabTest.LabCanCollect) then
+                            cboCollType.SelectByID('SP');
+                        SetupCollTimes(cboCollType.ItemID);
+                        if cboCollType.ItemID = 'LC' then
+                          begin
+                            with cboCollTime do
+                              if Length(ItemID) > 0 then
+                                begin
+                                  Responses.Update('START', 1, Copy(ItemID, 2, 999), Copy(ItemID, 2, 999));
+                                  FLastLabCollTime := ItemID + U + Text;
+                                end
+                              else if Length(Text) > 0 then
+                                begin
+                                  Responses.Update('START', 1, ValidCollTime(Text), Text) ;
+                                  FLastLabCollTime := ValidCollTime(Text);
+                                end;
+                          end
+                        else
+                          begin
+                            with calCollTime do
+                              if FMDateTime > 0 then
+                                begin
+                                  Responses.Update('START', 1, ValidCollTime(Text), Text);
+                                  FLastColltime := ValidCollTime(Text);
+                                end
+                              else
+                                begin
+                                  Responses.Update('START', 1, '', '') ;
+                                  FLastCollTime := '';
+                                end;
+                          end;
+                        if length(cboCollTime.ItemID) > 0 then aCollTime := cboCollTime.Items[cboCollTime.ItemIndex];
+                        with cboCollType do if Length(ItemID) > 0 then
+                          begin
+                            Responses.Update('COLLECT', 1, ItemID, ItemID) ;
+                            FLastCollType := ItemID;
+                          end;
+                        uTestSelected := true;
+                        with lvSelectionList do
+                          begin
+                            ListItem := Items.Add;
+                            ListItem.Caption := piece(cboAvailTest.Items[cboAvailTest.ItemIndex],'^',2);
+                            ListItem.SubItems.Add('');
+                            ListItem.SubItems.Add('');
+                            ListItem.SubItems.Add('');
+                            ListItem.SubItems.Add(piece(cboAvailTest.Items[cboAvailTest.ItemIndex],'^',1));
+                          end;
+                        CurAdd := 1;
+                        aStr := aTestYes + '^' + IntToStr(aLabTest.TestID) + '^' + tQuantity.Text + '^' + aModifier + '^' + aSpecimen + '^' + aCollTime + '^' + cboCollType.Text + '^' + IntToStr(aLabTest.ItemID);  //aSpecimen has 2 pieces
+                        uSelectedItems.Add(aStr);
+                        for i := 0 to uSelectedItems.Count - 1 do
+                          begin
+                            aName := lvSelectionList.Items[i].Caption;
+                            x := uSelectedItems[i];
+                            if piece(x,'^',1) = '1' then    //Diagnostic Test related fields
+                              begin
+                                if Length(piece(x,'^',2)) > 0 then Responses.Update('ORDERABLE', CurAdd, piece(x,'^',2), aName);
+                              end;
+                            Inc(CurAdd);
+                          end;
+                        memOrder.Text := Responses.OrderText;
+                      edtResults.Height := 247;
+                      edtInfo.Height := 247;
+                      if lvSelectionList.Items.Count > 0 then
+                        begin
+                          pnlSelectedTests.Visible := True;
+                          cmdAccept.Visible := True;
+                          memOrder.Visible := True;
+                          GroupBox1.Visible := False;
+                        end;
+                      end;
+                    end;
+                  AnInstance := NextInstance('ORDERABLE', AnInstance);
+              end;
+              //Quick Order
+          end;
+        for i := 0 to lvSelectionList.Items.Count - 1 do
+          begin
+            if lvSelectionList.Items[i].SubItems[3] = aTypeScreen then
+              begin
+                uGetTnS := 0;
+                uDfltUrgency := cboUrgency.ItemID;
+                lblTNS.Caption := '';
+                lblTNS.Visible := false;
+                memMessage.Text := '';
+                pnlMessage.Visible := false;
+                pnlDiagnosticTests.Caption := 'Diagnostic Tests';
+                if uTNSOrders.Count > 0 then
+                  begin
+                    for j := 0 to uTNSOrders.Count - 1 do
+                      aTNSString := aTNSString + CRLF + uTNSOrders[j];
+                    with Application do
+                      begin
+                        NormalizeTopMosts;
+                        aTNSDays := TNSDaysBack;
+                        aTNS :=
+                          MessageBox(PChar(aTNSString + CRLF + CRLF +
+                                     'Do you wish to continue with this request for Type & Screen?'),
+                                     PChar('Type & Screen Entered in Past ' + IntToStr(TNSDaysBack) + ' Days'),
+                                     MB_YESNO);
+                        RestoreTopMosts;
+                        if aTNS = 7 then
+                          begin
+                            lvSelectionList.ItemIndex := i;
+                            lvSelectionListClick(self);
+                            btnRemoveClick(self);
+                            break;
+                          end;
+                      end;
+                  end;
+                break;
+              end;
+          end;
+        if uGetTnS = 1 then
+          begin
+            lblTNS.Caption := 'TYPE + SCREEN must be added to order';
+            lblTNS.Visible := true;
+            memMessage.Text := 'TYPE + SCREEN must be added to order';
+            pnlMessage.Visible := true;
+            pnlDiagnosticTests.Caption := 'Diagnostic Tests*';
+          end;
+        if ALabTest <> nil then
+          begin
+            if ObtainCollSamp then
+              begin
+               //For BloodBank orders, this condition should never occur
+              end
+            else
+              begin
+                with ALabTest do
+                  with TCollSamp(CollSampList.Items[IndexOfCollSamp(CollSamp)]) do
+                    begin
+                      x := '' ;
+                      for i := 0 to WardComment.Count-1 do
+                      x := x + WardComment.strings[i]+#13#10 ;
+                      pnlMessage.TabOrder := cboAvailTest.TabOrder + 1;
+                      OrderMessage(x) ;
+                    end ;
+              end;
+            with ALabTest do
+              begin
+                if ObtainComment then
+                  LoadRequiredComment(FCmtTypes.IndexOf(CurReqComment))
+                else
+                  DisableCommentPanels;
+                x := '' ;
+                for i := 0 to CurWardComment.Count-1 do
+                  x := x + CurWardComment.strings[i]+#13#10 ;
+                i :=  IndexOfCollSamp(CollSamp);
+                if i > -1 then with TCollSamp(CollSampList.Items[IndexOfCollSamp(CollSamp)]) do
+                  for i := 0 to WardComment.Count-1 do
+                    x := x + WardComment.strings[i]+#13#10 ;
+                pnlMessage.TabOrder := cboAvailTest.TabOrder + 1;
+                OrderMessage(x) ;
+              end;
+            GroupBox1.Visible := False;
+          end;
+        StatusText('');
+        Changing := False;
+      end;
+  finally                      //**SubTest
+    alist.Free;
+    aTests.Free;
+  end;
 end;
 
@@ -422,4 +1462,5 @@
       LabSubscript := Piece(ExtractDefault(LoadData, 'Item ID'),U,2);
       TestReqComment := ExtractDefault(LoadData, 'ReqCom');
+      UniqueCollSamp := false;
       if Length(ExtractDefault(LoadData, 'Unique CollSamp')) > 0 then UniqueCollSamp := True;
       x := ExtractDefault(LoadData, 'Unique CollSamp');
@@ -431,4 +1472,20 @@
       ExtractItems(SpecimenList, LoadData, 'Specimens');
       if LRFSPEC <> '' then SpecimenList.Add(GetOneSpecimen(StrToInt(LRFSPEC)));
+      UrgencyList := TStringList.Create;
+      if Length(ExtractDefault(LoadData, 'Default Urgency')) > 0 then  { forced urgency }
+        begin
+          ForceUrgency := True;
+          UrgencyList.Add(ExtractDefault(LoadData, 'Default Urgency'));
+          Urgency := StrToInt(Piece(ExtractDefault(LoadData, 'Default Urgency'), '^', 1));
+          uDfltUrgency := Urgency;
+        end
+      else
+        begin                 { list of urgencies }
+          ExtractItems(UrgencyList, LoadData, 'Urgencies');
+          if StrToIntDef(LRFURG, 0) > 0 then
+            Urgency := StrToInt(LRFURG)
+          else
+            Urgency := uDfltUrgency;
+        end;
       Comment := TStringList.Create ;
       CurWardComment := TStringList.Create;
@@ -443,5 +1500,5 @@
           OneSamp := TStringList.Create;
           try
-            OneSamp.Assign(GetOneCollSamp(StrToInt(LRFSAMP)));
+            FastAssign(GetOneCollSamp(StrToInt(LRFSAMP)), OneSamp);
             FillCollSampList(OneSamp, CollSampList.Count);
           finally
@@ -471,4 +1528,5 @@
   CollSampList.Free;
   SpecimenList.Free;
+  UrgencyList.Free;
   CurWardComment.Free;
   Comment.Free;
@@ -631,5 +1689,5 @@
     begin
       if SpecimenList.Count = 0 then LoadSpecimens(SpecimenList) ;
-      AComboBox.Items.Assign(SpecimenList);
+      FastAssign(SpecimenList, AComboBox.Items);
       AComboBox.Items.Add('0^Other...');
       with QuickOrderResponses do tmpResp := FindResponseByName('SPECIMEN'  ,1);
@@ -659,4 +1717,25 @@
 end;
 
+procedure TLabTest.LoadUrgency(CollType: string; AComboBox:TORComboBox);
+var
+  i: integer;
+begin
+  if UrgencyList.Count < 1 then Exit;
+  with AComboBox do
+    begin
+      Clear;
+      for i := 0 to UrgencyList.Count - 1 do
+         if (CollType = 'LC') and (Piece(UrgencyList[i], U, 3) = '') then
+           Continue
+         else
+           Items.Add(UrgencyList[i]);
+      if (LRFURG <> '') and (ALabTest.ObtainUrgency) then
+        SelectByID(LRFURG)
+      else
+        SelectByIEN(uDfltUrgency);
+      Urgency := AComboBox.ItemIEN;
+    end;
+end;
+
 function TLabTest.NameOfCollSamp: string;
 var
@@ -683,4 +1762,17 @@
 end;
 
+function TLabTest.NameOfUrgency: string;
+var
+  i: Integer;
+begin
+  Result := '';
+  with UrgencyList do for i := 0 to Count - 1 do
+  begin
+    if StrToInt(Piece(Strings[i], '^', 1)) = Urgency
+      then Result := Piece(Strings[i], '^', 2);
+    break;
+  end;
+end;
+
 function TLabTest.ObtainCollSamp: Boolean;
 begin
@@ -698,4 +1790,9 @@
 end;
 
+function TLabTest.ObtainUrgency: Boolean;
+begin
+  Result := not ForceUrgency;
+end;
+
 function TLabTest.ObtainComment: Boolean;
 begin
@@ -708,4 +1805,9 @@
 end;
 
+procedure TfrmODBBank.ExtractReasons(OutList:TStrings; AList:TStrings);
+begin
+  ExtractItems(Outlist, AList,'REASONS');
+end;
+
 procedure TfrmODBBank.ExtractUrgencies(OutList:TStrings; AList:TStrings);
 begin
@@ -713,4 +1815,9 @@
 end;
 
+procedure TfrmODBBank.ExtractTNSOrders(OutList:TStrings; AList:TStrings);
+begin
+  ExtractItems(Outlist, AList,'TNS ORDERS');
+end;
+
 procedure TfrmODBBank.ExtractSurgeries(OutList:TStrings; AList:TStrings);
 begin
@@ -726,4 +1833,9 @@
 begin
   ExtractItems(OutList, AList, 'TYPE AND SCREEN');
+end;
+
+procedure TfrmODBBank.ExtractOther(OutList:TStrings; AList:TStrings);
+begin
+  ExtractItems(OutList, AList, 'OTHER');
 end;
 
@@ -813,7 +1925,14 @@
   inherited;
   if uSelectedItems.Count < 1 then
-    SetError(TX_NO_TESTS);
+    begin
+      SetError(TX_NO_TESTS);
+      Exit;
+    end;
   if uGetTns = 1 then
-    SetError(TX_TNS_REQUIRED);
+    begin
+      SetError(TX_TNS_REQUIRED);
+      Exit;
+    end;
+  ValidateAdd(AnErrMsg);
 end;
 
@@ -827,40 +1946,42 @@
 
 var
-  i, CmtType, DaysofFuturePast: integer;
+  aList: TStringList;
+  i, DaysofFuturePast: integer;
   d1, d2: TDateTime;
-  x: string;
+  x,test,aOther: string;
 const
   {Diagnostic Test Errors}
-  TX_NO_TIME        = 'Collection Time is required.' ;
-  TX_NO_TCOLLTYPE   = 'Collection Type is required.' ;
-  TX_NO_TESTS       = 'A Lab Test or tests must be selected.' ;
+  TX_NO_TIME        = 'Collection Time is required' ;
+  TX_NO_TCOLLTYPE   = 'Collection Type is required' ;
+  TX_NO_TESTS       = 'A Lab Test or tests must be selected' ;
   TX_BAD_TIME       = 'Collection times must be chosen from the drop down list or entered as valid' +
-                      ' Fileman date/times (T@1700, T+1@0800, etc.).' ;
-  TX_PAST_TIME      = 'Collection times in the past are not allowed.';
-  TX_NO_DAYS        = 'A number of days must be entered for continuous orders.';
-  TX_NO_TIMES       = 'A number of times must be entered for continuous orders.';
-  TX_NO_STOP_DATE   = 'Could not calculate the stop date for the order.  Check "for n Days".';
+                      ' Fileman date/times (T@1700, T+1@0800, etc.)' ;
+  TX_PAST_TIME      = 'Collection times in the past are not allowed';
+  TX_NO_DAYS        = 'A number of days must be entered for continuous orders';
+  TX_NO_TIMES       = 'A number of times must be entered for continuous orders';
+  TX_NO_STOP_DATE   = 'Could not calculate the stop date for the order.  Check "for n Days"';
   TX_TOO_MANY_DAYS  = 'Maximum number of days allowed is ';
   TX_TOO_MANY_TIMES = 'For this frequency, the maximum number of times allowed is:  X';
   //TX_NO_COMMENT     = 'A comment is required for this test and collection sample.';
-  TX_NUMERIC_REQD   = 'A numeric value is required for urine volume.';
-  TX_DOSEDRAW_REQD  = 'Both DOSE and DRAW times are required for this order.';
-  TX_TDM_REQD       = 'A value for LEVEL is required for this order.';
+  TX_NUMERIC_REQD   = 'A numeric value is required for urine volume';
+  TX_DOSEDRAW_REQD  = 'Both DOSE and DRAW times are required for this order';
+  TX_TDM_REQD       = 'A value for LEVEL is required for this order';
   //TX_ANTICOAG_REQD  = 'You must specify an anticoagulant on this order.' ;
-  TX_NO_COLLSAMPLE  = 'A collection sample MUST be specified.';
-  TX_NO_SPECIMEN    = 'A specimen MUST be specified.';
-  TX_NO_URGENCY     = 'An urgency MUST be specified.';
-  TX_NO_FREQUENCY   = 'A collection frequency MUST be specified.';
-  TX_NOT_LAB_COLL_TIME = ' is not a routine lab collection time.';
-  TX_NO_ALPHA       = 'For continuous orders, enter a number of days, or an "X" followed by a number of times.';
+  TX_NO_COLLSAMPLE  = 'A collection sample MUST be specified';
+  TX_NO_SPECIMEN    = 'A specimen MUST be specified';
+  TX_NO_URGENCY     = 'An urgency MUST be specified';
+  TX_NO_FREQUENCY   = 'A collection frequency MUST be specified';
+  TX_NOT_LAB_COLL_TIME = ' is not a routine lab collection time';
+  TX_NO_ALPHA       = 'For continuous orders, enter a number of days, or an "X" followed by a number of times';
   TX_BADTIME_CAP    = 'Invalid Immediate Collect Time';
   {Component/Type & Screen Errors}
-  TX_NO_COMPONENTS  = 'A Blood Product MUST be selected.';
-  TX_NO_QUANTITY    = 'The number of units MUST be specified under "Quantity".';
-  TX_HIGH_QUANTITY  = 'Quantity too high.';
+  TX_NO_COMPONENTS  = 'A Blood Product MUST be selected';
+  TX_NO_QUANTITY    = 'The number of units MUST be specified under "Quantity"';
+  TX_HIGH_QUANTITY  = 'Quantity too high';
   TX_NO_DATEMODIFIED= 'A Date/time Wanted MUST be specified';
-  //TX_NO_PREPARATION = 'Preparation MUST be specified - either "Hold" or "Immediate".';
   TX_NO_SURGERY     = 'A Surgery MUST be specified for Pre-Op orders';         //only if Pre-op selected
   TX_NO_REASON      = 'A Reason for Request MUST be entered';
+  TX_REASON_TOO_LONG= 'Reason for Request MUST be less than 76 characters long';
+  TX_MODIFIER_TOO_LONG = 'Modifer text MUST be less than 51 characters long';
   TX_NO_COMMENT     = 'A Comment MUST be entered for this Component';
   TX_DUPLICATE      = 'Duplicate Test/Component not allowed';
@@ -870,131 +1991,115 @@
   inherited;
   AnErrMsg := '';
-  if aLabTest = nil then
-    begin
-      AnErrMsg := TX_NO_TEST_SELECTED;
-      Exit;
-    end;
-  for i := 0 to uSelectedItems.Count - 1 do
-    if IntToStr(aLabTest.TestID) = piece(uSelectedItems[i],'^',2) then
+  aList := TStringList.Create;
+  try
+    ExtractOther(aList, uVBECList);
+    if aList.Count > 0 then aOther := aList[0];
+    aList.Clear;
+    if uSelectedItems.Count < 1 then
       begin
-        AnErrMsg := TX_DUPLICATE;
+        AnErrMsg := TX_NO_TEST_SELECTED;
         Exit;
       end;
-  if LRORDERMODE = TORDER_MODE_DIAG then
-    begin
-      with cboAvailTest do if ItemIEN <= 0 then SetError(TX_NO_TESTS);
-
-      if ALabTest <> nil then
-        if (cboCollType.ItemID = 'I') and (not ALabTest.LabCanCollect) then
+    for i := 0 to uSelectedItems.Count - 1 do
+      begin
+        x := uSelectedItems[i];
+        test := lvSelectionList.Items[i].Caption;
+        if piece(x,'^',1) = '1' then    //Diagnostic Test
           begin
-            SetError(TX_NO_IMMED);
-            cboCollType.ItemIndex := -1;
+            if uSpecimen = 0 then
+              if cboCollType.ItemID = '' then
+                SetError(TX_NO_TCOLLTYPE + ' (' + test + ')')
+              else if cboCollType.ItemID = 'LC' then
+                begin
+                 if Length(cboCollTime.Text) = 0 then SetError(TX_NO_TIME + ' (' + test + ')');
+                 with cboCollTime do if (Length(Text) > 0) and (ItemIndex = -1) then
+                   begin
+                     if StrToFMDateTime(Text) < 0 then
+                       SetError(TX_BAD_TIME + ' (' + test + ')')
+                     else if StrToFMDateTime(Text) < FMNow then
+                       SetError(TX_PAST_TIME + ' (' + test + ')')
+                     else if OrderForInpatient then
+                       begin
+                         d1 := FMDateTimeToDateTime(Trunc(StrToFMDateTime(cboColltime.Text)));
+                         d2 := FMDateTimeToDateTime(FMToday);
+                         if EvtDelayLoc > 0 then
+                           DaysofFuturePast := LabCollectFutureDays(EvtDelayLoc,EvtDivision)
+                         else
+                           DaysofFuturePast := LabCollectFutureDays(Encounter.Location);
+                         if DaysofFuturePast = 0 then DaysofFuturePast := 7;
+                         if ((d1 - d2) > DaysofFuturePast) then
+                           SetError('A lab collection cannot be ordered more than '
+                             + IntToStr(DaysofFuturePast) + ' days in advance');
+                       end
+                     else if EvtDelayLoc > 0 then
+                       begin
+                         if (not IsLabCollectTime(StrToFMDateTime(cboCollTime.Text), EvtDelayLoc)) then
+                           SetError(cboCollTime.Text + TX_NOT_LAB_COLL_TIME + ' (' + test + ')');
+                       end
+                     else if EvtDelayLoc <= 0 then
+                       begin
+                         if (not IsLabCollectTime(StrToFMDateTime(cboCollTime.Text), Encounter.Location)) then
+                           SetError(cboCollTime.Text + TX_NOT_LAB_COLL_TIME + ' (' + test + ')');
+                       end;
+                   end;
+                end
+              else
+                begin
+                  if cboCollType.ItemID = 'I' then
+                    begin
+                      calCollTime.Text := txtImmedColl.Text;
+                      x := ValidImmCollTime(calCollTime.FMDateTime);
+                      if (Piece(x, U, 1) <> '1') then
+                        SetError(Piece(x, U, 2));
+                    end;
+
+                  with calColltime do
+                    begin
+                      if FMDateTime = 0 then SetError(TX_BAD_TIME + ' (' + test + ')')
+                      else
+                        begin
+                          // date only was entered
+                          if (FMDateTime - Trunc(FMDateTime) = 0) then
+                            begin
+                              if (Trunc(FMDateTime) < FMToday) then SetError(TX_PAST_TIME + ' (' + test + ')');
+                            end
+                          // date/time was entered
+                          else
+                            begin
+                              if (UpperCase(Text) <> 'NOW') and (FMDateTime < FMNow) then SetError(TX_PAST_TIME + ' (' + test + ')');
+                            end;
+                        end;
+                    end;
+                end;
+
+            with cboUrgency do if ItemIEN  <= 0 then SetError(TX_NO_URGENCY + ' (' + test + ')');
+          end
+        else                            //Component
+          begin
+            if piece(x,'^',3) ='' then SetError(TX_NO_QUANTITY + ' (' + test + ')')
+              else
+                begin
+                  if StrToInt(piece(x,'^',3)) < 1 then SetError(TX_NO_QUANTITY + ' (' + test + ')');
+                  if StrToInt(piece(x,'^',3)) > 100 then SetError(TX_HIGH_QUANTITY + ' (' + test + ')');
+                end;
+            if calWantTime.Text = '' then SetError(TX_NO_DATEMODIFIED + ' (' + test + ')');
+            if (cboReasons.Text = '') and not(uReason = '') then
+              begin
+                SetError(TX_NO_REASON + ' (' + test + ').' + ' Previously entered ''Reason for Request'' will be retained.');
+                cboReasons.Text := uReason; //reset reason back to previous value
+              end;
+              if (cboReasons.Text = '') then
+                begin
+                  SetError(TX_NO_REASON + ' (' + test + ').');
+                end;
+            if (memDiagComment.Text = '') and (piece(x,'^',2) = aOther) then SetError(TX_NO_COMMENT + ' (' + test + ')');
+            if (cboUrgency.Text = 'PRE-OP') and (length(cboSurgery.Text) < 1) then SetError(TX_NO_SURGERY + ' (' + test + ')');
+            if (length(cboReasons.Text) > 75) then SetError(TX_REASON_TOO_LONG);
+            if (length(cboModifiers.Text) > 50) then SetError(TX_MODIFIER_TOO_LONG);
           end;
-      if uSpecimen = 0 then
-        if cboCollType.ItemID = '' then
-          SetError(TX_NO_TCOLLTYPE)
-        else if cboCollType.ItemID = 'LC' then
-          begin
-           if Length(cboCollTime.Text) = 0 then SetError(TX_NO_TIME);
-           with cboCollTime do if (Length(Text) > 0) and (ItemIndex = -1) then
-             begin
-               if StrToFMDateTime(Text) < 0 then
-                 SetError(TX_BAD_TIME)
-               else if StrToFMDateTime(Text) < FMNow then
-                 SetError(TX_PAST_TIME)
-               else if OrderForInpatient then
-                 begin
-                   d1 := FMDateTimeToDateTime(Trunc(StrToFMDateTime(cboColltime.Text)));
-                   d2 := FMDateTimeToDateTime(FMToday);
-                   if EvtDelayLoc > 0 then
-                     DaysofFuturePast := LabCollectFutureDays(EvtDelayLoc,EvtDivision)
-                   else
-                     DaysofFuturePast := LabCollectFutureDays(Encounter.Location);
-                   if DaysofFuturePast = 0 then DaysofFuturePast := 7;
-                   if ((d1 - d2) > DaysofFuturePast) then
-                     SetError('A lab collection cannot be ordered more than '
-                       + IntToStr(DaysofFuturePast) + ' days in advance');
-                 end
-               else if EvtDelayLoc > 0 then
-                 begin
-                   if (not IsLabCollectTime(StrToFMDateTime(cboCollTime.Text), EvtDelayLoc)) then
-                     SetError(cboCollTime.Text + TX_NOT_LAB_COLL_TIME);
-                 end
-               else if EvtDelayLoc <= 0 then
-                 begin
-                   if (not IsLabCollectTime(StrToFMDateTime(cboCollTime.Text), Encounter.Location)) then
-                     SetError(cboCollTime.Text + TX_NOT_LAB_COLL_TIME);
-                 end;
-             end;
-          end
-        else
-          begin
-            if cboCollType.ItemID = 'I' then
-              begin
-                calCollTime.Text := txtImmedColl.Text;
-                x := ValidImmCollTime(calCollTime.FMDateTime);
-                if (Piece(x, U, 1) <> '1') then
-                  SetError(Piece(x, U, 2));
-              end;
-
-            with calColltime do
-              begin
-                if FMDateTime = 0 then SetError(TX_BAD_TIME)
-                else
-                  begin
-                    // date only was entered
-                    if (FMDateTime - Trunc(FMDateTime) = 0) then
-                      begin
-                        if (Trunc(FMDateTime) < FMToday) then SetError(TX_PAST_TIME);
-                      end
-                    // date/time was entered
-                    else
-                      begin
-                        if (UpperCase(Text) <> 'NOW') and (FMDateTime < FMNow) then SetError(TX_PAST_TIME);
-                      end;
-                  end;
-              end;
-          end;
-
-      with cboUrgency do if ItemIEN  <= 0 then SetError(TX_NO_URGENCY);
-      if ALabTest <> nil then
-        begin
-          CmtType := FCmtTypes.IndexOf(ALabTest.CurReqComment) ;
-          with ALabTest do
-          case CmtType of
-            0 : {ANTICOAGULATION}         {if (Pos('ANTICOAGULANT',Comment.Text)=0) then
-                                         SetError(TX_ANTICOAG_REQD)};
-            1 : {DOSE/DRAW TIMES}         if (Pos('Last dose:',Comment.Text)=0) or
-                                          (Pos('draw time:',Comment.Text)=0) then
-                                         SetError(TX_DOSEDRAW_REQD);
-            2 : {ORDER COMMENT}           {if (Length(Comment.Text)=0) then
-                                         SetError(TX_NO_COMMENT)};
-            3 : {ORDER COMMENT MODIFIED}  {if (Length(Comment.Text)=0) then
-                                         SetError(TX_NO_COMMENT)};
-            4 : {TDM (PEAK-TROUGH}        if (Pos('Dose is expected',Comment.Text)=0) then
-                                         SetError(TX_TDM_REQD);
-            5 : {TRANSFUSION}             {if (Length(Comment.Text)=0) then
-                                         SetError(TX_NO_COMMENT)};
-            6 : {URINE VOLUME}            if (Length(Comment.Text)>0) and
-                                       (ExtractInteger(Comment.Text)<=0) then
-                                          Comment.Text := '?';
-                                         {SetError(TX_NUMERIC_REQD);}
-          end;
-        end;
-    end
-  else if LRORDERMODE = TORDER_MODE_COMP then
-    begin
-      with cboAvailComp do
-        begin
-          if ItemIEN <= 0 then SetError(TX_NO_COMPONENTS);
-        end;
-      if StrToInt(tQuantity.Text) < 1 then SetError(TX_NO_QUANTITY);
-      if calWantTime.Text = '' then SetError(TX_NO_DATEMODIFIED);
-      //if cboPreparation.Text ='' then SetError(TX_NO_PREPARATION);
-      if StrToInt(tQuantity.Text) > 100 then SetError(TX_HIGH_QUANTITY);
-      if tReason.Text = '' then SetError(TX_NO_REASON);
-      if (txtDiagComment.Text = '') and (cboAvailComp.Text = 'OTHER') then SetError(TX_NO_COMMENT);
-      if (cboUrgency.Text = 'PRE-OP') and (length(cboSurgery.ItemID) < 1) then SetError(TX_NO_SURGERY);
-    end;
+      end;
+  finally
+    aList.Free;
+  end;
 end;
 
@@ -1273,238 +2378,556 @@
 end;
 
+procedure TfrmODBBank.cboQuickClick(Sender: TObject);
+begin
+  inherited;
+  SetOnQuickOrder;
+end;
+
+procedure TfrmODBBank.cboReasonsChange(Sender: TObject);
+begin
+  inherited;
+  if (length(cboReasons.Text) > 75) then
+    begin
+      ShowMsg('REASON FOR REQUEST cannot be longer than 75 characters');
+      cboReasons.Text := Copy(cboReasons.Text,0,75);
+      Exit;
+    end;
+  if Length(cboReasons.Text) > 0 then Responses.Update('REASON', 1, cboReasons.Text, cboReasons.Text);
+  memOrder.Text := Responses.OrderText;
+end;
+
+procedure TfrmODBBank.cboReasonsEnter(Sender: TObject);
+begin
+  inherited;
+  if Length(cboReasons.Text) > 0 then
+    uReason := cboReasons.Text;
+end;
+
+procedure TfrmODBBank.cboReasonsExit(Sender: TObject);
+begin
+  inherited;
+  if Length(cboReasons.Text) > 0 then
+    uReason := cboReasons.Text;
+end;
+
 procedure TfrmODBBank.cboAvailTestSelect(Sender: TObject);
 var
-  x: string;
   i: integer;
-begin
-  DisableComponentControls;
-  EnableDiagTestControls;
-  LRORDERMODE := TORDER_MODE_DIAG;
-  with cboAvailTest do
-    begin
-      if (Length(ItemID) = 0) or (ItemID = '0') then Exit;
+  text : string;
+  ListItem: TListItem;
+  aCollTime,aTypeScreen,aStr,aModifier,aSpecimen,aTestYes,x,aName,aTNSString: string;
+  aList: TStringList;
+  curAdd,AnInstance,aTNS,aTNSDays: Integer;
+  sub,sub1: string;
+  AResponse: TResponse;
+begin
+  if cboAvailTest.ItemID = '' then Exit;
+  aList := TStringList.Create;
+  try
+    ALabTest := nil;
+    aTypeScreen := '';
+    aSpecimen := '^';
+    aTestYes := '1';
+    aModifier := '';
+    changing := true;
+    tQuantity.Text := '';
+    sub1 := '';
+    cboModifiers.ItemIndex := -1;
+    DisableComponentControls;
+    EnableDiagTestControls;
+    LRORDERMODE := TORDER_MODE_DIAG;
+    ALabTest := TLabTest.Create(cboAvailTest.ItemID, Responses);
+    sub := GetSubtype(ALabTest.TestName);
+    with CtrlInits do
+        begin
+          SetControl(cboCollType, 'Collection Types');
+          LoadCollType(cboCollType);
+          if FLastCollType <> '' then
+            cboCollType.SelectByID(FLastCollType)
+          else if uDfltCollType <> '' then
+            cboCollType.SelectByID(uDfltCollType)
+          else if OrderForInpatient then
+            if (ALabTest.LabCanCollect) then
+              cboCollType.SelectByID('LC')
+            else
+              cboCollType.SelectByID('WC')
+          else
+            cboCollType.SelectByID('SP');
+          SetupCollTimes(cboCollType.ItemID);
+        end;
+    with cboAvailTest do
+      begin
+        if (Length(ItemID) = 0) or (ItemID = '0') then Exit;
+        FLastLabID := ItemID ;
+        FLastItemID := ItemID;
+        for i := 0 to uSelectedItems.Count - 1 do
+          if ItemID = piece(uSelectedItems[i],'^',2) then
+            begin
+              ItemIndex := -1;
+              lvSelectionList.Items[i].Selected := true;
+              lvSelectionListClick(self);
+              Exit;
+            end;
+        Changing := True;
+        Changing := False;
+        ExtractTypeScreen(aList, uVBECList);
+        if aList.Count > 0 then aTypeScreen := aList[0];
+        aList.Clear;
+        aTNSString := '';
+        if (StrToInt(aTypeScreen) = cboAvailTest.ItemID) and (uTNSOrders.Count > 0) then
+          begin
+            for i := 0 to uTNSOrders.Count - 1 do
+              aTNSString := aTNSString + CRLF + uTNSOrders[i];
+            with Application do
+              begin
+                NormalizeTopMosts;
+                aTNSDays := TNSDaysBack;
+                aTNS :=
+                  MessageBox(PChar(aTNSString + CRLF + CRLF +
+                             'Do you wish to continue?'),
+                             PChar('Type & Screen Entered in Past ' + IntToStr(TNSDaysBack) + ' Days'),
+                             MB_YESNO);
+                RestoreTopMosts;
+                if aTNS = 7 then
+                  begin
+                    cboAvailTest.ItemIndex := -1;
+                    exit;
+                  end;
+              end;
+          end;
+        if sub = 't' then with ALabTest do      //DIAGNOSTIC TEST
+          begin
+            if ObtainCollSamp then
+              begin
+              //For BloodBank orders, this condition should never occur
+              end
+            else
+              begin
+                with ALabTest do
+                  with TCollSamp(CollSampList.Items[IndexOfCollSamp(CollSamp)]) do
+                    begin
+                      x := '' ;
+                      for i := 0 to WardComment.Count-1 do
+                      x := x + WardComment.strings[i]+#13#10 ;
+                      pnlMessage.TabOrder := cboAvailTest.TabOrder + 1;
+                      OrderMessage(x) ;
+                    end ;
+              end;
+        end;
+        Changing := False;
+      end;
+    if LRORDERMODE = TORDER_MODE_DIAG then
+      begin
+        if Length(calWantTime.Text) > 0 then Responses.Update('DATETIME',1,ValidCollTime(calWantTime.Text),calWantTime.Text);
+        with cboCollType do if Length(ItemID) > 0 then
+          begin
+            Responses.Update('COLLECT', 1, ItemID, ItemID) ;
+            FLastCollType := ItemID;
+          end;
+        if Length(cboUrgency.Text) > 0 then Responses.Update('URGENCY',1,cboUrgency.ItemID,cboUrgency.Text)
+        else
+          begin
+            cboUrgency.ItemIndex := 1;
+            Responses.Update('URGENCY',1,cboUrgency.ItemID,cboUrgency.Text);
+          end;
+        if Length(memDiagComment.Text) > 0 then Responses.Update('COMMENT',1,memDiagComment.Text,memDiagComment.Text);
+        if Length(cboReasons.Text) > 0 then Responses.Update('REASON',1,cboReasons.Text,cboReasons.Text);
+        if cboCollType.ItemID = 'LC' then
+          begin
+            with cboCollTime do
+              if Length(ItemID) > 0 then
+                begin
+                  Responses.Update('START', 1, Copy(ItemID, 2, 999), Copy(ItemID, 2, 999));
+                  FLastLabCollTime := ItemID + U + Text;
+                end
+              else if Length(Text) > 0 then
+                begin
+                  Responses.Update('START', 1, ValidCollTime(Text), Text) ;
+                  FLastLabCollTime := ValidCollTime(Text);
+                end;
+          end
+          else
+            begin
+              with calCollTime do
+                if FMDateTime > 0 then
+                  begin
+                    Responses.Update('START', 1, ValidCollTime(Text), Text);
+                    FLastColltime := ValidCollTime(Text);
+                  end
+                else
+                  begin
+                    Responses.Update('START', 1, '', '') ;
+                    FLastCollTime := '';
+                  end;
+            end;
+          if Length(cboCollType.Text) > 0 then Responses.Update('COLLECT',1,cboCollType.ItemID,cboCollType.ItemID);
+      end;
+    if length(cboCollTime.ItemID) > 0 then aCollTime := cboCollTime.Items[cboCollTime.ItemIndex];
+    uTestSelected := true;
+    with lvSelectionList do
+      begin
+        ListItem := Items.Add;
+        ListItem.Caption := piece(cboAvailTest.Items[cboAvailTest.ItemIndex],'^',2);
+        ListItem.SubItems.Add('');
+        ListItem.SubItems.Add('');
+        ListItem.SubItems.Add('');
+        ListItem.SubItems.Add(piece(cboAvailTest.Items[cboAvailTest.ItemIndex],'^',1));
+        if piece(cboAvailTest.Items[cboAvailTest.ItemIndex],'^',1) = aTypeScreen then
+          begin
+            lblTNS.Caption := '';
+            lblTNS.Visible := false;
+            memMessage.Text := '';
+            pnlMessage.Visible := false;
+            uGetTnS := 0;
+            pnlDiagnosticTests.Caption := 'Diagnostic Tests';
+          end;
+      end;
+    aStr := aTestYes + '^' + IntToStr(aLabTest.TestID) + '^' + tQuantity.Text + '^' + aModifier + '^' + aSpecimen + '^' + aCollTime + '^' + cboCollType.Text + '^' + IntToStr(aLabTest.ItemID);  //aSpecimen has 2 pieces
+    uSelectedItems.Add(aStr);
+    CurAdd := 1;
+    for i := 0 to uSelectedItems.Count - 1 do
+      begin
+        aName := lvSelectionList.Items[i].Caption;
+        x := uSelectedItems[i];
+        if piece(x,'^',1) = '1' then    //Diagnostic Test related fields
+          begin
+            if Length(piece(x,'^',2)) > 0 then Responses.Update('ORDERABLE', CurAdd, piece(x,'^',2), aName);
+          end;
+        Inc(CurAdd);
+      end;
+    memOrder.Text := Responses.OrderText;
+  finally
+    aList.Free;
+  end;
+  edtResults.Height := 247;
+  edtInfo.Height := 247;
+  if lvSelectionList.Items.Count > 0 then
+    begin
+      pnlSelectedTests.Visible := True;
+      cmdAccept.Visible := True;
+      memOrder.Visible := True;
+      GroupBox1.Visible := False;
+    end;
+end;
+
+procedure TfrmODBBank.cboAvailCompSelect(Sender: TObject);
+ var
+  aList,aTests: TStringList;
+  i,j,k,getTest,TestAdded: integer;
+  text : string;
+  aMSBOS,aMSBOSContinue,curAdd,AnInstance: integer;
+  sub,sub1: string;
+  AResponse: TResponse;
+  ListItem: TListItem;
+  aTypeScreen,aSpecimen,aTestYes,aStr,aMsg,aModifier,x,x1,aReason,aSurgery,aCollTime,aCollSave,aName: String;
+begin
+  if cboAvailComp.ItemID = '' then Exit;
+  aList := TStringList.Create;
+  aTests := TStringList.Create;
+  sub1 := '';
+  try
+    DisableDiagTestControls;
+    EnableComponentControls;
+    if not(changing = true) then
+      begin
+        changing := true;
+        tQuantity.Text := '';
+        cboModifiers.ItemIndex := -1;
+        changing := false;
+      end;
+    LRORDERMODE := TORDER_MODE_COMP;
+    with cboAvailComp do
+      begin
+        if (Length(ItemID) = 0) or (ItemID = '0') then Exit;
+        FLastLabID := ItemID ;
+        FLastItemID := ItemID;
+        for i := 0 to uSelectedItems.Count - 1 do
+          if ItemID = piece(uSelectedItems[i],'^',2) then
+            begin
+              ItemIndex := -1;
+              lvSelectionList.Items[i].Selected := true;
+              lvSelectionListClick(self);
+              Exit;
+            end;
+        ALabTest := TLabTest.Create(ItemID, Responses);
+        sub := GetSubtype(ALabTest.TestName);
+        Changing := False;
+        StatusText('');
+      end;
+    //Check for and display any associated Lab Results
+    aList.Clear;
+    TestAdded := 0;
+    getTest := 0;
+    ExtractTests(aList, uVBECList);   //Get Results associated with ordered components
+      for j := 0 to aList.Count - 1 do
+        begin
+          if StrToInt(piece(aList[j],'^',1)) = aLabTest.ItemID then
+            begin
+              if uTestsForResults.Count < 1 then getTest := 1;
+              for k := 0 to uTestsForResults.Count - 1 do
+                begin
+                  if piece(uTestsForResults[k],'^',1) = piece(aList[j],'^',3) then
+                    begin
+                      getTest := 0;
+                      break;
+                    end
+                  else getTest := 1;
+                end;
+              if getTest = 1 then
+                begin
+                  uTestsForResults.Add(piece(aList[j],'^',3));
+                  TestAdded := 1;
+                end;
+            end;
+        end;
+      if TestAdded = 1 then
+        begin
+          edtResults.Clear;
+          aTests.Clear;
+          GetPatientBloodResults(aTests, Patient.DFN, uTestsForResults);
+          QuickCopy(ATests,edtResults);
+          if edtResults.Lines.Count > 0 then TabResults.Caption := 'Lab Results Available';
+          uRaw.Clear;
+          GetPatientBloodResultsRaw(uRaw, Patient.DFN, uTestsForResults);
+        end;
+      CurAdd := 1;
+      if uRaw.Count > 0 then
+      for j := 0 to uRaw.Count - 1 do
+        begin
+          if Length(uRaw[j]) > 0 then Responses.Update('RESULTS', CurAdd, uRaw[j], piece(uRaw[j],'^',1));
+          Inc(CurAdd);
+        end;
+    aTypeScreen := '';
+    aSpecimen := '^';
+    aTestYes := '0';
+    aReason := '';
+    aSurgery := '';
+    aCollTime := '';
+    aList.Clear;
+    ExtractTypeScreen(aList, uVBECList);
+    if aList.Count > 0 then aTypeScreen := aList[0];
+    aList.Clear;
+    ExtractSpecimen(aList, uVBECList);
+    if aList.Count > 0 then aSpecimen := aList[0];
+    if length(cboModifiers.ItemID) > 0 then aModifier := cboModifiers.Items[cboModifiers.ItemIndex];
+    if length(cboReasons.ItemID) > 0 then aReason := cboReasons.Items[cboReasons.ItemIndex];
+    if length(cboSurgery.ItemID) > 0 then aSurgery := cboSurgery.Items[cboSurgery.ItemIndex];
+    if length(cboCollTime.ItemID) > 0 then aCollTime := cboCollTime.Items[cboCollTime.ItemIndex];
+    if Length(cboSurgery.ItemID) > 0 then
+      begin
+        aList.Clear;
+        ExtractMSBOS(aList, uVBECList);    //Get maximum units for selected Surgey
+        for i := 0 to aList.Count - 1 do
+          begin
+            if (StrToInt(piece(aList[i],'^',1)) = aLabTest.ItemID)
+             and (piece(aList[i],'^',3) = cboSurgery.Text) then
+              begin
+                aMSBOS := StrToInt(piece(aList[i],'^',4));
+                if (aMSBOS > 0) and (Length(tQuantity.Text) > 0) and (StrToInt(tQuantity.Text) > aMSBOS) then
+                  begin
+                    with Application do
+                    begin
+                      NormalizeTopMosts;
+                      aMSBOSContinue :=
+                        MessageBox(PChar('The number of units ordered (' + tQuantity.Text +
+                                   ') for ' + aLabTest.TestName + ' exceeds the maximum number of units ('
+                                   + IntToStr(aMSBOS) +
+                                   ') for the ' + cboSurgery.text +
+                                   ' surgical procedure selected.' + CRLF + CRLF + 'Do you wish to continue?'),
+                                   PChar('Maximum Number of Units Exceeded'),
+                                   MB_YESNO);
+                      RestoreTopMosts;
+                    end;
+                    if aMSBOSContinue = 7 then
+                      begin
+                        ShowMsg(cboAvailComp.Text + ' has NOT been added to this request.');
+                        exit;
+                      end;
+                  end;
+              end;
+          end;
+      end;
+    if (uTNSOrders.Count < 1) then // SpecimenNeeded(aList, uVBECList, aLabTest.ItemID) then  //check to see if type and screen is needed
+      begin
+        uGetTnS := 1;
+        for i := 0 to lvSelectionList.Items.Count - 1 do
+          begin
+            if lvSelectionList.Items[i].SubItems[3] = aTypeScreen then
+              begin
+                uGetTnS := 0;
+                if length(cboUrgency.ItemID) > 0 then uDfltUrgency := cboUrgency.ItemID;
+                lblTNS.Caption := '';
+                lblTNS.Visible := false;
+                memMessage.Text := '';
+                pnlMessage.Visible := false;
+                pnlDiagnosticTests.Caption := 'Diagnostic Tests';
+                break;
+              end;
+          end;
+      end;
+    aList.Clear;
+    ExtractSpecimens(aList, uVBECList);    //Get specimen values to pass back to Server
+    for i := 0 to aList.Count - 1 do
+      begin
+        if (StrToInt(piece(aList[i],'^',1)) = aLabTest.ItemID) then
+          begin
+            aSpecimen := piece(aList[i],'^',2) + '^' + aSpecimen;
+            break;
+          end;
+      end;
+    uComponentSelected := true;
+    with lvSelectionList do
+      begin
+        ListItem := Items.Add;
+        ListItem.Caption := piece(cboAvailComp.Items[cboAvailComp.ItemIndex],'^',2);
+        ListItem.SubItems.Add(tQuantity.Text);
+        if length(cboModifiers.ItemID) > 0 then
+          begin
+            ListItem.SubItems.Add(cboModifiers.Items[cboModifiers.ItemIndex]);
+            ListItem.SubItems.Add(IntToStr(cboModifiers.ItemIndex));
+          end
+          else
+            begin
+              ListItem.SubItems.Add('');
+              ListItem.SubItems.Add('');
+            end;
+        ListItem.SubItems.Add(piece(cboAvailComp.Items[cboAvailComp.ItemIndex],'^',1));
+      end;
+      aStr := aTestYes + '^' + IntToStr(aLabTest.TestID) + '^' + tQuantity.Text + '^' + aModifier + '^' + aSpecimen + '^' + IntToStr(aLabTest.ItemID);  //aSpecimen has 2 pieces additional pieces added for Tests
+      uSelectedItems.Add(aStr);
+      CurAdd := 1;
       for i := 0 to uSelectedItems.Count - 1 do
-        if ItemID = piece(uSelectedItems[i],'^',1) then
+        begin
+          aName := lvSelectionList.Items[i].Caption;
+          x := uSelectedItems[i];
+          if piece(x,'^',1) = '1' then    //Diagnostic Test related fields
+            begin
+              if Length(piece(x,'^',2)) > 0 then Responses.Update('ORDERABLE', CurAdd, piece(x,'^',2), aName);
+            end
+          else
+            begin
+              if Length(piece(x,'^',2)) > 0 then Responses.Update('ORDERABLE', CurAdd, piece(x,'^',2), aName);
+              if Length(piece(x,'^',3)) > 0 then Responses.Update('QTY', CurAdd, piece(x,'^',3), piece(x,'^',3));
+              if Length(piece(x,'^',4)) > 0 then Responses.Update('MODIFIER', CurAdd, piece(x,'^',4), piece(x,'^',4));
+              if Length(piece(x,'^',5)) > 0 then Responses.Update('SPECSTS', CurAdd, pieces(x,'^',5,7), piece(x,'^',5));
+              if Length(cboSurgery.Text) > 0 then Responses.Update('MISC',1,cboSurgery.Text,cboSurgery.Text);
+              if Length(calWantTime.Text) > 0 then Responses.Update('DATETIME',1,ValidCollTime(calWantTime.Text),calWantTime.Text);
+              if Length(cboUrgency.Text) > 0 then Responses.Update('URGENCY',1,cboUrgency.ItemID,cboUrgency.Text)
+                else
+                  begin
+                    cboUrgency.ItemIndex := 1;
+                    Responses.Update('URGENCY',1,cboUrgency.ItemID,cboUrgency.Text);
+                  end;
+            end;
+          Inc(CurAdd);
+        end;
+      memOrder.Text := Responses.OrderText;
+  finally
+    alist.Free;
+    aTests.Free;
+  end;
+  aMsg := '';
+  LRORDERMODE := TORDER_MODE_INFO;
+  if uGetTnS = 1 then
+    begin
+      lblTNS.Caption := 'TYPE + SCREEN must be added to order';
+      lblTNS.Visible := true;
+      memMessage.Text := 'TYPE + SCREEN must be added to order';
+      pnlMessage.Visible := true;
+      pnlDiagnosticTests.Caption := 'Diagnostic Tests*';
+    end;
+  {if uGetTnS = 1 then
+    begin
+      if responses.QuickOrder < 1 then
+        begin
+          for i := 1 to cboAvailTest.Items.Count - 1 do
+            begin
+              if piece(cboAvailTest.Items[i],'^',1) = aTypeScreen then
+                begin
+                  if piece(aSpecimen,'^',1) = '1' then
+                    begin
+                      cboCollTime.Text := calWantTime.Text;
+                      aCollSave := cboCollTime.Text + '^' + cboCollTime.ItemID + '^' + cboCollType.Text + '^' + cboCollType.ItemID;
+                      cboCollTime.Text := '';
+                      cboCollType.Text := '';
+                      uSpecimen := 1;
+                    end;
+                  cboModifiers.Text := '';
+                  cboAvailTest.SelectByID(aTypeScreen);
+                  cboTests.SelectByID(aTypeScreen);
+                  cboTestsClick(self);
+                  //cboAvailTestSelect(Self);
+                  uSpecimen := 0;
+                  cboCollTime.Text := piece(aCollSave,'^',1);
+                  cboCollType.Text := piece(aCollSave,'^',3);
+                  aCollSave := '';
+                  break;
+                end;
+            end;
+          aMsg := 'An order for Type and Screen has been added to this request' + '.';
+        end
+        else
           begin
-            ShowMessage('This test has already been selected!');
-            Exit;
+            lblTNS.Caption := 'TYPE + SCREEN must be added to order';
+            lblTNS.Visible := true;
+            memMessage.Text := 'TYPE + SCREEN must be added to order';
+            memMessage.Visible := false;
+            pnlMessage.Visible := true;
           end;
-      FLastLabID := ItemID ;
-      FLastItemID := ItemID;
-      Changing := True;
-      if Sender <> Self then
-        Responses.Clear;       // Sender=Self when called from SetupDialog
-      if CharAt(ItemID, 1) = 'Q' then
-        with Responses do
-          begin
-            FLastItemID := ItemID;
-            QuickOrder := ExtractInteger(ItemID);
-            SetControl(cboAvailTest, 'ORDERABLE', 1);
-            if (Length(ItemID) = 0) or (ItemID = '0') then Exit;
-            FLastLabID := ItemID;
-          end;
-      ALabTest := TLabTest.Create(ItemID, Responses);
-    end;
-  with ALabTest do
-  begin
-
-    {with Responses do if QuickOrder > 0 then
-     begin
-      StatusText('Initializing Quick Order');
-      Changing := True;
-      SetControl(cboAvailTest,       'ORDERABLE', 1);
-      DetermineCollectionDefaults(Responses);
-      LoadUrgency(cboCollType.ItemID, cboUrgency);
-      SetControl(cboUrgency,         'URGENCY', 1);
-      Urgency := cboUrgency.ItemIEN;
-      if (Urgency = 0) and (cboUrgency.Items.Count = 1) then
-        begin
-          cboUrgency.ItemIndex := 0;
-          Urgency := cboUrgency.ItemIEN;
-        end;
-      tmpResp := FindResponseByName('SPECIMEN'  ,1);
-      i := 1 ;
-      tmpResp := Responses.FindResponseByName('COMMENT',i);
-      while tmpResp <> nil do
-        begin
-          Comment.Add(tmpResp.EValue);
-          Inc(i);
-          tmpResp := Responses.FindResponseByName('COMMENT',i);
-        end ;
-      end;  //  Quick Order}
-    if ObtainCollSamp then
-      begin
-        //For BloodBank orders, this condition should never occur
-      end
+      end;
+  if (uGetTnS = 1) then
+    begin
+      if length(aMsg) > 0 then aMsg := aMsg + crlf + crlf;
+      ShowMsg(aMsg);
+    end;  }
+  edtResults.Height := 247;
+  edtInfo.Height := 247;
+  if lvSelectionList.Items.Count > 0 then
+    begin
+      pnlSelectedTests.Visible := True;
+      cmdAccept.Visible := True;
+      memOrder.Visible := True;
+      GroupBox1.Visible := False;
+    end;
+  if tQuantity.CanFocus = true then tQuantity.SetFocus;
+end;
+
+procedure TfrmODBBank.DisableCommentPanels;
+begin
+  lblReqComment.Visible := False;
+end;
+
+procedure TfrmODBBank.DisableComponentControls;
+begin
+  lblQuantity.Enabled := false;
+  tQuantity.Enabled := false;
+  lblModifiers.Enabled := false;
+  cboModifiers.Enabled := false;
+  cboAvailComp.ItemIndex := -1;
+end;
+
+procedure TfrmODBBank.EnableComponentControls;
+begin
+  lblQuantity.Enabled := true;
+  tQuantity.Enabled := true;
+  lblModifiers.Enabled := true;
+  cboModifiers.Enabled := true;
+  if not(changing) then
+    if not(uSelUrgency = 'PRE-OP') then
+      if uSelUrgency = '' then
+        if lvSelectionList.Items.Count < 1 then
+          cboUrgency.SelectByID(IntToStr(uDfltUrgency));
+  if cboUrgency.Text = 'PRE-OP' then
+    begin
+      lblSurgery.Enabled := true;
+      cboSurgery.Enabled := true;
+      lblSurgery.Caption := 'Surgery*';
+    end
     else
       begin
-        with ALabTest do
-          with TCollSamp(CollSampList.Items[IndexOfCollSamp(CollSamp)]) do
-            begin
-              x := '' ;
-              for i := 0 to WardComment.Count-1 do
-                x := x + WardComment.strings[i]+#13#10 ;
-              pnlMessage.TabOrder := cboAvailTest.TabOrder + 1;
-              OrderMessage(x) ;
-            end ;
+        lblSurgery.Enabled := false;
+        cboSurgery.Enabled := false;
+        lblSurgery.Caption := 'Surgery';
       end;
-    if ObtainComment then
-      LoadRequiredComment(FCmtTypes.IndexOf(CurReqComment))
-    else
-      DisableCommentPanels;
-    x := '' ;
-    for i := 0 to CurWardComment.Count-1 do
-      x := x + CurWardComment.strings[i]+#13#10 ;
-    i :=  IndexOfCollSamp(CollSamp);
-    if i > -1 then with TCollSamp(CollSampList.Items[IndexOfCollSamp(CollSamp)]) do
-       for i := 0 to WardComment.Count-1 do
-         x := x + WardComment.strings[i]+#13#10 ;
-    pnlMessage.TabOrder := cboAvailTest.TabOrder + 1;
-    OrderMessage(x) ;
-   end; { with }
-  StatusText('');
-  Changing := False;
-end;
-
-procedure TfrmODBBank.cboAvailCompSelect(Sender: TObject);
-var
-  x: string;
-  i: integer;
-begin
-  DisableDiagTestControls;
-  EnableComponentControls;
-  LRORDERMODE := TORDER_MODE_COMP;
-  with cboAvailComp do
-    begin
-      if (Length(ItemID) = 0) or (ItemID = '0') then Exit;
-      for i := 0 to uSelectedItems.Count - 1 do
-        if ItemID = piece(uSelectedItems[i],'^',1) then
-          begin
-            ShowMessage('This component has already been selected!');
-            Exit;
-          end;
-      FLastLabID := ItemID ;
-      FLastItemID := ItemID;
-      Changing := True;
-      if Sender <> Self then
-        Responses.Clear;       // Sender=Self when called from SetupDialog
-      if CharAt(ItemID, 1) = 'Q' then
-        with Responses do
-          begin
-            FLastItemID := ItemID;
-            QuickOrder := ExtractInteger(ItemID);
-            SetControl(cboAvailComp, 'ORDERABLE', 1);
-            if (Length(ItemID) = 0) or (ItemID = '0') then Exit;
-            FLastLabID := ItemID;
-          end;
-      ALabTest := TLabTest.Create(ItemID, Responses);
-    end;
-  with ALabTest do
-  begin
-
-    {with Responses do if QuickOrder > 0 then
-     begin
-      StatusText('Initializing Quick Order');
-      Changing := True;
-      SetControl(cboAvailTest,       'ORDERABLE', 1);
-      DetermineCollectionDefaults(Responses);
-      LoadUrgency(cboCollType.ItemID, cboUrgency);
-      SetControl(cboUrgency,         'URGENCY', 1);
-      Urgency := cboUrgency.ItemIEN;
-      if (Urgency = 0) and (cboUrgency.Items.Count = 1) then
-        begin
-          cboUrgency.ItemIndex := 0;
-          Urgency := cboUrgency.ItemIEN;
-        end;
-      tmpResp := FindResponseByName('SPECIMEN'  ,1);
-      i := 1 ;
-      tmpResp := Responses.FindResponseByName('COMMENT',i);
-      while tmpResp <> nil do
-        begin
-          Comment.Add(tmpResp.EValue);
-          Inc(i);
-          tmpResp := Responses.FindResponseByName('COMMENT',i);
-        end ;
-      end;  //  Quick Order}
-    {if ObtainCollSamp then
-      begin
-        // should not occur with Blood orders
-      end
-    else
-      begin
-        with ALabTest do
-          with TCollSamp(CollSampList.Items[IndexOfCollSamp(CollSamp)]) do
-            begin
-              x := '' ;
-              for i := 0 to WardComment.Count-1 do
-                x := x + WardComment.strings[i]+#13#10 ;
-              pnlMessage.TabOrder := cboAvailTest.TabOrder + 1;
-              OrderMessage(x) ;
-            end ;
-      end;
-     }
-    if ObtainComment then
-      LoadRequiredComment(FCmtTypes.IndexOf(CurReqComment))
-    else
-      DisableCommentPanels;
-    x := '' ;
-    for i := 0 to CurWardComment.Count-1 do
-      x := x + CurWardComment.strings[i]+#13#10 ;
-    i :=  IndexOfCollSamp(CollSamp);
-    if i > -1 then with TCollSamp(CollSampList.Items[IndexOfCollSamp(CollSamp)]) do
-       for i := 0 to WardComment.Count-1 do
-         x := x + WardComment.strings[i]+#13#10 ;
-    pnlMessage.TabOrder := cboAvailComp.TabOrder + 1;
-    OrderMessage(x) ;
-   end; { with }
-  StatusText('');
-  Changing := False;
-end;
-
-procedure TfrmODBBank.DisableCommentPanels;
-begin
-  lblReqComment.Visible := False;
-end;
-
-procedure TfrmODBBank.DisableComponentControls;
-begin
-  lblModifiers.Enabled := false;
-  cboModifiers.Enabled := false;
-  lblWanted.Enabled := false;
-  calWantTime.Enabled := false;
-  //lblPreparation.Enabled := false;
-  //cboPreparation.Enabled := false;
-  lblSurgery.Enabled := false;
-  cboSurgery.Enabled := false;
-  lblReason.Enabled := false;
-  tReason.Enabled := false;
-  chkConsent.Enabled := false;
-  lblQuantity.Enabled := false;
-  tQuantity.Enabled := false;
-  upQuantity.Enabled := false;
-  cboAvailComp.ItemIndex := -1;
-  tQuantity.Text := '0';
-end;
-
-procedure TfrmODBBank.EnableComponentControls;
-begin
-  lblModifiers.Enabled := true;
-  cboModifiers.Enabled := true;
-  lblWanted.Enabled := true;
-  calWantTime.Enabled := true;
-  //lblPreparation.Enabled := true;
-  //cboPreparation.Enabled := true;
-  if cboUrgency.Text = 'PRE-OP' then
-    begin
-      lblSurgery.Enabled := true;
-      cboSurgery.Enabled := true;
-    end;
-  lblReason.Enabled := true;
-  tReason.Enabled := true;
-  chkConsent.Enabled := true;
-  lblQuantity.Enabled := true;
-  tQuantity.Enabled := true;
-  upQuantity.Enabled := true;
-  txtDiagComment.Enabled := true;
   lblDiagComment.Enabled := true;
 end;
@@ -1515,14 +2938,13 @@
   calCollTime.Enabled := false;
   cboCollTime.Enabled := false;
-  cboAvailTest.ItemIndex := -1;
   lblCollType.Enabled := false;
   cboCollType.Enabled := false;
   cmdImmedColl.Enabled := false;
+  cboAvailTest.ItemIndex := -1;
+  cboAvailTest.InitLongList('');
 end;
 
 procedure TfrmODBBank.EnableDiagTestControls;
 begin
-  calWantTime.Enabled := true;
-  lblWanted.Enabled := true;
   lblCollTime.Enabled := true;
   calCollTime.Enabled := true;
@@ -1530,9 +2952,10 @@
   lblCollType.Enabled := true;
   cboCollType.Enabled := true;
-  lblUrgency.Enabled := true;
-  cboUrgency.Enabled := true;
-  txtDiagComment.Enabled := true;
-  lblDiagComment.Enabled := true;
   cmdImmedColl.Enabled := true;
+  if not(changing) then
+    if not(uSelUrgency = 'PRE-OP') then
+      if uSelUrgency = '' then
+        if lvSelectionList.Items.Count < 1 then
+          cboUrgency.SelectByID(IntToStr(uDfltUrgency));
 end;
 
@@ -1548,4 +2971,5 @@
 begin
   if ALabTest = nil then exit;
+  if ALabTest.LabSubscript = 'BB' then exit;
   calCollTime.Clear;
   cboCollTime.Clear;
@@ -1618,4 +3042,11 @@
 end;
 
+procedure TfrmODBBank.cboAvailCompChange(Sender: TObject);
+begin
+  inherited;
+  changing := true;
+  changing := false;
+end;
+
 procedure TfrmODBBank.cboAvailCompExit(Sender: TObject);
 begin
@@ -1662,441 +3093,59 @@
   inherited;
   case pgeProduct.TabIndex of
-  TI_ORDER :     begin
-                  memMessage.Visible := true;
+  TI_COMPONENT :     begin
                   memOrder.Visible := true;
                   cmdAccept.Visible := true;
                   pnlSelectedTests.Visible := true;
-                  pgeProduct.Height := 281;
+                  lvSelectionList.Width := lvSelectionList.Width + 1; //added to fix font resize issue - funky column display
                 end;
   TI_INFO :     begin
-                  if lvSelectionList.Items.Count > 0 then exit;
-                  LRORDERMODE := TORDER_MODE_INFO;
-                  memMessage.Visible := false;
-                  memOrder.Visible := false;
-                  cmdAccept.Visible := false;
-                  pnlSelectedTests.Visible := false;
-                  pgeProduct.Height := 411;
+                  if lvSelectionList.Items.Count > 0 then
+                  begin
+                    memOrder.Visible := true;
+                    cmdAccept.Visible := true;
+                    pnlSelectedTests.Visible := true;
+                  end
+                  else
+                  begin
+                    memOrder.Visible := false;
+                    cmdAccept.Visible := false;
+                    pnlSelectedTests.Visible := false;
+                  end;
                 end;
   TI_RESULTS :  begin
-                  if lvSelectionList.Items.Count > 0 then exit;
-                  memMessage.Visible := false;
-                  memOrder.Visible := false;
-                  cmdAccept.Visible := false;
-                  pnlSelectedTests.Visible := false;
-                  pgeProduct.Height := 411;
+                  if lvSelectionList.Items.Count > 0 then
+                  begin
+                    memOrder.Visible := true;
+                    cmdAccept.Visible := true;
+                    pnlSelectedTests.Visible := true;
+                  end
+                  else
+                  begin
+                    memOrder.Visible := false;
+                    cmdAccept.Visible := false;
+                    pnlSelectedTests.Visible := false;
+                  end;
                 end;
   end; {case}
 end;
 
-procedure TfrmODBBank.cboCollTypeChange(Sender: TObject);
-begin
-  if (ALabTest = nil) or Changing or (cboCollType.ItemID = '') then exit;
-  if (cboCollType.ItemID = 'I') and (not ALabTest.LabCanCollect) then
-    begin
-      InfoBox(TX_NO_IMMED, TX_NO_IMMED_CAP, MB_OK or MB_ICONWARNING);
-      cboCollType.ItemIndex := -1;
-      Exit;
-    end;
-  SetupCollTimes(cboCollType.ItemID);
-end;
-
-procedure TfrmODBBank.LoadModifiers(AComboBox:TORComboBox);
+procedure TfrmODBBank.cboCollTimeChange(Sender: TObject);
 var
-  i: integer;
-begin
-  with AComboBox do
-    begin
-      Clear;
-      for i := 0 to uModifierList.Count - 1 do
-           Items.Add(uModifierList[i]);
-    end;
-end;
-
-procedure TfrmODBBank.LoadUrgencies(AComboBox:TORComboBox);
-var
-  i: integer;
-begin
-  with AComboBox do
-    begin
-      Clear;
-      for i := 0 to uUrgencyList.Count - 1 do
-         if (piece(uUrgencyList[i],'^',2) = 'STAT') and (StatAllowed(Patient.DFN) = false) then
-           Continue
-         else
-           Items.Add(uUrgencyList[i]);
-    end;
-end;
-
-procedure TfrmODBBank.btnAddTestsClick(Sender: TObject);
-var
-  aList, aTests, aRaw: TStringList;
-  ListItem: TListItem;
-  aStr, aMsg: String;                  //add independent structures for components, Tests, and associated fields.
-  aCollType, aModifier, aPreparation, aSurgery, aCollTime, aTestYes, aSpecimen, aCollSave: String;
-  CurAdd, i, j, k, getTest, TestAdded, aMSBOS, aMSBOSContinue: Integer;
-  x, name, aTypeScreen: String;
-begin
-  if not ValidAdd then Exit;
-  aList := TStringList.Create;
-  aTests := TStringList.Create;
-  aRaw := TStringList.Create;
-  try
-    aCollType := '';
-    aModifier := '';
-    aPreparation := '';
-    aSurgery := '';
-    aCollTime := '';
-    aTestYes := '0';
-    aTypeScreen := '';
-    uGetTnS := 0;
-    aSpecimen := '';
-    ExtractTypeScreen(aList, uVBECList);
-    if aList.Count > 0 then aTypeScreen := aList[0];
-    aList.Clear;
-    ExtractSpecimen(aList, uVBECList);
-    if aList.Count > 0 then aSpecimen := aList[0];
-    if LRORDERMODE = TORDER_MODE_DIAG then aTestYes := '1';
-    if length(cboModifiers.ItemID) > 0 then aModifier := cboModifiers.Items[cboModifiers.ItemIndex];
-    //if length(cboPreparation.ItemID) > 0 then aPreparation := cboPreparation.Items[cboPreparation.ItemIndex];
-    if length(cboSurgery.ItemID) > 0 then aSurgery := cboSurgery.Items[cboSurgery.ItemIndex];
-    if length(cboCollTime.ItemID) > 0 then aCollTime := cboCollTime.Items[cboCollTime.ItemIndex];
-    if (LRORDERMODE = TORDER_MODE_DIAG) and (length(cboAvailTest.ItemID) > 0) then
-      begin
-        uTestSelected := true;
-        with lvSelectionList do
-          begin
-            ListItem := Items.Add;
-            ListItem.Caption := piece(cboAvailTest.Items[cboAvailTest.ItemIndex],'^',2);
-            ListItem.SubItems.Add('');
-            if length(cboModifiers.ItemID) > 0 then ListItem.SubItems.Add(cboModifiers.Items[cboModifiers.ItemIndex])
-              else ListItem.SubItems.Add('');
-            ListItem.SubItems.Add(piece(cboAvailTest.Items[cboAvailTest.ItemIndex],'^',1));
-            if piece(cboAvailTest.Items[cboAvailTest.ItemIndex],'^',1) = aTypeScreen then
-              begin
-                lblTNS.Caption := '';
-                lblTNS.Visible := false;
-              end;
-          end;
-        lblCollTime.Enabled := false;
-        calCollTime.Enabled := false;
-        cboCollTime.Enabled := false;
-        lblCollType.Enabled := false;
-        cboCollType.Enabled := false;
-        cboAvailTest.ItemIndex := -1;
-      end;
-    if (LRORDERMODE = TORDER_MODE_COMP) and (length(cboAvailComp.ItemID) > 0) then
-      begin
-        if Length(cboSurgery.ItemID) > 0 then
-          begin
-            aList.Clear;
-            ExtractMSBOS(aList, uVBECList);    //Get maximum units for selected Surgey
-            for i := 0 to aList.Count - 1 do
-              begin
-                if (StrToInt(piece(aList[i],'^',1)) = aLabTest.ItemID)
-                 and (StrToInt(piece(aList[i],'^',2)) = cboSurgery.ItemID) then
-                  begin
-                    aMSBOS := StrToInt(piece(aList[i],'^',4));
-                    if (aMSBOS > 0) and (StrToInt(tQuantity.Text) > aMSBOS) then
-                      begin
-                        with Application do
-                        begin
-                          NormalizeTopMosts;
-                          aMSBOSContinue :=
-                            MessageBox(PChar('The number of units ordered (' + tQuantity.Text +
-                                       ') exceeds the maximum number of units (' + IntToStr(aMSBOS) +
-                                       ') for the ' + cboSurgery.text +
-                                       ' surgical procedure selected.' + CRLF + CRLF + 'Do you wish to continue?'),
-                                       PChar('Maximum Number of Units Exceeded'),
-                                       MB_YESNO);
-                          RestoreTopMosts;
-                        end;
-                        if aMSBOSContinue = 7 then
-                          begin
-                            ShowMessage(cboAvailComp.Text + ' has NOT been added to this request.');
-                            exit;
-                          end;
-                      end;
-                  end;
-              end;
-          end;
-        if SpecimenNeeded(aList, uVBECList, aLabTest.ItemID) then  //check to see if type and screen is needed
-          begin
-            uGetTnS := 1;
-            for i := 0 to lvSelectionList.Items.Count - 1 do
-              begin
-                if lvSelectionList.Items[i].SubItems[2] = aTypeScreen then
-                  begin
-                    uGetTnS := 0;
-                    uDfltUrgency := cboUrgency.ItemID;
-                    lblTNS.Caption := '';
-                    lblTNS.Visible := false;
-                    break;
-                  end;
-              end;
-          end;
-        aList.Clear;
-        ExtractSpecimens(aList, uVBECList);    //Get specimen values to pass back to Server
-        for i := 0 to aList.Count - 1 do
-          begin
-            if (StrToInt(piece(aList[i],'^',1)) = aLabTest.ItemID) then
-              begin
-                aSpecimen := piece(aList[i],'^',2) + '^' + aSpecimen;
-                break;
-              end;
-          end;
-        uComponentSelected := true;
-        with lvSelectionList do
-          begin
-            ListItem := Items.Add;
-            ListItem.Caption := piece(cboAvailComp.Items[cboAvailComp.ItemIndex],'^',2);
-            ListItem.SubItems.Add(tQuantity.Text);
-            if length(cboModifiers.ItemID) > 0 then ListItem.SubItems.Add(cboModifiers.Items[cboModifiers.ItemIndex])
-              else ListItem.SubItems.Add('');
-            ListItem.SubItems.Add(piece(cboAvailComp.Items[cboAvailComp.ItemIndex],'^',1));
-          end;
-        lblWanted.Enabled := false;
-        calWantTime.Enabled := false;
-        //lblPreparation.Enabled := false;
-        //cboPreparation.Enabled := false;
-        lblSurgery.Enabled := false;
-        cboSurgery.Enabled := false;
-        lblReason.Enabled := false;
-        tReason.Enabled := false;
-        chkConsent.Enabled := false;
-        cboAvailComp.ItemIndex := -1;
-      end;
-    if Sender <> Self then
-      Responses.Clear;       // Sender=Self when called from SELF
-    CurAdd := 1;
-    aStr := aTestYes + '^' + IntToStr(aLabTest.TestID) + '^' + tQuantity.Text + '^' + aModifier + '^' + aSpecimen;  //aSpecimen has 2 pieces
-    uSelectedItems.Add(aStr);
-    for i := 0 to uSelectedItems.Count - 1 do
-      begin
-        name := lvSelectionList.Items[i].Caption;
-        x := uSelectedItems[i];
-        if piece(x,'^',1) = '1' then    //Diagnostic Test related fields
-          begin
-            if Length(piece(x,'^',2)) > 0 then Responses.Update('ORDERABLE', CurAdd, piece(x,'^',2), name);
-          end
-        else
-          begin
-            if Length(piece(x,'^',2)) > 0 then Responses.Update('ORDERABLE', CurAdd, piece(x,'^',2), name);
-            if Length(piece(x,'^',3)) > 0 then Responses.Update('QTY', CurAdd, piece(x,'^',3), piece(x,'^',3));
-            if Length(piece(x,'^',4)) > 0 then Responses.Update('MODIFIER', CurAdd, piece(x,'^',4), aModifier);
-            if Length(piece(x,'^',5)) > 0 then Responses.Update('SPECSTS', CurAdd, pieces(x,'^',5,7), piece(x,'^',5));
-            if Length(cboSurgery.Text) > 0 then Responses.Update('MISC',1,cboSurgery.Text,cboSurgery.Text);
-          end;
-        Inc(CurAdd);
-        aList.Clear;
-        TestAdded := 0;
-        getTest := 0;
-        ExtractTests(aList, uVBECList);   //Get Results associated with ordered components
-        for j := 0 to aList.Count - 1 do
-          begin
-            if StrToInt(piece(aList[j],'^',1)) = aLabTest.ItemID then
-              begin
-                if uTestsForResults.Count < 1 then getTest := 1;
-                for k := 0 to uTestsForResults.Count - 1 do
-                  begin
-                    if piece(uTestsForResults[k],'^',1) = piece(aList[j],'^',3) then
-                      begin
-                        getTest := 0;
-                        break;
-                      end
-                    else getTest := 1;
-                  end;
-                if getTest = 1 then
-                  begin
-                    uTestsForResults.Add(piece(aList[j],'^',3));
-                    TestAdded := 1;
-                  end;
-              end;
-          end;
-        if TestAdded = 1 then
-          begin
-            edtResults.Clear;
-            aTests.Clear;
-            GetPatientBloodResults(aTests, Patient.DFN, uTestsForResults);
-            QuickCopy(ATests,edtResults);
-            if edtResults.Lines.Count > 0 then TabResults.ImageIndex := 1;
-            uRaw.Clear;
-            GetPatientBloodResultsRaw(uRaw, Patient.DFN, uTestsForResults);
-          end;
-      end;
-    if LRORDERMODE = TORDER_MODE_DIAG then
-      begin
-        if Length(calWantTime.Text) > 0 then Responses.Update('DATETIME',1,ValidCollTime(calWantTime.Text),calWantTime.Text);
-        with cboCollType do if Length(ItemID) > 0 then
-          begin
-            Responses.Update('COLLECT', 1, ItemID, ItemID) ;
-            FLastCollType := ItemID;
-          end;
-        if Length(cboUrgency.Text) > 0 then Responses.Update('URGENCY',1,cboUrgency.ItemID,cboUrgency.Text);
-        if Length(txtDiagComment.Text) > 0 then Responses.Update('COMMENT',1,txtDiagComment.Text,txtDiagComment.Text);
-        if cboCollType.ItemID = 'LC' then
-          begin
-            with cboCollTime do
-              if Length(ItemID) > 0 then
-                begin
-                  Responses.Update('START', 1, Copy(ItemID, 2, 999), Copy(ItemID, 2, 999));
-                  FLastLabCollTime := ItemID + U + Text;
-                end
-              else if Length(Text) > 0 then
-                begin
-                  Responses.Update('START', 1, ValidCollTime(Text), Text) ;
-                  FLastLabCollTime := ValidCollTime(Text);
-                end;
-          end
-        else
-          begin
-            with calCollTime do
-              if FMDateTime > 0 then
-                begin
-                  Responses.Update('START', 1, ValidCollTime(Text), Text);
-                  FLastColltime := ValidCollTime(Text);
-                end
-              else
-                begin
-                  Responses.Update('START', 1, '', '') ;
-                  FLastCollTime := '';
-                end;
-          end;
-      end;
-    if LRORDERMODE = TORDER_MODE_COMP then
-      begin
-        if Length(cboUrgency.Text) > 0 then Responses.Update('URGENCY',1,cboUrgency.ItemID,cboUrgency.Text);
-        if Length(txtDiagComment.Text) > 0 then Responses.Update('COMMENT',1,txtDiagComment.Text,txtDiagComment.Text);
-        if Length(calWantTime.Text) > 0 then Responses.Update('DATETIME',1,ValidCollTime(calWantTime.Text),calWantTime.Text);
-        //if Length(cboPreparation.Text) > 0 then Responses.Update('XFUSION',1,cboPreparation.ItemID,cboPreparation.Text);
-        if Length(cboSurgery.Text) > 0 then Responses.Update('MISC',1,cboSurgery.Text,cboSurgery.Text);
-        if Length(tReason.Text) > 0 then Responses.Update('REASON',1,tReason.Text,tReason.Text);
-        if chkConsent.Checked = true then Responses.Update('YN',1,'1','Yes');
-      end;
-    memOrder.Text := Responses.OrderText;
-    CurAdd := 1;
-    if uRaw.Count > 0 then
-      for j := 0 to uRaw.Count - 1 do
+  CollType: string;
+const
+  TX_BAD_TIME         = ' is not a routine lab collection time.' ;
+  TX_BAD_TIME_CAP     = 'Invalid Time';
+begin
+  CollType := 'LC';
+  with cboCollTime do
+    begin
+      if ItemID = 'LO' then
         begin
-          if Length(uRaw[j]) > 0 then Responses.Update('RESULTS', CurAdd, uRaw[j], piece(uRaw[j],'^',1));
-          Inc(CurAdd);
+          ItemIndex := -1;
+          Text := GetFutureLabTime(FMToday);
         end;
-    tQuantity.Text := '0';
-    ALabTest := nil;
-  finally
-    aList.Free;
-    aTests.Free;
-    aRaw.Free;
-  end;
-  aMsg := '';
-  if UgetTnS = 1 then
-    begin
-      lblTNS.Caption := 'TYPE + SCREEN must be added to order';
-      lblTNS.Visible := true;
-      cboAvailTest.SelectByID(aTypeScreen);
-      cboAvailTestSelect(self);
-    end;
-  {if getTnS = 1 then
-    begin
-      for i := 1 to cboAvailTest.Items.Count - 1 do
-        begin
-          if piece(cboAvailTest.Items[i],'^',1) = aTypeScreen then
-            begin
-              if piece(aSpecimen,'^',1) = '1' then
-                begin
-                  cboCollTime.Text := calWantTime.Text;
-                  aCollSave := cboCollTime.Text + '^' + cboCollTime.ItemID + '^' + cboCollType.Text + '^' + cboCollType.ItemID;
-                  cboCollTime.Text := '';
-                  cboCollType.Text := '';
-                  uSpecimen := 1;
-                end;
-              cboModifiers.Text := '';
-              cboAvailTest.SelectByID(aTypeScreen);
-              cboAvailTestSelect(Self);
-              btnAddTestsClick(Self);
-              uSpecimen := 0;
-              cboCollTime.Text := piece(aCollSave,'^',1);
-              cboCollType.Text := piece(aCollSave,'^',3);
-              aCollSave := '';
-              break;
-            end;
-        end;
-      aMsg := 'An order for Type and Screen has been added to this request' + '.';
-    end;
-  if (getTns = 1) then
-    begin
-      if length(aMsg) > 0 then aMsg := aMsg + crlf + crlf;
-      ShowMessage(aMsg);
-    end;}
-  cboModifiers.Text := '';
-  edtResults.Height := 247;
-  edtInfo.Height := 247;
-end;
-
-procedure TfrmODBBank.FormDestroy(Sender: TObject);
-begin
-  inherited;
-  uSelectedItems.Free;
-  uVBECList.Free;
-  uTestsForResults.Free;
-  uUrgencyList.Free;
-  uModifierList.Free;
-  uRaw.Free;
-end;
-
-procedure TfrmODBBank.btnRemoveClick(Sender: TObject);
-var
-  i,j,curAdd: integer;
-  x, name, aModifier, aTypeScreen: string;
-  aList: TStringList;
-begin
-  inherited;
-  aList := TStringList.Create;
-  curAdd := 1;
-  aModifier := '';
-  aTypeScreen := '';
-  ExtractTypeScreen(aList, uVBECList);
-  if aList.Count > 0 then aTypeScreen := aList[0];
-  aList.Clear;
-  if length(cboModifiers.ItemID) > 0 then aModifier := cboModifiers.Items[cboModifiers.ItemIndex];
-  with lvSelectionList do
-    begin
-      for i := lvSelectionList.Items.Count - 1 downto 0 do
-        begin
-          if lvSelectionList.Items[i].Selected = true then
-            for j := uSelectedItems.Count - 1 downto 0 do
-            if lvSelectionList.Items[i].SubItems[2] = piece(uSelectedItems[j],'^',2) then
-              begin
-                if lvSelectionList.Items[i].SubItems[2] = aTypeScreen then
-                  begin
-                    uGetTnS := 1;
-                    lblTNS.Caption := 'TYPE+SCREEN must be added to order';
-                    lblTNS.Visible := true;
-                  end;
-                uSelectedItems.Delete(j);
-                lvSelectionList.Items[i].Delete;
-                break;
-              end;
-        end;
-    end;
-  Responses.Clear;
-  for i := 0 to uSelectedItems.Count - 1 do
-    begin
-      name := lvSelectionList.Items[i].Caption;
-      x := uSelectedItems[i];
-      if piece(x,'^',1) = '1' then    //Diagnostic Test related fields
-        begin
-          if Length(piece(x,'^',2)) > 0 then Responses.Update('ORDERABLE', CurAdd, piece(x,'^',2), name);
-        end
-      else
-        begin
-          if Length(piece(x,'^',2)) > 0 then Responses.Update('ORDERABLE', CurAdd, piece(x,'^',2), name);
-          if Length(piece(x,'^',3)) > 0 then Responses.Update('QTY', CurAdd, piece(x,'^',3), piece(x,'^',3));
-          if Length(piece(x,'^',4)) > 0 then Responses.Update('MODIFIER', CurAdd, piece(x,'^',4), aModifier);
-          if Length(piece(x,'^',5)) > 0 then Responses.Update('SPECSTS', CurAdd, pieces(x,'^',5,7), piece(x,'^',5));
-        end;
-      Inc(CurAdd);
-    end;
-  if Length(calWantTime.Text) > 0 then Responses.Update('DATETIME',1,ValidCollTime(calWantTime.Text),calWantTime.Text);
-  if cboCollType.ItemID = 'LC' then
+    end;
+  cboCollType.SelectByID(CollType);
+  if uSelectedItems.Count > 0 then
     begin
       with cboCollTime do
@@ -2111,45 +3160,394 @@
             FLastLabCollTime := ValidCollTime(Text);
           end;
+    end;
+end;
+
+procedure TfrmODBBank.cboCollTypeChange(Sender: TObject);
+begin
+  if (ALabTest = nil) or Changing or (cboCollType.ItemID = '') then exit;
+  if (cboCollType.ItemID = 'I') and (not ALabTest.LabCanCollect) then
+    begin
+      InfoBox(TX_NO_IMMED, TX_NO_IMMED_CAP, MB_OK or MB_ICONWARNING);
+      cboCollType.ItemIndex := -1;
+      Exit;
+    end;
+  if cboCollType.ItemID = 'I' then
+  begin
+    cboCollTime.ItemIndex := -1;
+    cboCollTime.Text := 'NOW';
+    calCollTime.Text := 'NOW';
+  end;
+  SetupCollTimes(cboCollType.ItemID);
+  if Length(cboCollType.Text) > 0 then Responses.Update('COLLECT',1,cboCollType.ItemID,cboCollType.ItemID);
+  FLastCollType := cboCollType.ItemID;
+  calCollTimeChange(self);
+end;
+
+procedure TfrmODBBank.cboModifiersChange(Sender: TObject);
+var
+  i: integer;
+  ListItem: TListItem;
+  x,q,m: string;
+begin
+  inherited;
+  if changing = true then Exit;
+  if (cboAvailComp.ItemIndex <> -1) and (uSelectedItems.Count > 0) then
+    begin
+      for i := 0 to lvSelectionList.Items.Count - 1 do
+        begin
+          x := uSelectedItems[i];
+          m := piece(x,'^',4);
+          q := piece(x,'^',3);
+          if lvSelectionList.Items[i].Caption = piece(cboAvailComp.Items[cboAvailComp.ItemIndex],'^',2) then
+            begin
+              ListItem := lvSelectionList.Items[i];
+              ListItem.SubItems.Clear;
+              ListItem.SubItems.Add(q);
+              if length(cboModifiers.ItemID) > 0 then
+                begin
+                  ListItem.SubItems.Add(cboModifiers.Items[cboModifiers.ItemIndex]);
+                  ListItem.SubItems.Add(IntToStr(cboModifiers.ItemIndex));
+                end
+                else
+                  begin
+                    ListItem.SubItems.Add('');
+                    ListItem.SubItems.Add('');
+                  end;
+              ListItem.SubItems.Add(piece(cboAvailComp.Items[cboAvailComp.ItemIndex],'^',1));
+              Responses.Update('MODIFIER', (i+1), cboModifiers.Text, cboModifiers.Text);
+              Break;
+            end;
+        end;
+    end;
+  if Length(cboModifiers.Text) > 0 then
+    begin
+      memOrder.Text := Responses.OrderText;
+    end;
+end;
+
+procedure TfrmODBBank.LoadModifiers(AComboBox:TORComboBox);
+var
+  i: integer;
+begin
+  with AComboBox do
+    begin
+      Clear;
+      for i := 0 to uModifierList.Count - 1 do
+           Items.Add(uModifierList[i]);
+    end;
+end;
+
+procedure TfrmODBBank.LoadReasons(AComboBox:TORComboBox);
+var
+  i: integer;
+begin
+  with AComboBox do
+    begin
+      Clear;
+      for i := 0 to uReasonsList.Count - 1 do
+           Items.Add(uReasonsList[i]);
+    end;
+end;
+
+procedure TfrmODBBank.LoadUrgencies(AComboBox:TORComboBox);
+var
+  i: integer;
+begin
+  with AComboBox do
+    begin
+      Clear;
+      for i := 0 to uUrgencyList.Count - 1 do
+         if (piece(uUrgencyList[i],'^',2) = 'STAT') and (StatAllowed(Patient.DFN) = false) then
+           Continue
+         else
+           Items.Add(uUrgencyList[i]);
+    end;
+end;
+
+procedure TfrmODBBank.lvSelectionListClick(Sender: TObject);
+var
+  ListItem: TListItem;
+  x,y: string;
+  i,j: integer;
+begin
+  inherited;
+  if lvSelectionList.Selected = nil then Exit;
+  ListItem := lvSelectionList.Selected;
+  changing := true;
+  tQuantity.Text := '';
+  cboModifiers.ItemIndex := -1;
+  i := lvSelectionList.ItemIndex;
+  j := 0;
+  if cboCollType.ItemID = 'LC' then
+    begin
+      if FLastLabCollTime <> '' then
+        cboCollTime.SelectByID(piece(FLastLabCollTime,'^',1));
     end
   else
     begin
-      with calCollTime do
-        if FMDateTime > 0 then
+      if FLastCollTime = 'TODAY' then
+        calCollTime.Text := FLastCollTime
+      else if FLastCollTime = 'NOW' then
+        calCollTime.Text := FLastCollTime
+      else if FLastCollTime <> '' then
+        calCollTime.Text := FormatFMDateTime('mmm dd,yyyy@hh:nn',StrToFMDateTime(FLastCollTime));
+    end;
+  if FLastCollType <> '' then
+    cboCollType.SelectByID(FLastCollType);
+  if uSelectedItems.Count > 0 then
+    begin
+      x := uSelectedItems[i];
+      ALabTest := TLabTest.Create(piece(uSelectedItems[i],'^',2), Responses);
+      if not(piece(x,'^',2) = '') then j := StrToInt(piece(x,'^',2));
+      if not(piece(x,'^',1) = '1') and (j > 0) then //Components
+        begin
+          DisableDiagTestControls;
+          EnableComponentControls;
+          y := ListItem.SubItems[2];
+          changing := true;
+          cboModifiers.Text := '';
+          cboAvailComp.SelectByIEN(j);
+          tQuantity.Text := ListItem.SubItems[0];
+          changing := false;
+          if y <> '' then cboModifiers.ItemIndex := StrToInt(y);
+        end
+      else                            //Diagnostic Tests
+        begin
+          DisableComponentControls;
+          EnableDiagTestControls;
+          cboAvailTest.SelectByIEN(j);
+        end;
+    end;
+  changing := false;
+end;
+
+procedure TfrmODBBank.memDiagCommentChange(Sender: TObject);
+begin
+  inherited;
+  if (length(memDiagComment.Text) > 250) then
+    begin
+      ShowMsg('COMMENT cannot be longer than 250 characters');
+      memDiagComment.Text := Copy(memDiagComment.Text,0,250);
+      Exit;
+    end;
+  if lvSelectionList.Items.Count < 1 then Exit;
+
+  if uSelectedItems = nil then Exit;
+  
+  if uSelectedItems.Count > 0 then
+    Responses.Update('COMMENT',1,memDiagComment.Text,memDiagComment.Text);
+  memOrder.Text := Responses.OrderText;
+end;
+
+procedure TfrmODBBank.FormDestroy(Sender: TObject);
+begin
+  inherited;
+  uSelectedItems.Free;
+  uVBECList.Free;
+  uTestsForResults.Free;
+  uUrgencyList.Free;
+  uTNSOrders.Free;
+  uModifierList.Free;
+  uReasonsList.Free;
+  uRaw.Free;
+end;
+
+procedure TfrmODBBank.btnRemoveClick(Sender: TObject);
+var
+  i,j,curAdd: integer;
+  x, aName, aModifier, aReason, aTypeScreen: string;
+  aList: TStringList;
+  aSel, aSelTst : boolean;
+begin
+  inherited;
+  aList := TStringList.Create;
+  try
+    curAdd := 1;
+    aModifier := '';
+    aReason := '';
+    aTypeScreen := '';
+    aSel := false;
+    aSelTst := false;
+    ExtractTypeScreen(aList, uVBECList);
+    if aList.Count > 0 then aTypeScreen := aList[0];
+    aList.Clear;
+    if length(cboModifiers.ItemID) > 0 then aModifier := cboModifiers.Items[cboModifiers.ItemIndex];
+    if length(cboReasons.ItemID) > 0 then aReason := cboReasons.Items[cboReasons.ItemIndex];
+    if lvSelectionList.Items.Count < 1 then
+      begin
+        ShowMsg('There is nothing in the list to remove.');
+        exit;
+      end;
+    cboAvailComp.ItemIndex := -1;
+    tQuantity.Text := '';
+    cboAvailTest.ItemIndex := -1;
+    uGetTnS := 0;
+    lblTNS.Caption := '';
+    lblTNS.Visible := false;
+    memMessage.Text := '';
+    pnlMessage.Visible := false;
+    pnlDiagnosticTests.Caption := 'Diagnostic Tests';
+    with lvSelectionList do
+      begin
+        for i := lvSelectionList.Items.Count - 1 downto 0 do
           begin
-            Responses.Update('START', 1, ValidCollTime(Text), Text);
-            FLastColltime := ValidCollTime(Text);
+            if lvSelectionList.Items[i].Selected = true then
+              begin
+                aSel := true;
+                for j := uSelectedItems.Count - 1 downto 0 do
+                  if lvSelectionList.Items[i].SubItems[3] = piece(uSelectedItems[j],'^',2) then
+                    begin
+                      {if (uGetTnS = 1) and (lvSelectionList.Items[i].SubItems[3] = aTypeScreen) then
+                        begin
+                          uGetTnS := 1;
+                          lblTNS.Caption := 'TYPE+SCREEN must be added to order';
+                          lblTNS.Visible := true;
+                          memMessage.Text := 'TYPE + SCREEN must be added to order';
+                          //memMessage.Visible := true;
+                          pnlMessage.Visible := true;
+                          pnlDiagnosticTests.Caption := 'Diagnostic Tests*';
+                        end; }
+                      uSelectedItems.Delete(j);
+                      lvSelectionList.Items[i].Delete;
+                      break;
+                    end;
+              end;
+          end;
+      end;
+    for i := uSelectedItems.Count - 1 downto 0 do
+      begin
+        if (not(piece(uSelectedItems[i],'^',1) = '1')) and (uTNSOrders.Count < 1) then // and (SpecimenNeeded(aList, uVBECList, StrToInt(piece(uSelectedItems[i],'^',9)))) then
+          begin
+            uGetTnS := 1;
+            lblTNS.Caption := 'TYPE+SCREEN must be added to order';
+            lblTNS.Visible := true;
+            memMessage.Text := 'TYPE + SCREEN must be added to order';
+            //memMessage.Visible := true;
+            pnlMessage.Visible := true;
+            pnlDiagnosticTests.Caption := 'Diagnostic Tests*';
+            break;
+          end;
+      end;
+      
+    if (aSel = false) and (lvSelectionList.Items.Count > 0) then
+      begin
+        ShowMsg('Please select an item from the list to be removed.');
+        exit;
+      end;
+    Responses.Clear;
+    if lvSelectionList.Items.Count < 1 then
+      begin
+        cboReasons.ItemIndex := -1;
+        memDiagComment.Text := '';
+        cboSurgery.ItemIndex := -1;
+        cboUrgency.ItemIndex := -1;
+        cboCollType.ItemIndex := -1;
+        cboCollTime.ItemIndex := -1;
+        cboQuick.ItemIndex := -1;
+        calCollTime.Text := '';
+      end;
+    for i := 0 to uSelectedItems.Count - 1 do
+      begin
+        aName := lvSelectionList.Items[i].Caption;
+        x := uSelectedItems[i];
+        if piece(x,'^',1) = '1' then    //Diagnostic Test related fields
+          begin
+            if Length(piece(x,'^',2)) > 0 then Responses.Update('ORDERABLE', CurAdd, piece(x,'^',2), aName);
+            aSelTst := true;
           end
         else
           begin
-            Responses.Update('START', 1, '', '') ;
-            FLastCollTime := '';
+            if Length(piece(x,'^',2)) > 0 then Responses.Update('ORDERABLE', CurAdd, piece(x,'^',2), aName);
+            if Length(piece(x,'^',3)) > 0 then Responses.Update('QTY', CurAdd, piece(x,'^',3), piece(x,'^',3));
+            if Length(piece(x,'^',4)) > 0 then Responses.Update('MODIFIER', CurAdd, piece(x,'^',4), aModifier);
+            if Length(piece(x,'^',5)) > 0 then Responses.Update('SPECSTS', CurAdd, pieces(x,'^',5,7), piece(x,'^',5));
+            cboModifiers.ItemIndex := -1;
+            cboAvailComp.ItemIndex := -1;
+            tQuantity.Text := '';
           end;
-    end;
-  with cboCollType do if Length(ItemID) > 0 then
-    begin
-      Responses.Update('COLLECT', 1, ItemID, ItemID) ;
-      FLastCollType := ItemID;
-    end;
-  if Length(cboUrgency.Text) > 0 then Responses.Update('URGENCY',1,cboUrgency.ItemID,cboUrgency.Text);
-  if Length(txtDiagComment.Text) > 0 then Responses.Update('COMMENT',1,txtDiagComment.Text,txtDiagComment.Text);
-  //if Length(cboPreparation.Text) > 0 then Responses.Update('XFUSION',1,cboPreparation.ItemID,cboPreparation.Text);
-  if Length(cboSurgery.Text) > 0 then Responses.Update('MISC',1,cboSurgery.Text,cboSurgery.Text);
-  if Length(tReason.Text) > 0 then Responses.Update('REASON',1,tReason.Text,tReason.Text);
-  if chkConsent.Checked = true then Responses.Update('YN',1,'1','Yes');
-  memOrder.Text := Responses.OrderText;
-  CurAdd := 1;
-  if uRaw.Count > 0 then
-    for j := 0 to uRaw.Count - 1 do
-      begin
-        if Length(uRaw[j]) > 0 then Responses.Update('RESULTS', CurAdd, uRaw[j], piece(uRaw[j],'^',1));
         Inc(CurAdd);
       end;
-  if uSelectedItems.Count < 1 then
-    begin
-      uGetTnS := 0;
-      lblTNS.Caption := '';
-      lblTNS.Visible := false;
-    end;
-  aList.Free;
+    if aSelTst = false then
+      begin
+        cboCollType.ItemIndex := -1;
+        cboCollTime.ItemIndex := -1;
+        calCollTime.Text := '';
+      end;
+    if Length(calWantTime.Text) > 0 then Responses.Update('DATETIME',1,ValidCollTime(calWantTime.Text),calWantTime.Text);
+    if cboCollType.ItemID = 'LC' then
+      begin
+        with cboCollTime do
+          if Length(ItemID) > 0 then
+            begin
+              Responses.Update('START', 1, Copy(ItemID, 2, 999), Copy(ItemID, 2, 999));
+              FLastLabCollTime := ItemID + U + Text;
+            end
+          else if Length(Text) > 0 then
+            begin
+              Responses.Update('START', 1, ValidCollTime(Text), Text) ;
+              FLastLabCollTime := ValidCollTime(Text);
+            end;
+      end
+    else
+      begin
+        with calCollTime do
+          if FMDateTime > 0 then
+            begin
+              Responses.Update('START', 1, ValidCollTime(Text), Text);
+              FLastColltime := ValidCollTime(Text);
+            end
+          else
+            begin
+              Responses.Update('START', 1, '', '') ;
+              FLastCollTime := '';
+            end;
+      end;
+    with cboCollType do if Length(ItemID) > 0 then
+      begin
+        Responses.Update('COLLECT', 1, ItemID, ItemID) ;
+        FLastCollType := ItemID;
+      end;
+    if Length(cboUrgency.Text) > 0 then Responses.Update('URGENCY',1,cboUrgency.ItemID,cboUrgency.Text);
+    if Length(memDiagComment.Text) > 0 then Responses.Update('COMMENT',1,memDiagComment.Text,memDiagComment.Text);
+    if Length(cboSurgery.Text) > 0 then Responses.Update('MISC',1,cboSurgery.Text,cboSurgery.Text);
+    if Length(cboReasons.Text) > 0 then Responses.Update('REASON',1,cboReasons.Text,cboReasons.Text);
+    if chkConsent.Checked = true then Responses.Update('YN',1,'1','Yes');
+    memOrder.Text := Responses.OrderText;
+    CurAdd := 1;
+    if uRaw.Count > 0 then
+      for j := 0 to uRaw.Count - 1 do
+        begin
+          if Length(uRaw[j]) > 0 then Responses.Update('RESULTS', CurAdd, uRaw[j], piece(uRaw[j],'^',1));
+          Inc(CurAdd);
+        end;
+    if uSelectedItems.Count < 1 then
+      begin
+        uGetTnS := 0;
+        lblTNS.Caption := '';
+        lblTNS.Visible := false;
+        memMessage.Text := '';
+        pnlMessage.Visible := false;
+        GroupBox1.Visible := true;
+        pnlDiagnosticTests.Caption := 'Diagnostic Tests';
+      end;
+  finally
+    aList.Free;
+  end;
+end;
+
+procedure TfrmODBBank.btnUpdateCommentsClick(Sender: TObject);
+begin
+  inherited;
+  pnlComments.Visible := false;
+  pnlComments.SendToBack;
+  Responses.Update('COMMENT',1,memDiagComment.Text,memDiagComment.Text);
+  memOrder.Text := Responses.OrderText;
+end;
+
+procedure TfrmODBBank.btnCancelCommentClick(Sender: TObject);
+begin
+  inherited;
+  pnlComments.Visible := false;
+  pnlComments.SendToBack;
 end;
 
@@ -2157,4 +3555,9 @@
 begin
   inherited;
+  if lvSelectionList.Items.Count < 1 then
+    begin
+      ShowMsg('There is nothing in the list to remove.');
+      exit;
+    end;
   lvSelectionList.Clear;
   uSelectedItems.Clear;
@@ -2164,5 +3567,24 @@
   lblTNS.Caption := '';
   lblTNS.Visible := false;
+  memMessage.Text := '';
+  pnlMessage.Visible := false;
   InitDialog;
+  cboModifiers.ItemIndex := -1;
+  cboAvailTest.ItemIndex := -1;
+  cboAvailComp.ItemIndex := -1;
+  cboSurgery.ItemIndex := -1;
+  cboUrgency.ItemIndex := -1;
+  cboReasons.ItemIndex := -1;
+  cboCollType.ItemIndex := -1;
+  cboCollTime.ItemIndex := -1;
+  cboQuick.ItemIndex := -1;
+  calWantTime.Text := '';
+  memDiagComment.Text := '';
+  GroupBox1.Visible := true;
+  tQuantity.Text := '';
+  FLastCollType := '';
+  FLastCollTime := '';
+  FLastLabCollTime := '';
+  txtImmedColl.Text := '';
 end;
 
@@ -2175,4 +3597,5 @@
   Txt2 = #13+#13+'An order for TYPE and SCREEN must be created with this order set.';
 begin
+  if not ValidAdd then Exit;
   if uGetTnS = 1 then
     begin
@@ -2191,5 +3614,8 @@
     end;
   if Comp = true then
-    ShowMessage('The nursing blood administration order must be entered separately' + '.');
+    begin
+      if NursAdminSuppress = true then
+        ShowMsg('The nursing blood administration order must be entered separately' + '.');
+    end;
   inherited;
 end;
@@ -2199,5 +3625,31 @@
   inherited;
   if uSelectedItems.Count > 0 then
-    if Length(calWantTime.Text) > 0 then Responses.Update('DATETIME',1,ValidCollTime(calWantTime.Text),calWantTime.Text);
+    begin
+      with calWantTime do if not Changing then
+        begin
+          if FMDateTime = 0 then
+            begin
+              ShowMsg('Invalid Date/Time entered');
+              Changing := true;
+              calWantTime.Text := '';
+              Changing := false;
+              Exit;
+            end
+          else
+            begin
+              // date/time was entered
+              if (UpperCase(Text) <> 'NOW') and not(Trunc(FMNow) = Trunc(FMDateTime)) and (FMDateTime < FMNow) then
+                begin
+                  ShowMsg('Date/Time Wanted must be a future Date/Time');
+                  Changing := true;
+                  calWantTime.Text := '';
+                  Changing := false;
+                  Exit;
+                end;
+            end;
+        end;
+      if Length(calWantTime.Text) > 0 then Responses.Update('DATETIME',1,ValidCollTime(calWantTime.Text),calWantTime.Text);
+      memOrder.Text := Responses.OrderText;
+    end;
 end;
 
@@ -2207,6 +3659,6 @@
   if uSelectedItems.Count > 0 then
     begin
-      if chkConsent.Checked = true then Responses.Update('YN',1,'1','Yes')
-      else Responses.Update('YN',1,'0','No');
+      if chkConsent.Checked = true then Responses.Update('YN',1,'1','Yes');
+      memOrder.Text := Responses.OrderText;
     end;
 end;
@@ -2218,8 +3670,10 @@
     begin
       Responses.Update('URGENCY',1,cboUrgency.ItemID,cboUrgency.Text);
+      uSelUrgency := cboUrgency.Text;
       if cboUrgency.Text = 'PRE-OP' then
         begin
           lblSurgery.Enabled := true;
           cboSurgery.Enabled := true;
+          lblSurgery.Caption := 'Surgery*';
         end
       else
@@ -2227,41 +3681,254 @@
           lblSurgery.Enabled := false;
           cboSurgery.Enabled := false;
-          cboSurgery.Text := '';
-          if uSelectedItems.Count > 0 then
-            Responses.Update('MISC',1,cboSurgery.Text,cboSurgery.Text);
+          lblSurgery.Caption := 'Surgery';
+          cboSurgery.ItemIndex := -1;
+          Responses.Update('MISC',1,cboSurgery.Text,cboSurgery.Text);
         end;
-    end;
-end;
-
-procedure TfrmODBBank.txtDiagCommentChange(Sender: TObject);
+    end
+  else
+    cboUrgency.SelectByID(IntToStr(uDfltUrgency));
+  memOrder.Text := Responses.OrderText;
+end;
+
+procedure TfrmODBBank.cboUrgencyExit(Sender: TObject);
 begin
   inherited;
-  if uSelectedItems.Count > 0 then
-    Responses.Update('COMMENT',1,txtDiagComment.Text,txtDiagComment.Text);
-end;
-
-procedure TfrmODBBank.cboPreparationChange(Sender: TObject);
+  if Length(cboUrgency.Text) < 1 then
+    cboUrgency.SelectByID(IntToStr(uDfltUrgency));
+end;
+
+procedure TfrmODBBank.cboSurgeryChange(Sender: TObject);
+var
+  aList: TStringList;
+  i,j,aMSBOS,aMSBOSContinue: integer;
+  x: string;
+  handled: boolean;
 begin
   inherited;
-  Exit;  // disable Preparation, since it is no longer needed by VBECS
-  if uSelectedItems.Count > 0 then
-    if Length(cboPreparation.Text) > 0 then
-      Responses.Update('XFUSION',1,cboPreparation.ItemID,cboPreparation.Text);
-end;
-
-procedure TfrmODBBank.cboSurgeryChange(Sender: TObject);
+  aList := TStringList.Create;
+  handled := false;
+  try
+    if (Length(cboSurgery.ItemID) > 0) and (Length(tQuantity.Text) > 0) then
+      begin
+        aList.Clear;
+        ExtractMSBOS(aList, uVBECList);    //Get maximum units for selected Surgey
+        for i := 0 to aList.Count - 1 do
+          begin
+            if (StrToInt(piece(aList[i],'^',1)) = aLabTest.ItemID)
+             and (piece(aList[i],'^',3) = cboSurgery.Text) then
+              begin
+                aMSBOS := StrToInt(piece(aList[i],'^',4));
+                if (aMSBOS > 0) and (StrToInt(tQuantity.Text) > aMSBOS) then
+                  begin
+                    with Application do
+                    begin
+                      NormalizeTopMosts;
+                      aMSBOSContinue :=
+                        MessageBox(PChar('The number of unit Quantity selected (' + tQuantity.Text +
+                                   ') for ' + aLabTest.TestName + ' exceeds the maximum number of units ('
+                                   + IntToStr(aMSBOS) +
+                                   ') for the ' + cboSurgery.text +
+                                   ' surgical procedure selected.' + CRLF + CRLF + 'Continue to order ' + tQuantity.Text + ' units?'),
+                                   PChar('Maximum Number of Units Exceeded'),
+                                   MB_YESNO);
+                      RestoreTopMosts;
+                    end;
+                    if aMSBOSContinue = 7 then
+                      begin
+                        ShowMsg('Please enter a new quantity for ' + cboAvailComp.Text);
+                        tQuantity.Text := '0';
+                        tQuantity.SelLength := 2;
+                        tQuantity.SelectAll;
+                        break;
+                      end;
+                  end;
+                handled := true;
+                break;
+              end;
+          end;
+      end;
+    if (handled = false) and (Length(cboSurgery.ItemID) > 0) and (uSelectedItems.Count > 0) then
+      begin
+        aList.Clear;
+        ExtractMSBOS(aList, uVBECList);    //Get maximum units for selected Surgey
+        for j := 0 to uSelectedItems.Count - 1 do
+          begin
+            ALabTest := TLabTest.Create(piece(uSelectedItems[j],'^',2), Responses);
+            for i := 0 to aList.Count - 1 do
+              begin
+                if (piece(uSelectedItems[j],'^',1) = '0')
+                 and (StrToInt(piece(aList[i],'^',1)) = aLabTest.ItemID)
+                 and (piece(aList[i],'^',3) = cboSurgery.Text) then
+                  begin
+                    aMSBOS := StrToInt(piece(aList[i],'^',4));
+                    if (aMSBOS > 0) and (length(piece(uSelectedItems[j],'^',3)) > 0) and (StrToInt(piece(uSelectedItems[j],'^',3)) > aMSBOS) then
+                      begin
+                        with Application do
+                        begin
+                          NormalizeTopMosts;
+                          aMSBOSContinue :=
+                            MessageBox(PChar('The number of unit Quantity selected (' + piece(uSelectedItems[j],'^',3) +
+                               ') for ' + lvSelectionList.Items[j].Caption + ' exceeds the maximum number of units ('
+                               + IntToStr(aMSBOS) +
+                               ') for the ' + cboSurgery.text +
+                               ' surgical procedure selected.' + CRLF + CRLF + 'Continue to order ' + piece(uSelectedItems[j],'^',3) + ' units?'),
+                               PChar('Maximum Number of Units Exceeded'),
+                               MB_YESNO);
+                          RestoreTopMosts;
+                        end;
+                        if aMSBOSContinue = 7 then
+                          begin
+                            ShowMsg('Please enter a new quantity for ' + lvSelectionList.Items[j].Caption);
+                            tQuantity.Text := '0';
+                            tQuantity.SelLength := 2;
+                            tQuantity.SelectAll;
+                            x := uSelectedItems[j];
+                            SetPiece(x,U,3,'');
+                            uSelectedItems[j] := x;
+                            lvSelectionList.Items[j].SubItems[0] := '';
+                            RePaint;
+                            break;
+                          end;
+                      end;
+                    break;
+                  end;
+              end;
+          end;
+      end;
+    if uSelectedItems.Count > 0 then
+      if Length(cboSurgery.Text) > 0 then
+        Responses.Update('MISC',1,cboSurgery.Text,cboSurgery.Text);
+    uSelSurgery := 0;
+    if Length(cboSurgery.Text) > 0 then
+      begin
+        if length(cboSurgery.ItemID) > 0 then uSelSurgery := cboSurgery.ItemID;
+        cboReasons.Text := cboSurgery.Text;
+        Responses.Update('REASON',1,cboReasons.Text,cboReasons.Text);
+      end;
+    memOrder.Text := Responses.OrderText; 
+    finally
+      aList.Free;
+    end;
+end;
+
+procedure TfrmODBBank.cboSurgeryClick(Sender: TObject);
 begin
   inherited;
-  if uSelectedItems.Count > 0 then
-    if Length(cboSurgery.Text) > 0 then
-      Responses.Update('MISC',1,cboSurgery.Text,cboSurgery.Text);
-end;
-
-procedure TfrmODBBank.tReasonChange(Sender: TObject);
+  if Length(cboSurgery.Text) > 0 then uSelSurgery := cboSurgery.ItemID;
+end;
+
+procedure TfrmODBBank.tQuantityChange(Sender: TObject);
+var
+  aList: TStringList;
+  i,aMSBOS,aMSBOSContinue: integer;
+  ListItem: TListItem;
+  x,m: string;
 begin
   inherited;
-  if uSelectedItems.Count > 0 then
-    if Length(tReason.Text) > 0 then
-      Responses.Update('REASON',1,tReason.Text,tReason.Text);
+  if changing = true then Exit;
+  aList := TStringList.Create;
+  if Length(tQuantity.Text) > 0 then
+    begin
+      if Length(tQuantity.Text) > 2 then
+        begin
+          ShowMsg('Invalid entry. Please select a numeric value <100');
+          tQuantity.Text := '';
+          Exit;
+        end;
+      if StrToInt(tQuantity.Text) > 100 then
+        begin
+          ShowMsg('Quantity too high. Please select a value <100');
+          tQuantity.Text := Copy(tQuantity.Text,0,1);
+          Exit;
+        end;
+    end;
+  try
+    if (Length(cboSurgery.ItemID) > 0) and (Length(tQuantity.Text) > 0) then
+      begin
+        aList.Clear;
+        ExtractMSBOS(aList, uVBECList);    //Get maximum units for selected Surgery
+        for i := 0 to aList.Count - 1 do
+          begin
+            if (StrToInt(piece(aList[i],'^',1)) = aLabTest.ItemID)
+             and (piece(aList[i],'^',3) = cboSurgery.Text) then
+              begin
+                aMSBOS := StrToInt(piece(aList[i],'^',4));
+                if (aMSBOS > 0) and (StrToInt(tQuantity.Text) > aMSBOS) then
+                  begin
+                    with Application do
+                    begin
+                      NormalizeTopMosts;
+                      aMSBOSContinue :=
+                        MessageBox(PChar('The number of units ordered (' + tQuantity.Text +
+                                   ') for ' + aLabTest.TestName + ' exceeds the maximum number of units ('
+                                   + IntToStr(aMSBOS) +
+                                   ') for the ' + cboSurgery.text +
+                                   ' surgical procedure selected.' + CRLF + CRLF + 'Do you wish to continue?'),
+                                   PChar('Maximum Number of Units Exceeded'),
+                                   MB_YESNO);
+                      RestoreTopMosts;
+                    end;
+                    if aMSBOSContinue = 7 then
+                      begin
+                        ShowMsg('Please enter a new quantity for ' + cboAvailComp.Text);
+                        tQuantity.Text := '0';
+                        tQuantity.SelLength := 2;
+                        tQuantity.SelectAll;
+                        break;
+                      end;
+                  end;
+                break;
+              end;
+          end;
+      end;
+    if (cboAvailComp.ItemIndex <> -1) and (uSelectedItems.Count > 0) then
+      for i := 0 to lvSelectionList.Items.Count - 1 do
+        begin
+          if lvSelectionList.Items[i].Caption = piece(cboAvailComp.Items[cboAvailComp.ItemIndex],'^',2) then
+            begin
+              x := uSelectedItems[i];
+              m := piece(x,'^',4);
+              ListItem := lvSelectionList.Items[i];
+              ListItem.SubItems.Clear;
+              ListItem.SubItems.Add(tQuantity.Text);
+              SetPiece(x,U,3,tQuantity.Text);
+              Responses.Update('QTY', (i+1), tQuantity.Text, tQuantity.Text);
+              uSelectedItems[i] := x;
+              if length(cboModifiers.ItemID) > 0 then
+                begin
+                  ListItem.SubItems.Add(cboModifiers.Items[cboModifiers.ItemIndex]);
+                  ListItem.SubItems.Add(IntToStr(cboModifiers.ItemIndex));
+                end
+                else
+                  begin
+                    ListItem.SubItems.Add('');
+                    ListItem.SubItems.Add('');
+                  end;
+
+              ListItem.SubItems.Add(piece(cboAvailComp.Items[cboAvailComp.ItemIndex],'^',1));
+              Break;
+            end;
+        end;
+    if Length(tQuantity.Text) > 0 then
+      begin
+        memOrder.Text := Responses.OrderText;
+      end;
+  finally
+    aList.Free;
+  end;
+end;
+
+procedure TfrmODBBank.tQuantityClick(Sender: TObject);
+begin
+  inherited;
+  tQuantity.SelLength := 2;
+  tQuantity.SelectAll;
+end;
+
+procedure TfrmODBBank.tQuantityEnter(Sender: TObject);
+begin
+  inherited;
+  tQuantity.SelLength := 2;
+  tQuantity.SelectAll;
 end;
 
@@ -2299,4 +3966,5 @@
               end;
         end;
+      memOrder.Text := Responses.OrderText;
     end;
 end;
