source: cprs/branches/foia-cprs/CPRS-Chart/Orders/rODMeds.pas@ 1806

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

Adding foia-cprs branch

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