Ignore:
Timestamp:
May 7, 2015, 12:34:29 PM (9 years ago)
Author:
healthsevak
Message:

Updating the working copy to CPRS version 28

File:
1 edited

Legend:

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

    r829 r1679  
    5757    txtImmedColl: TCaptionEdit;
    5858    pnlCollTimeButton: TKeyClickPanel;
     59    lblTNS: TLabel;
     60    lblNoBloodReq: TLabel;
    5961    cmdImmedColl: TSpeedButton;
    60     lblTNS: TLabel;
     62    Splitter1: TSplitter;
    6163    procedure FormCreate(Sender: TObject);
    6264    procedure cboAvailTestSelect(Sender: TObject);
     
    9799    procedure cboModifiersChange(Sender: TObject);
    98100    procedure lvSelectionListClick(Sender: TObject);
    99     procedure cboAvailCompChange(Sender: TObject);
    100101    procedure cboCollTimeChange(Sender: TObject);
    101102    procedure memDiagCommentChange(Sender: TObject);
    102103    procedure cboUrgencyExit(Sender: TObject);
     104    procedure pnlBloodComponentsEnter(Sender: TObject);
     105    procedure pnlDiagnosticTestsEnter(Sender: TObject);
     106    procedure pnlDiagnosticTestsExit(Sender: TObject);
     107    procedure pnlBloodComponentsExit(Sender: TObject);
     108    procedure pnlBloodComponentsClick(Sender: TObject);
     109    procedure pnlDiagnosticTestsClick(Sender: TObject);
     110    procedure cboCollTypeClick(Sender: TObject);
     111    procedure cboAvailTestEnter(Sender: TObject);
     112    procedure cboCollTypeEnter(Sender: TObject);
     113    procedure txtImmedCollEnter(Sender: TObject);
     114    procedure calCollTimeEnter(Sender: TObject);
     115    procedure cboCollTimeEnter(Sender: TObject);
     116    procedure cboModifiersEnter(Sender: TObject);
     117    procedure calWantTimeEnter(Sender: TObject);
     118    procedure cboAvailCompEnter(Sender: TObject);
     119    procedure FormShow(Sender: TObject);
    103120  protected
    104121    FCmtTypes: TStringList ;
     
    244261  ALabTest: TLabTest;
    245262  UserHasLRLABKey: boolean;
     263  uChangingMSBOS: boolean;
    246264  LRFZX     : string;  //the default collection type  (LC,WC,SP,I)
    247265  LRFSAMP   : string;  //the default sample           (ptr)
     
    293311  uSelUrgency := '';
    294312  uSelSurgery := 0;
     313  uChangingMSBOS := false;
    295314  TabResults.Caption := 'Lab Results';
    296315  edtResults.Lines.Clear;
     
    314333    UserHasLRLABKey := User.HasKey('LRLAB');
    315334    AllowQuickOrder := True;
     335    if GetDiagnosticPanelLocation then
     336      begin
     337        pnlDiagnosticTests.Left := 0;
     338        pnlBloodComponents.Left := (pnlDiagnosticTests.Width + 10);
     339        pnlDiagnosticTests.TabOrder := 0;
     340        pnlBloodComponents.TabOrder := 1;
     341      end
     342    else
     343      begin
     344        pnlBloodComponents.Left := 0;
     345        pnlDiagnosticTests.Left := (pnlBloodComponents.Width + 10);
     346        pnlBloodComponents.TabOrder := 0;
     347        pnlDiagnosticTests.TabOrder := 1;
     348      end;
    316349    StatusText('Loading Dialog Definition');
    317350    FCmtTypes := TStringList.Create;
     
    342375      else
    343376        cboCollType.SelectByID('SP');
    344       SetupCollTimes(cboCollType.ItemID);
    345       StatusText('Initializing List of Tests');
    346       FVbecLookup := 'S.VBT';
    347       cboAvailTest.InitLongList('');      //Populates cboAvailTest control based on S.VBT xref
    348     end;
     377      //SetupCollTimes(cboCollType.ItemID);
     378    end;
     379    cboAvailTest.Clear;
     380    aList.Clear;
     381    GetDiagnosticTests(aList);            //Get Tests in right order
     382    for i := 0 to aList.Count - 1 do
     383      cboAvailTest.Items.Add(aList[i]);
    349384    cboAvailComp.Clear;
    350385    aList.Clear;
     
    365400    AList.Clear;
    366401    ExtractUrgencies(uUrgencyList, uVBECList);
    367     ExtractTNSOrders(uTNSOrders, uVBECList);
     402    if not(self.EvtID > 0) then ExtractTNSOrders(uTNSOrders, uVBECList);
    368403    LoadUrgencies(cboUrgency);
    369404    ExtractModifiers(uModifierList, uVBECList);
     
    371406    LoadModifiers(cboModifiers);
    372407    LoadReasons(cboReasons);
    373     calWantTime.Text := 'NOW'; //FormatFMDateTime('mmm dd,yyyy@hh:nn',DateTimeToFMDateTime(Now));
    374408    pgeProduct.TabIndex := TI_INFO;
    375409    lvSelectionList.Column[0].Width := 240;
     
    378412    DisableComponentControls;
    379413    DisableDiagTestControls;
     414    pnlDiagnosticTests.Caption := 'Diagnostic Tests';
    380415    pgeProduct.ActivePageIndex := TI_INFO;
    381416    StatusText('');
     
    425460  AnInstance, CurAdd: Integer;
    426461  AResponse: TResponse;
    427   i, j, k, aTNS, aTNSDays, getTest, TestAdded: integer;
    428   aStr, aTestYes, aName, aTypeScreen, aSpecimen, aModifier, sub, sub1, x, aTNSString: string;
     462  i, j, k, aTNS, getTest, TestAdded, aMSBOSContinue: integer;
     463  aStr, aTestYes, aName, aTypeScreen, aSpecimen, aSpecimenUID, aSpecimenReq, aModifier, sub, sub1, x, aTNSString, aUrgText: string;
    429464  ListItem: TListItem;
    430   aList: TStringList;
     465  aList, cList: TStringList;
    431466  aTests: TStringList;
     467  xLabTest: TLabTest;
     468  aGotTNS : Boolean;
    432469begin
    433470  inherited;
    434471  aList := TStringList.Create;
     472  cList := TStringList.Create;
    435473  aTests:= TStringList.Create;
     474  aGotTNS := false;
    436475  try
    437476  FOrderAction := OrderAction;
     
    439478  sub1 := '';
    440479  aTypeScreen := '';
    441   aSpecimen := '^';
     480  aSpecimen := '';
     481  aSpecimenUID := '';
     482  aSpecimenReq := '';
    442483  aModifier := '';
    443484  if OrderAction in [ORDER_COPY, ORDER_EDIT, ORDER_QUICK] then with Responses, ALabTest do
    444485    begin
     486      pgeProduct.ActivePageIndex := TI_COMPONENT;
    445487      AnInstance := NextInstance('ORDERABLE', 0);
    446488      while AnInstance > 0 do
     
    453495                begin
    454496                  SetControl(cboAvailTest,        'ORDERABLE', AnInstance);
    455                   ALabTest := TLabTest.Create(cboAvailTest.ItemID, Responses);
     497                  changing := true;
     498                  cboAvailTestSelect(Self);
     499                  changing := false;
    456500                end
    457501              else
     
    468512                  SetControl(chkConsent,         'YN', AnInstance);
    469513                  //DetermineCollectionDefaults(Responses);
    470                   SetControl(cboCollType,        'COLLECT', AnInstance);
    471                   SetControl(cboCollTime,        'START', AnInstance);
    472                   SetupCollTimes(cboCollType.ItemID);
     514                  SetControl(cboSurgery,         'MISC', AnInstance);
    473515                  SetControl(cboUrgency,         'URGENCY', AnInstance);
    474                   SetControl(cboSurgery,         'MISC', AnInstance);
     516                  if cboUrgency.ItemIEN = 0 then
     517                    begin
     518                      if StrToIntDef(LRFURG, 0) > 0 then
     519                        cboUrgency.SelectByID(LRFURG)
     520                      else if (Urgency = 0) and (cboUrgency.Items.Count = 1) then
     521                        cboUrgency.ItemIndex := 0;
     522                    end;
    475523                  Urgency := cboUrgency.ItemIEN;
    476524                  if (Urgency = 0) and (cboUrgency.Items.Count = 1) then
     
    487535                      AResponse := Responses.FindResponseByName('COMMENT',i);
    488536                    end ;
     537                  cboUrgencyChange(self);
    489538                end;
    490539              if sub = 't' then with ALabTest do      //DIAGNOSTIC TEST
     
    494543                  EnableDiagTestControls;
    495544                  LRORDERMODE := TORDER_MODE_DIAG;
     545                  //DetermineCollectionDefaults(Responses);
    496546                  aList.Clear;
    497547                  aTestYes := '1';
     
    499549                  if aList.Count > 0 then aTypeScreen := aList[0];
    500550                  aList.Clear;
    501                   with lvSelectionList do
    502                     begin
    503                       ListItem := Items.Add;
    504                       ListItem.Caption := piece(cboAvailTest.Items[cboAvailTest.ItemIndex],'^',2);
    505                       ListItem.SubItems.Add('');
    506                       ListItem.SubItems.Add('');
    507                       ListItem.SubItems.Add('');
    508                       ListItem.SubItems.Add(piece(cboAvailTest.Items[cboAvailTest.ItemIndex],'^',1));
    509                       if piece(cboAvailTest.Items[cboAvailTest.ItemIndex],'^',1) = aTypeScreen then
    510                         begin
    511                           lblTNS.Caption := '';
    512                           lblTNS.Visible := false;
    513                           memMessage.Text := '';
    514                           pnlMessage.Visible := false;
    515                           uGetTnS := 0;
    516                           pnlDiagnosticTests.Caption := 'Diagnostic Tests';
    517                         end;
    518                     end;
    519                   aStr := aTestYes + '^' + IntToStr(aLabTest.TestID) + '^' + tQuantity.Text + '^' + aModifier + '^' + aSpecimen + '^' + IntToStr(aLabTest.ItemID);  //aSpecimen has 2 pieces additional pieces added for Tests
    520                   uSelectedItems.Add(aStr);
    521551                  if Length(calWantTime.Text) > 0 then Responses.Update('DATETIME',1,ValidCollTime(calWantTime.Text),calWantTime.Text);
    522                   {with cboCollType do if Length(ItemID) > 0 then
    523                     begin
    524                       Responses.Update('COLLECT', 1, ItemID, ItemID) ;
    525                       FLastCollType := ItemID;
    526                     end;  }
    527                   if Length(cboUrgency.Text) > 0 then Responses.Update('URGENCY',1,cboUrgency.ItemID,cboUrgency.Text);
     552                  if Length(cboUrgency.Text) > 0 then Responses.Update('URGENCY',1,cboUrgency.ItemID,cboUrgency.Text)
     553                    else
     554                      begin
     555                        cboUrgency.ItemIndex := 2;
     556                        for i := 0 to cboUrgency.Items.Count - 1 do
     557                          begin
     558                            aUrgText := cboUrgency.Items[i];
     559                            if aUrgText = '9^ROUTINE' then    // Find urgency default of ROUTINE
     560                              begin
     561                                cboUrgency.ItemIndex := i;
     562                                break;
     563                              end;
     564                          end;
     565                        Responses.Update('URGENCY',1,cboUrgency.ItemID,cboUrgency.Text);
     566                        cboUrgencyChange(self);
     567                      end;
    528568                  if Length(memDiagComment.Text) > 0 then Responses.Update('COMMENT',1,memDiagComment.Text,memDiagComment.Text);
    529569                  if Length(cboReasons.Text) > 0 then Responses.Update('REASON',1,cboReasons.Text,cboReasons.Text);
    530                   LoadCollType(cboCollType);
    531                   if (cboCollType.ItemID = 'LC') or (cboCollType.ItemID = 'I') then
    532                     if not(ALabTest.LabCanCollect) and OrderForInpatient then
    533                       cboCollType.SelectByID('WC')
    534                     else if not(ALabTest.LabCanCollect) then
    535                       cboCollType.SelectByID('SP');
    536                   SetupCollTimes(cboCollType.ItemID);
    537                   if cboCollType.ItemID = 'LC' then
    538                     begin
    539                       with cboCollTime do
    540                         if Length(ItemID) > 0 then
    541                           begin
    542                             Responses.Update('START', 1, Copy(ItemID, 2, 999), Copy(ItemID, 2, 999));
    543                             FLastLabCollTime := ItemID + U + Text;
    544                           end
    545                         else if Length(Text) > 0 then
    546                           begin
    547                             Responses.Update('START', 1, ValidCollTime(Text), Text) ;
    548                             FLastLabCollTime := ValidCollTime(Text);
    549                           end;
    550                     end
    551                   else
    552                     begin
    553                       with calCollTime do
    554                         if FMDateTime > 0 then
    555                           begin
    556                             Responses.Update('START', 1, ValidCollTime(Text), Text);
    557                             FLastColltime := ValidCollTime(Text);
    558                           end
    559                         else
    560                           begin
    561                             Responses.Update('START', 1, '', '') ;
    562                             FLastCollTime := '';
    563                           end;
    564                     end;
    565                   with cboCollType do if Length(ItemID) > 0 then
    566                     begin
    567                       Responses.Update('COLLECT', 1, ItemID, ItemID) ;
    568                       FLastCollType := ItemID;
    569                     end;
    570                   //if Length(cboCollType.Text) > 0 then Responses.Update('COLLECT',1,cboCollType.ItemID,cboCollType.ItemID);
    571570                  memOrder.Text := Responses.OrderText;
    572571                  Changing := False;
     
    625624                    if TestAdded = 1 then
    626625                      begin
    627                         edtResults.Clear;
    628626                        aTests.Clear;
    629627                        GetPatientBloodResults(aTests, Patient.DFN, uTestsForResults);
    630                         QuickCopy(ATests,edtResults);
    631                         if edtResults.Lines.Count > 0 then TabResults.Caption := 'Lab Results Available'; //TabResults.ImageIndex := 1;
    632                         uRaw.Clear;
    633                         GetPatientBloodResultsRaw(uRaw, Patient.DFN, uTestsForResults);
     628                        if aTests.Count > 0 then
     629                          begin
     630                            edtResults.Clear;
     631                            QuickCopy(ATests,edtResults);
     632                            TabResults.Caption := 'Lab Results Available';
     633                            uRaw.Clear;
     634                            GetPatientBloodResultsRaw(uRaw, Patient.DFN, uTestsForResults);
     635                          end;
    634636                      end;
    635637                    CurAdd := 1;
     
    640642                        Inc(CurAdd);
    641643                      end;
     644                  for i := lvSelectionList.Items.Count - 1 downto 0 do
     645                    begin
     646                      if lvSelectionList.Items[i].SubItems[3] = aTypeScreen then
     647                        begin
     648                          aGotTNS := true;
     649                          break;
     650                        end;
     651                    end;
     652                  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
     653                    begin
     654                      uGetTnS := 1;
     655                    end;
     656                  if aList.Count > 0 then
     657                    begin
     658                      aSpecimen := piece(aList[0], '^',1);
     659                      aSpecimenUID := piece(aList[0], '^',2);
     660                    end;
     661                  aList.Clear;
     662                  ExtractSpecimens(aList, uVBECList);    //Get specimen values to pass back to Server
     663                  for i := 0 to aList.Count - 1 do
     664                    begin
     665                      if (StrToInt(piece(aList[i],'^',1)) = aLabTest.ItemID) then
     666                        begin
     667                          aSpecimenReq := piece(aList[i],'^',2);
     668                          if (SpecimenNeeded(aList, uVBECList, aLabTest.ItemID)) then
     669                            aSpecimenUID := '';
     670                          break;
     671                        end;
     672                    end;
    642673                  with lvSelectionList do
    643674                    begin
     
    657688                      ListItem.SubItems.Add(piece(cboAvailComp.Items[cboAvailComp.ItemIndex],'^',1));
    658689                    end;
    659                   aStr := aTestYes + '^' + IntToStr(aLabTest.TestID) + '^' + tQuantity.Text + '^' + aModifier + '^' + aSpecimen + '^' + IntToStr(aLabTest.ItemID);  //aSpecimen has 2 pieces additional pieces added for Tests
     690                  aStr := aTestYes + '^' + IntToStr(aLabTest.TestID) + '^' + tQuantity.Text + '^' + aModifier + '^' + aSpecimenReq + '^' + aSpecimen + '^' + aSpecimenUID + '^' + IntToStr(aLabTest.ItemID);
    660691                  uSelectedItems.Add(aStr);
    661692                  memOrder.Text := Responses.OrderText;
    662693                  Changing := False;
     694                  if (Length(cboSurgery.Text) > 0) then
     695                    begin
     696                      for i := 0 to cboSurgery.Items.Count - 1 do
     697                        if uppercase(cboSurgery.Text) = uppercase(piece(cboSurgery.Items[i],'^',2)) then
     698                          begin
     699                            cboSurgery.ItemIndex := i;
     700                            Break;
     701                          end;
     702                      cboSurgeryChange(self);
     703                    end;
    663704                end;
    664705            end;
     
    669710      DisableDiagTestControls;
    670711    end;
     712    cList.Clear;
     713    if (Length(cboSurgery.ItemID) > 0) then
     714      begin
     715        for j := 0 to uSelectedItems.Count - 1 do
     716          begin
     717            xLabTest := TLabTest.Create(piece(uSelectedItems[j],'^',2), Responses);
     718            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
     719              begin
     720                cList.Add(xLabTest.TestName + '^' + piece(uSelectedItems[j],'^',3));
     721              end;
     722            xLabTest.Free;
     723          end;
     724      end;
     725    if (uChangingMSBOS = false) and (cList.Count > 0) then
     726      begin
     727        lblNoBloodReq.Visible := true;
     728        with Application do
     729          begin
     730            NormalizeTopMosts;
     731            aMSBOSContinue :=
     732              MessageBox(PChar('No blood is required for the surgical procedure: ' + cboSurgery.text +
     733               '.' + CRLF +
     734               'If you still need to order any components, please enter a justification in the Comment box.'
     735                + CRLF + CRLF + 'Do you want me to remove ALL the component orders you''ve just entered? '),
     736               PChar('No Blood Required'),MB_YESNO);
     737            RestoreTopMosts;
     738          end;
     739        if aMSBOSContinue = 6 then
     740          begin
     741            tQuantity.Text := '';
     742            for j := uSelectedItems.Count - 1 downto 0 do
     743              begin
     744                if not(lvSelectionList.Items[j] = nil) and (piece(uSelectedItems[j],'^',1) = '0') then
     745                  begin
     746                    lvSelectionList.Items[j].Delete;
     747                    uSelectedItems.Delete(j);
     748                    Responses.Update('ORDERABLE', (j+1) ,'', '');
     749                    Responses.Update('MODIFIER', (j+1), '', '');
     750                    Responses.Update('QTY', (j+1), '', '');
     751                  end;
     752              end;
     753            cboAvailComp.Text := '';
     754            cboAvailComp.ItemIndex := -1;
     755            cboModifiers.Text := '';
     756            cboModifiers.ItemIndex := -1;
     757            lblNoBloodReq.Visible := false;
     758            //if fODBBank. Active then cboAvailTest.SetFocus;
     759            lblTNS.Caption := '';
     760            lblTNS.Visible := false;
     761            DisableComponentControls;
     762          end;
     763      end;
     764      for i := 0 to lvSelectionList.Items.Count - 1 do
     765        begin
     766          if lvSelectionList.Items[i].SubItems[3] = aTypeScreen then
     767            begin
     768              uGetTnS := 0;
     769              aGotTNS := true;
     770              uDfltUrgency := cboUrgency.ItemID;
     771              lblTNS.Caption := '';
     772              lblTNS.Visible := false;
     773              memMessage.Text := '';
     774              pnlMessage.Visible := false;
     775              pnlDiagnosticTests.Caption := 'Diagnostic Tests';
     776              if uTNSOrders.Count > 0 then
     777                begin
     778                  for j := 0 to uTNSOrders.Count - 1 do
     779                    aTNSString := aTNSString + CRLF + uTNSOrders[j];
     780                  with Application do
     781                    begin
     782                      NormalizeTopMosts;
     783                      aTNS :=
     784                        MessageBox(PChar(aTNSString + CRLF + CRLF +
     785                           'Do you wish to cancel this request for Type & Screen?'),
     786                           PChar('Type & Screen Entered in Past ' + IntToStr(TNSDaysBack) + ' Days'),
     787                           MB_YESNO);
     788                      RestoreTopMosts;
     789                      if aTNS = 6 then
     790                        begin
     791                          lvSelectionList.ItemIndex := i;
     792                          lvSelectionListClick(self);
     793                          btnRemoveClick(self);
     794                          break;
     795                        end;
     796                    end;
     797                end;
     798              break;
     799            end;
     800        end;
     801      if uSelectedItems.Count < 1 then uGetTNS := 0;
     802
     803      for i := uSelectedItems.Count - 1 downto 0 do
     804        begin
     805          if (aGotTNS = false) and not(piece(uSelectedItems[i],'^',1) = '1') and (uTNSOrders.Count < 1) and (piece(uSelectedItems[i],'^',5) = '1') then //CQ 17349
     806            begin
     807              uGetTnS := 1;
     808              break;
     809            end;
     810        end;
     811
    671812    CurAdd := 1;
    672813    for i := 0 to uSelectedItems.Count - 1 do
     
    689830              else
    690831                begin
    691                   cboUrgency.ItemIndex := 1;
     832                  cboUrgency.ItemIndex := 2;
     833                  for j := 0 to cboUrgency.Items.Count - 1 do
     834                    begin
     835                      aUrgText := cboUrgency.Items[j];
     836                      if aUrgText = '9^ROUTINE' then    // Find urgency default of ROUTINE
     837                        begin
     838                          cboUrgency.ItemIndex := j;
     839                          break;
     840                        end;
     841                    end;
    692842                  Responses.Update('URGENCY',1,cboUrgency.ItemID,cboUrgency.Text);
    693843                  cboUrgencyChange(self);
     
    696846        Inc(CurAdd);
    697847      end;
    698     for i := 0 to lvSelectionList.Items.Count - 1 do
    699       begin
    700         if lvSelectionList.Items[i].SubItems[3] = aTypeScreen then
    701           begin
    702             if uTNSOrders.Count > 0 then
    703               begin
    704                 for j := 0 to uTNSOrders.Count - 1 do
    705                   aTNSString := aTNSString + CRLF + uTNSOrders[j];
    706                 with Application do
    707                   begin
    708                     NormalizeTopMosts;
    709                     aTNSDays := TNSDaysBack;
    710                     aTNS :=
    711                       MessageBox(PChar(aTNSString + CRLF + CRLF +
    712                                  'Do you wish to continue with this request for Type & Screen?'),
    713                                  PChar('Type & Screen Entered in Past ' + IntToStr(TNSDaysBack) + ' Days'),
    714                                  MB_YESNO);
    715                     RestoreTopMosts;
    716                     if aTNS = 7 then
    717                       begin
    718                         lvSelectionList.ItemIndex := i;
    719                         lvSelectionListClick(self);
    720                         btnRemoveClick(self);
    721                         break;
    722                       end;
    723                   end;
    724               end;
    725             break;
    726           end;
    727       end;
    728   {if OrderAction in [ORDER_COPY, ORDER_EDIT, ORDER_QUICK] then with Responses, ALabTest do
    729     begin
    730       if OrderAction in [ORDER_QUICK, ORDER_EDIT] then uQuickInProcess := 1;
    731       AnInstance := NextInstance('ORDERABLE', 0);
    732       while AnInstance > 0 do
    733         begin
    734           AResponse := FindResponseByName('ORDERABLE', AnInstance);
    735           if AResponse <> nil then
    736             begin
    737               sub := GetSubtype(AResponse.EValue);
    738               if sub = 't' then
    739                 begin
    740                   SetControl(cboAvailTest,        'ORDERABLE', AnInstance);
    741                   ALabTest := TLabTest.Create(cboAvailTest.ItemID, Responses);
    742                 end
    743               else
    744                 begin
    745                   SetControl(cboAvailComp,        'ORDERABLE', AnInstance);
    746                   ALabTest := TLabTest.Create(cboAvailComp.ItemID, Responses);
    747                 end;
    748               //SetControl(cboTests,           'ORDERABLE', AnInstance);
    749               //ALabTest := TLabTest.Create(cboTests.ItemID, Responses);
    750               if ALabTest = nil then Exit;  // Causes access violation
    751               //sub := GetSubtype(ALabTest.TestName);
    752               if AnInstance = 1 then
    753                 begin
    754                   DetermineCollectionDefaults(Responses);
    755                   SetControl(cboReasons,         'REASON', AnInstance);
    756                   SetControl(chkConsent,         'YN', AnInstance);
    757                   SetControl(cboSurgery,         'MISC', AnInstance);
    758                   //SetControl(cboCollType,        'COLLECT', AnInstance);
    759                   //SetControl(cboCollTime,        'START', AnInstance);
    760                   SetControl(calWantTime,        'DATETIME', AnInstance);
    761                   //LoadUrgency(cboCollType.ItemID, cboUrgency);
    762                   SetControl(cboUrgency,         'URGENCY', AnInstance);
    763                   Urgency := cboUrgency.ItemIEN;
    764                   if (Urgency = 0) and (cboUrgency.Items.Count = AnInstance) then
    765                     begin
    766                       cboUrgency.ItemIndex := 0;
    767                       Urgency := cboUrgency.ItemIEN;
    768                     end;
    769                   i := 1 ;
    770                   AResponse := Responses.FindResponseByName('COMMENT',i);
    771                   while AResponse <> nil do
    772                       begin
    773                         if Length(AResponse.Evalue) > 0 then
    774                           Comment.Add(AResponse.EValue);
    775                         Inc(i);
    776                         AResponse := Responses.FindResponseByName('COMMENT',i);
    777                       end ;
    778                 end;
    779               if sub = 't' then with ALabTest do      //DIAGNOSTIC TEST
    780                 begin
    781                   Changing := True;
    782                   DisableComponentControls;
    783                   EnableDiagTestControls;
    784                   LRORDERMODE := TORDER_MODE_DIAG;
    785                   with Responses do
    786                     begin
    787                       StatusText('Initializing Order');
    788                       AResponse := FindResponseByName('ORDERABLE', AnInstance);
    789                       if AResponse <> nil then
    790                         sub1 := GetSubtype(AResponse.EValue);
    791                       if sub1 = 't' then
    792                         begin
    793                           SetControl(cboAvailTest,       'ORDERABLE', AnInstance);
    794                           //SetControl(cboTests,           'ORDERABLE', AnInstance);
    795                           //DetermineCollectionDefaults(Responses);   //cboCollType = COLLECT , calCollTime = START
    796                           cboAvailTestSelect(self);
    797                         end;
    798                     end;
    799                   Changing := False;
    800                   if ObtainCollSamp then
    801                     begin
    802                       //For BloodBank orders, this condition should never occur
    803                     end
    804                   else
    805                     begin
    806                       with ALabTest do
    807                         with TCollSamp(CollSampList.Items[IndexOfCollSamp(CollSamp)]) do
    808                           begin
    809                             x := '' ;
    810                             for i := 0 to WardComment.Count-1 do
    811                             x := x + WardComment.strings[i]+#13#10 ;
    812                             pnlMessage.TabOrder := cboAvailTest.TabOrder + 1;
    813                             OrderMessage(x) ;
    814                           end ;
    815                     end;
    816                 end;
    817               if sub = 'c' then with ALabTest do  //COMPONENT
    818                 begin
    819                   Changing := True;
    820                   DisableDiagTestControls;
    821                   EnableComponentControls;
    822                   LRORDERMODE := TORDER_MODE_COMP;
    823                   with Responses do
    824                     begin
    825                       StatusText('Initializing Order');
    826                       AResponse := FindResponseByName('ORDERABLE', AnInstance);
    827                       if AResponse <> nil then
    828                         sub1 := GetSubtype(AResponse.EValue);
    829                       if sub1 = 'c' then
    830                         begin
    831                           SetControl(cboAvailComp,       'ORDERABLE', AnInstance);
    832                           //SetControl(cboTests,           'ORDERABLE', AnInstance);
    833                           SetControl(cboModifiers,       'MODIFIER', AnInstance);
    834                           SetControl(tQuantity,          'QTY', AnInstance);
    835                           //DetermineCollectionDefaults(Responses);
    836                           cboAvailCompSelect(self);
    837                         end;
    838                     end;
    839                   Changing := False;
    840                 end;
    841               with ALabTest do
    842                 begin
    843                   if ObtainComment then
    844                     LoadRequiredComment(FCmtTypes.IndexOf(CurReqComment))
    845                   else
    846                     DisableCommentPanels;
    847                   x := '' ;
    848                   for i := 0 to CurWardComment.Count-1 do
    849                     x := x + CurWardComment.strings[i]+#13#10 ;
    850                   i :=  IndexOfCollSamp(CollSamp);
    851                   if i > -1 then with TCollSamp(CollSampList.Items[IndexOfCollSamp(CollSamp)]) do
    852                     for i := 0 to WardComment.Count-1 do
    853                       x := x + WardComment.strings[i]+#13#10 ;
    854                   pnlMessage.TabOrder := cboAvailTest.TabOrder + 1;
    855                   if Length(x) > 0 then
    856                     begin
    857                       OrderMessage(x) ;
    858                     end;
    859                 end;
    860               StatusText('');
    861               Changing := True;
    862               //if not(FOrderAction = ORDER_EDIT) then DetermineCollectionDefaults(Responses);
    863               Changing := False;
    864             end;
    865           AnInstance := NextInstance('ORDERABLE', AnInstance);
    866         end; //while AnInstance - ORDERABLE
    867       DisableComponentControls;
    868       DisableDiagTestControls;
    869       uQuickInProcess := 0;
    870     end;  }
     848    if uGetTnS = 1 then
     849      begin
     850        lblTNS.Caption := 'TYPE + SCREEN must be added to order';
     851        lblTNS.Visible := true;
     852        memMessage.Text := 'TYPE + SCREEN must be added to order';
     853        pnlMessage.Visible := true;
     854        pnlDiagnosticTests.Caption := 'Diagnostic Tests*';
     855      end
     856      else pnlDiagnosticTests.Caption := 'Diagnostic Tests';
    871857  finally
    872858    aList.Free;
     859    cList.Free;
    873860    aTests.Free;
    874861  end;
    875   edtResults.Height := 247;
    876   edtInfo.Height := 247;
    877862  if lvSelectionList.Items.Count > 0 then
    878863    begin
     
    881866      memOrder.Visible := True;
    882867      GroupBox1.Visible := False;
     868      lvSelectionList.Items[0].Selected := true;
     869      lvSelectionListClick(self);
    883870    end;
    884871end;
     
    890877  i: integer;
    891878  x,sub,sub1,aTNSString: string;
    892   aList: TStringList;
    893   aGotIt: boolean;
     879  aList, cList: TStringList;
     880  aGotIt, aGotTNS: boolean;
    894881  aTests: TStringList;
    895882  ListItem: TListItem;
    896   aName, aMsg, aStr, aModifier, aReason, aSurgery, aCollTime, aTestYes, aSpecimen, aTypeScreen: String;
    897   CurAdd, j, k, getTest, TestAdded, aMSBOS, aMSBOSContinue, aTNS, aTNSDays: Integer;
     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;
    898886begin
    899887  inherited;
    900888  aList := TStringList.Create;
     889  cList := TStringList.Create;
    901890  aTests := TStringList.Create;
     891  pgeProduct.ActivePageIndex := TI_COMPONENT;
    902892  try
    903893    aModifier := '';
     
    908898    aTypeScreen := '';
    909899    aSpecimen := '';
     900    aSpecimenUID := '';
     901    aSpecimenReq := '';
    910902    sub1 := '';
     903    aGotTNS := false;
    911904    ExtractTypeScreen(aList, uVBECList);
    912905    if aList.Count > 0 then aTypeScreen := aList[0];
    913906    aList.Clear;
    914     Extractspecimen(aList, uVBECList);
    915     if aList.Count > 0 then aSpecimen := aList[0];
     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;
    916913    with Responses, ALabTest do
    917914      begin
     
    963960                    SetControl(chkConsent,         'YN', AnInstance);
    964961                    //DetermineCollectionDefaults(Responses);
    965                     SetControl(cboCollType,        'COLLECT', AnInstance);
    966                     SetupCollTimes(cboCollType.ItemID);
    967                     //SetControl(cboCollTime,        'START', AnInstance);
    968                     //LoadUrgency(cboCollType.ItemID, cboUrgency);
    969962                    SetControl(cboUrgency,         'URGENCY', AnInstance);
    970                     Urgency := cboUrgency.ItemIEN;
    971                     if (Urgency = 0) and (cboUrgency.Items.Count = AnInstance) then
     963                    if cboUrgency.ItemIEN = 0 then
    972964                      begin
    973                         cboUrgency.ItemIndex := 0;
    974                         Urgency := cboUrgency.ItemIEN;
    975                         cboUrgencyChange(self);
     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;
    976969                      end;
    977970                    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;
    978981                    if not(ALabTest = nil) then
    979982                      begin
    980                         Urgency := cboUrgency.ItemIEN;
    981                         if (Urgency = 0) and (cboUrgency.Items.Count = 1) then
    982                           begin
    983                             cboUrgency.ItemIndex := 0;
    984                             Urgency := cboUrgency.ItemIEN;
    985                           end;
    986983                        i := 1 ;
    987984                        AResponse := Responses.FindResponseByName('COMMENT',i);
     
    992989                            AResponse := Responses.FindResponseByName('COMMENT',i);
    993990                          end ;
    994                       end;
    995                     if not(cboCollType.ItemID = 'LC') then
    996                       begin
    997                         if Length(cboCollTime.Text) > 0 then
    998                           begin
    999                             calCollTime.FMDateTime := StrToFMDateTime(cboCollTime.Text);
    1000                             FLastCollTime := cboCollTime.Text;
    1001                           end
    1002                         else
    1003                           begin
    1004                             FLastCollTime := '';
    1005                           end;
    1006991                      end;
    1007992                  end;
     
    1014999                    SetControl(cboModifiers,       'MODIFIER', AnInstance);
    10151000                    SetControl(tQuantity,          'QTY', AnInstance);
    1016                     //DetermineCollectionDefaults(Responses);
    1017                     //Check for and display any associated Lab Results
    10181001                    aList.Clear;
    10191002                    TestAdded := 0;
     
    10431026                      if TestAdded = 1 then
    10441027                        begin
    1045                           edtResults.Clear;
    10461028                          aTests.Clear;
    10471029                          GetPatientBloodResults(aTests, Patient.DFN, uTestsForResults);
    1048                           QuickCopy(ATests,edtResults);
    1049                           if edtResults.Lines.Count > 0 then TabResults.Caption := 'Lab Results Available'; //TabResults.ImageIndex := 1;
    1050                           uRaw.Clear;
    1051                           GetPatientBloodResultsRaw(uRaw, 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;
    10521038                        end;
    10531039                      CurAdd := 1;
     
    10581044                          Inc(CurAdd);
    10591045                        end;
    1060                     aSpecimen := '^';
     1046                    aSpecimen := '';
     1047                    aSpecimenUID := '';
     1048                    aSpecimenReq := '';
    10611049                    aTestYes := '0';
    10621050                    aReason := '';
     
    10641052                    aCollTime := '';
    10651053                    ExtractSpecimen(aList, uVBECList);
    1066                     if aList.Count > 0 then aSpecimen := aList[0];
     1054                    if aList.Count > 0 then
     1055                      begin
     1056                        aSpecimen := piece(aList[0], '^', 1);
     1057                        aSpecimenUID := piece(aList[0], '^', 2);
     1058                      end;
    10671059                    if length(cboModifiers.ItemID) > 0 then aModifier := cboModifiers.Items[cboModifiers.ItemIndex];
    10681060                    if length(cboReasons.ItemID) > 0 then aReason := cboReasons.Items[cboReasons.ItemIndex];
    10691061                    if length(cboSurgery.ItemID) > 0 then aSurgery := cboSurgery.Items[cboSurgery.ItemIndex];
    1070                     if length(cboCollTime.ItemID) > 0 then aCollTime := cboCollTime.Items[cboCollTime.ItemIndex];
    10711062                    if Length(cboSurgery.ItemID) > 0 then
    10721063                      begin
     
    10761067                          begin
    10771068                            if (StrToInt(piece(aList[i],'^',1)) = aLabTest.ItemID)
    1078                              and (piece(aList[i],'^',3) = cboSurgery.Text) then
     1069                             and (uppercase((piece(aList[i],'^',3))) = uppercase(cboSurgery.Text)) then
    10791070                              begin
    10801071                                aMSBOS := StrToInt(piece(aList[i],'^',4));
     
    10861077                                      aMSBOSContinue :=
    10871078                                        MessageBox(PChar('The number of units ordered (' + tQuantity.Text +
    1088                                                    ') for ' + aLabTest.TestName + ' exceeds the maximum number of units ('
    1089                                                    + IntToStr(aMSBOS) +
    1090                                                    ') for the ' + cboSurgery.text +
    1091                                                    ' surgical procedure selected.' + CRLF + CRLF + 'Do you wish to continue?'),
    1092                                                    PChar('Maximum Number of Units Exceeded'),
    1093                                                    MB_YESNO);
     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);
    10941087                                      RestoreTopMosts;
    10951088                                    end;
    1096                                     if aMSBOSContinue = 7 then
     1089                                    if aMSBOSContinue = 6 then
    10971090                                      begin
    10981091                                        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 := '';
    10991121                                        exit;
    11001122                                      end;
     
    11031125                          end;
    11041126                      end;
    1105                     if (uTNSOrders.Count < 1) then //SpecimenNeeded(aList, uVBECList, aLabTest.ItemID) then  //check to see if type and screen is needed
     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
    11061136                      begin
    11071137                        uGetTnS := 1;
     
    11131143                        if (StrToInt(piece(aList[i],'^',1)) = aLabTest.ItemID) then
    11141144                          begin
    1115                             aSpecimen := piece(aList[i],'^',2) + '^' + aSpecimen;
     1145                            aSpecimenReq := piece(aList[i],'^',2);
     1146                            if (SpecimenNeeded(aList, uVBECList, aLabTest.ItemID)) then
     1147                              aSpecimenUID := '';
    11161148                            break;
    11171149                          end;
     
    11361168                      end;
    11371169                    CurAdd := 1;
    1138                     aStr := aTestYes + '^' + IntToStr(aLabTest.TestID) + '^' + tQuantity.Text + '^' + aModifier + '^' + aSpecimen + '^' + IntToStr(aLabTest.ItemID);  //aSpecimen has 2 pieces additional pieces added for Tests
     1170                    aStr := aTestYes + '^' + IntToStr(aLabTest.TestID) + '^' + tQuantity.Text + '^' + aModifier + '^' + aSpecimenReq + '^' + aSpecimen + '^' + aSpecimenUID + '^' + IntToStr(aLabTest.ItemID);
    11391171                    uSelectedItems.Add(aStr);
    11401172                    for i := 0 to uSelectedItems.Count - 1 do
     
    11601192                  aMsg := '';
    11611193                  LRORDERMODE := TORDER_MODE_INFO;
    1162                   {if uGetTnS = 1 then
    1163                     begin
    1164                       lblTNS.Caption := 'TYPE + SCREEN must be added to order';
    1165                       lblTNS.Visible := true;
    1166                       memMessage.Text := 'TYPE + SCREEN must be added to order';
    1167                       memMessage.Visible := false;
    1168                       pnlMessage.Visible := true;
    1169                       pnlDiagnosticTests.Caption := 'Diagnostic Tests*';
    1170                     end;  }
    1171                   {if uGetTnS = 1 then
    1172                     begin
    1173                       if responses.QuickOrder < 1 then
    1174                         begin
    1175                           for i := 1 to cboAvailTest.Items.Count - 1 do
    1176                             begin
    1177                               if piece(cboAvailTest.Items[i],'^',1) = aTypeScreen then
    1178                                 begin
    1179                                   if piece(aSpecimen,'^',1) = '1' then
    1180                                     begin
    1181                                       cboCollTime.Text := calWantTime.Text;
    1182                                       aCollSave := cboCollTime.Text + '^' + cboCollTime.ItemID + '^' + cboCollType.Text + '^' + cboCollType.ItemID;
    1183                                       cboCollTime.Text := '';
    1184                                       cboCollType.Text := '';
    1185                                       uSpecimen := 1;
    1186                                     end;
    1187                                   cboModifiers.Text := '';
    1188                                   cboAvailTest.SelectByID(aTypeScreen);
    1189                                   cboTests.SelectByID(aTypeScreen);
    1190                                   cboTestsClick(self);
    1191                                   //cboAvailTestSelect(Self);
    1192                                   uSpecimen := 0;
    1193                                   cboCollTime.Text := piece(aCollSave,'^',1);
    1194                                   cboCollType.Text := piece(aCollSave,'^',3);
    1195                                   aCollSave := '';
    1196                                   break;
    1197                                 end;
    1198                             end;
    1199                           aMsg := 'An order for Type and Screen has been added to this request' + '.';
    1200                         end
    1201                         else
    1202                           begin
    1203                             lblTNS.Caption := 'TYPE + SCREEN must be added to order';
    1204                             lblTNS.Visible := true;
    1205                             memMessage.Text := 'TYPE + SCREEN must be added to order';
    1206                             memMessage.Visible := false;
    1207                             pnlMessage.Visible := true;
    1208                           end;
    1209                     end;
    1210                   if (uGetTnS = 1) then
    1211                     begin
    1212                       if length(aMsg) > 0 then aMsg := aMsg + crlf + crlf;
    1213                       ShowMsg(aMsg);
    1214                     end;  }
    1215 
    1216                   //cboModifiers.Text := '';
    1217                   edtResults.Height := 247;
    1218                   edtInfo.Height := 247;
    12191194                  if lvSelectionList.Items.Count > 0 then
    12201195                    begin
     
    12341209                        aTestYes := '1';
    12351210                        SetControl(cboAvailTest,       'ORDERABLE', AnInstance);
    1236                         //DetermineCollectionDefaults(Responses);   //cboCollType = COLLECT , calCollTime = START
     1211                        //DetermineCollectionDefaults(Responses); //cboCollType = COLLECT , calCollTime = START
    12371212                        i := 1 ;
    12381213                        AResponse := Responses.FindResponseByName('COMMENT',i);
     
    12601235                          end;
    12611236                        if Length(calWantTime.Text) > 0 then Responses.Update('DATETIME',1,ValidCollTime(calWantTime.Text),calWantTime.Text);
    1262                         with cboCollType do if Length(ItemID) > 0 then
    1263                           begin
    1264                             Responses.Update('COLLECT', 1, ItemID, ItemID) ;
    1265                             FLastCollType := ItemID;
    1266                           end;
    12671237                        if Length(cboUrgency.Text) > 0 then Responses.Update('URGENCY',1,cboUrgency.ItemID,cboUrgency.Text)
    12681238                          else
    12691239                            begin
    1270                               cboUrgency.ItemIndex := 1;
     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;
    12711250                              Responses.Update('URGENCY',1,cboUrgency.ItemID,cboUrgency.Text);
    12721251                              cboUrgencyChange(self);
     
    12741253                        if Length(memDiagComment.Text) > 0 then Responses.Update('COMMENT',1,memDiagComment.Text,memDiagComment.Text);
    12751254                        if Length(cboReasons.Text) > 0 then Responses.Update('REASON',1,cboReasons.Text,cboReasons.Text);
    1276                         LoadCollType(cboCollType);
    1277                         if (cboCollType.ItemID = 'LC') or (cboCollType.ItemID = 'I') then
    1278                           if not(ALabTest.LabCanCollect) and OrderForInpatient then
    1279                             cboCollType.SelectByID('WC')
    1280                           else if not(ALabTest.LabCanCollect) then
    1281                             cboCollType.SelectByID('SP');
    1282                         SetupCollTimes(cboCollType.ItemID);
    1283                         if cboCollType.ItemID = 'LC' then
    1284                           begin
    1285                             with cboCollTime do
    1286                               if Length(ItemID) > 0 then
    1287                                 begin
    1288                                   Responses.Update('START', 1, Copy(ItemID, 2, 999), Copy(ItemID, 2, 999));
    1289                                   FLastLabCollTime := ItemID + U + Text;
    1290                                 end
    1291                               else if Length(Text) > 0 then
    1292                                 begin
    1293                                   Responses.Update('START', 1, ValidCollTime(Text), Text) ;
    1294                                   FLastLabCollTime := ValidCollTime(Text);
    1295                                 end;
    1296                           end
    1297                         else
    1298                           begin
    1299                             with calCollTime do
    1300                               if FMDateTime > 0 then
    1301                                 begin
    1302                                   Responses.Update('START', 1, ValidCollTime(Text), Text);
    1303                                   FLastColltime := ValidCollTime(Text);
    1304                                 end
    1305                               else
    1306                                 begin
    1307                                   Responses.Update('START', 1, '', '') ;
    1308                                   FLastCollTime := '';
    1309                                 end;
    1310                           end;
    1311                         if length(cboCollTime.ItemID) > 0 then aCollTime := cboCollTime.Items[cboCollTime.ItemIndex];
    1312                         with cboCollType do if Length(ItemID) > 0 then
    1313                           begin
    1314                             Responses.Update('COLLECT', 1, ItemID, ItemID) ;
    1315                             FLastCollType := ItemID;
    1316                           end;
    13171255                        uTestSelected := true;
    13181256                        with lvSelectionList do
     
    13261264                          end;
    13271265                        CurAdd := 1;
    1328                         aStr := aTestYes + '^' + IntToStr(aLabTest.TestID) + '^' + tQuantity.Text + '^' + aModifier + '^' + aSpecimen + '^' + aCollTime + '^' + cboCollType.Text + '^' + IntToStr(aLabTest.ItemID);  //aSpecimen has 2 pieces
     1266                        aStr := aTestYes + '^' + IntToStr(aLabTest.TestID) + '^' + tQuantity.Text + '^' + aModifier + '^' + aSpecimenReq + '^' + aSpecimen + '^' + aSpecimenUID + '^' + IntToStr(aLabTest.ItemID);
    13291267                        uSelectedItems.Add(aStr);
    13301268                        for i := 0 to uSelectedItems.Count - 1 do
     
    13391277                          end;
    13401278                        memOrder.Text := Responses.OrderText;
    1341                       edtResults.Height := 247;
    1342                       edtInfo.Height := 247;
    13431279                      if lvSelectionList.Items.Count > 0 then
    13441280                        begin
     
    13531289              end;
    13541290              //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;
    13551343          end;
    13561344        for i := 0 to lvSelectionList.Items.Count - 1 do
     
    13721360                      begin
    13731361                        NormalizeTopMosts;
    1374                         aTNSDays := TNSDaysBack;
    13751362                        aTNS :=
    13761363                          MessageBox(PChar(aTNSString + CRLF + CRLF +
    1377                                      'Do you wish to continue with this request for Type & Screen?'),
    1378                                      PChar('Type & Screen Entered in Past ' + IntToStr(TNSDaysBack) + ' Days'),
    1379                                      MB_YESNO);
     1364                             'Do you wish to cancel this request for Type & Screen?'),
     1365                             PChar('Type & Screen Entered in Past ' + IntToStr(TNSDaysBack) + ' Days'),
     1366                             MB_YESNO);
    13801367                        RestoreTopMosts;
    1381                         if aTNS = 7 then
     1368                        if aTNS = 6 then
    13821369                          begin
    13831370                            lvSelectionList.ItemIndex := i;
     
    13981385            pnlMessage.Visible := true;
    13991386            pnlDiagnosticTests.Caption := 'Diagnostic Tests*';
    1400           end;
     1387          end
     1388          else pnlDiagnosticTests.Caption := 'Diagnostic Tests';
    14011389        if ALabTest <> nil then
    14021390          begin
     
    14401428  finally                      //**SubTest
    14411429    alist.Free;
     1430    cList.Free;
    14421431    aTests.Free;
    14431432  end;
     
    17191708procedure TLabTest.LoadUrgency(CollType: string; AComboBox:TORComboBox);
    17201709var
    1721   i: integer;
     1710  i, PreviousSelectionIndex: integer;
     1711  PreviousSelectionString: String;
    17221712begin
    17231713  if UrgencyList.Count < 1 then Exit;
    17241714  with AComboBox do
    17251715    begin
     1716     PreviousSelectionIndex := -1;
     1717     PreviousSelectionString := SelText;
    17261718      Clear;
    17271719      for i := 0 to UrgencyList.Count - 1 do
     1720        begin
    17281721         if (CollType = 'LC') and (Piece(UrgencyList[i], U, 3) = '') then
    17291722           Continue
    17301723         else
    17311724           Items.Add(UrgencyList[i]);
     1725         if (PreviousSelectionString <> '') and (PreviousSelectionString = Piece(UrgencyList[i], U, 2)) then
     1726           PreviousSelectionIndex := i;
     1727        end;
    17321728      if (LRFURG <> '') and (ALabTest.ObtainUrgency) then
    17331729        SelectByID(LRFURG)
     1730      else if PreviousSelectionIndex > -1 then
     1731        ItemIndex := PreviousSelectionIndex
    17341732      else
    17351733        SelectByIEN(uDfltUrgency);
     
    18641862  i:integer;
    18651863  aborh: boolean;
    1866   aSpecimen, aSpecimenDate: string;
     1864  aSpecimen, aSpecimenUID, aSpecimenDate: string;
    18671865  aWantDateTime, aExpiredSpecimenDate: TFMDateTime;
    18681866begin
     
    18701868  aborh := false;
    18711869  aSpecimen := '';
     1870  aSpecimenUID := '';
    18721871  OutList.Clear;
    18731872  ExtractItems(OutList,Alist,'ABORH');
     
    18861885  OutList.Clear;
    18871886  ExtractSpecimen(OutList, uVBECList);
    1888   if OutList.Count > 0 then aSpecimen := OutList[0];
     1887  if OutList.Count > 0 then
     1888    begin
     1889      aSpecimen := Piece(OutList[0], '^',1);
     1890      aSpecimenUID := Piece(OutList[0], '^',2);
     1891    end;
    18891892  OutList.Clear;
    18901893  ExtractItems(OutList,AList,'SPECIMENS');
    18911894  aWantDateTime := calWantTime.FMDateTime;
    1892   aSpecimenDate := piece(aSpecimen,'^',1);
     1895  aSpecimenDate := aSpecimen;
    18931896  aExpiredSpecimenDate := 0;
    18941897  if Length(aSpecimenDate) > 0 then aExpiredSpecimenDate := StrToFloat(aSpecimenDate);
    1895 
    18961898  for i := 0 to OutList.Count - 1 do
    18971899    begin
    18981900      if (IntToStr(aLabTest.ItemID) = piece(OutList[i],'^',1)) and (piece(OutList[i],'^',2) = '1') then
    1899         if aSpecimen = '' then
    1900           begin
    1901             result := true;
    1902             exit;
    1903           end
    1904         else if (Length(calWantTime.Text) > 0) and (aExpiredSpecimenDate < aWantDateTime) then
    1905           begin
    1906             result := true;
    1907             exit;
    1908           end;
     1901        begin
     1902          if self.EvtID > 0 then
     1903            begin
     1904              result := true;
     1905              exit;
     1906            end;
     1907          if aSpecimen = '' then
     1908            begin
     1909              result := true;
     1910              exit;
     1911            end
     1912          else if (Length(calWantTime.Text) > 0) and (aExpiredSpecimenDate < aWantDateTime) then
     1913            begin
     1914              result := true;
     1915              exit;
     1916            end;
     1917        end;
    19091918    end;
    19101919end;
     
    19631972  TX_TOO_MANY_DAYS  = 'Maximum number of days allowed is ';
    19641973  TX_TOO_MANY_TIMES = 'For this frequency, the maximum number of times allowed is:  X';
    1965   //TX_NO_COMMENT     = 'A comment is required for this test and collection sample.';
    19661974  TX_NUMERIC_REQD   = 'A numeric value is required for urine volume';
    19671975  TX_DOSEDRAW_REQD  = 'Both DOSE and DRAW times are required for this order';
    19681976  TX_TDM_REQD       = 'A value for LEVEL is required for this order';
    1969   //TX_ANTICOAG_REQD  = 'You must specify an anticoagulant on this order.' ;
    19701977  TX_NO_COLLSAMPLE  = 'A collection sample MUST be specified';
    19711978  TX_NO_SPECIMEN    = 'A specimen MUST be specified';
     
    21892196  tmpImmTime, tmpTime: TFMDateTime;
    21902197  x, tmpORECALLType, tmpORECALLTime: string;
    2191 begin
     2198  j: integer;
     2199  havetest: boolean;
     2200begin
     2201  havetest := false;
     2202  for j := uSelectedItems.Count - 1 downto 0 do
     2203    begin
     2204      if not(lvSelectionList.Items[j] = nil) and (piece(uSelectedItems[j],'^',1) = '1') and ((length(calCollTime.Text) > 0) or (length(cboCollTime.Text) > 0)) then
     2205        begin
     2206          havetest := true;
     2207          Break;
     2208        end;
     2209    end;
     2210  //if (havetest = True) and (not(FOrderAction in [ORDER_QUICK, ORDER_EDIT])) then havetest := false;
    21922211  x := GetLastCollectionTime;
    21932212  tmpORECALLType := Piece(x, U, 1);
    21942213  tmpORECALLTime := Piece(x, U, 2);
    21952214  if CollType = 'SP' then
     2215    begin
     2216      cboColltime.Visible    := False;
     2217      txtImmedColl.Visible   := False;
     2218      pnlCollTimeButton.Visible   := False;
     2219      pnlCollTimeButton.TabStop := False;
     2220      calCollTime.Visible    := True;
     2221      calCollTime.Enabled    := True;
     2222      if FLastCollTime <> '' then
     2223        begin
     2224          calCollTime.Text := ValidCollTime(FLastColltime);
     2225          if IsFMDateTime(calCollTime.Text) then
     2226            begin
     2227              calCollTime.Text := FormatFMDateTime('mmm dd,yy@hh:nn', StrToFMDateTime(calColltime.Text));
     2228              calCollTime.FMDateTime := StrToFMDateTime(FLastCollTime);
     2229            end;
     2230        end
     2231      else if tmpORECALLTime <> '' then
     2232        begin
     2233          calCollTime.Text := ValidCollTime(tmpORECALLTime);
     2234          if IsFMDateTime(calCollTime.Text) then
     2235            begin
     2236              calCollTime.Text := FormatFMDateTime('mmm dd,yy@hh:nn', StrToFMDateTime(calColltime.Text));
     2237              calCollTime.FMDateTime := StrToFMDateTime(tmpORECALLTime);
     2238            end;
     2239        end
     2240      else if LRFDATE <> '' then
     2241        calCollTime.Text     := LRFDATE
     2242      else if not(FOrderAction in [ORDER_EDIT]) then
     2243        calCollTime.Text     := 'TODAY'
     2244      else if (havetest = false) then
     2245        calCollTime.Text     := 'TODAY';
     2246     if (havetest = false) and (RemoveCollTimeDefault = True) then
     2247        begin
     2248          calCollTime.Text := '';
     2249          calCollTime.FMDateTime := 0;
     2250        end;
     2251    end
     2252  else if CollType = 'WC' then
    21962253    begin
    21972254      cboColltime.Visible    := False;
     
    22032260      if FLastCollTime <> '' then
    22042261        begin
    2205           calCollTime.Text := ValidCollTime(FLastColltime);
     2262          calCollTime.Text := ValidColltime(FLastColltime);
    22062263          if IsFMDateTime(calCollTime.Text) then
    22072264            begin
    22082265              calCollTime.Text := FormatFMDateTime('mmm dd,yy@hh:nn', StrToFMDateTime(calColltime.Text));
    2209               calColltime.FMDateTime := StrToFMDateTime(FLastCollTime);
     2266              calCollTime.FMDateTime := StrToFMDateTime(FLastCollTime);
    22102267            end;
    22112268        end
    22122269      else if tmpORECALLTime <> '' then
    22132270        begin
    2214           calCollTime.Text := ValidCollTime(tmpORECALLTime);
     2271          calCollTime.Text := ValidColltime(tmpORECALLTime);
    22152272          if IsFMDateTime(calCollTime.Text) then
    22162273            begin
    22172274              calCollTime.Text := FormatFMDateTime('mmm dd,yy@hh:nn', StrToFMDateTime(calColltime.Text));
    2218               calColltime.FMDateTime := StrToFMDateTime(tmpORECALLTime);
     2275              calCollTime.FMDateTime := StrToFMDateTime(tmpORECALLTime);
    22192276            end;
    22202277        end
    22212278      else if LRFDATE <> '' then
    22222279        calCollTime.Text     := LRFDATE
    2223       else
    2224         calCollTime.Text     := 'TODAY';
    2225     end
    2226   else if CollType = 'WC' then
    2227     begin
    2228       cboColltime.Visible    := False;
    2229       txtImmedColl.Visible   := False;
    2230       pnlCollTimeButton.Visible   := False;
    2231       pnlCollTimeButton.TabStop := False;
    2232       calCollTime.Visible    := True;
    2233       calColltime.Enabled    := True;
    2234       if FLastCollTime <> '' then
    2235         begin
    2236           calCollTime.Text := ValidColltime(FLastColltime);
    2237           if IsFMDateTime(calCollTime.Text) then
    2238             begin
    2239               calCollTime.Text := FormatFMDateTime('mmm dd,yy@hh:nn', StrToFMDateTime(calColltime.Text));
    2240               calColltime.FMDateTime := StrToFMDateTime(FLastCollTime);
    2241             end;
    2242         end
    2243       else if tmpORECALLTime <> '' then
    2244         begin
    2245           calCollTime.Text := ValidColltime(tmpORECALLTime);
    2246           if IsFMDateTime(calCollTime.Text) then
    2247             begin
    2248               calCollTime.Text := FormatFMDateTime('mmm dd,yy@hh:nn', StrToFMDateTime(calColltime.Text));
    2249               calColltime.FMDateTime := StrToFMDateTime(tmpORECALLTime);
    2250             end;
    2251         end
    2252       else if LRFDATE <> '' then
    2253         calCollTime.Text     := LRFDATE
    2254       else
     2280      else if not(FOrderAction in [ORDER_EDIT]) then
    22552281        calCollTime.Text     := 'NOW';
     2282      if (havetest = false) and (RemoveCollTimeDefault = True) then
     2283        begin
     2284          calCollTime.Text := '';
     2285          calCollTime.FMDateTime := 0;
     2286        end;
    22562287    end
    22572288  else if CollType = 'LC' then
     
    22742305      else
    22752306        cboCollTime.ItemIndex := 0;
     2307      if (havetest = false) and (RemoveCollTimeDefault = True) then
     2308        begin
     2309          cboCollTime.Text := '';
     2310        end;
    22762311    end
    22772312  else if CollType = 'I' then
     
    22792314      cboColltime.Visible    := False;
    22802315      calCollTime.Visible    := False;
    2281       calColltime.Enabled    := False;
     2316      calCollTime.Enabled    := False;
    22822317      txtImmedColl.Visible   := True;
    22832318      pnlCollTimeButton.Visible   := True;
     
    22912326      else if LRFDATE <> '' then
    22922327        tmpTime := StrToFMDateTime(LRFDATE);
    2293 
    22942328      if tmpTime > tmpImmTime then
    22952329        begin
     
    23012335          calCollTime.FMDateTime := GetDefaultImmCollTime;
    23022336          txtImmedColl.Text      := FormatFMDateTime('mmm dd,yy@hh:nn', calCollTime.FMDateTime);
     2337        end;
     2338      if (havetest = false) and (RemoveCollTimeDefault = True) then
     2339        begin
     2340          calCollTime.Text := '';
     2341          calCollTime.FMDateTime := 0;
     2342          txtImmedColl.Text := '';
    23032343        end;
    23042344    end;
     
    23872427begin
    23882428  inherited;
     2429  cboReasons.Text := StringReplace(cboReasons.Text,CRLF,'  ',[rfReplaceAll]);
    23892430  if (length(cboReasons.Text) > 75) then
    23902431    begin
     
    24142455var
    24152456  i: integer;
    2416   text : string;
    24172457  ListItem: TListItem;
    2418   aCollTime,aTypeScreen,aStr,aModifier,aSpecimen,aTestYes,x,aName,aTNSString: string;
     2458  aCollTime,aTypeScreen,aStr,aModifier,aSpecimen,aSpecimenUID,aSpecimenReq,aTestYes,x,aName,aTNSString, aUrgText: string;
    24192459  aList: TStringList;
    2420   curAdd,AnInstance,aTNS,aTNSDays: Integer;
     2460  curAdd,aTNS: Integer;
    24212461  sub,sub1: string;
    2422   AResponse: TResponse;
     2462  aChanging: Boolean;
    24232463begin
    24242464  if cboAvailTest.ItemID = '' then Exit;
    24252465  aList := TStringList.Create;
     2466  aChanging := changing;
    24262467  try
    24272468    ALabTest := nil;
    24282469    aTypeScreen := '';
    2429     aSpecimen := '^';
     2470    aSpecimen := '';
     2471    aSpecimenUID := '';
     2472    aSpecimenReq := '';
    24302473    aTestYes := '1';
    24312474    aModifier := '';
    24322475    changing := true;
    24332476    tQuantity.Text := '';
     2477    changing := aChanging;
    24342478    sub1 := '';
    24352479    cboModifiers.ItemIndex := -1;
     
    24392483    ALabTest := TLabTest.Create(cboAvailTest.ItemID, Responses);
    24402484    sub := GetSubtype(ALabTest.TestName);
    2441     with CtrlInits do
    2442         begin
    2443           SetControl(cboCollType, 'Collection Types');
    2444           LoadCollType(cboCollType);
    2445           if FLastCollType <> '' then
    2446             cboCollType.SelectByID(FLastCollType)
    2447           else if uDfltCollType <> '' then
    2448             cboCollType.SelectByID(uDfltCollType)
    2449           else if OrderForInpatient then
    2450             if (ALabTest.LabCanCollect) then
    2451               cboCollType.SelectByID('LC')
    2452             else
    2453               cboCollType.SelectByID('WC')
    2454           else
    2455             cboCollType.SelectByID('SP');
    2456           SetupCollTimes(cboCollType.ItemID);
    2457         end;
     2485    {if not(FOrderAction in [ORDER_COPY, ORDER_EDIT, ORDER_QUICK]) then
     2486      DetermineCollectionDefaults(Responses); }
     2487    DetermineCollectionDefaults(Responses);
    24582488    with cboAvailTest do
    24592489      begin
    2460         if (Length(ItemID) = 0) or (ItemID = '0') then Exit;
     2490        if (Length(ItemID) = 0) or (ItemID = '0') then
     2491          begin
     2492            changing := aChanging;
     2493            Exit;
     2494          end;
    24612495        FLastLabID := ItemID ;
    24622496        FLastItemID := ItemID;
     
    24672501              lvSelectionList.Items[i].Selected := true;
    24682502              lvSelectionListClick(self);
     2503              changing := aChanging;
    24692504              Exit;
    24702505            end;
    2471         Changing := True;
    2472         Changing := False;
    24732506        ExtractTypeScreen(aList, uVBECList);
    24742507        if aList.Count > 0 then aTypeScreen := aList[0];
    24752508        aList.Clear;
    24762509        aTNSString := '';
    2477         if (StrToInt(aTypeScreen) = cboAvailTest.ItemID) and (uTNSOrders.Count > 0) then
     2510        if (Changing = false) and (StrToInt(aTypeScreen) = cboAvailTest.ItemID) and (uTNSOrders.Count > 0) then
    24782511          begin
    24792512            for i := 0 to uTNSOrders.Count - 1 do
     
    24822515              begin
    24832516                NormalizeTopMosts;
    2484                 aTNSDays := TNSDaysBack;
    24852517                aTNS :=
    24862518                  MessageBox(PChar(aTNSString + CRLF + CRLF +
    2487                              'Do you wish to continue?'),
    2488                              PChar('Type & Screen Entered in Past ' + IntToStr(TNSDaysBack) + ' Days'),
    2489                              MB_YESNO);
     2519                   'Do you wish to cancel this request for Type & Screen?'),
     2520                   PChar('Type & Screen Entered in Past ' + IntToStr(TNSDaysBack) + ' Days'),
     2521                   MB_YESNO);
    24902522                RestoreTopMosts;
    2491                 if aTNS = 7 then
     2523                if aTNS = 6 then
    24922524                  begin
    24932525                    cboAvailTest.ItemIndex := -1;
     
    25152547              end;
    25162548        end;
    2517         Changing := False;
    25182549      end;
    25192550    if LRORDERMODE = TORDER_MODE_DIAG then
    25202551      begin
    25212552        if Length(calWantTime.Text) > 0 then Responses.Update('DATETIME',1,ValidCollTime(calWantTime.Text),calWantTime.Text);
    2522         with cboCollType do if Length(ItemID) > 0 then
     2553        if Length(cboUrgency.Text) > 0 then Responses.Update('URGENCY',1,cboUrgency.ItemID,cboUrgency.Text)
     2554        else if changing = false then
    25232555          begin
    2524             Responses.Update('COLLECT', 1, ItemID, ItemID) ;
    2525             FLastCollType := ItemID;
    2526           end;
    2527         if Length(cboUrgency.Text) > 0 then Responses.Update('URGENCY',1,cboUrgency.ItemID,cboUrgency.Text)
    2528         else
    2529           begin
    2530             cboUrgency.ItemIndex := 1;
     2556            for i := 0 to cboUrgency.Items.Count - 1 do
     2557              begin
     2558                aUrgText := cboUrgency.Items[i];
     2559                if aUrgText = '9^ROUTINE' then    // Find urgency default of ROUTINE
     2560                  begin
     2561                    cboUrgency.ItemIndex := i;
     2562                    break;
     2563                  end;
     2564              end;
    25312565            Responses.Update('URGENCY',1,cboUrgency.ItemID,cboUrgency.Text);
    25322566          end;
    25332567        if Length(memDiagComment.Text) > 0 then Responses.Update('COMMENT',1,memDiagComment.Text,memDiagComment.Text);
    25342568        if Length(cboReasons.Text) > 0 then Responses.Update('REASON',1,cboReasons.Text,cboReasons.Text);
     2569        with cboCollTime do
     2570
    25352571        if cboCollType.ItemID = 'LC' then
    25362572          begin
     
    25472583                end;
    25482584          end
    2549           else
    2550             begin
    2551               with calCollTime do
    2552                 if FMDateTime > 0 then
    2553                   begin
    2554                     Responses.Update('START', 1, ValidCollTime(Text), Text);
    2555                     FLastColltime := ValidCollTime(Text);
    2556                   end
    2557                 else
    2558                   begin
    2559                     Responses.Update('START', 1, '', '') ;
    2560                     FLastCollTime := '';
    2561                   end;
    2562             end;
    2563           if Length(cboCollType.Text) > 0 then Responses.Update('COLLECT',1,cboCollType.ItemID,cboCollType.ItemID);
     2585        else
     2586          begin
     2587            with calCollTime do
     2588              if FMDateTime > 0 then
     2589                begin
     2590                  Responses.Update('START', 1, ValidCollTime(Text), Text);
     2591                  FLastColltime := ValidCollTime(Text);
     2592                end
     2593              else
     2594                begin
     2595                  Responses.Update('START', 1, '', '') ;
     2596                  FLastCollTime := '';
     2597                end;
     2598          end;
     2599        if Length(cboCollType.Text) > 0 then Responses.Update('COLLECT',1,cboCollType.ItemID,cboCollType.ItemID);
    25642600      end;
    2565     if length(cboCollTime.ItemID) > 0 then aCollTime := cboCollTime.Items[cboCollTime.ItemIndex];
    25662601    uTestSelected := true;
    25672602    with lvSelectionList do
     
    25832618          end;
    25842619      end;
    2585     aStr := aTestYes + '^' + IntToStr(aLabTest.TestID) + '^' + tQuantity.Text + '^' + aModifier + '^' + aSpecimen + '^' + aCollTime + '^' + cboCollType.Text + '^' + IntToStr(aLabTest.ItemID);  //aSpecimen has 2 pieces
     2620    aStr := aTestYes + '^' + IntToStr(aLabTest.TestID) + '^' + tQuantity.Text + '^' + aModifier + '^' + aSpecimenReq + '^' + aSpecimen + '^' + aSpecimenUID + '^' + IntToStr(aLabTest.ItemID);
    25862621    uSelectedItems.Add(aStr);
    25872622    CurAdd := 1;
     
    26002635    aList.Free;
    26012636  end;
    2602   edtResults.Height := 247;
    2603   edtInfo.Height := 247;
    26042637  if lvSelectionList.Items.Count > 0 then
    26052638    begin
     
    26182651  aMSBOS,aMSBOSContinue,curAdd,AnInstance: integer;
    26192652  sub,sub1: string;
    2620   AResponse: TResponse;
    26212653  ListItem: TListItem;
    2622   aTypeScreen,aSpecimen,aTestYes,aStr,aMsg,aModifier,x,x1,aReason,aSurgery,aCollTime,aCollSave,aName: String;
     2654  aTypeScreen,aSpecimen,aSpecimenUID,aSpecimenReq,aTestYes,aStr,aMsg,aModifier,x,x1,aReason,aSurgery,aCollTime,aCollSave,aName,aUrgText: String;
     2655  aChanging: Boolean;
    26232656begin
    26242657  if cboAvailComp.ItemID = '' then Exit;
     
    26262659  aTests := TStringList.Create;
    26272660  sub1 := '';
     2661  aChanging := changing;
    26282662  try
    26292663    DisableDiagTestControls;
     
    26342668        tQuantity.Text := '';
    26352669        cboModifiers.ItemIndex := -1;
    2636         changing := false;
     2670        changing := aChanging;
    26372671      end;
    26382672    LRORDERMODE := TORDER_MODE_COMP;
     
    26522686        ALabTest := TLabTest.Create(ItemID, Responses);
    26532687        sub := GetSubtype(ALabTest.TestName);
    2654         Changing := False;
     2688        changing := aChanging;
    26552689        StatusText('');
    26562690      end;
    2657     //Check for and display any associated Lab Results
    26582691    aList.Clear;
    26592692    TestAdded := 0;
    26602693    getTest := 0;
    2661     ExtractTests(aList, uVBECList);   //Get Results associated with ordered components
     2694    ExtractTests(aList, uVBECList);   //Get Lab Results associated with ordered components
    26622695      for j := 0 to aList.Count - 1 do
    26632696        begin
     
    26832716      if TestAdded = 1 then
    26842717        begin
    2685           edtResults.Clear;
    26862718          aTests.Clear;
    26872719          GetPatientBloodResults(aTests, Patient.DFN, uTestsForResults);
    2688           QuickCopy(ATests,edtResults);
    2689           if edtResults.Lines.Count > 0 then TabResults.Caption := 'Lab Results Available';
    2690           uRaw.Clear;
    2691           GetPatientBloodResultsRaw(uRaw, Patient.DFN, uTestsForResults);
     2720          if aTests.Count > 0 then
     2721            begin
     2722              edtResults.Clear;
     2723              QuickCopy(ATests,edtResults);
     2724              TabResults.Caption := 'Lab Results Available';
     2725              uRaw.Clear;
     2726              GetPatientBloodResultsRaw(uRaw, Patient.DFN, uTestsForResults);
     2727            end;
    26922728        end;
    26932729      CurAdd := 1;
     
    26992735        end;
    27002736    aTypeScreen := '';
    2701     aSpecimen := '^';
     2737    aSpecimen := '';
     2738    aSpecimenUID := '';
     2739    aSpecimenReq := '';
    27022740    aTestYes := '0';
    27032741    aReason := '';
     
    27092747    aList.Clear;
    27102748    ExtractSpecimen(aList, uVBECList);
    2711     if aList.Count > 0 then aSpecimen := aList[0];
     2749    if aList.Count > 0 then
     2750      begin
     2751        aSpecimen := piece(aList[0], '^', 1);
     2752        aSpecimenUID := piece(aList[0], '^', 2);
     2753      end;
     2754    if (cboSurgery.ItemID = '') and (length(cboSurgery.Text) > 0) then
     2755      begin
     2756        for i := 0 to cboSurgery.Items.Count - 1 do
     2757          if uppercase(cboSurgery.Text) = uppercase(piece(cboSurgery.Items[i],'^',2)) then
     2758            begin
     2759              cboSurgery.ItemIndex := i;
     2760              Break;
     2761            end;
     2762      end;
    27122763    if length(cboModifiers.ItemID) > 0 then aModifier := cboModifiers.Items[cboModifiers.ItemIndex];
    27132764    if length(cboReasons.ItemID) > 0 then aReason := cboReasons.Items[cboReasons.ItemIndex];
    27142765    if length(cboSurgery.ItemID) > 0 then aSurgery := cboSurgery.Items[cboSurgery.ItemIndex];
    2715     if length(cboCollTime.ItemID) > 0 then aCollTime := cboCollTime.Items[cboCollTime.ItemIndex];
    2716     if Length(cboSurgery.ItemID) > 0 then
    2717       begin
     2766    if (Length(cboSurgery.ItemID) > 0) and (length(tQuantity.Text) > 0) and (strToInt(tQuantity.Text) > 0) then
     2767      begin
     2768        uChangingMSBOS := true;
     2769        cboSurgeryChange(self);
     2770        uChangingMSBOS := false;
     2771        if cboAvailComp.ItemIndex = -1 then Exit;
    27182772        aList.Clear;
    27192773        ExtractMSBOS(aList, uVBECList);    //Get maximum units for selected Surgey
     
    27212775          begin
    27222776            if (StrToInt(piece(aList[i],'^',1)) = aLabTest.ItemID)
    2723              and (piece(aList[i],'^',3) = cboSurgery.Text) then
     2777             and (uppercase((piece(aList[i],'^',3))) = uppercase(cboSurgery.Text)) then
    27242778              begin
    27252779                aMSBOS := StrToInt(piece(aList[i],'^',4));
     
    27312785                      aMSBOSContinue :=
    27322786                        MessageBox(PChar('The number of units ordered (' + tQuantity.Text +
    2733                                    ') for ' + aLabTest.TestName + ' exceeds the maximum number of units ('
    2734                                    + IntToStr(aMSBOS) +
    2735                                    ') for the ' + cboSurgery.text +
    2736                                    ' surgical procedure selected.' + CRLF + CRLF + 'Do you wish to continue?'),
    2737                                    PChar('Maximum Number of Units Exceeded'),
    2738                                    MB_YESNO);
     2787                         ') for ' + aLabTest.TestName + ' Exceeds the maximum number recommended ('
     2788                         + IntToStr(aMSBOS) +
     2789                         ') for the ' + cboSurgery.text +
     2790                         ' surgical procedure.' + CRLF +
     2791                         'If you need to order more than the maximum number of units, please enter a justification in the Comment box.'
     2792                          + CRLF + CRLF + 'Edit the Blood component Quantity?'),
     2793                         PChar('Maximum Number of Units Exceeded'),
     2794                         MB_YESNO);
    27392795                      RestoreTopMosts;
    27402796                    end;
    2741                     if aMSBOSContinue = 7 then
     2797                    if aMSBOSContinue = 6 then
    27422798                      begin
    27432799                        ShowMsg(cboAvailComp.Text + ' has NOT been added to this request.');
     
    27482804          end;
    27492805      end;
    2750     if (uTNSOrders.Count < 1) then // SpecimenNeeded(aList, uVBECList, aLabTest.ItemID) then  //check to see if type and screen is needed
     2806    if (uTNSOrders.Count < 1) and (SpecimenNeeded(aList, uVBECList, aLabTest.ItemID)) then  //check to see if type and screen is needed CQ 17349
    27512807      begin
    27522808        uGetTnS := 1;
     
    27722828        if (StrToInt(piece(aList[i],'^',1)) = aLabTest.ItemID) then
    27732829          begin
    2774             aSpecimen := piece(aList[i],'^',2) + '^' + aSpecimen;
     2830            aSpecimenReq := piece(aList[i],'^',2);
     2831            if (SpecimenNeeded(aList, uVBECList, aLabTest.ItemID)) then
     2832              aSpecimenUID := '';
    27752833            break;
    27762834          end;
     
    27942852        ListItem.SubItems.Add(piece(cboAvailComp.Items[cboAvailComp.ItemIndex],'^',1));
    27952853      end;
    2796       aStr := aTestYes + '^' + IntToStr(aLabTest.TestID) + '^' + tQuantity.Text + '^' + aModifier + '^' + aSpecimen + '^' + IntToStr(aLabTest.ItemID);  //aSpecimen has 2 pieces additional pieces added for Tests
     2854      aStr := aTestYes + '^' + IntToStr(aLabTest.TestID) + '^' + tQuantity.Text + '^' + aModifier + '^' + aSpecimenReq + '^' + aSpecimen + '^' + aSpecimenUID + '^' + IntToStr(aLabTest.ItemID);
    27972855      uSelectedItems.Add(aStr);
    27982856      CurAdd := 1;
     
    28162874                else
    28172875                  begin
    2818                     cboUrgency.ItemIndex := 1;
     2876                    cboUrgency.ItemIndex := 2;
     2877                    for j := 0 to cboUrgency.Items.Count - 1 do
     2878                      begin
     2879                        aUrgText := cboUrgency.Items[j];
     2880                        if aUrgText = '9^ROUTINE' then    // Find urgency default of ROUTINE
     2881                          begin
     2882                            cboUrgency.ItemIndex := i;
     2883                            break;
     2884                          end;
     2885                      end;
    28192886                    Responses.Update('URGENCY',1,cboUrgency.ItemID,cboUrgency.Text);
    28202887                  end;
     
    28362903      pnlMessage.Visible := true;
    28372904      pnlDiagnosticTests.Caption := 'Diagnostic Tests*';
    2838     end;
    2839   {if uGetTnS = 1 then
    2840     begin
    2841       if responses.QuickOrder < 1 then
    2842         begin
    2843           for i := 1 to cboAvailTest.Items.Count - 1 do
    2844             begin
    2845               if piece(cboAvailTest.Items[i],'^',1) = aTypeScreen then
    2846                 begin
    2847                   if piece(aSpecimen,'^',1) = '1' then
    2848                     begin
    2849                       cboCollTime.Text := calWantTime.Text;
    2850                       aCollSave := cboCollTime.Text + '^' + cboCollTime.ItemID + '^' + cboCollType.Text + '^' + cboCollType.ItemID;
    2851                       cboCollTime.Text := '';
    2852                       cboCollType.Text := '';
    2853                       uSpecimen := 1;
    2854                     end;
    2855                   cboModifiers.Text := '';
    2856                   cboAvailTest.SelectByID(aTypeScreen);
    2857                   cboTests.SelectByID(aTypeScreen);
    2858                   cboTestsClick(self);
    2859                   //cboAvailTestSelect(Self);
    2860                   uSpecimen := 0;
    2861                   cboCollTime.Text := piece(aCollSave,'^',1);
    2862                   cboCollType.Text := piece(aCollSave,'^',3);
    2863                   aCollSave := '';
    2864                   break;
    2865                 end;
    2866             end;
    2867           aMsg := 'An order for Type and Screen has been added to this request' + '.';
    2868         end
    2869         else
    2870           begin
    2871             lblTNS.Caption := 'TYPE + SCREEN must be added to order';
    2872             lblTNS.Visible := true;
    2873             memMessage.Text := 'TYPE + SCREEN must be added to order';
    2874             memMessage.Visible := false;
    2875             pnlMessage.Visible := true;
    2876           end;
    2877       end;
    2878   if (uGetTnS = 1) then
    2879     begin
    2880       if length(aMsg) > 0 then aMsg := aMsg + crlf + crlf;
    2881       ShowMsg(aMsg);
    2882     end;  }
    2883   edtResults.Height := 247;
    2884   edtInfo.Height := 247;
     2905    end
     2906    else pnlDiagnosticTests.Caption := 'Diagnostic Tests';
    28852907  if lvSelectionList.Items.Count > 0 then
    28862908    begin
     
    28992921
    29002922procedure TfrmODBBank.DisableComponentControls;
     2923var
     2924  j: integer;
    29012925begin
    29022926  lblQuantity.Enabled := false;
     
    29042928  lblModifiers.Enabled := false;
    29052929  cboModifiers.Enabled := false;
     2930  lblQuantity.Caption := 'Quantity';
     2931  lblWanted.Caption := 'Date/Time Wanted';
     2932  lblReason.Caption := 'Reason for Request';
    29062933  cboAvailComp.ItemIndex := -1;
     2934  for j := uSelectedItems.Count - 1 downto 0 do
     2935    begin
     2936      if piece(uSelectedItems[j],'^',1) = '0' then
     2937        begin
     2938          lblReason.Caption := 'Reason for Request*';
     2939          lblWanted.Caption := 'Date/Time Wanted*';
     2940          Break;
     2941        end;
     2942    end;
    29072943end;
    29082944
     
    29132949  lblModifiers.Enabled := true;
    29142950  cboModifiers.Enabled := true;
     2951  lblQuantity.Caption := 'Quantity*';
     2952  lblWanted.Caption := 'Date/Time Wanted*';
     2953  lblReason.Caption := 'Reason for Request*';
    29152954  if not(changing) then
    29162955    if not(uSelUrgency = 'PRE-OP') then
     
    29192958          cboUrgency.SelectByID(IntToStr(uDfltUrgency));
    29202959  if cboUrgency.Text = 'PRE-OP' then
    2921     begin
    2922       lblSurgery.Enabled := true;
    2923       cboSurgery.Enabled := true;
    2924       lblSurgery.Caption := 'Surgery*';
    2925     end
    2926     else
    2927       begin
    2928         lblSurgery.Enabled := false;
    2929         cboSurgery.Enabled := false;
    2930         lblSurgery.Caption := 'Surgery';
    2931       end;
     2960        begin
     2961          lblSurgery.Enabled := true;
     2962          cboSurgery.Enabled := true;
     2963          lblSurgery.Caption := 'Surgery*';
     2964        end
     2965      else
     2966        begin
     2967          if Length(cboSurgery.Text) > 0 then
     2968            begin
     2969              lblSurgery.Enabled := true;
     2970              cboSurgery.Enabled := true;
     2971              lblSurgery.Caption := 'Surgery*';
     2972            end
     2973            else
     2974            begin
     2975              lblSurgery.Enabled := false;
     2976              cboSurgery.Enabled := false;
     2977              lblSurgery.Caption := 'Surgery';
     2978              cboSurgery.ItemIndex := -1;
     2979              Responses.Update('MISC',1,cboSurgery.Text,cboSurgery.Text);
     2980            end;
     2981        end;
     2982
    29322983  lblDiagComment.Enabled := true;
    29332984end;
    29342985
    29352986procedure TfrmODBBank.DisableDiagTestControls;
    2936 begin
    2937   lblCollTime.Enabled := false;
    2938   calCollTime.Enabled := false;
    2939   cboCollTime.Enabled := false;
    2940   lblCollType.Enabled := false;
    2941   cboCollType.Enabled := false;
    2942   cmdImmedColl.Enabled := false;
     2987var
     2988  i,j: integer;
     2989  diagflg: boolean;
     2990begin
     2991  diagflg := false;
     2992  for i := 0 to uSelectedItems.Count - 1 do
     2993    begin
     2994      if (piece(uSelectedItems[i],'^',1) = '1') then
     2995        begin
     2996          diagflg := true;
     2997          Break;
     2998        end;
     2999    end;
     3000  if diagflg = false then
     3001    begin
     3002      lblCollTime.Enabled := false;
     3003      calCollTime.Enabled := false;
     3004      cboCollTime.Enabled := false;
     3005      lblCollType.Enabled := false;
     3006      cboCollType.Enabled := false;
     3007      cmdImmedColl.Enabled := false;
     3008    end;
     3009  lblCollTime.Caption := 'Collection Date/Time';
     3010  lblCollType.Caption := 'Collection Type';
    29433011  cboAvailTest.ItemIndex := -1;
    2944   cboAvailTest.InitLongList('');
     3012  for j := uSelectedItems.Count - 1 downto 0 do
     3013    begin
     3014      if piece(uSelectedItems[j],'^',1) = '1' then
     3015        begin
     3016          lblCollTime.Caption := 'Collection Date/Time*';
     3017          lblCollType.Caption := 'Collection Type*';
     3018          Break;
     3019        end;
     3020    end;
    29453021end;
    29463022
     
    29533029  cboCollType.Enabled := true;
    29543030  cmdImmedColl.Enabled := true;
     3031  lblCollTime.Caption := 'Collection Date/Time*';
     3032  lblCollType.Caption := 'Collection Type*';
    29553033  if not(changing) then
    29563034    if not(uSelUrgency = 'PRE-OP') then
     
    29713049begin
    29723050  if ALabTest = nil then exit;
    2973   if ALabTest.LabSubscript = 'BB' then exit;
    2974   calCollTime.Clear;
    2975   cboCollTime.Clear;
    29763051  calCollTime.Enabled := True;
    29773052  lblCollTime.Enabled := True;
     
    30243099              begin
    30253100                calCollTime.Enabled := False;
    3026                 if RespStart <> nil then txtImmedColl.Text := RespStart.EValue;
     3101                cboCollType.SelectByID('I');
     3102                SetupCollTimes('I');
     3103                //cboCollTypeClick(self);
     3104                //txtImmedColl.Enabled := True;
     3105                if RespStart <> nil then
     3106                  begin
     3107                    txtImmedColl.Text := RespStart.EValue;
     3108                  end;
    30273109              end;
    30283110        end
     
    30323114end;
    30333115
     3116procedure TfrmODBBank.cboAvailTestEnter(Sender: TObject);
     3117var
     3118  j: integer;
     3119begin
     3120  inherited;
     3121  if Length(cboAvailTest.Text) > 0 then Exit;
     3122  for j := uSelectedItems.Count - 1 downto 0 do
     3123    begin
     3124      if not(lvSelectionList.Items[j] = nil) and (piece(uSelectedItems[j],'^',1) = '1') then
     3125        begin
     3126          lvSelectionList.Items[j].Selected := true;
     3127          lvSelectionListClick(self);
     3128          Break;
     3129        end;
     3130    end;
     3131end;
     3132
    30343133procedure TfrmODBBank.cboAvailTestExit(Sender: TObject);
    30353134begin
    30363135  inherited;
    3037   if (Length(cboAvailTest.ItemID) = 0) or (cboAvailTest.ItemID = '0') then Exit;
     3136  if (Length(cboAvailTest.Text)>0) and (Length(cboAvailTest.ItemID) = 0) or (cboAvailTest.ItemID = '0') then
     3137    begin
     3138      ShowMsg('Invalid Test Selection. Please select a valid Test.');
     3139      cboAvailTestSelect(cboAvailTest);
     3140      cboAvailTest.SetFocus;
     3141      Exit;
     3142    end;
    30383143  if cboAvailTest.ItemID = FLastLabID then Exit;
    3039   cboAvailTestSelect(cboAvailTest);
    3040   cboAvailTest.SetFocus;
    3041   PostMessage(Handle, WM_NEXTDLGCTL, 0, 0);
    3042 end;
    3043 
    3044 procedure TfrmODBBank.cboAvailCompChange(Sender: TObject);
    3045 begin
    3046   inherited;
    3047   changing := true;
    3048   changing := false;
     3144  if not (Length(cboAvailTest.ItemID) = 0) then cboAvailTestSelect(cboAvailTest);
     3145end;
     3146
     3147procedure TfrmODBBank.cboAvailCompEnter(Sender: TObject);
     3148var
     3149  j: integer;
     3150begin
     3151  inherited;
     3152  if Length(cboAvailComp.Text) > 0 then Exit;
     3153  for j := uSelectedItems.Count - 1 downto 0 do
     3154    begin
     3155      if not(lvSelectionList.Items[j] = nil) and (piece(uSelectedItems[j],'^',1) = '0') then
     3156        begin
     3157          lvSelectionList.Items[j].Selected := true;
     3158          lvSelectionListClick(self);
     3159          Break;
     3160        end;
     3161    end;
    30493162end;
    30503163
     
    30523165begin
    30533166  inherited;
    3054   if (Length(cboAvailComp.ItemID) = 0) or (cboAvailComp.ItemID = '0') then Exit;
     3167  if (Length(cboAvailComp.Text)>0) and (Length(cboAvailComp.ItemID) = 0) or (cboAvailComp.ItemID = '0') then
     3168    begin
     3169      ShowMsg('Invalid Component selection. Please select a valid Component.');
     3170      cboAvailCompSelect(cboAvailComp);
     3171      cboAvailComp.SetFocus;
     3172      Exit;
     3173    end;
    30553174  if cboAvailComp.ItemID = FLastLabID then Exit;
    3056   cboAvailCompSelect(cboAvailComp);
    3057   cboAvailComp.SetFocus;
    3058   PostMessage(Handle, WM_NEXTDLGCTL, 0, 0);
     3175  if not (Length(cboAvailComp.ItemID) = 0) then cboAvailCompSelect(cboAvailComp);
    30593176end;
    30603177
     
    31303247end;
    31313248
     3249procedure TfrmODBBank.pnlBloodComponentsClick(Sender: TObject);
     3250begin
     3251  inherited;
     3252  cboAvailComp.SetFocus;
     3253end;
     3254
     3255procedure TfrmODBBank.pnlBloodComponentsEnter(Sender: TObject);
     3256begin
     3257  inherited;
     3258  pnlBloodComponents.Color := clActiveborder;
     3259end;
     3260
     3261procedure TfrmODBBank.pnlBloodComponentsExit(Sender: TObject);
     3262begin
     3263  inherited;
     3264  pnlBloodcomponents.Color := clBtnFace;
     3265end;
     3266
     3267procedure TfrmODBBank.pnlDiagnosticTestsClick(Sender: TObject);
     3268begin
     3269  inherited;
     3270  cboAvailTest.SetFocus;
     3271end;
     3272
     3273procedure TfrmODBBank.pnlDiagnosticTestsEnter(Sender: TObject);
     3274begin
     3275  inherited;
     3276  pnlDiagnosticTests.Color := clActiveBorder;
     3277end;
     3278
     3279procedure TfrmODBBank.pnlDiagnosticTestsExit(Sender: TObject);
     3280begin
     3281  inherited;
     3282  pnlDiagnosticTests.Color := clBtnFace;
     3283end;
     3284
    31323285procedure TfrmODBBank.cboCollTimeChange(Sender: TObject);
    31333286var
     
    31633316end;
    31643317
     3318procedure TfrmODBBank.cboCollTimeEnter(Sender: TObject);
     3319var
     3320  j: integer;
     3321begin
     3322  inherited;
     3323  if Length(cboAvailTest.Text) > 0 then Exit;
     3324  for j := uSelectedItems.Count - 1 downto 0 do
     3325    begin
     3326      if not(lvSelectionList.Items[j] = nil) and (piece(uSelectedItems[j],'^',1) = '1') then
     3327        begin
     3328          lvSelectionList.Items[j].Selected := true;
     3329          lvSelectionListClick(self);
     3330          Break;
     3331        end;
     3332    end;
     3333end;
     3334
    31653335procedure TfrmODBBank.cboCollTypeChange(Sender: TObject);
    31663336begin
     
    31803350  SetupCollTimes(cboCollType.ItemID);
    31813351  if Length(cboCollType.Text) > 0 then Responses.Update('COLLECT',1,cboCollType.ItemID,cboCollType.ItemID);
    3182   FLastCollType := cboCollType.ItemID;
    31833352  calCollTimeChange(self);
     3353end;
     3354
     3355procedure TfrmODBBank.cboCollTypeClick(Sender: TObject);
     3356begin
     3357  inherited;
     3358  FOrderAction := 0;
     3359end;
     3360
     3361procedure TfrmODBBank.cboCollTypeEnter(Sender: TObject);
     3362var
     3363  j: integer;
     3364begin
     3365  inherited;
     3366  if Length(cboAvailTest.Text) > 0 then Exit;
     3367  for j := uSelectedItems.Count - 1 downto 0 do
     3368    begin
     3369      if not(lvSelectionList.Items[j] = nil) and (piece(uSelectedItems[j],'^',1) = '1') then
     3370        begin
     3371          lvSelectionList.Items[j].Selected := true;
     3372          lvSelectionListClick(self);
     3373          Break;
     3374        end;
     3375    end;
    31843376end;
    31853377
     
    32263418end;
    32273419
     3420procedure TfrmODBBank.cboModifiersEnter(Sender: TObject);
     3421var
     3422  j: integer;
     3423begin
     3424  inherited;
     3425  if Length(cboAvailComp.Text) > 0 then Exit;
     3426  for j := uSelectedItems.Count - 1 downto 0 do
     3427    begin
     3428      if not(lvSelectionList.Items[j] = nil) and (piece(uSelectedItems[j],'^',1) = '0') then
     3429        begin
     3430          lvSelectionList.Items[j].Selected := true;
     3431          lvSelectionListClick(self);
     3432          Break;
     3433        end;
     3434    end;
     3435end;
     3436
    32283437procedure TfrmODBBank.LoadModifiers(AComboBox:TORComboBox);
    32293438var
     
    32573466    begin
    32583467      Clear;
    3259       for i := 0 to uUrgencyList.Count - 1 do
     3468      {for i := 0 to uUrgencyList.Count - 1 do
    32603469         if (piece(uUrgencyList[i],'^',2) = 'STAT') and (StatAllowed(Patient.DFN) = false) then
    32613470           Continue
    32623471         else
    3263            Items.Add(uUrgencyList[i]);
     3472           Items.Add(uUrgencyList[i]); }
     3473      for i := 0 to uUrgencyList.Count - 1 do
     3474        Items.Add(uUrgencyList[i]);
    32643475    end;
    32653476end;
     
    32813492  if cboCollType.ItemID = 'LC' then
    32823493    begin
    3283       if FLastLabCollTime <> '' then
     3494      if (FLastLabCollTime <> '') and (length(cboCollTime.Text) < 1) then
    32843495        cboCollTime.SelectByID(piece(FLastLabCollTime,'^',1));
    32853496    end
    3286   else
     3497  else if length(calcollTime.Text) < 1 then
    32873498    begin
    32883499      if FLastCollTime = 'TODAY' then
     
    32933504        calCollTime.Text := FormatFMDateTime('mmm dd,yyyy@hh:nn',StrToFMDateTime(FLastCollTime));
    32943505    end;
    3295   if FLastCollType <> '' then
     3506  if (FLastCollType <> '') and (length(cboCollType.Text) < 1) then
    32963507    cboCollType.SelectByID(FLastCollType);
    32973508  if uSelectedItems.Count > 0 then
     
    33253536begin
    33263537  inherited;
     3538  memDiagComment.Text := StringReplace(memDiagComment.Text,CRLF,'  ',[rfReplaceAll]);
    33273539  if (length(memDiagComment.Text) > 250) then
    33283540    begin
     
    33533565end;
    33543566
     3567procedure TfrmODBBank.FormShow(Sender: TObject);
     3568begin
     3569  inherited;
     3570  pgeProduct.SetFocus;
     3571end;
     3572
    33553573procedure TfrmODBBank.btnRemoveClick(Sender: TObject);
    33563574var
     
    33583576  x, aName, aModifier, aReason, aTypeScreen: string;
    33593577  aList: TStringList;
    3360   aSel, aSelTst : boolean;
     3578  aSel, aSelTst, aSelComp, aGotTNS : boolean;
    33613579begin
    33623580  inherited;
     
    33693587    aSel := false;
    33703588    aSelTst := false;
     3589    aSelComp := false;
     3590    aGotTNS := false;
    33713591    ExtractTypeScreen(aList, uVBECList);
    33723592    if aList.Count > 0 then aTypeScreen := aList[0];
     
    33813601    cboAvailComp.ItemIndex := -1;
    33823602    tQuantity.Text := '';
     3603    tQuantity.Enabled := false;
     3604    lblQuantity.Enabled := false;
    33833605    cboAvailTest.ItemIndex := -1;
    33843606    uGetTnS := 0;
     
    33983620                  if lvSelectionList.Items[i].SubItems[3] = piece(uSelectedItems[j],'^',2) then
    33993621                    begin
    3400                       {if (uGetTnS = 1) and (lvSelectionList.Items[i].SubItems[3] = aTypeScreen) then
    3401                         begin
    3402                           uGetTnS := 1;
    3403                           lblTNS.Caption := 'TYPE+SCREEN must be added to order';
    3404                           lblTNS.Visible := true;
    3405                           memMessage.Text := 'TYPE + SCREEN must be added to order';
    3406                           //memMessage.Visible := true;
    3407                           pnlMessage.Visible := true;
    3408                           pnlDiagnosticTests.Caption := 'Diagnostic Tests*';
    3409                         end; }
    34103622                      uSelectedItems.Delete(j);
    34113623                      lvSelectionList.Items[i].Delete;
     
    34153627          end;
    34163628      end;
    3417     for i := uSelectedItems.Count - 1 downto 0 do
    3418       begin
    3419         if (not(piece(uSelectedItems[i],'^',1) = '1')) and (uTNSOrders.Count < 1) then // and (SpecimenNeeded(aList, uVBECList, StrToInt(piece(uSelectedItems[i],'^',9)))) then
     3629    for i := lvSelectionList.Items.Count - 1 downto 0 do
     3630      begin
     3631        if lvSelectionList.Items[i].SubItems[3] = aTypeScreen then
    34203632          begin
    3421             uGetTnS := 1;
    3422             lblTNS.Caption := 'TYPE+SCREEN must be added to order';
    3423             lblTNS.Visible := true;
    3424             memMessage.Text := 'TYPE + SCREEN must be added to order';
    3425             //memMessage.Visible := true;
    3426             pnlMessage.Visible := true;
    3427             pnlDiagnosticTests.Caption := 'Diagnostic Tests*';
     3633            aGotTNS := true;
    34283634            break;
    34293635          end;
    34303636      end;
    3431      
     3637    if aGotTNS = false then
     3638      begin
     3639        for i := uSelectedItems.Count - 1 downto 0 do
     3640          begin
     3641            if not(piece(uSelectedItems[i],'^',1) = '1') and (uTNSOrders.Count < 1) and (piece(uSelectedItems[i],'^',5) = '1') then //CQ 17349
     3642              begin
     3643                uGetTnS := 1;
     3644                lblTNS.Caption := 'TYPE + SCREEN must be added to order';
     3645                lblTNS.Visible := true;
     3646                memMessage.Text := 'TYPE + SCREEN must be added to order';
     3647                pnlMessage.Visible := true;
     3648                pnlDiagnosticTests.Caption := 'Diagnostic Tests*';
     3649                break;
     3650              end
     3651              else pnlDiagnosticTests.Caption := 'Diagnostic Tests';
     3652          end;
     3653      end;
    34323654    if (aSel = false) and (lvSelectionList.Items.Count > 0) then
    34333655      begin
     
    34363658      end;
    34373659    Responses.Clear;
     3660    pnlDiagnosticTests.Caption := 'Diagnostic Tests';
     3661    lblCollTime.Caption := 'Collection Date/Time';
     3662    lblCollType.Caption := 'Collection Type';
     3663    lblQuantity.Caption := 'Quantity';
     3664    lblWanted.Caption := 'Date/Time Wanted';
     3665    lblReason.Caption := 'Reason for Request';
    34383666    if lvSelectionList.Items.Count < 1 then
    34393667      begin
    3440         cboReasons.ItemIndex := -1;
    3441         memDiagComment.Text := '';
    3442         cboSurgery.ItemIndex := -1;
    3443         cboUrgency.ItemIndex := -1;
     3668        uGetTnS := 0;
     3669        lblTNS.Caption := '';
     3670        lblTNS.Visible := false;
     3671        memMessage.Text := '';
     3672        pnlMessage.Visible := false;
     3673        FLastItemID := '';
     3674        InitDialog;
     3675        cboModifiers.ItemIndex := -1;
     3676        cboAvailTest.ItemIndex := -1;
     3677        cboAvailComp.ItemIndex := -1;
    34443678        cboCollType.ItemIndex := -1;
    34453679        cboCollTime.ItemIndex := -1;
    34463680        cboQuick.ItemIndex := -1;
    3447         calCollTime.Text := '';
     3681        calWantTime.Text := '';
     3682        GroupBox1.Visible := true;
     3683        tQuantity.Text := '';
     3684        FLastCollType := '';
     3685        FLastCollTime := '';
     3686        FLastLabCollTime := '';
     3687        txtImmedColl.Text := '';
     3688        calCollTime.text := '';
     3689        lblNoBloodReq.Visible := false;
    34483690      end;
    34493691    for i := 0 to uSelectedItems.Count - 1 do
     
    34543696          begin
    34553697            if Length(piece(x,'^',2)) > 0 then Responses.Update('ORDERABLE', CurAdd, piece(x,'^',2), aName);
     3698            lblCollTime.Caption := 'Collection Date/Time*';
     3699            lblCollType.Caption := 'Collection Type*';
    34563700            aSelTst := true;
    34573701          end
     
    34653709            cboAvailComp.ItemIndex := -1;
    34663710            tQuantity.Text := '';
     3711            lblQuantity.Caption := 'Quantity*';
     3712            lblWanted.Caption := 'Date/Time Wanted*';
     3713            lblReason.Caption := 'Reason for Request*';
     3714            //aSelComp := true;
    34673715          end;
    34683716        Inc(CurAdd);
     
    34743722        calCollTime.Text := '';
    34753723      end;
     3724    {if aSelcomp = false then
     3725      lblNoBloodReq.Visible := false
     3726    else
     3727      lblNoBloodReq.Visible := true;  }
    34763728    if Length(calWantTime.Text) > 0 then Responses.Update('DATETIME',1,ValidCollTime(calWantTime.Text),calWantTime.Text);
    34773729    if cboCollType.ItemID = 'LC' then
     
    35693821  memMessage.Text := '';
    35703822  pnlMessage.Visible := false;
     3823  FLastItemID := '';
    35713824  InitDialog;
    35723825  cboModifiers.ItemIndex := -1;
     
    35833836  GroupBox1.Visible := true;
    35843837  tQuantity.Text := '';
     3838  tQuantity.Enabled := false;
     3839  lblQuantity.Enabled := false;
    35853840  FLastCollType := '';
    35863841  FLastCollTime := '';
    35873842  FLastLabCollTime := '';
    35883843  txtImmedColl.Text := '';
     3844  calCollTime.text := '';
     3845  lblNoBloodReq.Visible := false;
     3846  pnlDiagnosticTests.Caption := 'Diagnostic Tests';
     3847  lblCollTime.Caption := 'Collection Date/Time';
     3848  lblCollType.Caption := 'Collection Type';
     3849  lblQuantity.Caption := 'Quantity';
     3850  lblWanted.Caption := 'Date/Time Wanted';
     3851  lblReason.Caption := 'Reason for Request';
    35893852end;
    35903853
     
    36223885
    36233886procedure TfrmODBBank.calWantTimeChange(Sender: TObject);
    3624 begin
    3625   inherited;
     3887var
     3888  i: integer;
     3889  aList: TStringList;
     3890  aSpecimen, aSpecimenUID, aSpecimenReq: string;
     3891  aChanging: Boolean;
     3892begin
     3893  inherited;
     3894  aList := TStringList.Create;
     3895  aChanging := changing;
     3896  try
     3897  aSpecimen := '';
     3898  aSpecimenUID := '';
     3899  aSpecimenReq := '';
    36263900  if uSelectedItems.Count > 0 then
    36273901    begin
    3628       with calWantTime do if not Changing then
     3902      with calWantTime do if not changing then
    36293903        begin
    36303904          if FMDateTime = 0 then
    36313905            begin
    36323906              ShowMsg('Invalid Date/Time entered');
    3633               Changing := true;
     3907              changing := true;
    36343908              calWantTime.Text := '';
    3635               Changing := false;
     3909              changing := aChanging;
    36363910              Exit;
    36373911            end
     
    36423916                begin
    36433917                  ShowMsg('Date/Time Wanted must be a future Date/Time');
    3644                   Changing := true;
     3918                  changing := true;
    36453919                  calWantTime.Text := '';
    3646                   Changing := false;
     3920                  changing := aChanging;
    36473921                  Exit;
    36483922                end;
     
    36513925      if Length(calWantTime.Text) > 0 then Responses.Update('DATETIME',1,ValidCollTime(calWantTime.Text),calWantTime.Text);
    36523926      memOrder.Text := Responses.OrderText;
     3927      aList.Clear;
     3928      ExtractSpecimen(aList, uVBECList);
     3929      if aList.Count > 0 then
     3930      begin
     3931        aSpecimen := piece(aList[0], '^', 1);
     3932        aSpecimenUID := piece(aList[0], '^', 2);
     3933      end;
     3934      aList.Clear;
     3935      ExtractSpecimens(aList, uVBECList);    //Get specimen values to pass back to Server
     3936      for i := 0 to aList.Count - 1 do
     3937        begin
     3938          if (StrToInt(piece(aList[i],'^',1)) = aLabTest.ItemID) then
     3939            begin
     3940              aSpecimenReq := piece(aList[i],'^',2);
     3941              if (SpecimenNeeded(aList, uVBECList, aLabTest.ItemID)) then
     3942                aSpecimenUID := '';
     3943              break;
     3944            end;
     3945        end;
     3946      Responses.Update('SPECSTS', 1, aSpecimenReq + '^' + aSpecimen + '^' + aSpecimenUID, aSpecimenReq);
     3947    end;
     3948  finally
     3949    aList.Free;
     3950  end;
     3951end;
     3952
     3953procedure TfrmODBBank.calWantTimeEnter(Sender: TObject);
     3954var
     3955  j: integer;
     3956begin
     3957  inherited;
     3958  if Length(cboAvailComp.Text) > 0 then Exit;
     3959  for j := uSelectedItems.Count - 1 downto 0 do
     3960    begin
     3961      if not(lvSelectionList.Items[j] = nil) and (piece(uSelectedItems[j],'^',1) = '0') then
     3962        begin
     3963          lvSelectionList.Items[j].Selected := true;
     3964          lvSelectionListClick(self);
     3965          Break;
     3966        end;
    36533967    end;
    36543968end;
     
    36793993      else
    36803994        begin
    3681           lblSurgery.Enabled := false;
    3682           cboSurgery.Enabled := false;
    3683           lblSurgery.Caption := 'Surgery';
    3684           cboSurgery.ItemIndex := -1;
    3685           Responses.Update('MISC',1,cboSurgery.Text,cboSurgery.Text);
     3995          if Length(cboSurgery.Text) > 0 then
     3996            begin
     3997              lblSurgery.Enabled := true;
     3998              cboSurgery.Enabled := true;
     3999              lblSurgery.Caption := 'Surgery*';
     4000            end
     4001            else
     4002            begin
     4003              lblSurgery.Enabled := false;
     4004              cboSurgery.Enabled := false;
     4005              lblSurgery.Caption := 'Surgery';
     4006              cboSurgery.ItemIndex := -1;
     4007              Responses.Update('MISC',1,cboSurgery.Text,cboSurgery.Text);
     4008            end;
    36864009        end;
    36874010    end
     
    37004023procedure TfrmODBBank.cboSurgeryChange(Sender: TObject);
    37014024var
    3702   aList: TStringList;
     4025  aList, bList, cList: TStringList;
    37034026  i,j,aMSBOS,aMSBOSContinue: integer;
    3704   x: string;
    3705   handled: boolean;
    3706 begin
    3707   inherited;
     4027  x,aTypeScreen: string;
     4028  handled,aGotTNS: boolean;
     4029  xLabTest: TLabTest;
     4030begin
     4031  inherited;
     4032  cboSurgery.Text := StringReplace(cboSurgery.Text,CRLF,'  ',[rfReplaceAll]);
    37084033  aList := TStringList.Create;
     4034  bList := TStringList.Create;
     4035  cList := TStringList.Create;
    37094036  handled := false;
     4037  //uGetTNS := 0;
     4038  //aGotTNS := false;
     4039  ExtractTypeScreen(aList, uVBECList);
     4040  if aList.Count > 0 then aTypeScreen := aList[0];
     4041  aList.Clear;
     4042  bList.Clear;
     4043  cList.Clear;
    37104044  try
    3711     if (Length(cboSurgery.ItemID) > 0) and (Length(tQuantity.Text) > 0) then
     4045    cboSurgery.DroppedDown := false;
     4046    if (Length(cboSurgery.ItemID) > 0) then
     4047      begin
     4048        for j := 0 to uSelectedItems.Count - 1 do
     4049          begin
     4050            xLabTest := TLabTest.Create(piece(uSelectedItems[j],'^',2), Responses);
     4051            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
     4052              begin
     4053                cList.Add(xLabTest.TestName + '^' + piece(uSelectedItems[j],'^',3));
     4054              end;
     4055            xLabTest.Free;
     4056          end;
     4057      end;
     4058    if (Length(cboSurgery.ItemID) > 0) and (Length(tQuantity.Text) > 0) and (Length(cboAvailComp.Text) > 0) then
    37124059      begin
    37134060        aList.Clear;
     
    37164063          begin
    37174064            if (StrToInt(piece(aList[i],'^',1)) = aLabTest.ItemID)
    3718              and (piece(aList[i],'^',3) = cboSurgery.Text) then
     4065             and (uppercase((piece(aList[i],'^',3))) = uppercase(cboSurgery.Text)) then
    37194066              begin
    37204067                aMSBOS := StrToInt(piece(aList[i],'^',4));
    37214068                if (aMSBOS > 0) and (StrToInt(tQuantity.Text) > aMSBOS) then
    37224069                  begin
    3723                     with Application do
    3724                     begin
    3725                       NormalizeTopMosts;
    3726                       aMSBOSContinue :=
    3727                         MessageBox(PChar('The number of unit Quantity selected (' + tQuantity.Text +
    3728                                    ') for ' + aLabTest.TestName + ' exceeds the maximum number of units ('
    3729                                    + IntToStr(aMSBOS) +
    3730                                    ') for the ' + cboSurgery.text +
    3731                                    ' surgical procedure selected.' + CRLF + CRLF + 'Continue to order ' + tQuantity.Text + ' units?'),
    3732                                    PChar('Maximum Number of Units Exceeded'),
    3733                                    MB_YESNO);
    3734                       RestoreTopMosts;
    3735                     end;
    3736                     if aMSBOSContinue = 7 then
    3737                       begin
    3738                         ShowMsg('Please enter a new quantity for ' + cboAvailComp.Text);
    3739                         tQuantity.Text := '0';
    3740                         tQuantity.SelLength := 2;
    3741                         tQuantity.SelectAll;
    3742                         break;
    3743                       end;
     4070                    bList.Add(aLabTest.TestName + '^' + tQuantity.Text + '^' + IntToStr(aMSBOS));
    37444071                  end;
    37454072                handled := true;
     
    37544081        for j := 0 to uSelectedItems.Count - 1 do
    37554082          begin
    3756             ALabTest := TLabTest.Create(piece(uSelectedItems[j],'^',2), Responses);
     4083            xLabTest := TLabTest.Create(piece(uSelectedItems[j],'^',2), Responses);
    37574084            for i := 0 to aList.Count - 1 do
    37584085              begin
    37594086                if (piece(uSelectedItems[j],'^',1) = '0')
    3760                  and (StrToInt(piece(aList[i],'^',1)) = aLabTest.ItemID)
    3761                  and (piece(aList[i],'^',3) = cboSurgery.Text) then
     4087                 and (StrToInt(piece(aList[i],'^',1)) = xLabTest.ItemID)
     4088                 and (uppercase((piece(aList[i],'^',3))) = uppercase(cboSurgery.Text)) then
    37624089                  begin
    37634090                    aMSBOS := StrToInt(piece(aList[i],'^',4));
    37644091                    if (aMSBOS > 0) and (length(piece(uSelectedItems[j],'^',3)) > 0) and (StrToInt(piece(uSelectedItems[j],'^',3)) > aMSBOS) then
    37654092                      begin
    3766                         with Application do
    3767                         begin
    3768                           NormalizeTopMosts;
    3769                           aMSBOSContinue :=
    3770                             MessageBox(PChar('The number of unit Quantity selected (' + piece(uSelectedItems[j],'^',3) +
    3771                                ') for ' + lvSelectionList.Items[j].Caption + ' exceeds the maximum number of units ('
    3772                                + IntToStr(aMSBOS) +
    3773                                ') for the ' + cboSurgery.text +
    3774                                ' surgical procedure selected.' + CRLF + CRLF + 'Continue to order ' + piece(uSelectedItems[j],'^',3) + ' units?'),
    3775                                PChar('Maximum Number of Units Exceeded'),
    3776                                MB_YESNO);
    3777                           RestoreTopMosts;
    3778                         end;
    3779                         if aMSBOSContinue = 7 then
    3780                           begin
    3781                             ShowMsg('Please enter a new quantity for ' + lvSelectionList.Items[j].Caption);
    3782                             tQuantity.Text := '0';
    3783                             tQuantity.SelLength := 2;
    3784                             tQuantity.SelectAll;
    3785                             x := uSelectedItems[j];
    3786                             SetPiece(x,U,3,'');
    3787                             uSelectedItems[j] := x;
    3788                             lvSelectionList.Items[j].SubItems[0] := '';
    3789                             RePaint;
    3790                             break;
    3791                           end;
     4093                        bList.Add(xLabTest.TestName + '^' + piece(uSelectedItems[j],'^',3) + '^' + IntToStr(aMSBOS));
    37924094                      end;
    37934095                    break;
    37944096                  end;
    37954097              end;
     4098            xLabTest.Free;
     4099          end;
     4100      end;
     4101    if (uChangingMSBOS = false) and (cList.Count > 0) then
     4102      begin
     4103        lblNoBloodReq.Visible := true;
     4104        with Application do
     4105          begin
     4106            NormalizeTopMosts;
     4107            aMSBOSContinue :=
     4108              MessageBox(PChar('No blood is required for the surgical procedure: ' + cboSurgery.text +
     4109               '.' + CRLF +
     4110               'If you still need to order any components, please enter a justification in the Comment box.'
     4111                + CRLF + CRLF + 'Do you want me to remove ALL the component orders you''ve just entered? '),
     4112               PChar('No Blood Required'),MB_YESNO);
     4113            RestoreTopMosts;
     4114          end;
     4115        if aMSBOSContinue = 6 then
     4116          begin
     4117            tQuantity.Text := '';
     4118            bList.Clear;
     4119            for j := uSelectedItems.Count - 1 downto 0 do
     4120              begin
     4121                if not(lvSelectionList.Items[j] = nil) and (piece(uSelectedItems[j],'^',1) = '0') then
     4122                  begin
     4123                    lvSelectionList.Items[j].Delete;
     4124                    uSelectedItems.Delete(j);
     4125                    Responses.Update('ORDERABLE', (j+1) ,'', '');
     4126                    Responses.Update('MODIFIER', (j+1), '', '');
     4127                    Responses.Update('QTY', (j+1), '', '');
     4128                  end;
     4129              end;
     4130            cboAvailComp.Text := '';
     4131            cboAvailComp.ItemIndex := -1;
     4132            cboModifiers.Text := '';
     4133            cboModifiers.ItemIndex := -1;
     4134            lblNoBloodReq.Visible := false;
     4135            //if fODBBank. Active then cboAvailTest.SetFocus;
     4136            lblTNS.Caption := '';
     4137            lblTNS.Visible := false;
     4138            uGetTNS := 0;
     4139            aGotTNS := false;
     4140            DisableComponentControls;
     4141            for i := lvSelectionList.Items.Count - 1 downto 0 do
     4142              begin
     4143                if lvSelectionList.Items[i].SubItems[3] = aTypeScreen then
     4144                  begin
     4145                    aGotTNS := true;
     4146                    break;
     4147                  end;
     4148              end;
     4149            for i := uSelectedItems.Count - 1 downto 0 do
     4150              begin
     4151                if (aGotTNS = false) and not(piece(uSelectedItems[i],'^',1) = '1') and (uTNSOrders.Count < 1) and (piece(uSelectedItems[i],'^',5) = '1') then //CQ 17349
     4152                  begin
     4153                    uGetTnS := 1;
     4154                    lblTNS.Caption := 'TYPE + SCREEN must be added to order';
     4155                    lblTNS.Visible := true;
     4156                    memMessage.Text := 'TYPE + SCREEN must be added to order';
     4157                    pnlMessage.Visible := true;
     4158                    pnlDiagnosticTests.Caption := 'Diagnostic Tests*';
     4159                    break;
     4160                  end
     4161                  else pnlDiagnosticTests.Caption := 'Diagnostic Tests';
     4162              end;
     4163          end;
     4164      end
     4165      else
     4166        begin
     4167          lblNoBloodReq.Visible := false;
     4168        end;
     4169
     4170    if (uChangingMSBOS = false) and (bList.Count > 0) then
     4171      begin
     4172        x := '';
     4173        for i := 0 to bList.Count - 1 do
     4174          begin
     4175            x := x + CRLF + piece(bList[i],'^',1) + ' (' + piece(bList[i],'^',2) + ') Max allowed: ' + piece(bList[i],'^',3);
     4176          end;
     4177        with Application do
     4178          begin
     4179            NormalizeTopMosts;
     4180            aMSBOSContinue :=
     4181              MessageBox(PChar('The number of units ordered' + x + CRLF +
     4182               'Exceeds the maximum number recommended for '
     4183               + cboSurgery.text + CRLF + CRLF +
     4184               'If you need to order more than the recommended maximum units, please enter a justification in the Comment box.')
     4185               ,PChar('Maximum Number of Units Exceeded'),
     4186               MB_OK);
     4187            RestoreTopMosts;
    37964188          end;
    37974189      end;
     
    38064198        Responses.Update('REASON',1,cboReasons.Text,cboReasons.Text);
    38074199      end;
    3808     memOrder.Text := Responses.OrderText; 
     4200    memOrder.Text := Responses.OrderText;
    38094201    finally
    38104202      aList.Free;
     4203      bList.Free;
     4204      cList.Free;
    38114205    end;
    38124206end;
     
    38444238    end;
    38454239  try
    3846     if (Length(cboSurgery.ItemID) > 0) and (Length(tQuantity.Text) > 0) then
    3847       begin
     4240    if not(aLabTest = nil) and (Length(cboSurgery.ItemID) > 0) and (Length(tQuantity.Text) > 0) then
     4241      begin
     4242        uChangingMSBOS := true;
     4243        cboSurgeryChange(self);
     4244        uChangingMSBOS := false;
    38484245        aList.Clear;
    38494246        ExtractMSBOS(aList, uVBECList);    //Get maximum units for selected Surgery
     
    38514248          begin
    38524249            if (StrToInt(piece(aList[i],'^',1)) = aLabTest.ItemID)
    3853              and (piece(aList[i],'^',3) = cboSurgery.Text) then
     4250             and (uppercase((piece(aList[i],'^',3))) = uppercase(cboSurgery.Text)) and (Length(tQuantity.Text) > 0) then
    38544251              begin
    38554252                aMSBOS := StrToInt(piece(aList[i],'^',4));
     
    38614258                      aMSBOSContinue :=
    38624259                        MessageBox(PChar('The number of units ordered (' + tQuantity.Text +
    3863                                    ') for ' + aLabTest.TestName + ' exceeds the maximum number of units ('
    3864                                    + IntToStr(aMSBOS) +
    3865                                    ') for the ' + cboSurgery.text +
    3866                                    ' surgical procedure selected.' + CRLF + CRLF + 'Do you wish to continue?'),
    3867                                    PChar('Maximum Number of Units Exceeded'),
    3868                                    MB_YESNO);
     4260                         ') for ' + aLabTest.TestName + ' Exceeds the maximum number recommended ('
     4261                         + IntToStr(aMSBOS) +
     4262                         ') for the ' + cboSurgery.text +
     4263                         ' surgical procedure.' + CRLF +
     4264                         'If you need to order more than the maximum number of units, please enter a justification in the Comment box.'
     4265                          + CRLF + CRLF + 'Edit the Blood component Quantity?'),
     4266                         PChar('Maximum Number of Units Exceeded'),
     4267                         MB_YESNO);
     4268
    38694269                      RestoreTopMosts;
    38704270                    end;
    3871                     if aMSBOSContinue = 7 then
     4271                    if aMSBOSContinue = 6 then
    38724272                      begin
    38734273                        ShowMsg('Please enter a new quantity for ' + cboAvailComp.Text);
     
    39274327
    39284328procedure TfrmODBBank.tQuantityEnter(Sender: TObject);
     4329var
     4330  j: integer;
    39294331begin
    39304332  inherited;
    39314333  tQuantity.SelLength := 2;
    39324334  tQuantity.SelectAll;
     4335  if Length(cboAvailComp.Text) > 0 then Exit;
     4336  for j := uSelectedItems.Count - 1 downto 0 do
     4337    begin
     4338      if not(lvSelectionList.Items[j] = nil) and (piece(uSelectedItems[j],'^',1) = '0') then
     4339        begin
     4340          lvSelectionList.Items[j].Selected := true;
     4341          lvSelectionListClick(self);
     4342          Break;
     4343        end;
     4344    end;
     4345end;
     4346
     4347procedure TfrmODBBank.txtImmedCollEnter(Sender: TObject);
     4348var
     4349  j: integer;
     4350begin
     4351  inherited;
     4352  if Length(cboAvailTest.Text) > 0 then Exit;
     4353  for j := uSelectedItems.Count - 1 downto 0 do
     4354    begin
     4355      if not(lvSelectionList.Items[j] = nil) and (piece(uSelectedItems[j],'^',1) = '1') then
     4356        begin
     4357          lvSelectionList.Items[j].Selected := true;
     4358          lvSelectionListClick(self);
     4359          Break;
     4360        end;
     4361    end;
    39334362end;
    39344363
     
    39704399end;
    39714400
     4401procedure TfrmODBBank.calCollTimeEnter(Sender: TObject);
     4402var
     4403  j: integer;
     4404begin
     4405  inherited;
     4406  if Length(cboAvailTest.Text) > 0 then Exit;
     4407  for j := uSelectedItems.Count - 1 downto 0 do
     4408    begin
     4409      if not(lvSelectionList.Items[j] = nil) and (piece(uSelectedItems[j],'^',1) = '1') then
     4410        begin
     4411          lvSelectionList.Items[j].Selected := true;
     4412          lvSelectionListClick(self);
     4413          Break;
     4414        end;
     4415    end;
     4416end;
     4417
    39724418end.
Note: See TracChangeset for help on using the changeset viewer.