Procedure

TfrmODBBank.SetOnQuickOrder

Module

fODBBank

Last Modified

7/15/2014 3:26:40 PM

Visibility

Private

Owner

TfrmODBBank

Declaration

procedure SetOnQuickOrder;

Calls Hierarchy


TfrmODBBank.SetOnQuickOrder
 ├TfrmODBBank.ExtractTypeScreen
 ├TfrmODBBank.ExtractSpecimen
 ├TResponses.SetQuickOrder
 │ ├TResponses.Clear
 │ └LoadResponses
 │   └ExtractToResponses
 │     └ExpandOrderObjects
 │       ├TdmodShared.BoilerplateOK
 │       │ ├ErrCount
 │       │ ├AddErr
 │       │ └TdmodShared.LoadTIUObjects
 │       │   └GetObjectList
 │       └GetTemplateText
 │         └TEncounter.GetVisitStr
 │           └TEncounter.GetVisitCategory
 ├TResponses.NextInstance
 ├TResponses.FindResponseByName
 ├GetSubtype
 ├TResponses.SetControl
 │ ├TResponses.FindResponseByName
 │ └AssignBPText
 │   ├DisplayGroupToLinkType
 │   │ └DisplayGroupByName
 │   ├TResponses.EValueFor
 │   ├GetServiceIEN
 │   ├TResponses.IValueFor
 │   ├GetProcedureIEN
 │   ├ExpandOrderObjects...
 │   ├SetTemplateDialogCanceled
 │   ├CheckBoilerplate4Fields
 │   ├ExecuteTemplateOrBoilerPlate
 │   └WasTemplateDialogCanceled
 ├TLabTest.Create
 │ ├LoadLabTestData
 │ ├GetOneSpecimen
 │ ├TLabTest.FillCollSampList
 │ ├TResponses.FindResponseByName
 │ ├TLabTest.IndexOfCollSamp
 │ ├GetOneCollSamp
 │ ├TLabTest.LoadAllSamples
 │ │ ├LoadSamples
 │ │ └TLabTest.FillCollSampList
 │ └TLabTest.SetCollSampDflts
 │   ├TResponses.FindResponseByName
 │   ├TLabTest.ChangeSpecimen
 │   └TLabTest.IndexOfCollSamp
 ├TfrmODBBank.cboSurgeryChange
 │ ├TfrmODBBank.ExtractTypeScreen
 │ ├TLabTest.Create...
 │ ├TfrmODBBank.ExtractMSBOS
 │ ├TResponses.Update
 │ │ ├TResponses.FindResponseByName
 │ │ └TResponses.IENForPrompt
 │ ├TfrmODBBank.DisableComponentControls
 │ └TResponses.GetOrderText
 │   ├TResponses.NextInstance
 │   ├TResponses.FindResponseByName
 │   ├TResponses.FormatResponse
 │   │ └TResponses.FindResponseByIEN
 │   └TResponses.AppendChildren
 │     ├TResponses.FindPromptByIEN
 │     ├TResponses.FindResponseByIEN
 │     └TResponses.FormatResponse...
 ├TfrmODBBank.DisableDiagTestControls
 ├TfrmODBBank.EnableComponentControls
 │ └TResponses.Update...
 ├TfrmODBBank.ExtractTests
 ├GetPatientBloodResults
 ├GetPatientBloodResultsRaw
 ├TResponses.Update...
 ├TfrmODBBank.ExtractMSBOS
 ├TfrmODBBank.InitDialog
 │ ├TLabTest.Destroy
 │ └TfrmODBBank.DisableCommentPanels
 ├TfrmODBBank.SpecimenNeeded
 │ └TfrmODBBank.ExtractSpecimen
 ├TfrmODBBank.ExtractSpecimens
 ├TResponses.GetOrderText...
 ├TfrmODBBank.DisableComponentControls
 ├TfrmODBBank.EnableDiagTestControls
 ├TLabTest.ObtainCollSamp
 ├TLabTest.IndexOfCollSamp
 ├TfrmODBase.OrderMessage
 │ └TfrmODBase.ShowOrderMessage
 ├TfrmODBBank.ValidCollTime
 │ └StrToFMDateTime
 ├TfrmODBBank.cboUrgencyChange
 │ ├TResponses.Update...
 │ └TResponses.GetOrderText...
 ├TNSDaysBack
 ├TfrmODBBank.lvSelectionListClick
 │ ├StrToFMDateTime
 │ ├TLabTest.Create...
 │ ├TfrmODBBank.DisableDiagTestControls
 │ ├TfrmODBBank.EnableComponentControls...
 │ ├TfrmODBBank.DisableComponentControls
 │ └TfrmODBBank.EnableDiagTestControls
 ├TfrmODBBank.btnRemoveClick
 │ ├TfrmODBBank.ExtractTypeScreen
 │ ├TResponses.Clear
 │ ├TfrmODBBank.InitDialog...
 │ ├TResponses.Update...
 │ ├TfrmODBBank.ValidCollTime...
 │ └TResponses.GetOrderText...
 ├TLabTest.ObtainComment
 ├TfrmODBBank.LoadRequiredComment
 │ └TfrmODBBank.DisableCommentPanels
 └TfrmODBBank.DisableCommentPanels

Called-By Hierarchy


TfrmODBBank.SetOnQuickOrder
TfrmODBBank.cboQuickClick┘ 

Calls

Name Declaration Comments
TfrmODBBank.btnRemoveClick procedure btnRemoveClick(Sender: TObject); -
TfrmODBBank.cboSurgeryChange procedure cboSurgeryChange(Sender: TObject); -
TfrmODBBank.cboUrgencyChange procedure cboUrgencyChange(Sender: TObject); -
TLabTest.Create constructor Create(const LabTestIEN: string; Responses: TResponses); -
TfrmODBBank.DisableCommentPanels procedure DisableCommentPanels; -
TfrmODBBank.DisableComponentControls procedure DisableComponentControls; -
TfrmODBBank.DisableDiagTestControls procedure DisableDiagTestControls; -
TfrmODBBank.EnableComponentControls procedure EnableComponentControls; -
TfrmODBBank.EnableDiagTestControls procedure EnableDiagTestControls; -
TfrmODBBank.ExtractMSBOS procedure ExtractMSBOS(OutList:TStrings; AList:TStrings); -
TfrmODBBank.ExtractSpecimen procedure ExtractSpecimen(OutList:TStrings; AList:TStrings); -
TfrmODBBank.ExtractSpecimens procedure ExtractSpecimens(OutList:TStrings; AList:TStrings); -
TfrmODBBank.ExtractTests procedure ExtractTests(OutList:TStrings; AList:TStrings); -
TfrmODBBank.ExtractTypeScreen procedure ExtractTypeScreen(OutList:TStrings; AList:TStrings); -
TResponses.FindResponseByName function FindResponseByName(const APromptID: string; AnInstance: Integer): TResponse; -
TResponses.GetOrderText function GetOrderText: string; -
GetPatientBloodResults procedure GetPatientBloodResults(Dest: TStrings; PatientID: string; ATests: TStringList); -
GetPatientBloodResultsRaw procedure GetPatientBloodResultsRaw(Dest: TStrings; PatientID: string; ATests: TStringList); -
GetSubtype function GetSubtype(TestName: string): string; -
TLabTest.IndexOfCollSamp function IndexOfCollSamp(CollSampIEN: Integer): Integer; -
TfrmODBBank.InitDialog procedure InitDialog; override; -
TfrmODBBank.LoadRequiredComment procedure LoadRequiredComment(CmtType: integer); -
TfrmODBBank.lvSelectionListClick procedure lvSelectionListClick(Sender: TObject); -
TResponses.NextInstance function NextInstance(const APromptID: string; LastInstance: Integer): Integer; -
TLabTest.ObtainCollSamp function ObtainCollSamp: Boolean; -
TLabTest.ObtainComment function ObtainComment: Boolean; -
TfrmODBase.OrderMessage procedure OrderMessage(const AMessage: string); -
TResponses.SetControl procedure SetControl(AControl: TControl; const APromptID: string; AnInstance: Integer); -
TResponses.SetQuickOrder procedure SetQuickOrder(AnIEN: Integer); -
TfrmODBBank.SpecimenNeeded function SpecimenNeeded(OutList:TStrings; AList:TStrings; CompID:integer): Boolean; -
TNSDaysBack function TNSDaysBack: integer; -
TResponses.Update procedure Update(const APromptID: string; AnInstance: Integer; const AnIValue, AnEValue: string); -
TfrmODBBank.ValidCollTime function ValidCollTime(UserEntry: string): string; -

Called-By

Name Declaration Comments
TfrmODBBank.cboQuickClick procedure cboQuickClick(Sender: TObject); -


Source

873   procedure TfrmODBBank.SetOnQuickOrder;
874     var
875     AnInstance: Integer;
876     AResponse: TResponse;
877     i: integer;
878     x,sub,sub1,aTNSString: string;
879     aList, cList: TStringList;
880     aGotIt, aGotTNS: boolean;
881     aTests: TStringList;
882     ListItem: TListItem;
883     xLabTest: TLabTest;
884     aName, aMsg, aStr, aModifier, aReason, aSurgery, aCollTime, aTestYes, aSpecimen, aSpecimenUID, aSpecimenReq, aTypeScreen, aUrgText: String;
885     CurAdd, j, k, getTest, TestAdded, aMSBOS, aMSBOSContinue, aTNS: Integer;
886   begin
887     inherited;
888     aList := TStringList.Create;
889     cList := TStringList.Create;
890     aTests := TStringList.Create;
891     pgeProduct.ActivePageIndex := TI_COMPONENT;
892     try
893       aModifier := '';
894       aReason := '';
895       aSurgery := '';
896       aCollTime := '';
897       aTestYes := '0';
898       aTypeScreen := '';
899       aSpecimen := '';
900       aSpecimenUID := '';
901       aSpecimenReq := '';
902       sub1 := '';
903       aGotTNS := false;
904       ExtractTypeScreen(aList, uVBECList);
905       if aList.Count > 0 then aTypeScreen := aList[0];
906       aList.Clear;
907       ExtractSpecimen(aList, uVBECList);
908       if aList.Count > 0 then
909         begin
910           aSpecimen := piece(aList[0], '^',1);
911           aSpecimenUID := piece(aList[0], '^',2);
912         end;
913       with Responses, ALabTest do
914         begin
915           Changing := True;
916           aGotIt := False;
917           FLastItemID := cboQuick.ItemID;
918           QuickOrder := ExtractInteger(cboQuick.ItemID);
919           with Responses do
920             begin
921               StatusText('Initializing Quick Order');
922               AnInstance := NextInstance('ORDERABLE', 0);
923               while AnInstance > 0 do
924                 begin
925                   AResponse := FindResponseByName('ORDERABLE', AnInstance);
926                   sub := GetSubtype(AResponse.EValue);
927                   if sub = 't' then
928                     begin
929                       SetControl(cboAvailTest,        'ORDERABLE', AnInstance);
930                       ALabTest := TLabTest.Create(cboAvailTest.ItemID, Responses);
931                     end
932                   else
933                     begin
934                       SetControl(cboAvailComp,        'ORDERABLE', AnInstance);
935                       ALabTest := TLabTest.Create(cboAvailComp.ItemID, Responses);
936                     end;
937                   for i := 0 to aList.Count - 1 do
938                     if aList[i] = ALabTest.TestName then
939                       begin
940                         aGotIt := true;
941                         break;
942                       end;
943                   if aGotIt = true then
944                     begin
945                       aGotIt := false;
946                       AnInstance := NextInstance('ORDERABLE', AnInstance);
947                       Continue;
948                     end
949                     else
950                       begin
951                         aList.Add(ALabTest.TestName);
952                       end;
953                   if AResponse <> nil then
954                     sub1 := GetSubtype(AResponse.EValue);
955                   if AnInstance = 1 then
956                     begin
957                       SetControl(cboReasons,         'REASON', AnInstance);
958                       SetControl(calWantTime,        'DATETIME', AnInstance);
959                       SetControl(memDiagComment,     'COMMENT', AnInstance);
960                       SetControl(chkConsent,         'YN', AnInstance);
961                       //DetermineCollectionDefaults(Responses);
962                       SetControl(cboUrgency,         'URGENCY', AnInstance);
963                       if cboUrgency.ItemIEN = 0 then
964                         begin
965                           if StrToIntDef(LRFURG, 0) > 0 then
966                             cboUrgency.SelectByID(LRFURG)
967                           else if (Urgency = 0) and (cboUrgency.Items.Count = 1) then
968                             cboUrgency.ItemIndex := 0;
969                         end;
970                       SetControl(cboSurgery,         'MISC', AnInstance);
971                       if Length(cboSurgery.Text) > 0 then
972                         begin
973                           for i := 0 to cboSurgery.Items.Count - 1 do
974                             if uppercase(cboSurgery.Text) = uppercase(piece(cboSurgery.Items[i],'^',2)) then
975                               begin
976                                 cboSurgery.ItemIndex := i;
977                                 Break;
978                               end;
979                           cboSurgeryChange(self);
980                         end;
981                       if not(ALabTest = nil) then
982                         begin
983                           i := 1 ;
984                           AResponse := Responses.FindResponseByName('COMMENT',i);
985                           while AResponse <> nil do
986                             begin
987                               Comment.Add(AResponse.EValue);
988                               Inc(i);
989                               AResponse := Responses.FindResponseByName('COMMENT',i);
990                             end ;
991                         end;
992                     end;
993                   if sub1 = 'c' then
994                     begin
995                       DisableDiagTestControls;
996                       EnableComponentControls;
997                       LRORDERMODE := TORDER_MODE_COMP;
998                       SetControl(cboAvailComp,       'ORDERABLE', AnInstance);
999                       SetControl(cboModifiers,       'MODIFIER', AnInstance);
1000                      SetControl(tQuantity,          'QTY', AnInstance);
1001                      aList.Clear;
1002                      TestAdded := 0;
1003                      getTest := 0;
1004                      ExtractTests(aList, uVBECList);   //Get Results associated with ordered components
1005                        for j := 0 to aList.Count - 1 do
1006                          begin
1007                            if StrToInt(piece(aList[j],'^',1)) = aLabTest.ItemID then
1008                              begin
1009                                if uTestsForResults.Count < 1 then getTest := 1;
1010                                for k := 0 to uTestsForResults.Count - 1 do
1011                                  begin
1012                                    if piece(uTestsForResults[k],'^',1) = piece(aList[j],'^',3) then
1013                                      begin
1014                                        getTest := 0;
1015                                        break;
1016                                      end
1017                                    else getTest := 1;
1018                                  end;
1019                                if getTest = 1 then
1020                                  begin
1021                                    uTestsForResults.Add(piece(aList[j],'^',3));
1022                                    TestAdded := 1;
1023                                  end;
1024                              end;
1025                          end;
1026                        if TestAdded = 1 then
1027                          begin
1028                            aTests.Clear;
1029                            GetPatientBloodResults(aTests, Patient.DFN, uTestsForResults);
1030                            if aTests.Count > 0 then
1031                              begin
1032                                edtResults.Clear;
1033                                QuickCopy(ATests,edtResults);
1034                                TabResults.Caption := 'Lab Results Available';
1035                                uRaw.Clear;
1036                                GetPatientBloodResultsRaw(uRaw, Patient.DFN, uTestsForResults);
1037                              end;
1038                          end;
1039                        CurAdd := 1;
1040                        if uRaw.Count > 0 then
1041                        for j := 0 to uRaw.Count - 1 do
1042                          begin
1043                            if Length(uRaw[j]) > 0 then Responses.Update('RESULTS', CurAdd, uRaw[j], piece(uRaw[j],'^',1));
1044                            Inc(CurAdd);
1045                          end;
1046                      aSpecimen := '';
1047                      aSpecimenUID := '';
1048                      aSpecimenReq := '';
1049                      aTestYes := '0';
1050                      aReason := '';
1051                      aSurgery := '';
1052                      aCollTime := '';
1053                      ExtractSpecimen(aList, uVBECList);
1054                      if aList.Count > 0 then
1055                        begin
1056                          aSpecimen := piece(aList[0], '^', 1);
1057                          aSpecimenUID := piece(aList[0], '^', 2);
1058                        end;
1059                      if length(cboModifiers.ItemID) > 0 then aModifier := cboModifiers.Items[cboModifiers.ItemIndex];
1060                      if length(cboReasons.ItemID) > 0 then aReason := cboReasons.Items[cboReasons.ItemIndex];
1061                      if length(cboSurgery.ItemID) > 0 then aSurgery := cboSurgery.Items[cboSurgery.ItemIndex];
1062                      if Length(cboSurgery.ItemID) > 0 then
1063                        begin
1064                          aList.Clear;
1065                          ExtractMSBOS(aList, uVBECList);    //Get maximum units for selected Surgey
1066                          for i := 0 to aList.Count - 1 do
1067                            begin
1068                              if (StrToInt(piece(aList[i],'^',1)) = aLabTest.ItemID)
1069                               and (uppercase((piece(aList[i],'^',3))) = uppercase(cboSurgery.Text)) then
1070                                begin
1071                                  aMSBOS := StrToInt(piece(aList[i],'^',4));
1072                                  if (aMSBOS > 0) and (StrToInt(tQuantity.Text) > aMSBOS) then
1073                                    begin
1074                                      with Application do
1075                                      begin
1076                                        NormalizeTopMosts;
1077                                        aMSBOSContinue :=
1078                                          MessageBox(PChar('The number of units ordered (' + tQuantity.Text +
1079                                             ') for ' + aLabTest.TestName + ' Exceeds the maximum number recommended ('
1080                                             + IntToStr(aMSBOS) +
1081                                             ') for the ' + cboSurgery.text +
1082                                             ' surgical procedure.' + CRLF +
1083                                             'If you need to order more than the maximum number of units, please enter a justification in the Comment box.'
1084                                              + CRLF + CRLF + 'Edit the Blood component Quantity?'),
1085                                             PChar('Maximum Number of Units Exceeded'),
1086                                             MB_YESNO);
1087                                        RestoreTopMosts;
1088                                      end;
1089                                      if aMSBOSContinue = 6 then
1090                                        begin
1091                                          ShowMsg(cboAvailComp.Text + ' has NOT been added to this request.');
1092                                          lvSelectionList.Clear;
1093                                          uSelectedItems.Clear;
1094                                          uTestsForResults.Clear;
1095                                          uRaw.Clear;
1096                                          uGetTnS := 0;
1097                                          lblTNS.Caption := '';
1098                                          lblTNS.Visible := false;
1099                                          memMessage.Text := '';
1100                                          pnlMessage.Visible := false;
1101                                          FLastItemID := '';
1102                                          InitDialog;
1103                                          cboModifiers.ItemIndex := -1;
1104                                          cboAvailTest.ItemIndex := -1;
1105                                          cboAvailComp.ItemIndex := -1;
1106                                          cboSurgery.ItemIndex := -1;
1107                                          cboUrgency.ItemIndex := -1;
1108                                          cboReasons.ItemIndex := -1;
1109                                          cboCollType.ItemIndex := -1;
1110                                          cboCollTime.ItemIndex := -1;
1111                                          cboQuick.ItemIndex := -1;
1112                                          calWantTime.Text := '';
1113                                          memDiagComment.Text := '';
1114                                          GroupBox1.Visible := true;
1115                                          tQuantity.Text := '';
1116                                          FLastCollType := '';
1117                                          FLastCollTime := '';
1118                                          FLastLabCollTime := '';
1119                                          txtImmedColl.Text := '';
1120                                          calCollTime.text := '';
1121                                          exit;
1122                                        end;
1123                                    end;
1124                                end;
1125                            end;
1126                        end;
1127                      for i := lvSelectionList.Items.Count - 1 downto 0 do
1128                        begin
1129                          if lvSelectionList.Items[i].SubItems[3] = aTypeScreen then
1130                            begin
1131                              aGotTNS := true;
1132                              break;
1133                            end;
1134                        end;
1135                      if (uTNSOrders.Count < 1) and (aGotTNS = false) and (SpecimenNeeded(aList, uVBECList, aLabTest.ItemID)) then  //check to see if type and screen is needed CQ 17349
1136                        begin
1137                          uGetTnS := 1;
1138                        end;
1139                      aList.Clear;
1140                      ExtractSpecimens(aList, uVBECList);    //Get specimen values to pass back to Server
1141                      for i := 0 to aList.Count - 1 do
1142                        begin
1143                          if (StrToInt(piece(aList[i],'^',1)) = aLabTest.ItemID) then
1144                            begin
1145                              aSpecimenReq := piece(aList[i],'^',2);
1146                              if (SpecimenNeeded(aList, uVBECList, aLabTest.ItemID)) then
1147                                aSpecimenUID := '';
1148                              break;
1149                            end;
1150                        end;
1151                      uComponentSelected := true;
1152                      with lvSelectionList do
1153                        begin
1154                          ListItem := Items.Add;
1155                          ListItem.Caption := piece(cboAvailComp.Items[cboAvailComp.ItemIndex],'^',2);
1156                          ListItem.SubItems.Add(tQuantity.Text);
1157                          if length(cboModifiers.ItemID) > 0 then
1158                            begin
1159                              ListItem.SubItems.Add(cboModifiers.Items[cboModifiers.ItemIndex]);
1160                              ListItem.SubItems.Add(IntToStr(cboModifiers.ItemIndex));
1161                            end
1162                            else
1163                              begin
1164                                ListItem.SubItems.Add('');
1165                                ListItem.SubItems.Add('');
1166                              end;
1167                          ListItem.SubItems.Add(piece(cboAvailComp.Items[cboAvailComp.ItemIndex],'^',1));
1168                        end;
1169                      CurAdd := 1;
1170                      aStr := aTestYes + '^' + IntToStr(aLabTest.TestID) + '^' + tQuantity.Text + '^' + aModifier + '^' + aSpecimenReq + '^' + aSpecimen + '^' + aSpecimenUID + '^' + IntToStr(aLabTest.ItemID);
1171                      uSelectedItems.Add(aStr);
1172                      for i := 0 to uSelectedItems.Count - 1 do
1173                        begin
1174                          aName := lvSelectionList.Items[i].Caption;
1175                          x := uSelectedItems[i];
1176                          if piece(x,'^',1) = '1' then    //Diagnostic Test related fields
1177                            begin
1178                              if Length(piece(x,'^',2)) > 0 then Responses.Update('ORDERABLE', CurAdd, piece(x,'^',2), aName);
1179                            end
1180                          else
1181                            begin
1182                              if Length(piece(x,'^',2)) > 0 then Responses.Update('ORDERABLE', CurAdd, piece(x,'^',2), aName);
1183                              if Length(piece(x,'^',3)) > 0 then Responses.Update('QTY', CurAdd, piece(x,'^',3), piece(x,'^',3));
1184                              if Length(piece(x,'^',4)) > 0 then Responses.Update('MODIFIER', CurAdd, piece(x,'^',4), aModifier);
1185                              if Length(piece(x,'^',5)) > 0 then Responses.Update('SPECSTS', CurAdd, pieces(x,'^',5,7), piece(x,'^',5));
1186                              if Length(cboSurgery.Text) > 0 then Responses.Update('MISC',1,cboSurgery.Text,cboSurgery.Text);
1187                            end;
1188                          Inc(CurAdd);
1189                        end;
1190                      memOrder.Text := Responses.OrderText;
1191                      GroupBox1.Visible := False;
1192                    aMsg := '';
1193                    LRORDERMODE := TORDER_MODE_INFO;
1194                    if lvSelectionList.Items.Count > 0 then
1195                      begin
1196                        pnlSelectedTests.Visible := True;
1197                        cmdAccept.Visible := True;
1198                        memOrder.Visible := True;
1199                        GroupBox1.Visible := False;
1200                      end;
1201                    end
1202                    else
1203                      begin
1204                        if sub1 = 't' then
1205                        begin
1206                          DisableComponentControls;
1207                          EnableDiagTestControls;
1208                          LRORDERMODE := TORDER_MODE_DIAG;
1209                          aTestYes := '1';
1210                          SetControl(cboAvailTest,       'ORDERABLE', AnInstance);
1211                          //DetermineCollectionDefaults(Responses); //cboCollType = COLLECT , calCollTime = START
1212                          i := 1 ;
1213                          AResponse := Responses.FindResponseByName('COMMENT',i);
1214                          while AResponse <> nil do
1215                            begin
1216                              Comment.Add(AResponse.EValue);
1217                              Inc(i);
1218                              AResponse := Responses.FindResponseByName('COMMENT',i);
1219                            end ;
1220                          if ObtainCollSamp then
1221                            begin
1222                            //For BloodBank orders, this condition should never occur
1223                            end
1224                          else
1225                            begin
1226                              with ALabTest do
1227                                with TCollSamp(CollSampList.Items[IndexOfCollSamp(CollSamp)]) do
1228                                  begin
1229                                    x := '' ;
1230                                    for i := 0 to WardComment.Count-1 do
1231                                    x := x + WardComment.strings[i]+#13#10 ;
1232                                    pnlMessage.TabOrder := cboAvailTest.TabOrder + 1;
1233                                    OrderMessage(x) ;
1234                                  end ;
1235                            end;
1236                          if Length(calWantTime.Text) > 0 then Responses.Update('DATETIME',1,ValidCollTime(calWantTime.Text),calWantTime.Text);
1237                          if Length(cboUrgency.Text) > 0 then Responses.Update('URGENCY',1,cboUrgency.ItemID,cboUrgency.Text)
1238                            else
1239                              begin
1240                                cboUrgency.ItemIndex := 2;
1241                                for i := 0 to cboUrgency.Items.Count - 1 do
1242                                  begin
1243                                    aUrgText := cboUrgency.Items[i];
1244                                    if aUrgText = '9^ROUTINE' then    // Find urgency default of ROUTINE
1245                                      begin
1246                                        cboUrgency.ItemIndex := i;
1247                                        break;
1248                                      end;
1249                                  end;
1250                                Responses.Update('URGENCY',1,cboUrgency.ItemID,cboUrgency.Text);
1251                                cboUrgencyChange(self);
1252                              end;
1253                          if Length(memDiagComment.Text) > 0 then Responses.Update('COMMENT',1,memDiagComment.Text,memDiagComment.Text);
1254                          if Length(cboReasons.Text) > 0 then Responses.Update('REASON',1,cboReasons.Text,cboReasons.Text);
1255                          uTestSelected := true;
1256                          with lvSelectionList do
1257                            begin
1258                              ListItem := Items.Add;
1259                              ListItem.Caption := piece(cboAvailTest.Items[cboAvailTest.ItemIndex],'^',2);
1260                              ListItem.SubItems.Add('');
1261                              ListItem.SubItems.Add('');
1262                              ListItem.SubItems.Add('');
1263                              ListItem.SubItems.Add(piece(cboAvailTest.Items[cboAvailTest.ItemIndex],'^',1));
1264                            end;
1265                          CurAdd := 1;
1266                          aStr := aTestYes + '^' + IntToStr(aLabTest.TestID) + '^' + tQuantity.Text + '^' + aModifier + '^' + aSpecimenReq + '^' + aSpecimen + '^' + aSpecimenUID + '^' + IntToStr(aLabTest.ItemID);
1267                          uSelectedItems.Add(aStr);
1268                          for i := 0 to uSelectedItems.Count - 1 do
1269                            begin
1270                              aName := lvSelectionList.Items[i].Caption;
1271                              x := uSelectedItems[i];
1272                              if piece(x,'^',1) = '1' then    //Diagnostic Test related fields
1273                                begin
1274                                  if Length(piece(x,'^',2)) > 0 then Responses.Update('ORDERABLE', CurAdd, piece(x,'^',2), aName);
1275                                end;
1276                              Inc(CurAdd);
1277                            end;
1278                          memOrder.Text := Responses.OrderText;
1279                        if lvSelectionList.Items.Count > 0 then
1280                          begin
1281                            pnlSelectedTests.Visible := True;
1282                            cmdAccept.Visible := True;
1283                            memOrder.Visible := True;
1284                            GroupBox1.Visible := False;
1285                          end;
1286                        end;
1287                      end;
1288                    AnInstance := NextInstance('ORDERABLE', AnInstance);
1289                end;
1290                //Quick Order
1291            end;
1292          cList.Clear;
1293          if (Length(cboSurgery.ItemID) > 0) then
1294            begin
1295              for j := 0 to uSelectedItems.Count - 1 do
1296                begin
1297                  xLabTest := TLabTest.Create(piece(uSelectedItems[j],'^',2), Responses);
1298                  if (piece(uSelectedItems[j],'^',1) = '0') and (not(piece(uSelectedItems[j],'^',3)='')) and (StrToInt(piece(uSelectedItems[j],'^',3)) > 0) and (piece(cboSurgery.Items[cboSurgery.ItemIndex],'^',3) = '1') then
1299                    begin
1300                      cList.Add(xLabTest.TestName + '^' + piece(uSelectedItems[j],'^',3));
1301                    end;
1302                  xLabTest.Free;
1303                end;
1304            end;
1305          if (uChangingMSBOS = false) and (cList.Count > 0) then
1306            begin
1307              lblNoBloodReq.Visible := true;
1308              with Application do
1309                begin
1310                  NormalizeTopMosts;
1311                  aMSBOSContinue :=
1312                    MessageBox(PChar('No blood is required for the surgical procedure: ' + cboSurgery.text +
1313                     '.' + CRLF +
1314                     'If you still need to order any components, please enter a justification in the Comment box.'
1315                      + CRLF + CRLF + 'Do you want me to remove ALL the component orders you''ve just entered? '),
1316                     PChar('No Blood Required'),MB_YESNO);
1317                  RestoreTopMosts;
1318                end;
1319              if aMSBOSContinue = 6 then
1320                begin
1321                  tQuantity.Text := '';
1322                  for j := uSelectedItems.Count - 1 downto 0 do
1323                    begin
1324                      if not(lvSelectionList.Items[j] = nil) and (piece(uSelectedItems[j],'^',1) = '0') then
1325                        begin
1326                          lvSelectionList.Items[j].Delete;
1327                          uSelectedItems.Delete(j);
1328                          Responses.Update('ORDERABLE', (j+1) ,'', '');
1329                          Responses.Update('MODIFIER', (j+1), '', '');
1330                          Responses.Update('QTY', (j+1), '', '');
1331                        end;
1332                    end;
1333                  cboAvailComp.Text := '';
1334                  cboAvailComp.ItemIndex := -1;
1335                  cboModifiers.Text := '';
1336                  cboModifiers.ItemIndex := -1;
1337                  lblNoBloodReq.Visible := false;
1338                  //if fODBBank. Active then cboAvailTest.SetFocus;
1339                  lblTNS.Caption := '';
1340                  lblTNS.Visible := false;
1341                  DisableComponentControls;
1342                end;
1343            end;
1344          for i := 0 to lvSelectionList.Items.Count - 1 do
1345            begin
1346              if lvSelectionList.Items[i].SubItems[3] = aTypeScreen then
1347                begin
1348                  uGetTnS := 0;
1349                  uDfltUrgency := cboUrgency.ItemID;
1350                  lblTNS.Caption := '';
1351                  lblTNS.Visible := false;
1352                  memMessage.Text := '';
1353                  pnlMessage.Visible := false;
1354                  pnlDiagnosticTests.Caption := 'Diagnostic Tests';
1355                  if uTNSOrders.Count > 0 then
1356                    begin
1357                      for j := 0 to uTNSOrders.Count - 1 do
1358                        aTNSString := aTNSString + CRLF + uTNSOrders[j];
1359                      with Application do
1360                        begin
1361                          NormalizeTopMosts;
1362                          aTNS :=
1363                            MessageBox(PChar(aTNSString + CRLF + CRLF +
1364                               'Do you wish to cancel this request for Type & Screen?'),
1365                               PChar('Type & Screen Entered in Past ' + IntToStr(TNSDaysBack) + ' Days'),
1366                               MB_YESNO);
1367                          RestoreTopMosts;
1368                          if aTNS = 6 then
1369                            begin
1370                              lvSelectionList.ItemIndex := i;
1371                              lvSelectionListClick(self);
1372                              btnRemoveClick(self);
1373                              break;
1374                            end;
1375                        end;
1376                    end;
1377                  break;
1378                end;
1379            end;
1380          if uGetTnS = 1 then
1381            begin
1382              lblTNS.Caption := 'TYPE + SCREEN must be added to order';
1383              lblTNS.Visible := true;
1384              memMessage.Text := 'TYPE + SCREEN must be added to order';
1385              pnlMessage.Visible := true;
1386              pnlDiagnosticTests.Caption := 'Diagnostic Tests*';
1387            end
1388            else pnlDiagnosticTests.Caption := 'Diagnostic Tests';
1389          if ALabTest <> nil then
1390            begin
1391              if ObtainCollSamp then
1392                begin
1393                 //For BloodBank orders, this condition should never occur
1394                end
1395              else
1396                begin
1397                  with ALabTest do
1398                    with TCollSamp(CollSampList.Items[IndexOfCollSamp(CollSamp)]) do
1399                      begin
1400                        x := '' ;
1401                        for i := 0 to WardComment.Count-1 do
1402                        x := x + WardComment.strings[i]+#13#10 ;
1403                        pnlMessage.TabOrder := cboAvailTest.TabOrder + 1;
1404                        OrderMessage(x) ;
1405                      end ;
1406                end;
1407              with ALabTest do
1408                begin
1409                  if ObtainComment then
1410                    LoadRequiredComment(FCmtTypes.IndexOf(CurReqComment))
1411                  else
1412                    DisableCommentPanels;
1413                  x := '' ;
1414                  for i := 0 to CurWardComment.Count-1 do
1415                    x := x + CurWardComment.strings[i]+#13#10 ;
1416                  i :=  IndexOfCollSamp(CollSamp);
1417                  if i > -1 then with TCollSamp(CollSampList.Items[IndexOfCollSamp(CollSamp)]) do
1418                    for i := 0 to WardComment.Count-1 do
1419                      x := x + WardComment.strings[i]+#13#10 ;
1420                  pnlMessage.TabOrder := cboAvailTest.TabOrder + 1;
1421                  OrderMessage(x) ;
1422                end;
1423              GroupBox1.Visible := False;
1424            end;
1425          StatusText('');
1426          Changing := False;
1427        end;
1428    finally                      //**SubTest
1429      alist.Free;
1430      cList.Free;
1431      aTests.Free;
1432    end;
1433  end;