Procedure

TfrmODMeds.Validate

Directives

Override

Module

fODMeds

Last Modified

7/15/2014 3:26:42 PM

Visibility

Protected

Overrides

TfrmODBase.Validate

Owner

TfrmODMeds

Declaration

procedure Validate(var AnErrMsg: string); override;

Calls Hierarchy


TfrmODMeds.Validate
 ├TfrmODMeds.ControlChange
 │ ├TResponses.Clear
 │ ├TResponses.Update
 │ │ ├TResponses.FindResponseByName
 │ │ └TResponses.IENForPrompt
 │ ├TfrmODMeds.FindCommonDrug
 │ │ ├TfrmODMeds.FindDoseFields
 │ │ ├SaveDrug
 │ │ └KillDrug
 │ ├TfrmODMeds.ConstructedDoseFields
 │ ├TfrmODMeds.ValueOf
 │ │ ├GetSingleDoseSchedule
 │ │ ├GetSingleDoseScheduleEX
 │ │ ├TfrmODMeds.FieldsForDose
 │ │ │ └TfrmODMeds.ConstructedDoseFields
 │ │ ├TfrmODMeds.FieldsForDrug
 │ │ ├GetComplexDoseSchedule
 │ │ │ └TfrmODMeds.ValFor
 │ │ └GetComplexDoseScheduleEX
 │ │   └TfrmODMeds.ValFor
 │ ├TfrmODMeds.lblAdminSchGetText
 │ ├TfrmODMeds.ValFor
 │ ├TfrmODMeds.InpatientSig
 │ │ ├TfrmODMeds.ValueOf...
 │ │ └TfrmODMeds.CheckDecimal
 │ │   └TfrmODMeds.TextDosage
 │ ├TfrmODMeds.OutpatientSig
 │ │ ├TfrmODMeds.ValueOf...
 │ │ └TfrmODMeds.CheckDecimal...
 │ └TResponses.GetOrderText
 │   ├TResponses.NextInstance
 │   ├TResponses.FindResponseByName
 │   ├TResponses.FormatResponse
 │   │ └TResponses.FindResponseByIEN
 │   └TResponses.AppendChildren
 │     ├TResponses.FindPromptByIEN
 │     ├TResponses.FindResponseByIEN
 │     └TResponses.FormatResponse...
 ├SetError
 ├TResponses.InstanceCount
 ├TResponses.NextInstance
 ├TfrmODMeds.ValueOfResponse
 │ └TResponses.IValueFor
 ├TResponses.IValueFor
 ├ValidateRoute
 │ ├TfrmODMeds.IsSupplyAndOutPatient
 │ │ └MedIsSupply
 │ ├SetError
 │ ├LookupRoute
 │ └TResponses.Update...
 ├TResponses.EValueFor
 ├ValidateSchedule
 │ ├TfrmODMeds.ValueOfResponse...
 │ ├SetError
 │ ├ScheduleRequired
 │ └ValidSchedule
 ├TfrmODMeds.ValFor
 ├TfrmODMeds.UpdateRefills
 │ └CalcMaxRefills
 ├ValidQuantity
 ├ValidateDaySupplyandQuantityErrorMsg
 └ClearMaxData

Calls

Name Declaration Comments
ClearMaxData procedure ClearMaxData; -
TfrmODMeds.ControlChange procedure ControlChange(Sender: TObject); -
TResponses.EValueFor function EValueFor(const APromptID: string; AnInstance: Integer): string; -
TResponses.InstanceCount function InstanceCount(const APromptID: string): Integer; -
TResponses.IValueFor function IValueFor(const APromptID: string; AnInstance: Integer): string; -
TResponses.NextInstance function NextInstance(const APromptID: string; LastInstance: Integer): Integer; -
SetError procedure SetError(const x: string); -
TfrmODMeds.UpdateRefills procedure UpdateRefills(const CurDispDrug: string; CurSupply: Integer); -
TfrmODMeds.ValFor function ValFor(FieldID, ARow: Integer): string; -
ValidateDaySupplyandQuantityErrorMsg function ValidateDaySupplyandQuantityErrorMsg(DaySupply, quantity: integer): String; -
ValidateRoute procedure ValidateRoute(const x: string; NeedLookup: Boolean; AnInstance: Integer); -
ValidateSchedule procedure ValidateSchedule(const x: string; AnInstance: Integer); -
ValidQuantity function ValidQuantity(const x: string): Boolean; -
TfrmODMeds.ValueOfResponse function ValueOfResponse(FieldID: Integer; AnInstance: Integer = 1): string; -


Source

838   procedure TfrmODMeds.Validate(var AnErrMsg: string);
839   var
840     i,ie,code, curSupply, tempRefills: Integer;
841     curDispDrug, tmpError, temp, x: string;
842   
843     procedure SetError(const x: string);
844     begin
845       if Length(AnErrMsg) > 0 then AnErrMsg := AnErrMsg + CRLF;
846       AnErrMsg := AnErrMsg + x;
847     end;
848   
849     procedure ValidateDosage(const x: string);
850     begin
851       if Length(x) = 0 then SetError(TX_NO_DOSE);
852     end;
853   
854     procedure ValidateRoute(const x: string; NeedLookup: Boolean; AnInstance: Integer);
855     var
856       RouteID, RouteAbbr: string;
857     begin
858       //if order does not have route, and is not a supply order,
859       // and is not an outpaitent order, then display error text to require route
860       if (Length(x) = 0) and (Not IsSupplyAndOutPatient) then
861       begin
862         if cboRoute.Showing = true then cboRoute.SetFocus;  //CQ: 7467
863         SetError(TX_NO_ROUTE);
864       end;
865       if (Length(x) > 0) and NeedLookup then
866       begin
867         LookupRoute(x, RouteID, RouteAbbr);
868         if RouteID = '0'
869           then
870           begin
871            if cboRoute.Showing = true then cboRoute.SetFocus;    //CQ: 7467
872           SetError(TX_NF_ROUTE);
873           end
874           else Responses.Update('ROUTE', AnInstance, RouteID, RouteAbbr);
875       end;
876     end;
877   
878     procedure ValidateSchedule(const x: string; AnInstance: Integer);
879     const
880       SCH_BAD = 0;
881       SCH_NO_RTN = -1;
882     var
883       ValidLevel: Integer;
884       ARoute, ADrug, tmpX: string;
885     begin
886       ARoute := ValueOfResponse(FLD_ROUTE_ID, AnInstance);
887       ADrug  := ValueOfResponse(FLD_DRUG_ID,  AnInstance);
888       tmpX := x; //Changed for CQ: 7370 - it was tmpX := Trim(x);
889       if Pos(CRLF, tmpX)> 0 then
890         begin
891           SetError('Schedule cannot contains control characters');
892           Exit;
893         end;
894       if (Length(tmpX) = 0) and (not FInptDlg) then SetError(TX_NO_SCHED)
895       else if (Length(tmpX) = 0) and FInptDlg and ScheduleRequired(txtMed.Tag, ARoute, ADrug)
896         then SetError(TX_NO_SCHED);
897       if Length(tmpX) > 0 then
898       begin
899         if FInptDlg then ValidLevel := ValidSchedule(tmpX) else ValidLevel := ValidSchedule(tmpX, 'O');
900      (*   if FInptDlg and (tmpX <> '') and (cboSchedule.ItemIndex = -1) and
901         (self.tabDose.TabIndex = TI_DOSE) then
902            //SetError('Unique Schedule Selection Required');
903            SetError('More than one schedule starts with "'+tmpX+'". Please select a schedule from the list.');  *)
904         if ValidLevel = SCH_NO_RTN then
905         begin
906           if Pos('"', tmpX) > 0                              then SetError(TX_SCH_QUOTE);
907           if Copy(tmpX, 1, 1) = '-'                          then SetError(TX_SCH_MINUS);
908           if Pos(' ', Copy(tmpX, Pos(' ', tmpX) + 1, 999)) > 0  then SetError(TX_SCH_SPACE);
909           if Length(tmpX) > 70                               then SetError(TX_SCH_LEN);
910           if (Pos('P RN', tmpX) > 0) or (Pos('PR N', tmpX) > 0) then SetError(TX_SCH_PRN);
911           if Pos('Q0', tmpX) > 0                             then SetError(TX_SCH_ZERO);
912           if TrimLeft(tmpX) <> tmpX                             then SetError(TX_SCH_LSP);
913         end;
914         if ValidLevel = SCH_BAD then SetError(TX_SCH_NS);
915       end;
916     end;
917   
918   begin
919     inherited;
920     ControlChange(Self);                            // make sure everything is updated
921     if txtMed.Tag = 0 then SetError(TX_NO_MED);
922     if Responses.InstanceCount('INSTR') < 1 then SetError(TX_NO_DOSE);
923     if Pos(U, self.memComment.Text) > 0 then SetError('Comments cannot contain a "^".');
924     i := Responses.NextInstance('INSTR', 0);
925     while i > 0 do
926     begin
927       if (ValueOfResponse(FLD_DRUG_ID, i) = '') then
928       begin
929         if not ContainsAlpha(Responses.IValueFor('INSTR', i)) then
930         begin
931            SetError(TX_DOSE_NUM);
932            if tabDose.TabIndex = TI_DOSE then
933               cboDosage.SetFocus;    //CQ: 7467
934         end;
935         if Length(Responses.IValueFor('INSTR', i)) > 60       then
936         begin
937            if self.tabDose.TabIndex = TI_COMPLEX then
938              begin
939                 SetError('Dosage: ' + Responses.IValueFor('INSTR', i) + CRLF + TX_DOSE_LEN);
940              end
941            else
942              begin
943                 SetError(TX_DOSE_LEN);
944                 cboDosage.SetFocus;  //CQ: 7467
945              end;
946         end;
947       end;
948       ValidateRoute(Responses.EValueFor('ROUTE', i), Responses.IValueFor('ROUTE', i) = '', i);
949       ValidateSchedule(ValueOfResponse(FLD_SCHEDULE, i), i);
950       i := Responses.NextInstance('INSTR', i);
951     end;
952     if self.tabDose.TabIndex = TI_DOSE then
953        begin
954            if (LeftStr(cboDosage.Text,1)='.') then
955          begin
956            SetError('Dosage must have a leading numeric value');
957            Exit;
958          end;
959        end;
960     //AGP Change 26.45 Fix for then/and conjucntion PSI-04-069
961     if self.tabDose.TabIndex = TI_COMPLEX then
962       begin
963          for i := 1 to self.grdDoses.RowCount do
964            begin
965              temp := ValFor(COL_DOSAGE, i);
966              if (LeftStr(temp,1) = '.') then
967                begin
968                   SetError('All dosage must have a leading numeric value');
969                   Exit;
970                end;
971              if (i > 1) and ((ValFor(COL_DOSAGE, i-1) <> '') and (ValFor(COL_DOSAGE, i) <> '')) and (ValFor(COL_SEQUENCE,i-1) = '') then
972                 begin
973                   SetError(TX_NO_SEQ);
974                   Exit;
975                 end;
976              if Uppercase(ValFor(Col_Sequence, i)) = 'THEN' then
977                begin
978                   if ValFor(Col_Duration,i) = '' then
979                     begin
980                       SetError('A duration is required when using "Then" as a sequence.');
981                       Exit;
982                     end;
983                end;
984            end;
985       end;
986     if not FInptDlg then                            // outpatient stuff
987     begin
988       if Responses.IValueFor('PICKUP', 1) = '' then SetError(TX_NO_PICK);
989       temp := Responses.IValueFor('REFILLS', 1);
990       for i := 1 to Length(temp) do if not (temp[i] in ['0'..'9']) then
991         begin
992           SetError('Refills can only be a number');
993           Exit;
994         end;
995       tempRefills := StrToIntDef(temp, 0);
996       if (spnRefills.Max > 0) and (tempRefills > 0) then
997         begin
998           i := Responses.NextInstance('DOSE', 0);
999           while i > 0 do
1000          begin
1001            x := ValueOfResponse(FLD_DRUG_ID,   i);
1002            CurDispDrug := CurDispDrug + x + U;
1003            i := Responses.NextInstance('DOSE', i);
1004          end;
1005          CurSupply   := StrToIntDef(ValueOfResponse(FLD_SUPPLY)   ,0);
1006          UpdateRefills(CurDispDrug, CurSupply);
1007        end;
1008      if tempRefills > spnRefills.Max
1009        then SetError(TX_RNG_REFILL + IntToStr(spnRefills.Max));
1010      with txtQuantity do
1011        begin
1012          if not ValidQuantity(Responses.IValueFor('QTY', 1)) then
1013            SetError(TX_QTY_NV);
1014        (*  else
1015            begin
1016              Quantity := ValidateQuantityErrorMsg(StrtoIntDef(Responses.IValueFor('QTY', 1), 0));
1017              if Quantity <> '' then SetError(Quantity);
1018            end; *)
1019        end;
1020      with txtSupply do
1021      begin
1022        txtSupply.Text := Trim(txtSupply.Text);
1023        Val( txtSupply.Text, ie, code);
1024        if (code <> 0) and (ie = 0)then
1025        begin
1026          SetError(TX_SUPPLY_NINT);
1027          Exit;
1028        end;
1029        if (StrToIntDef(Responses.IValueFor('SUPPLY', 1), 0) > 90) then SetError(TX_SUPPLY_LIM);
1030        if (StrToIntDef(Responses.IValueFor('SUPPLY', 1), 0) < 1)  then SetError(TX_SUPPLY_LIM1);
1031        //Supply := ValidateDaySupplyandQuantityErrorMsg(strtoInt(Responses.IValueFor('SUPPLY',1)));
1032        //if Supply <> '' then  SetError(Supply);
1033      end;
1034      tmpError :=  ValidateDaySupplyandQuantityErrorMsg(strtoInt(Responses.IValueFor('SUPPLY',1)),StrtoIntDef(Responses.IValueFor('QTY', 1), 0));
1035      if tmpError <> '' then SetError(tmpError)
1036      else ClearMaxData;
1037    end;
1038  end;