| 1 | //kt -- Modified with SourceScanner on 8/8/2007 | 
|---|
| 2 | unit rODDiet; | 
|---|
| 3 |  | 
|---|
| 4 | interface | 
|---|
| 5 |  | 
|---|
| 6 | uses SysUtils, Windows, Classes, ORNet, ORFn, uCore, uConst, rOrders; | 
|---|
| 7 |  | 
|---|
| 8 | type | 
|---|
| 9 | TOutpatientPatchInstalled = record | 
|---|
| 10 | PatchInstalled: boolean; | 
|---|
| 11 | PatchChecked: boolean; | 
|---|
| 12 | end; | 
|---|
| 13 |  | 
|---|
| 14 | TUserHasFHAUTHKey = record | 
|---|
| 15 | UserHasKey: boolean; | 
|---|
| 16 | KeyChecked: boolean; | 
|---|
| 17 | end; | 
|---|
| 18 |  | 
|---|
| 19 | TDietParams = record | 
|---|
| 20 | Tray: Boolean; | 
|---|
| 21 | Cafeteria: Boolean; | 
|---|
| 22 | DiningRm: Boolean; | 
|---|
| 23 | Bagged: Boolean; | 
|---|
| 24 | RegIEN: Integer; | 
|---|
| 25 | NPOIEN: Integer; | 
|---|
| 26 | EarlyIEN: string; | 
|---|
| 27 | LateIEN: string; | 
|---|
| 28 | CurTF:  string; | 
|---|
| 29 | BTimes: string; | 
|---|
| 30 | NTimes: string; | 
|---|
| 31 | ETimes: string; | 
|---|
| 32 | Alarms: string; | 
|---|
| 33 | OPMaxDays: integer; | 
|---|
| 34 | OPDefaultDiet: integer; | 
|---|
| 35 | end; | 
|---|
| 36 |  | 
|---|
| 37 | function CurrentDietText: string; | 
|---|
| 38 | function DietAttributes(OI: Integer): string; | 
|---|
| 39 | function ExpandedQuantity(Product, Strength: Integer; const Qty: string): string; | 
|---|
| 40 | procedure LoadDietParams(var DietParams: TDietParams; ALocation: string); | 
|---|
| 41 | procedure AppendTFProducts(Dest: TStrings); | 
|---|
| 42 | function SubSetOfDiets(const StartFrom: string; Direction: Integer): TStrings; | 
|---|
| 43 | function SubSetOfOPDiets: TStrings; | 
|---|
| 44 | procedure OrderLateTray(NewOrder: TOrder; Meal: Char; const MealTime: string; Bagged: Boolean); | 
|---|
| 45 | function IsolationID: string; | 
|---|
| 46 | function CurrentIsolation: string; | 
|---|
| 47 | procedure LoadIsolations(Dest: TStrings); | 
|---|
| 48 | procedure LoadDietQuickList(Dest: TStrings; const GroupID: string); | 
|---|
| 49 | function DietDialogType(GroupIEN: Integer): Char; | 
|---|
| 50 | function OutpatientPatchInstalled: boolean; | 
|---|
| 51 | function UserHasFHAUTHKey: boolean; | 
|---|
| 52 | procedure GetCurrentRecurringOPMeals(Dest: TStrings; MealType: string = ''); | 
|---|
| 53 | function OutpatientLocationConfigured(ALocation: string): boolean; | 
|---|
| 54 |  | 
|---|
| 55 |  | 
|---|
| 56 | implementation | 
|---|
| 57 |  | 
|---|
| 58 | uses TRPCB, rMisc, rCore; | 
|---|
| 59 |  | 
|---|
| 60 | var | 
|---|
| 61 | uOutpatientPatchInstalled: TOutpatientPatchInstalled; | 
|---|
| 62 | uUserHasFHAUTHKey: TUserHasFHAUTHKey; | 
|---|
| 63 |  | 
|---|
| 64 | function DietAttributes(OI: Integer): string; | 
|---|
| 65 | begin | 
|---|
| 66 | CallV('ORWDFH ATTR', [OI]); | 
|---|
| 67 | Result := RPCBrokerV.Results[0]; | 
|---|
| 68 | end; | 
|---|
| 69 |  | 
|---|
| 70 | procedure LoadDietParams(var DietParams: TDietParams; ALocation: string); | 
|---|
| 71 | begin | 
|---|
| 72 | CallV('ORWDFH PARAM', [Patient.DFN, ALocation]); | 
|---|
| 73 | with RPCBrokerV, DietParams do | 
|---|
| 74 | begin | 
|---|
| 75 | if Results.Count > 0 then | 
|---|
| 76 | begin | 
|---|
| 77 | BTimes := Pieces(Results[0], U,  1,  6); | 
|---|
| 78 | NTimes := Pieces(Results[0], U,  7, 12); | 
|---|
| 79 | ETimes := Pieces(Results[0], U, 13, 18); | 
|---|
| 80 | end; | 
|---|
| 81 | if Results.Count > 1 then | 
|---|
| 82 | begin | 
|---|
| 83 | Alarms := Pieces(Results[1], U, 1, 6); | 
|---|
| 84 | Bagged := Piece(Results[1], U, 10) = 'Y'; | 
|---|
| 85 | end; | 
|---|
| 86 | if Results.Count > 2 then | 
|---|
| 87 | begin | 
|---|
| 88 | Tray      := Pos('T', Results[2]) > 0; | 
|---|
| 89 | Cafeteria := Pos('C', Results[2]) > 0; | 
|---|
| 90 | DiningRm  := Pos('D', Results[2]) > 0; | 
|---|
| 91 | RegIEN    := StrToIntDef(Piece(Results[2], U, 2), 0); | 
|---|
| 92 | NPOIEN    := StrToIntDef(Piece(Results[2], U, 3), 0); | 
|---|
| 93 | EarlyIEN  := Piece(Results[2], U, 4); | 
|---|
| 94 | LateIEN   := Piece(Results[2], U, 5); | 
|---|
| 95 | CurTF     := Piece(Results[2], U, 6); | 
|---|
| 96 | end; | 
|---|
| 97 | if (not Tray) and (not Cafeteria) and (not DiningRm) then Tray := True; | 
|---|
| 98 | if Results.Count > 3 then | 
|---|
| 99 | OPMaxDays := StrToIntDef(Results[3], 30) | 
|---|
| 100 | else | 
|---|
| 101 | OPMaxDays := 30; | 
|---|
| 102 | if Results.Count > 4 then | 
|---|
| 103 | OPDefaultDiet := StrToIntDef(Results[4], 0) | 
|---|
| 104 | end; | 
|---|
| 105 | end; | 
|---|
| 106 |  | 
|---|
| 107 | function CurrentDietText: string; | 
|---|
| 108 | begin | 
|---|
| 109 | CallV('ORWDFH TXT', [Patient.DFN]); | 
|---|
| 110 | Result := RPCBrokerV.Results.Text; | 
|---|
| 111 | end; | 
|---|
| 112 |  | 
|---|
| 113 | function CurrentTFText(const IENStr: string): string; | 
|---|
| 114 | begin | 
|---|
| 115 | end; | 
|---|
| 116 |  | 
|---|
| 117 | procedure AppendTFProducts(Dest: TStrings); | 
|---|
| 118 | begin | 
|---|
| 119 | CallV('ORWDFH TFPROD', [nil]); | 
|---|
| 120 | Dest.AddStrings(RPCBrokerV.Results); | 
|---|
| 121 | end; | 
|---|
| 122 |  | 
|---|
| 123 | function ExpandedQuantity(Product, Strength: Integer; const Qty: string): string; | 
|---|
| 124 | begin | 
|---|
| 125 | Result := ''; | 
|---|
| 126 | if (Product = 0) or (Strength = 0) or (Length(Qty) = 0) then Exit; | 
|---|
| 127 | Result := sCallV('ORWDFH QTY2CC', [Product, Strength, Qty]); | 
|---|
| 128 | end; | 
|---|
| 129 |  | 
|---|
| 130 | function SubSetOfDiets(const StartFrom: string; Direction: Integer): TStrings; | 
|---|
| 131 | { returns a pointer to a list of orderable items matching an S.xxx cross reference (for use in | 
|---|
| 132 | a long list box) -  The return value is  a pointer to RPCBrokerV.Results, so the data must | 
|---|
| 133 | be used BEFORE the next broker call! } | 
|---|
| 134 | begin | 
|---|
| 135 | CallV('ORWDFH DIETS', [StartFrom, Direction]); | 
|---|
| 136 | Result := RPCBrokerV.Results; | 
|---|
| 137 | end; | 
|---|
| 138 |  | 
|---|
| 139 | function SubSetOfOPDiets: TStrings; | 
|---|
| 140 | begin | 
|---|
| 141 | CallV('ORWDFH OPDIETS', [nil]); | 
|---|
| 142 | Result := RPCBrokerV.Results; | 
|---|
| 143 | end; | 
|---|
| 144 |  | 
|---|
| 145 | procedure OrderLateTray(NewOrder: TOrder; Meal: Char; const MealTime: string; Bagged: Boolean); | 
|---|
| 146 | begin | 
|---|
| 147 | CallV('ORWDFH ADDLATE', [Patient.DFN, Encounter.Provider, Encounter.Location, Meal, MealTime, Bagged]); | 
|---|
| 148 | SetOrderFromResults(NewOrder); | 
|---|
| 149 | end; | 
|---|
| 150 |  | 
|---|
| 151 | function IsolationID: string; | 
|---|
| 152 | begin | 
|---|
| 153 | Result := sCallV('ORWDFH ISOIEN', [nil]); | 
|---|
| 154 | end; | 
|---|
| 155 |  | 
|---|
| 156 | function CurrentIsolation: string; | 
|---|
| 157 | begin | 
|---|
| 158 | Result := sCallV('ORWDFH CURISO', [Patient.DFN]); | 
|---|
| 159 | end; | 
|---|
| 160 |  | 
|---|
| 161 | procedure LoadIsolations(Dest: TStrings); | 
|---|
| 162 | begin | 
|---|
| 163 | CallV('ORWDFH ISOLIST', [nil]); | 
|---|
| 164 | Dest.Assign(RPCBrokerV.Results); | 
|---|
| 165 | end; | 
|---|
| 166 |  | 
|---|
| 167 | procedure LoadDietQuickList(Dest: TStrings; const GroupID: string); | 
|---|
| 168 | begin | 
|---|
| 169 | CallV('ORWDXQ GETQLST', [GroupID, 'Q']); | 
|---|
| 170 | Dest.Assign(RPCBrokerV.Results); | 
|---|
| 171 | end; | 
|---|
| 172 |  | 
|---|
| 173 | function DietDialogType(GroupIEN: Integer): Char; | 
|---|
| 174 | begin | 
|---|
| 175 | Result := CharAt(sCallV('ORWDFH FINDTYP', [GroupIEN]), 1); | 
|---|
| 176 | if not (Result in ['A', 'D', 'E', 'N', 'P', 'T', 'M']) then Result := 'D'; | 
|---|
| 177 | end; | 
|---|
| 178 |  | 
|---|
| 179 | function OutpatientPatchInstalled: boolean; | 
|---|
| 180 | begin | 
|---|
| 181 | with uOutpatientPatchInstalled do | 
|---|
| 182 | if not PatchChecked then | 
|---|
| 183 | begin | 
|---|
| 184 | //PatchInstalled := True; | 
|---|
| 185 | { TODO -oRich V. -cOutpatient Meals : Uncomment when available } | 
|---|
| 186 | PatchInstalled := (PackageVersion('FH') >= '5.5'); | 
|---|
| 187 | PatchChecked := True; | 
|---|
| 188 | end; | 
|---|
| 189 | Result := uOutpatientPatchInstalled.PatchInstalled; | 
|---|
| 190 | end; | 
|---|
| 191 |  | 
|---|
| 192 | function UserHasFHAUTHKey: boolean; | 
|---|
| 193 | begin | 
|---|
| 194 | with uUserHasFHAUTHKey do | 
|---|
| 195 | if not KeyChecked then | 
|---|
| 196 | begin | 
|---|
| 197 | UserHasKey := HasSecurityKey('FHAUTH'); | 
|---|
| 198 | KeyChecked := True; | 
|---|
| 199 | end; | 
|---|
| 200 | Result := uUserHasFHAUTHKey.UserHasKey; | 
|---|
| 201 | end; | 
|---|
| 202 |  | 
|---|
| 203 | procedure GetCurrentRecurringOPMeals(Dest: TStrings; MealType: string = ''); | 
|---|
| 204 | begin | 
|---|
| 205 | CallV('ORWDFH CURRENT MEALS', [Patient.DFN, MealType]); | 
|---|
| 206 | Dest.Assign(RPCBrokerV.Results); | 
|---|
| 207 | MixedCaseList(Dest); | 
|---|
| 208 | end; | 
|---|
| 209 |  | 
|---|
| 210 | function OutpatientLocationConfigured(ALocation: string): boolean; | 
|---|
| 211 | begin | 
|---|
| 212 | Result := (sCallV('ORWDFH NFSLOC READY', [ALocation]) = '1'); | 
|---|
| 213 | end; | 
|---|
| 214 |  | 
|---|
| 215 | end. | 
|---|