source: cprs/branches/tmg-cprs/CPRS-Chart/Orders/rODMeds.pas@ 1547

Last change on this file since 1547 was 453, checked in by Kevin Toppenberg, 16 years ago

Initial upload of TMG-CPRS 1.0.26.69

File size: 9.0 KB
Line 
1//kt -- Modified with SourceScanner on 8/8/2007
2unit rODMeds;
3
4interface
5
6uses SysUtils, Classes, ORNet, ORFn, uCore, uConst;
7
8function DEACheckFailed(AnOI: Integer; ForInpatient: Boolean): Boolean;
9function DEACheckFailedForIVOnOutPatient(AnOI: Integer; AnOIType: Char): boolean;
10procedure ListForOrderable(var AListIEN, ACount: Integer; const DGrpNm: string);
11procedure SubsetOfOrderable(Dest: TStringList; Append: Boolean; ListIEN, First, Last: Integer);
12function IndexOfOrderable(ListIEN: Integer; From: string): Integer;
13procedure IsActivateOI(var AMsg: string; theOI: integer);
14procedure ListForQuickOrders(var AListIEN, ACount: Integer; const DGrpNm: string);
15procedure SubsetOfQuickOrders(Dest: TStringList; AListIEN, First, Last: Integer);
16function IndexOfQuickOrder(AListIEN: Integer; From: string): Integer;
17procedure LoadFormularyAltOI(AList: TStringList; AnIEN: Integer; ForInpatient: Boolean);
18procedure LoadFormularyAltDose(AList: TStringList; DispDrug, OI: Integer; ForInpatient: Boolean);
19procedure LoadAdminInfo(const Schedule: string; OrdItem: Integer; var StartText: string;
20 var AdminTime: TFMDateTime; var Duration: string);
21function GetAdminTime(const StartText, Schedule: string; OrdItem: Integer): TFMDateTime;
22procedure LoadSchedules(Dest: TStrings; IsInptDlg: boolean = False);
23function QtyToDays(Quantity: Double; const UnitsPerDose, Schedule, Duration, Drug: string): Integer;
24function DaysToQty(DaysSupply: Integer; const UnitsPerDose, Schedule, Duration, Drug: string): Integer;
25function DurToQty(DaysSupply: Integer; const UnitStr, SchedStr: string): Integer;
26function DefaultDays(const ADrug, UnitStr, SchedStr: string): Integer;
27function CalcMaxRefills(const Drug: string; Days, OrdItem: Integer; Discharge: Boolean): Integer;
28function ScheduleRequired(OrdItem: Integer; const ARoute, ADrug: string): Boolean;
29function ODForMedsIn: TStrings;
30function ODForMedsOut: TStrings;
31function OIForMed(AnIEN: Integer; ForInpatient: Boolean; HavePI: boolean = True; PKIActive: Boolean = False): TStrings;
32function GetPickupForLocation(const Loc: string): string;
33function QOHasRouteDefined(AQOID: integer): boolean;
34procedure CheckExistingPI(AOrderId: string; var APtI: string);
35
36implementation
37
38function DEACheckFailed(AnOI: Integer; ForInpatient: Boolean): Boolean;
39var
40 PtType: Char;
41begin
42 if ForInpatient then PtType := 'I' else PtType := 'O';
43 Result := sCallV('ORWDPS1 FAILDEA', [AnOI, Encounter.Provider, PtType]) = '1';
44end;
45
46function DEACheckFailedForIVOnOutPatient(AnOI: Integer; AnOIType: Char): boolean;
47begin
48 Result := sCallV('ORWDPS1 IVDEA',[AnOI,AnOIType,Encounter.Provider]) = '1';
49end;
50
51procedure ListForOrderable(var AListIEN, ACount: Integer; const DGrpNm: string);
52begin
53 CallV('ORWUL FV4DG', [DGrpNm]);
54 AListIEN := StrToIntDef(Piece(RPCBrokerV.Results[0], U, 1), 0);
55 ACount := StrToIntDef(Piece(RPCBrokerV.Results[0], U, 2), 0);
56end;
57
58procedure SubsetOfOrderable(Dest: TStringList; Append: Boolean; ListIEN, First, Last: Integer);
59var
60 i: Integer;
61begin
62 CallV('ORWUL FVSUB', [ListIEN, First+1, Last+1]); // M side not 0-based
63 if Append then Dest.AddStrings(RPCBrokerV.Results) else
64 begin
65 for i := Pred(RPCBrokerV.Results.Count) downto 0 do Dest.Insert(0, RPCBrokerV.Results[i]);
66 end;
67end;
68
69function IndexOfOrderable(ListIEN: Integer; From: string): Integer;
70var
71 x: string;
72begin
73 Result := -1;
74 if From = '' then Exit;
75 // decrement last char & concat '~' for $ORDER on M side, limit string length
76 x := UpperCase(Copy(From, 1, 220));
77 x := Copy(x, 1, Length(x) - 1) + Pred(x[Length(x)]) + '~';
78 x := sCallV('ORWUL FVIDX', [ListIEN, x]);
79 // use Pred to make the index 0-based (first value = 1 on M side)
80 if CompareText(Copy(Piece(x, U, 2), 1, Length(From)), From) = 0
81 then Result := Pred(StrToIntDef(Piece(x, U, 1), 0));
82end;
83
84procedure IsActivateOI(var AMsg: string; theOI: integer);
85begin
86 AMsg := SCallV('ORWDXA ISACTOI', [theOI]);
87end;
88
89procedure ListForQuickOrders(var AListIEN, ACount: Integer; const DGrpNm: string);
90begin
91 CallV('ORWUL QV4DG', [DGrpNm]);
92 AListIEN := StrToIntDef(Piece(RPCBrokerV.Results[0], U, 1), 0);
93 ACount := StrToIntDef(Piece(RPCBrokerV.Results[0], U, 2), 0);
94end;
95
96procedure SubsetOfQuickOrders(Dest: TStringList; AListIEN, First, Last: Integer);
97var
98 i: Integer;
99begin
100 CallV('ORWUL QVSUB', [AListIEN,'','']);
101 for i := 0 to RPCBrokerV.Results.Count -1 do
102 Dest.Add(RPCBrokerV.Results[i]);
103end;
104
105function IndexOfQuickOrder(AListIEN: Integer; From: string): Integer;
106var
107 x: string;
108begin
109 Result := -1;
110 if From = '' then Exit;
111 // decrement last char & concat '~' for $ORDER on M side, limit string length
112 x := UpperCase(Copy(From, 1, 220));
113 x := Copy(x, 1, Length(x) - 1) + Pred(x[Length(x)]) + '~';
114 x := sCallV('ORWUL QVIDX', [AListIEN, x]);
115 // use Pred to made the index 0-based (first value = 1 on M side)
116 if CompareText(Copy(Piece(x, U, 2), 1, Length(From)), From) = 0
117 then Result := Pred(StrToIntDef(Piece(x, U, 1), 0));
118end;
119
120procedure LoadFormularyAltOI(AList: TStringList; AnIEN: Integer; ForInpatient: Boolean);
121var
122 PtType: Char;
123begin
124 if ForInpatient then PtType := 'I' else PtType := 'O';
125 CallV('ORWDPS1 FORMALT', [AnIEN, PtType]);
126 AList.Assign(RPCBrokerV.Results);
127end;
128
129procedure LoadFormularyAltDose(AList: TStringList; DispDrug, OI: Integer; ForInpatient: Boolean);
130var
131 PtType: Char;
132begin
133 if ForInpatient then PtType := 'I' else PtType := 'O';
134 CallV('ORWDPS1 DOSEALT', [DispDrug, OI, PtType]);
135 AList.Assign(RPCBrokerV.Results);
136end;
137
138procedure LoadAdminInfo(const Schedule: string; OrdItem: Integer; var StartText: string;
139 var AdminTime: TFMDateTime; var Duration: string);
140var
141 x: string;
142begin
143 x := sCallV('ORWDPS2 ADMIN', [Patient.DFN, Schedule, OrdItem, Encounter.Location]);
144 StartText := Piece(x, U, 1);
145 AdminTime := MakeFMDateTime(Piece(x, U, 4));
146 Duration := Piece(x, U, 3);
147end;
148
149function GetAdminTime(const StartText, Schedule: string; OrdItem: Integer): TFMDateTime;
150var
151 x: string;
152begin
153 x := sCallV('ORWDPS2 REQST', [Patient.DFN, Schedule, OrdItem, Encounter.Location, StartText]);
154 Result := MakeFMDateTime(x);
155end;
156
157procedure LoadSchedules(Dest: TStrings; IsInptDlg: boolean);
158begin
159 // if uMedSchedules = nil then CallV('ORWDPS ALLSCHD', [nil]); uMedSchedules.Assign(...);
160 CallV('ORWDPS1 SCHALL', [nil]);
161 Dest.Assign(RPCBrokerV.Results);
162 If (Dest.IndexOfName('OTHER') < 0) and IsInptDlg then
163 Dest.Add('OTHER');
164end;
165
166function QtyToDays(Quantity: Double; const UnitsPerDose, Schedule, Duration, Drug: string): Integer;
167begin
168 Result := StrToIntDef(sCallV('ORWDPS2 QTY2DAY',
169 [Quantity, UnitsPerDose, Schedule, Duration, Patient.DFN, Drug]), 0);
170end;
171
172function DaysToQty(DaysSupply: Integer; const UnitsPerDose, Schedule, Duration, Drug: string): Integer;
173begin
174 Result := StrToIntDef(sCallV('ORWDPS2 DAY2QTY',
175 [DaysSupply, UnitsPerDose, Schedule, Duration, Patient.DFN, Drug]), 0);
176end;
177
178function DurToQty(DaysSupply: Integer; const UnitStr, SchedStr: string): Integer;
179begin
180 Result := StrToIntDef(sCallV('ORWDPS2 DAY2QTY', [DaysSupply, UnitStr, SchedStr]), 0);
181end;
182
183function DefaultDays(const ADrug, UnitStr, SchedStr: string): Integer;
184begin
185 Result := StrToIntDef(sCallV('ORWDPS1 DFLTSPLY', [UnitStr, SchedStr, Patient.DFN, ADrug]), 0);
186end;
187
188function CalcMaxRefills(const Drug: string; Days, OrdItem: Integer; Discharge: Boolean): Integer;
189begin
190 Result := StrToIntDef(sCallV('ORWDPS2 MAXREF', [Patient.DFN, Drug, Days, OrdItem, Discharge]), 0);
191end;
192
193function ScheduleRequired(OrdItem: Integer; const ARoute, ADrug: string): Boolean;
194begin
195 Result := sCallV('ORWDPS2 SCHREQ', [OrdItem, ARoute, ADrug]) = '1';
196end;
197
198function ODForMedsIn: TStrings;
199{ Returns init values for inpatient meds dialog. The results must be used immediately. }
200begin
201 CallV('ORWDPS1 ODSLCT', [PST_UNIT_DOSE, Patient.DFN, Encounter.Location]);
202 Result := RPCBrokerV.Results;
203end;
204
205function ODForMedsOut: TStrings;
206{ Returns init values for outpatient meds dialog. The results must be used immediately. }
207begin
208 CallV('ORWDPS1 ODSLCT', [PST_OUTPATIENT, Patient.DFN, Encounter.Location]);
209 Result := RPCBrokerV.Results;
210end;
211
212function OIForMed(AnIEN: Integer; ForInpatient: Boolean; HavePI: Boolean; PKIActive: Boolean): TStrings;
213var
214 PtType: Char;
215 NeedPI: Char;
216 IsPKIActive: Char;
217begin
218 if HavePI then NeedPI := 'Y' else NeedPI := 'N';
219 if ForInpatient then PtType := 'U' else PtType := 'O';
220 if PKIActive then IsPKIActive := 'Y' else IsPKIActive := 'N';
221 CallV('ORWDPS2 OISLCT', [AnIEN, PtType, Patient.DFN, NeedPI, IsPKIActive]);
222 Result := RPCBrokerV.Results;
223end;
224
225function GetPickupForLocation(const Loc: string): string;
226begin
227 Result := sCallV('ORWDPS1 LOCPICK',[Loc]);
228end;
229
230function QOHasRouteDefined(AQOID: integer): boolean;
231begin
232 Result := False;
233 if ( sCallV('ORWDPS1 HASROUTE',[AQOID])='1' ) then
234 Result := True;
235end;
236
237procedure CheckExistingPI(AOrderId: string; var APtI: string);
238begin
239 APtI := sCallV('ORWDPS2 CHKPI', [AOrderId]);
240end;
241
242end.
Note: See TracBrowser for help on using the repository browser.