| [456] | 1 | unit rODLab; | 
|---|
|  | 2 |  | 
|---|
|  | 3 | interface | 
|---|
|  | 4 |  | 
|---|
|  | 5 | uses SysUtils, Classes, ORNet, ORFn, rCore, uCore, TRPCB, dialogs ; | 
|---|
|  | 6 |  | 
|---|
|  | 7 | { Laboratory Ordering Calls } | 
|---|
|  | 8 | function  ODForLab(Location: integer; Division: integer = 0): TStrings; | 
|---|
|  | 9 | procedure LoadLabTestData(LoadData: TStringList; LabTestIEN: string) ; | 
|---|
|  | 10 | procedure LoadSamples(LoadList: TStringList) ; | 
|---|
|  | 11 | procedure LoadSpecimens(SpecimenList: TStringList) ; | 
|---|
|  | 12 | function  SubsetOfSpecimens(const StartFrom: string; Direction: Integer): TStrings; | 
|---|
|  | 13 | function  CalcStopDate(Text: string): string ; | 
|---|
|  | 14 | function  MaxDays(Location, Schedule: integer): integer; | 
|---|
|  | 15 | function  IsLabCollectTime(ADateTime: TFMDateTime; Location: integer): boolean; | 
|---|
|  | 16 | function  ImmediateCollectTimes: TStrings; | 
|---|
|  | 17 | function  LabCollectFutureDays(Location: integer; Division: integer = 0): integer; | 
|---|
|  | 18 | function  GetDefaultImmCollTime: TFMDateTime; | 
|---|
|  | 19 | function  ValidImmCollTime(CollTime: TFMDateTime): string; | 
|---|
|  | 20 | function  GetOneCollSamp(LRFSAMP: integer): TStrings; | 
|---|
|  | 21 | function  GetOneSpecimen(LRFSPEC: integer): string; | 
|---|
|  | 22 | procedure GetLabTimesForDate(Dest: TStrings; LabDate: TFMDateTime; Location: integer); | 
|---|
|  | 23 | function  GetLastCollectionTime: string; | 
|---|
|  | 24 | procedure GetPatientBBInfo(Dest: TStrings; PatientID: string; Loc: integer); | 
|---|
| [829] | 25 | procedure ListForQuickOrders(var AListIEN, ACount: Integer; const DGrpNm: string); | 
|---|
|  | 26 | procedure SubsetOfQuickOrders(Dest: TStringList; AListIEN, First, Last: Integer); | 
|---|
| [456] | 27 | procedure GetPatientBloodResults(Dest: TStrings; PatientID: string; ATests: TStringList); | 
|---|
|  | 28 | procedure GetPatientBloodResultsRaw(Dest: TStrings; PatientID: string; ATests: TStringList); | 
|---|
|  | 29 | function  StatAllowed(PatientID: string): boolean; | 
|---|
|  | 30 | procedure GetBloodComponents(Dest: TStrings); | 
|---|
| [829] | 31 | function  NursAdminSuppress: boolean; | 
|---|
|  | 32 | function  GetSubtype(TestName: string): string; | 
|---|
|  | 33 | function  TNSDaysBack: integer; | 
|---|
|  | 34 | procedure CheckForChangeFromLCtoWCOnAccept(Dest: TStrings; ALocation: integer; AStartDate, ACollType, ASchedule, ADuration: string); | 
|---|
|  | 35 | procedure CheckForChangeFromLCtoWCOnRelease(Dest: TStrings; ALocation: integer; OrderList: TStringList); | 
|---|
|  | 36 | function  GetLCtoWCInstructions(Alocation: integer): string; | 
|---|
|  | 37 | procedure FormatLCtoWCDisplayTextOnAccept(InputList, OutputList: TStrings); | 
|---|
|  | 38 | procedure FormatLCtoWCDisplayTextOnRelease(InputList, OutputList: TStrings); | 
|---|
| [456] | 39 |  | 
|---|
| [829] | 40 | const | 
|---|
|  | 41 | TX0 = 'The following Lab orders will be changed to Ward Collect:'; | 
|---|
|  | 42 | TX2 = 'Order Date' + #9 +#9 + 'Reason Changed to Ward Collect'; | 
|---|
|  | 43 | TX5 = 'Please contact the ward staff to insure the specimen is collected.'; | 
|---|
|  | 44 | TX6 = 'You can print this screen for reference.'; | 
|---|
|  | 45 | TX_BLANK = ''; | 
|---|
|  | 46 |  | 
|---|
| [456] | 47 | implementation | 
|---|
|  | 48 |  | 
|---|
|  | 49 | uses  rODBase; | 
|---|
|  | 50 |  | 
|---|
|  | 51 | procedure GetBloodComponents(Dest: TStrings); | 
|---|
|  | 52 | begin | 
|---|
|  | 53 | tCallV(Dest, 'ORWDXVB COMPORD', []); | 
|---|
|  | 54 | end; | 
|---|
|  | 55 |  | 
|---|
| [829] | 56 | function NursAdminSuppress: boolean; | 
|---|
|  | 57 | begin | 
|---|
|  | 58 | Result := (StrToInt(sCallV('ORWDXVB NURSADMN',[nil])) < 1); | 
|---|
|  | 59 | end; | 
|---|
|  | 60 |  | 
|---|
| [456] | 61 | function  StatAllowed(PatientID: string): boolean; | 
|---|
|  | 62 | begin | 
|---|
|  | 63 | Result := (StrToInt(sCallV('ORWDXVB STATALOW',[PatientID])) > 0); | 
|---|
|  | 64 | end; | 
|---|
|  | 65 |  | 
|---|
|  | 66 | procedure GetPatientBloodResultsRaw(Dest: TStrings; PatientID: string; ATests: TStringList); | 
|---|
|  | 67 | begin | 
|---|
|  | 68 | tCallV(Dest, 'ORWDXVB RAW', [PatientID, ATests]); | 
|---|
|  | 69 | end; | 
|---|
|  | 70 |  | 
|---|
|  | 71 | procedure GetPatientBloodResults(Dest: TStrings; PatientID: string; ATests: TStringList); | 
|---|
|  | 72 | begin | 
|---|
|  | 73 | tCallV(Dest, 'ORWDXVB RESULTS', [PatientID, ATests]); | 
|---|
|  | 74 | end; | 
|---|
|  | 75 |  | 
|---|
|  | 76 | procedure GetPatientBBInfo(Dest: TStrings; PatientID: string; Loc: integer); | 
|---|
|  | 77 | begin | 
|---|
|  | 78 | tCallV(Dest, 'ORWDXVB GETALL', [PatientID, Loc]); | 
|---|
|  | 79 | end; | 
|---|
|  | 80 |  | 
|---|
| [829] | 81 | function GetSubtype(TestName: string): string; | 
|---|
|  | 82 | begin | 
|---|
|  | 83 | Result := sCallV('ORWDXVB SUBCHK', [TestName]); | 
|---|
|  | 84 | end; | 
|---|
|  | 85 |  | 
|---|
|  | 86 | function TNSDaysBack: integer; | 
|---|
|  | 87 | begin | 
|---|
|  | 88 | Result := StrToIntDef(sCallV('ORWDXVB VBTNS', [nil]),3); | 
|---|
|  | 89 | end; | 
|---|
|  | 90 |  | 
|---|
|  | 91 | procedure ListForQuickOrders(var AListIEN, ACount: Integer; const DGrpNm: string); | 
|---|
|  | 92 | begin | 
|---|
|  | 93 | CallV('ORWUL QV4DG', [DGrpNm]); | 
|---|
|  | 94 | AListIEN := StrToIntDef(Piece(RPCBrokerV.Results[0], U, 1), 0); | 
|---|
|  | 95 | ACount   := StrToIntDef(Piece(RPCBrokerV.Results[0], U, 2), 0); | 
|---|
|  | 96 | end; | 
|---|
|  | 97 |  | 
|---|
|  | 98 | procedure SubsetOfQuickOrders(Dest: TStringList; AListIEN, First, Last: Integer); | 
|---|
|  | 99 | var | 
|---|
|  | 100 | i: Integer; | 
|---|
|  | 101 | begin | 
|---|
|  | 102 | CallV('ORWUL QVSUB', [AListIEN,'','']); | 
|---|
|  | 103 | for i := 0 to RPCBrokerV.Results.Count -1 do | 
|---|
|  | 104 | Dest.Add(RPCBrokerV.Results[i]); | 
|---|
|  | 105 | end; | 
|---|
|  | 106 |  | 
|---|
| [456] | 107 | function ODForLab(Location, Division: integer): TStrings; | 
|---|
|  | 108 | { Returns init values for laboratory dialog.  The results must be used immediately. } | 
|---|
|  | 109 | begin | 
|---|
|  | 110 | CallV('ORWDLR32 DEF', [Location,Division]); | 
|---|
|  | 111 | Result := RPCBrokerV.Results; | 
|---|
|  | 112 | end; | 
|---|
|  | 113 |  | 
|---|
|  | 114 | procedure LoadLabTestData(LoadData: TStringList; LabTestIEN: string) ; | 
|---|
|  | 115 | begin | 
|---|
|  | 116 | tCallV(LoadData, 'ORWDLR32 LOAD', [LabTestIEN]); | 
|---|
|  | 117 | end ; | 
|---|
|  | 118 |  | 
|---|
|  | 119 | procedure LoadSamples(LoadList: TStringList) ; | 
|---|
|  | 120 | begin | 
|---|
|  | 121 | tCallV(LoadList, 'ORWDLR32 ALLSAMP', [nil]); | 
|---|
|  | 122 | end ; | 
|---|
|  | 123 |  | 
|---|
|  | 124 | function SubsetOfSpecimens(const StartFrom: string; Direction: Integer): TStrings; | 
|---|
|  | 125 | begin | 
|---|
|  | 126 | Callv('ORWDLR32 ALLSPEC',[StartFrom, Direction]); | 
|---|
|  | 127 | Result := RPCBrokerV.Results; | 
|---|
|  | 128 | end ; | 
|---|
|  | 129 |  | 
|---|
|  | 130 | procedure LoadSpecimens(SpecimenList: TStringList) ; | 
|---|
|  | 131 | begin | 
|---|
|  | 132 | tCallV(SpecimenList, 'ORWDLR32 ABBSPEC', [nil]); | 
|---|
|  | 133 | end ; | 
|---|
|  | 134 |  | 
|---|
|  | 135 | function CalcStopDate(Text: string): string ; | 
|---|
|  | 136 | begin | 
|---|
|  | 137 | Result := sCallV('ORWDLR32 STOP', [Text]); | 
|---|
|  | 138 | end ; | 
|---|
|  | 139 |  | 
|---|
|  | 140 | function MaxDays(Location, Schedule: integer): integer; | 
|---|
|  | 141 | begin | 
|---|
|  | 142 | Result := StrToInt(sCallV('ORWDLR32 MAXDAYS',[Location, Schedule])); | 
|---|
|  | 143 | end; | 
|---|
|  | 144 |  | 
|---|
|  | 145 | function IsLabCollectTime(ADateTime: TFMDateTime; Location: integer): boolean; | 
|---|
|  | 146 | begin | 
|---|
|  | 147 | Result := (StrToInt(sCallV('ORWDLR32 LAB COLL TIME',[ADateTime,Location])) > 0); | 
|---|
|  | 148 | end; | 
|---|
|  | 149 |  | 
|---|
|  | 150 | function  LabCollectFutureDays(Location: integer; Division: integer): integer; | 
|---|
|  | 151 | begin | 
|---|
|  | 152 | Result := StrToInt(sCallV('ORWDLR33 FUTURE LAB COLLECTS',[Location, Division])); | 
|---|
|  | 153 | end; | 
|---|
|  | 154 |  | 
|---|
|  | 155 | function  ImmediateCollectTimes: TStrings; | 
|---|
|  | 156 | begin | 
|---|
|  | 157 | CallV('ORWDLR32 IMMED COLLECT',[nil]); | 
|---|
|  | 158 | Result := RPCBrokerV.Results; | 
|---|
|  | 159 | end; | 
|---|
|  | 160 |  | 
|---|
|  | 161 | function  GetDefaultImmCollTime: TFMDateTime; | 
|---|
|  | 162 | begin | 
|---|
|  | 163 | CallV('ORWDLR32 IC DEFAULT',[nil]); | 
|---|
|  | 164 | Result := StrToFloat(Piece(RPCBrokerV.Results[0], U, 1)); | 
|---|
|  | 165 | end; | 
|---|
|  | 166 |  | 
|---|
|  | 167 | function  ValidImmCollTime(CollTime: TFMDateTime): string; | 
|---|
|  | 168 | begin | 
|---|
|  | 169 | CallV('ORWDLR32 IC VALID',[CollTime]); | 
|---|
|  | 170 | Result := RPCBrokerV.Results[0]; | 
|---|
|  | 171 | end; | 
|---|
|  | 172 |  | 
|---|
|  | 173 | function  GetOneCollSamp(LRFSAMP: integer): TStrings; | 
|---|
|  | 174 | begin | 
|---|
|  | 175 | CallV('ORWDLR32 ONE SAMPLE', [LRFSAMP]); | 
|---|
|  | 176 | Result := RPCBrokerV.Results; | 
|---|
|  | 177 | end; | 
|---|
|  | 178 |  | 
|---|
|  | 179 | function  GetOneSpecimen(LRFSPEC: integer): string; | 
|---|
|  | 180 | begin | 
|---|
|  | 181 | Result := sCallV('ORWDLR32 ONE SPECIMEN', [LRFSPEC]); | 
|---|
|  | 182 | end; | 
|---|
|  | 183 |  | 
|---|
|  | 184 | function  GetLastCollectionTime: string; | 
|---|
|  | 185 | begin | 
|---|
|  | 186 | Result := sCallV('ORWDLR33 LASTTIME', [nil]); | 
|---|
|  | 187 | end | 
|---|
|  | 188 | ; | 
|---|
|  | 189 | procedure GetLabTimesForDate(Dest: TStrings; LabDate: TFMDateTime; Location: integer); | 
|---|
|  | 190 | var | 
|---|
|  | 191 | Prefix: string; | 
|---|
|  | 192 | i: integer; | 
|---|
|  | 193 | begin | 
|---|
|  | 194 | CallV('ORWDLR32 GET LAB TIMES', [LabDate, Location]); | 
|---|
|  | 195 | with Dest do | 
|---|
|  | 196 | begin | 
|---|
|  | 197 | Assign(RPCBrokerV.Results); | 
|---|
|  | 198 | if (Count > 0) and (Piece(Strings[0], U, 1) <> '-1') then | 
|---|
|  | 199 | for i := 0 to Count - 1 do | 
|---|
|  | 200 | begin | 
|---|
|  | 201 | if Strings[i] > '1159' then Prefix := 'PM Collection:  ' else Prefix := 'AM Collection:  '; | 
|---|
|  | 202 | Strings[i] := Strings[i] + U + Prefix + Copy(Strings[i], 1, 2) + ':' + Copy(Strings[i], 3, 2); | 
|---|
|  | 203 | end; | 
|---|
|  | 204 | end; | 
|---|
|  | 205 | end; | 
|---|
|  | 206 |  | 
|---|
| [829] | 207 | procedure CheckForChangeFromLCtoWCOnAccept(Dest: TStrings; ALocation: integer; AStartDate, ACollType, ASchedule, ADuration: string); | 
|---|
|  | 208 | var | 
|---|
|  | 209 | AList: TStringList; | 
|---|
|  | 210 | begin | 
|---|
|  | 211 | AList := TStringList.Create; | 
|---|
|  | 212 | try | 
|---|
|  | 213 | CallV('ORCDLR2 CHECK ONE LC TO WC', [ALocation, '', AStartDate, ACollType, ASchedule, ADuration]); | 
|---|
|  | 214 | FastAssign(RPCBrokerV.Results, AList); | 
|---|
|  | 215 | FormatLCtoWCDisplayTextOnAccept(AList, Dest); | 
|---|
|  | 216 | finally | 
|---|
|  | 217 | AList.Free; | 
|---|
|  | 218 | end; | 
|---|
|  | 219 | end; | 
|---|
|  | 220 |  | 
|---|
|  | 221 | procedure CheckForChangeFromLCtoWCOnRelease(Dest: TStrings; ALocation: integer; OrderList: TStringList); | 
|---|
|  | 222 | var | 
|---|
|  | 223 | AList: TStringList; | 
|---|
|  | 224 | begin | 
|---|
|  | 225 | AList := TStringList.Create; | 
|---|
|  | 226 | try | 
|---|
|  | 227 | CallV('ORCDLR2 CHECK ALL LC TO WC', [ALocation, OrderList]); | 
|---|
|  | 228 | FastAssign(RPCBrokerV.Results, AList); | 
|---|
|  | 229 | FormatLCtoWCDisplayTextOnRelease(AList, Dest); | 
|---|
|  | 230 | finally | 
|---|
|  | 231 | AList.Free; | 
|---|
|  | 232 | end; | 
|---|
|  | 233 | end; | 
|---|
|  | 234 |  | 
|---|
|  | 235 | procedure FormatLCtoWCDisplayTextOnAccept(InputList, OutputList: TStrings); | 
|---|
|  | 236 | var | 
|---|
|  | 237 | i: integer; | 
|---|
|  | 238 | x: string; | 
|---|
|  | 239 | begin | 
|---|
|  | 240 | OutputList.Clear; | 
|---|
|  | 241 | for i := InputList.Count - 1 downto 0 do | 
|---|
|  | 242 | if Piece(InputList[i], U, 2) = '1' then InputList.Delete(i); | 
|---|
|  | 243 | if InputList.Count > 0 then | 
|---|
|  | 244 | begin | 
|---|
|  | 245 | SetListFMDateTime('mmm dd, yyyy@hh:nn', TStringList(InputList), U, 1); | 
|---|
|  | 246 | with OutputList do | 
|---|
|  | 247 | begin | 
|---|
|  | 248 | Add(TX0); | 
|---|
|  | 249 | Add(TX_BLANK); | 
|---|
|  | 250 | Add('Patient :' + #9 + Patient.Name); | 
|---|
|  | 251 | Add('SSN     :' + #9 + Patient.SSN); | 
|---|
|  | 252 | Add('Location:' + #9 + Encounter.LocationName + CRLF); | 
|---|
|  | 253 | for i := 0 to InputList.Count - 1 do | 
|---|
|  | 254 | Add(Piece(InputList[i], U, 1) + #9 + Piece(InputList[i], U, 3)); | 
|---|
|  | 255 | Add(TX_BLANK); | 
|---|
|  | 256 | x := GetLCtoWCInstructions(Encounter.Location); | 
|---|
|  | 257 | if x = '' then x := TX5; | 
|---|
|  | 258 | Add(x); | 
|---|
|  | 259 | Add(TX6); | 
|---|
|  | 260 | end; | 
|---|
|  | 261 | end; | 
|---|
|  | 262 | end; | 
|---|
|  | 263 |  | 
|---|
|  | 264 | procedure FormatLCtoWCDisplayTextOnRelease(InputList, OutputList: TStrings); | 
|---|
|  | 265 | var | 
|---|
|  | 266 | i, j, k, Changed: integer; | 
|---|
|  | 267 | AList: TStringlist; | 
|---|
|  | 268 | x: string; | 
|---|
|  | 269 | begin | 
|---|
|  | 270 | OutputList.Clear; | 
|---|
|  | 271 | Changed := StrToIntDef(ExtractDefault(InputList, 'COUNT'), 0); | 
|---|
|  | 272 | if Changed > 0 then | 
|---|
|  | 273 | begin | 
|---|
|  | 274 | AList := TStringList.Create; | 
|---|
|  | 275 | try | 
|---|
|  | 276 | with OutputList do | 
|---|
|  | 277 | begin | 
|---|
|  | 278 | Add(TX0); | 
|---|
|  | 279 | Add(TX_BLANK); | 
|---|
|  | 280 | Add('Patient :' + #9 + Patient.Name); | 
|---|
|  | 281 | Add('SSN     :' + #9 + Patient.SSN); | 
|---|
|  | 282 | Add('Location:' + #9 + Encounter.LocationName); | 
|---|
|  | 283 | for i := 1 to Changed do | 
|---|
|  | 284 | begin | 
|---|
|  | 285 | Add(TX_BLANK); | 
|---|
|  | 286 | AList.Clear; | 
|---|
|  | 287 | ExtractText(AList, InputList, 'ORDER_' + IntToStr(i)); | 
|---|
|  | 288 | Add('Order   :' + #9 + AList[0]); | 
|---|
|  | 289 | k := Length(OutputList[Count-1]); | 
|---|
|  | 290 | if AList.Count > 1 then | 
|---|
|  | 291 | for j := 1 to AList.Count - 1 do | 
|---|
|  | 292 | begin | 
|---|
|  | 293 | Add(StringOfChar(' ', 9) + #9 + AList[j]); | 
|---|
|  | 294 | k := HigherOf(k, Length(OutputList[Count - 1])); | 
|---|
|  | 295 | end; | 
|---|
|  | 296 | Add(StringOfChar('-', k + 4)); | 
|---|
|  | 297 | AList.Clear; | 
|---|
|  | 298 | ExtractItems(AList, InputList, 'ORDER_' + IntToStr(i)); | 
|---|
|  | 299 | SetListFMDateTime('mmm dd, yyyy@hh:nn', AList, U, 1); | 
|---|
|  | 300 | for j := 0 to AList.Count - 1 do | 
|---|
|  | 301 | OutputList.Add(Piece(AList[j], U, 1) + #9 + Piece(AList[j], U, 3)); | 
|---|
|  | 302 | end; | 
|---|
|  | 303 | Add(TX_BLANK); | 
|---|
|  | 304 | x := GetLCtoWCInstructions(Encounter.Location); | 
|---|
|  | 305 | if x = '' then x := TX5; | 
|---|
|  | 306 | Add(x); | 
|---|
|  | 307 | Add(TX6); | 
|---|
|  | 308 | end; | 
|---|
|  | 309 | finally | 
|---|
|  | 310 | AList.Free; | 
|---|
|  | 311 | end; | 
|---|
|  | 312 | end; | 
|---|
|  | 313 | end; | 
|---|
|  | 314 |  | 
|---|
|  | 315 | function GetLCtoWCInstructions(Alocation: integer): string; | 
|---|
|  | 316 | begin | 
|---|
|  | 317 | Result := sCallV('ORWDLR33 LC TO WC', [Encounter.Location]); | 
|---|
|  | 318 | end; | 
|---|
|  | 319 |  | 
|---|
| [456] | 320 | end. | 
|---|
| [829] | 321 |  | 
|---|
|  | 322 |  | 
|---|