Procedure

TfrmODLab.Validate

Directives

Override

Module

fODLab

Last Modified

7/15/2014 3:26:42 PM

Visibility

Protected

Overrides

TfrmODBase.Validate

Owner

TfrmODLab

Declaration

procedure Validate(var AnErrMsg: string); override;

Calls Hierarchy


TfrmODLab.Validate
 ├SetError
 ├TLabTest.LabCanCollect
 │ └TLabTest.IndexOfCollSamp
 ├StrToFMDateTime
 ├FMNow
 ├TfrmODBase.OrderForInpatient
 │ ├OrderEventTypeOnCreate
 │ └IsPassEvt1
 ├FMToday
 │ └FMNow
 ├LabCollectFutureDays
 ├IsLabCollectTime
 ├ValidImmCollTime
 ├TfrmODLab.GetAllCollSamples
 │ ├TLabTest.LoadAllSamples
 │ │ ├LoadSamples
 │ │ └TLabTest.FillCollSampList
 │ └SelectOtherCollSample
 │   └TfrmBase508Form.Create
 │     ├TfrmBase508Form.UpdateAccessibilityActions
 │     ├UnfocusableControlEnter
 │     └AdjustControls
 │       ├TfrmBase508Form.ModifyUnfocusableControl
 │       └..(rec)..
 ├TfrmODLab.GetAllSpecimens
 │ └SelectOtherSpecimen
 │   └TfrmBase508Form.Create...
 ├TLabTest.ChangeUrgency
 ├TfrmODLab.ControlChange
 │ ├TResponses.FindResponseByName
 │ ├TResponses.Clear
 │ ├TResponses.Update
 │ │ ├TResponses.FindResponseByName
 │ │ └TResponses.IENForPrompt
 │ ├TLabTest.NameOfCollSamp
 │ │ └TLabTest.IndexOfCollSamp
 │ ├TLabTest.NameOfSpecimen
 │ │ └TLabTest.IndexOfCollSamp
 │ ├TLabTest.NameOfUrgency
 │ ├TfrmODLab.ValidCollTime
 │ │ └StrToFMDateTime
 │ └TResponses.GetOrderText
 │   ├TResponses.NextInstance
 │   ├TResponses.FindResponseByName
 │   ├TResponses.FormatResponse
 │   │ └TResponses.FindResponseByIEN
 │   └TResponses.AppendChildren
 │     ├TResponses.FindPromptByIEN
 │     ├TResponses.FindResponseByIEN
 │     └TResponses.FormatResponse...
 ├MaxDays
 ├TResponses.Update...
 ├TResponses.FindResponseByName
 └TfrmODLab.DisplayChangedOrders
   ├TResponses.FindResponseByName
   ├CheckForChangeFromLCtoWCOnAccept
   │ └FormatLCtoWCDisplayTextOnAccept
   │   └GetLCtoWCInstructions
   ├TResponses.GetOrderText...
   └ReportBox
     └CreateReportBox
       └TfrmBase508Form.Create...

Calls

Name Declaration Comments
TLabTest.ChangeUrgency procedure ChangeUrgency(const UrgencyIEN: string); -
TfrmODLab.ControlChange procedure ControlChange(Sender: TObject); -
TfrmODLab.DisplayChangedOrders procedure DisplayChangedOrders(ACollType: string); -
TResponses.FindResponseByName function FindResponseByName(const APromptID: string; AnInstance: Integer): TResponse; -
FMNow function FMNow: TFMDateTime; -
FMToday function FMToday: TFMDateTime; -
TfrmODLab.GetAllCollSamples procedure GetAllCollSamples(AComboBox: TORComboBox); -
TfrmODLab.GetAllSpecimens procedure GetAllSpecimens(AComboBox: TORComboBox); -
IsLabCollectTime function IsLabCollectTime(ADateTime: TFMDateTime; Location: integer): boolean; -
TLabTest.LabCanCollect function LabCanCollect: Boolean; -
LabCollectFutureDays function LabCollectFutureDays(Location: integer; Division: integer = 0): integer; -
MaxDays function MaxDays(Location, Schedule: integer): integer; -
TfrmODBase.OrderForInpatient function OrderForInpatient: Boolean; -
SetError procedure SetError(const x: string); -
StrToFMDateTime function StrToFMDateTime(const AString: string): TFMDateTime; -
TResponses.Update procedure Update(const APromptID: string; AnInstance: Integer; const AnIValue, AnEValue: string); -
ValidImmCollTime function ValidImmCollTime(CollTime: TFMDateTime): string; -


Source

928   procedure TfrmODLab.Validate(var AnErrMsg: string);
929   
930     procedure SetError(const x: string);
931     begin
932       if Length(AnErrMsg) > 0 then AnErrMsg := AnErrMsg + CRLF;
933       AnErrMsg := AnErrMsg + x;
934     end;
935   
936   var
937     CmtType,DaysofFuturePast, y: integer;
938     (*Hours, *)DayMax, (*Daily, *)NoOfTimes, (*DayFreq,*) Minutes: integer;
939     d1, d2: TDateTime;
940     Days, MsgTxt: Double;
941     x: string;
942     ACollType: string;
943   const
944     TX_NO_TIME        = 'Collection Time is required.' ;
945     TX_NO_TCOLLTYPE   = 'Collection Type is required.' ;
946     TX_NO_TESTS       = 'A Lab Test or tests must be selected.' ;
947     TX_BAD_TIME       = 'Collection times must be chosen from the drop down list or entered as valid' +
948                         ' Fileman date/times (T@1700, T+1@0800, etc.).' ;
949     TX_PAST_TIME      = 'Collection times in the past are not allowed.';
950     TX_NO_DAYS        = 'A number of days must be entered for continuous orders.';
951     TX_NO_TIMES       = 'A number of times must be entered for continuous orders.';
952     TX_NO_STOP_DATE   = 'Could not calculate the stop date for the order.  Check "for n Days".';
953     TX_TOO_MANY_DAYS  = 'Maximum number of days allowed is ';
954     TX_TOO_MANY_TIMES = 'For this frequency, the maximum number of times allowed is:  X';
955     //TX_NO_COMMENT     = 'A comment is required for this test and collection sample.';
956     TX_NUMERIC_REQD   = 'A numeric value is required for urine volume.';
957     TX_DOSEDRAW_REQD  = 'Both DOSE and DRAW times are required for this order.';
958     TX_TDM_REQD       = 'A value for LEVEL is required for this order.';
959     //TX_ANTICOAG_REQD  = 'You must specify an anticoagulant on this order.' ;
960     TX_NO_COLLSAMPLE  = 'A collection sample MUST be specified.';
961     TX_NO_SPECIMEN    = 'A specimen MUST be specified.';
962     TX_NO_URGENCY     = 'An urgency MUST be specified.';
963     TX_NO_FREQUENCY   = 'A collection frequency MUST be specified.';
964     TX_NOT_LAB_COLL_TIME = ' is not a routine lab collection time.';
965     TX_NO_ALPHA       = 'For continuous orders, enter a number of days, or an "X" followed by a number of times.';
966     TX_BADTIME_CAP    = 'Invalid Immediate Collect Time';
967   
968   begin
969     inherited;
970     { need to go thru list and make sure everything is filled in }
971     with cboAvailTest do if ItemIEN <= 0 then SetError(TX_NO_TESTS);
972   
973     if ALabTest <> nil then
974       if (cboCollType.ItemID = 'I') and (not ALabTest.LabCanCollect) then
975         begin
976           SetError(TX_NO_IMMED);
977           cboCollType.ItemIndex := -1;
978         end;
979   
980     if cboCollType.ItemID = '' then
981       SetError(TX_NO_TCOLLTYPE)
982     else if cboCollType.ItemID = 'LC' then
983      begin
984        if Length(cboCollTime.Text) = 0 then SetError(TX_NO_TIME);
985        with cboCollTime do if (Length(Text) > 0) and (ItemIndex = -1) then
986          begin
987            if StrToFMDateTime(Text) < 0 then
988              SetError(TX_BAD_TIME)
989            else if StrToFMDateTime(Text) < FMNow then
990              SetError(TX_PAST_TIME)
991            else if OrderForInpatient then
992              begin
993                d1 := FMDateTimeToDateTime(Trunc(StrToFMDateTime(cboColltime.Text)));
994                d2 := FMDateTimeToDateTime(FMToday);
995                if EvtDelayLoc > 0 then
996                  DaysofFuturePast := LabCollectFutureDays(EvtDelayLoc,EvtDivision)
997                else
998                  DaysofFuturePast := LabCollectFutureDays(Encounter.Location);
999                if DaysofFuturePast = 0 then DaysofFuturePast := 7;
1000               if ((d1 - d2) > DaysofFuturePast) then
1001                 SetError('A lab collection cannot be ordered more than '
1002                   + IntToStr(DaysofFuturePast) + ' days in advance');
1003             end
1004           else if EvtDelayLoc > 0 then
1005             begin
1006               if (not IsLabCollectTime(StrToFMDateTime(cboCollTime.Text), EvtDelayLoc)) then
1007                 SetError(cboCollTime.Text + TX_NOT_LAB_COLL_TIME);
1008             end
1009           else if EvtDelayLoc <= 0 then
1010             begin
1011               if (not IsLabCollectTime(StrToFMDateTime(cboCollTime.Text), Encounter.Location)) then
1012                 SetError(cboCollTime.Text + TX_NOT_LAB_COLL_TIME);
1013             end;
1014         end;
1015     end
1016    else
1017      begin
1018        if cboCollType.ItemID = 'I' then
1019          begin
1020            calCollTime.Text := txtImmedColl.Text;
1021            x := ValidImmCollTime(calCollTime.FMDateTime);
1022            if (Piece(x, U, 1) <> '1') then
1023              SetError(Piece(x, U, 2));
1024          end;
1025  
1026        with calColltime do
1027          begin
1028            if FMDateTime = 0 then SetError(TX_BAD_TIME)
1029            else
1030              begin
1031                // date only was entered
1032                if (FMDateTime - Trunc(FMDateTime) = 0) then
1033                  begin
1034                    if (Trunc(FMDateTime) < FMToday) then SetError(TX_PAST_TIME);
1035                  end
1036                // date/time was entered
1037                else
1038                  begin
1039                    if (UpperCase(Text) <> 'NOW') and (FMDateTime < FMNow) then SetError(TX_PAST_TIME);
1040                  end;
1041              end;
1042          end;
1043      end;
1044  
1045    with cboCollSamp  do
1046      if ItemIndex < 0 then
1047        SetError(TX_NO_COLLSAMPLE)
1048      else if (ItemIndex >= 0) and (ItemIEN = 0) then
1049        begin
1050          if ALabTest <> nil then
1051            GetAllCollSamples(cboCollSamp);
1052          if ItemIEN = 0 then SetError(TX_NO_COLLSAMPLE);
1053        end;
1054  
1055    with cboSpecimen  do
1056      if ItemIndex < 0 then
1057        SetError(TX_NO_SPECIMEN)
1058      else if (ItemIndex >= 0) and (ItemIEN = 0) then
1059        begin
1060          if (ALabTest <> nil) and (cboCollSamp.ItemIEN > 0) then
1061            GetAllSpecimens(cboSpecimen);
1062          if ItemIEN = 0 then SetError(TX_NO_SPECIMEN);
1063        end;
1064        
1065    If ALabTest.Urgency <= 0 then begin
1066      with ALabTest do
1067      ChangeUrgency(cboUrgency.ItemID);
1068     ControlChange(Self);
1069    end;
1070  
1071    with cboUrgency   do if ItemIEN  <= 0 then SetError(TX_NO_URGENCY);
1072    with cboFrequency do if ItemIEN  <= 0 then SetError(TX_NO_FREQUENCY);
1073  
1074    if ALabTest <> nil then
1075      begin
1076        CmtType := FCmtTypes.IndexOf(ALabTest.CurReqComment) ;
1077        with ALabTest do
1078        case CmtType of
1079          0 : {ANTICOAGULATION}         {if (Pos('ANTICOAGULANT',Comment.Text)=0) then
1080                                       SetError(TX_ANTICOAG_REQD)};
1081          1 : {DOSE/DRAW TIMES}         if (Pos('Last dose:',Comment.Text)=0) or
1082                                        (Pos('draw time:',Comment.Text)=0) then
1083                                       SetError(TX_DOSEDRAW_REQD);
1084          2 : {ORDER COMMENT}           {if (Length(Comment.Text)=0) then
1085                                       SetError(TX_NO_COMMENT)};
1086          3 : {ORDER COMMENT MODIFIED}  {if (Length(Comment.Text)=0) then
1087                                       SetError(TX_NO_COMMENT)};
1088          4 : {TDM (PEAK-TROUGH}        if (Pos('Dose is expected',Comment.Text)=0) then
1089                                       SetError(TX_TDM_REQD);
1090          5 : {TRANSFUSION}             {if (Length(Comment.Text)=0) then
1091                                       SetError(TX_NO_COMMENT)};
1092          6 : {URINE VOLUME}            if (Length(Comment.Text)>0) and
1093                                     (ExtractInteger(Comment.Text)<=0) then
1094                                        Comment.Text := '?';
1095                                       {SetError(TX_NUMERIC_REQD);}
1096          {   else
1097                if (Length(CurReqComment)>0) and (Length(Comment.Text)=0) then
1098                  SetError(TX_NO_COMMENT); }
1099        end;
1100      end;
1101  
1102    with txtDays do if Enabled then
1103      begin
1104        DayMax := 0;
1105        if (cboCollType.ItemID = 'LC') or (cboCollType.ItemID = 'I') then
1106        begin
1107          if EvtDelayLoc > 0 then
1108            DayMax := LabCollectFutureDays(EvtDelayLoc,EvtDivision)
1109          else
1110            DayMax := LabCollectFutureDays(Encounter.Location);
1111        end;
1112        if DayMax = 0 then
1113        begin
1114           if EvtDelayLoc > 0 then
1115             DayMax := MaxDays(EvtDelayLoc, cboFrequency.ItemIEN)
1116           else
1117             DayMax := MaxDays(Encounter.Location, cboFrequency.ItemIEN);
1118        end;
1119        x := Piece(cboFrequency.Items[cboFrequency.ItemIndex], U, 3);
1120        if (x = 'C') or (x = 'D') then
1121          begin
1122            Minutes := StrToIntDef(Piece(cboFrequency.Items[cboFrequency.ItemIndex], U, 4), 0);
1123            Days := Minutes / 1440;
1124            if (Days = 0) then Days := 1;
1125            if Pos('X', UpperCase(txtDays.Text)) > 0 then
1126              begin
1127                x := Trim(Copy(txtDays.Text, 1, Pos('X', UpperCase(txtDays.Text)) - 1)) +
1128                     Trim(Copy(txtDays.Text, Pos('X', UpperCase(txtDays.Text)) + 1, 99));
1129                NoOfTimes := ExtractInteger(x);
1130                Days := NoOfTimes * Days;                                      // # days requested
1131                if FloatToStr(NoOfTimes) <> x then
1132                  SetError(TX_NO_ALPHA)
1133                else if NoOfTimes = 0 then
1134                  SetError(TX_NO_TIMES)
1135                else if (Days > DayMax) then
1136                  begin
1137                    MsgTxt := Minutes / 60;
1138                    x := ' hour';
1139                    if MsgTxt > 24 then
1140                      begin
1141                        MsgTxt := MsgTxt / 24;
1142                        x := ' day';
1143                      end;
1144                    if MsgTxt > 1 then x := x + 's';
1145                    y := 0;
1146                    if Minutes > 0 then y := (DayMax * 1440) div Minutes;
1147                    if y = 0 then y := 1;
1148                    //if y > 0 then
1149                      SetError(TX_TOO_MANY_TIMES + IntToStr(y) + CRLF +
1150                        '     (Every ' + FloatToStr(MsgTxt) + x + ' for a maximum of ' + IntToStr(DayMax) + ' days.)')
1151                    //else
1152                    //  Responses.Update('DAYS', 1, 'X1', 'X1');
1153                  end
1154                else
1155                  begin
1156                    x := 'X' + IntToStr(NoOfTimes);
1157                    Responses.Update('DAYS', 1, x, x);
1158                  end;
1159              end
1160            else
1161              begin
1162                Days := ExtractInteger(txtDays.Text);
1163                if FloatToStr(Days) <> Trim(txtDays.Text) then
1164                  SetError(TX_NO_ALPHA)
1165                  //SetError(TX_NO_DAYS)    v18.6  (RV)
1166                else if (Days > DayMax) then
1167                  SetError(TX_TOO_MANY_DAYS + IntToStr(DayMax))
1168                else
1169                  Responses.Update('DAYS', 1, txtDays.Text, txtDays.Text);
1170              end;
1171          end;
1172      end;
1173  
1174    if (AnErrMsg <> '') or (Self.EvtID > 0) then exit;
1175      
1176    // add check and display for auto-change from LC to WC - v27.1 - CQ #10226
1177    ACollType := Responses.FindResponseByName('COLLECT', 1).EValue;
1178    if ((ACollType = 'LC') or (ACollType = 'I')) then DisplayChangedOrders(ACollType);
1179  end;