[459] | 1 | unit rTIU;
|
---|
| 2 |
|
---|
| 3 | interface
|
---|
| 4 |
|
---|
| 5 | uses SysUtils, Classes, ORNet, ORFn, rCore, uCore, uConst, TRPCB, uTIU;
|
---|
| 6 |
|
---|
| 7 | { Progress Note Titles }
|
---|
| 8 | function DfltNoteTitle: Integer;
|
---|
| 9 | function DfltNoteTitleName: string;
|
---|
| 10 | procedure ResetNoteTitles;
|
---|
| 11 | function IsConsultTitle(TitleIEN: Integer): Boolean;
|
---|
| 12 | function IsClinProcTitle(TitleIEN: Integer): Boolean;
|
---|
| 13 | procedure ListNoteTitlesShort(Dest: TStrings);
|
---|
| 14 | procedure LoadBoilerPlate(Dest: TStrings; Title: Integer);
|
---|
| 15 | function PrintNameForTitle(TitleIEN: Integer): string;
|
---|
| 16 | function SubSetOfNoteTitles(const StartFrom: string; Direction: Integer; IDNotesOnly: boolean): TStrings;
|
---|
| 17 |
|
---|
| 18 | { TIU Preferences }
|
---|
| 19 | procedure ResetTIUPreferences;
|
---|
| 20 | function AskCosignerForNotes: Boolean;
|
---|
| 21 | function AskCosignerForDocument(ADocument: Integer; AnAuthor: Int64): Boolean;
|
---|
| 22 | function AskCosignerForTitle(ATitle: integer; AnAuthor: Int64): Boolean;
|
---|
| 23 | function AskSubjectForNotes: Boolean;
|
---|
| 24 | function CanCosign(ATitle, ADocType: integer; AUser: Int64): Boolean;
|
---|
| 25 | function CanChangeCosigner(IEN: integer): boolean;
|
---|
| 26 | procedure DefaultCosigner(var IEN: Int64; var Name: string);
|
---|
| 27 | function ReturnMaxNotes: Integer;
|
---|
| 28 | function SortNotesAscending: Boolean;
|
---|
| 29 | function GetCurrentTIUContext: TTIUContext;
|
---|
| 30 | procedure SaveCurrentTIUContext(AContext: TTIUContext) ;
|
---|
| 31 | function TIUSiteParams: string;
|
---|
| 32 | function DfltTIULocation: Integer;
|
---|
| 33 | function DfltTIULocationName: string;
|
---|
| 34 |
|
---|
| 35 | { Data Retrieval }
|
---|
| 36 | procedure ActOnDocument(var AuthSts: TActionRec; IEN: Integer; const ActionName: string);
|
---|
| 37 | function AuthorSignedDocument(IEN: Integer): boolean;
|
---|
| 38 | function CosignDocument(IEN: Integer): Boolean;
|
---|
| 39 | //function CPTRequiredForNote(IEN: Integer): Boolean;
|
---|
| 40 | procedure ListNotes(Dest: TStrings; Context: Integer; Early, Late: TFMDateTime;
|
---|
| 41 | Person: int64; OccLim: Integer; SortAscending: Boolean);
|
---|
| 42 | procedure ListNotesForTree(Dest: TStrings; Context: Integer; Early, Late: TFMDateTime;
|
---|
| 43 | Person: int64; OccLim: Integer; SortAscending: Boolean);
|
---|
| 44 | procedure ListConsultRequests(Dest: TStrings);
|
---|
| 45 | procedure ListDCSumm(Dest: TStrings);
|
---|
| 46 | procedure LoadDetailText(Dest: TStrings; IEN: Integer); //**KCM**
|
---|
| 47 | procedure LoadDocumentText(Dest: TStrings; IEN: Integer);
|
---|
| 48 | procedure GetNoteForEdit(var EditRec: TEditNoteRec; IEN: Integer);
|
---|
| 49 | function VisitStrForNote(IEN: Integer): string;
|
---|
| 50 | function GetCurrentSigners(IEN: integer): TStrings;
|
---|
| 51 | function TitleForNote(IEN: Int64): Integer;
|
---|
| 52 | function GetConsultIENforNote(NoteIEN: integer): Integer;
|
---|
| 53 | function GetPackageRefForNote(NoteIEN: integer): string;
|
---|
| 54 | procedure LockDocument(IEN: Int64; var AnErrMsg: string);
|
---|
| 55 | procedure UnlockDocument(IEN: Int64);
|
---|
| 56 | function LastSaveClean(IEN: Int64): Boolean;
|
---|
| 57 | function NoteHasText(NoteIEN: integer): boolean;
|
---|
| 58 | function GetTIUListItem(IEN: Int64): string;
|
---|
| 59 |
|
---|
| 60 | { Data Storage }
|
---|
| 61 | //procedure ClearCPTRequired(IEN: Integer);
|
---|
| 62 | procedure DeleteDocument(var DeleteSts: TActionRec; IEN: Integer; const Reason: string);
|
---|
| 63 | function JustifyDocumentDelete(IEN: Integer): Boolean;
|
---|
| 64 | procedure SignDocument(var SignSts: TActionRec; IEN: Integer; const ESCode: string);
|
---|
| 65 | procedure PutNewNote(var CreatedDoc: TCreatedDoc; const NoteRec: TNoteRec);
|
---|
| 66 | procedure PutAddendum(var CreatedDoc: TCreatedDoc; const NoteRec: TNoteRec; AddendumTo: Integer);
|
---|
| 67 | procedure PutEditedNote(var UpdatedDoc: TCreatedDoc; const NoteRec: TNoteRec; NoteIEN: Integer);
|
---|
| 68 | procedure PutTextOnly(var ErrMsg: string; NoteText: TStrings; NoteIEN: Int64);
|
---|
| 69 | procedure SetText(var ErrMsg: string; NoteText: TStrings; NoteIEN: Int64; Suppress: Integer);
|
---|
| 70 | procedure InitParams(NoteIEN: Int64; Suppress: Integer);
|
---|
| 71 | procedure UpdateAdditionalSigners(IEN: integer; Signers: TStrings);
|
---|
| 72 | procedure ChangeCosigner(IEN: integer; Cosigner: int64);
|
---|
| 73 |
|
---|
| 74 | { Printing }
|
---|
| 75 | function AllowChartPrintForNote(ANote: Integer): Boolean;
|
---|
| 76 | procedure PrintNoteToDevice(ANote: Integer; const ADevice: string; ChartCopy: Boolean;
|
---|
| 77 | var ErrMsg: string);
|
---|
| 78 | function GetFormattedNote(ANote: Integer; ChartCopy: Boolean): TStrings;
|
---|
| 79 |
|
---|
| 80 | // Interdisciplinary Notes
|
---|
| 81 | function IDNotesInstalled: boolean;
|
---|
| 82 | function CanTitleBeIDChild(Title: integer; var WhyNot: string): boolean;
|
---|
| 83 | function CanReceiveAttachment(DocID: string; var WhyNot: string): boolean;
|
---|
| 84 | function CanBeAttached(DocID: string; var WhyNot: string): boolean;
|
---|
| 85 | function DetachEntryFromParent(DocID: string; var WhyNot: string): boolean;
|
---|
| 86 | function AttachEntryToParent(DocID, ParentDocID: string; var WhyNot: string): boolean;
|
---|
| 87 | function OneNotePerVisit(NoteEIN: Integer; DFN: String;VisitStr: String): boolean;
|
---|
| 88 |
|
---|
| 89 |
|
---|
| 90 | //User Classes
|
---|
| 91 | function SubSetOfUserClasses(const StartFrom: string; Direction: Integer): TStrings;
|
---|
| 92 | function UserDivClassInfo(User: Int64): TStrings;
|
---|
| 93 | function UserInactive(EIN: String): boolean;
|
---|
| 94 |
|
---|
| 95 | const
|
---|
| 96 | CLS_PROGRESS_NOTES = 3;
|
---|
| 97 |
|
---|
| 98 | implementation
|
---|
| 99 |
|
---|
| 100 | var
|
---|
| 101 | uTIUSiteParams: string;
|
---|
| 102 | uTIUSiteParamsLoaded: boolean = FALSE;
|
---|
| 103 | uNoteTitles: TNoteTitles;
|
---|
| 104 | uTIUPrefs: TTIUPrefs;
|
---|
| 105 |
|
---|
| 106 |
|
---|
| 107 | { Progress Note Titles -------------------------------------------------------------------- }
|
---|
| 108 |
|
---|
| 109 | procedure LoadNoteTitles;
|
---|
| 110 | { private - called one time to set up the uNoteTitles object }
|
---|
| 111 | const
|
---|
| 112 | CLASS_PROGRESS_NOTES = 3;
|
---|
| 113 | var
|
---|
| 114 | x: string;
|
---|
| 115 | begin
|
---|
| 116 | if uNoteTitles <> nil then Exit;
|
---|
| 117 | CallV('TIU PERSONAL TITLE LIST', [User.DUZ, CLS_PROGRESS_NOTES]);
|
---|
| 118 | RPCBrokerV.Results.Insert(0, '~SHORT LIST'); // insert so can call ExtractItems
|
---|
| 119 | uNoteTitles := TNoteTitles.Create;
|
---|
| 120 | ExtractItems(uNoteTitles.ShortList, RPCBrokerV.Results, 'SHORT LIST');
|
---|
| 121 | x := ExtractDefault(RPCBrokerV.Results, 'SHORT LIST');
|
---|
| 122 | uNoteTitles.DfltTitle := StrToIntDef(Piece(x, U, 1), 0);
|
---|
| 123 | uNoteTitles.DfltTitleName := Piece(x, U, 2);
|
---|
| 124 | end;
|
---|
| 125 |
|
---|
| 126 | procedure ResetNoteTitles;
|
---|
| 127 | begin
|
---|
| 128 | if uNoteTitles <> nil then
|
---|
| 129 | begin
|
---|
| 130 | uNoteTitles.Free;
|
---|
| 131 | uNoteTitles := nil;
|
---|
| 132 | LoadNoteTitles;
|
---|
| 133 | end;
|
---|
| 134 | end;
|
---|
| 135 |
|
---|
| 136 | function DfltNoteTitle: Integer;
|
---|
| 137 | { returns the IEN of the user defined default progress note title (if any) }
|
---|
| 138 | begin
|
---|
| 139 | if uNoteTitles = nil then LoadNoteTitles;
|
---|
| 140 | Result := uNoteTitles.DfltTitle;
|
---|
| 141 | end;
|
---|
| 142 |
|
---|
| 143 | function DfltNoteTitleName: string;
|
---|
| 144 | { returns the name of the user defined default progress note title (if any) }
|
---|
| 145 | begin
|
---|
| 146 | if uNoteTitles = nil then LoadNoteTitles;
|
---|
| 147 | Result := uNoteTitles.DfltTitleName;
|
---|
| 148 | end;
|
---|
| 149 |
|
---|
| 150 | function IsConsultTitle(TitleIEN: Integer): Boolean;
|
---|
| 151 | begin
|
---|
| 152 | Result := False;
|
---|
| 153 | if TitleIEN <= 0 then Exit;
|
---|
| 154 | Result := sCallV('TIU IS THIS A CONSULT?', [TitleIEN]) = '1';
|
---|
| 155 | end;
|
---|
| 156 |
|
---|
| 157 | function IsClinProcTitle(TitleIEN: Integer): Boolean;
|
---|
| 158 | begin
|
---|
| 159 | Result := False;
|
---|
| 160 | if TitleIEN <= 0 then Exit;
|
---|
| 161 | Result := sCallV('TIU IS THIS A CLINPROC?', [TitleIEN]) = '1';
|
---|
| 162 | end;
|
---|
| 163 |
|
---|
| 164 | procedure ListNoteTitlesShort(Dest: TStrings);
|
---|
| 165 | { returns the user defined list (short list) of progress note titles }
|
---|
| 166 | begin
|
---|
| 167 | if uNoteTitles = nil then LoadNoteTitles;
|
---|
| 168 | Dest.AddStrings(uNoteTitles.ShortList);
|
---|
| 169 | if uNoteTitles.ShortList.Count > 0 then
|
---|
| 170 | begin
|
---|
| 171 | Dest.Add('0^________________________________________________________________________');
|
---|
| 172 | Dest.Add('0^ ');
|
---|
| 173 | end;
|
---|
| 174 | end;
|
---|
| 175 |
|
---|
| 176 | procedure LoadBoilerPlate(Dest: TStrings; Title: Integer);
|
---|
| 177 | { returns the boilerplate text (if any) for a given progress note title }
|
---|
| 178 | begin
|
---|
| 179 | CallV('TIU LOAD BOILERPLATE TEXT', [Title, Patient.DFN, Encounter.VisitStr]);
|
---|
| 180 | Dest.Assign(RPCBrokerV.Results);
|
---|
| 181 | end;
|
---|
| 182 |
|
---|
| 183 | function PrintNameForTitle(TitleIEN: Integer): string;
|
---|
| 184 | begin
|
---|
| 185 | Result := sCallV('TIU GET PRINT NAME', [TitleIEN]);
|
---|
| 186 | end;
|
---|
| 187 |
|
---|
| 188 | function SubSetOfNoteTitles(const StartFrom: string; Direction: Integer; IDNotesOnly: boolean): TStrings;
|
---|
| 189 | { returns a pointer to a list of progress note titles (for use in a long list box) -
|
---|
| 190 | The return value is a pointer to RPCBrokerV.Results, so the data must be used BEFORE
|
---|
| 191 | the next broker call! }
|
---|
| 192 | begin
|
---|
| 193 | if IDNotesOnly then
|
---|
| 194 | CallV('TIU LONG LIST OF TITLES', [CLS_PROGRESS_NOTES, StartFrom, Direction, IDNotesOnly])
|
---|
| 195 | else
|
---|
| 196 | CallV('TIU LONG LIST OF TITLES', [CLS_PROGRESS_NOTES, StartFrom, Direction]);
|
---|
| 197 | //MixedCaseList(RPCBrokerV.Results);
|
---|
| 198 | Result := RPCBrokerV.Results;
|
---|
| 199 | end;
|
---|
| 200 |
|
---|
| 201 | { TIU Preferences ------------------------------------------------------------------------- }
|
---|
| 202 |
|
---|
| 203 | procedure LoadTIUPrefs;
|
---|
| 204 | { private - creates TIUPrefs object for reference throughout the session }
|
---|
| 205 | var
|
---|
| 206 | x: string;
|
---|
| 207 | begin
|
---|
| 208 | uTIUPrefs := TTIUPrefs.Create;
|
---|
| 209 | with uTIUPrefs do
|
---|
| 210 | begin
|
---|
| 211 | x := sCallV('TIU GET PERSONAL PREFERENCES', [User.DUZ]);
|
---|
| 212 | DfltLoc := StrToIntDef(Piece(x, U, 2), 0);
|
---|
| 213 | DfltLocName := ExternalName(DfltLoc, FN_HOSPITAL_LOCATION);
|
---|
| 214 | SortAscending := Piece(x, U, 4) = 'A';
|
---|
| 215 | SortBy := Piece(x, U, 3);
|
---|
| 216 | AskNoteSubject := Piece(x, U, 8) = '1';
|
---|
| 217 | DfltCosigner := StrToInt64Def(Piece(x, U, 9), 0);
|
---|
| 218 | DfltCosignerName := ExternalName(DfltCosigner, FN_NEW_PERSON);
|
---|
| 219 | MaxNotes := StrToIntDef(Piece(x, U, 10), 0);
|
---|
| 220 | x := sCallV('TIU REQUIRES COSIGNATURE', [TYP_PROGRESS_NOTE, 0, User.DUZ]);
|
---|
| 221 | AskCosigner := Piece(x, U, 1) = '1';
|
---|
| 222 | end;
|
---|
| 223 | end;
|
---|
| 224 |
|
---|
| 225 | procedure ResetTIUPreferences;
|
---|
| 226 | begin
|
---|
| 227 | if uTIUPrefs <> nil then
|
---|
| 228 | begin
|
---|
| 229 | uTIUPrefs.Free;
|
---|
| 230 | uTIUPrefs := nil;
|
---|
| 231 | LoadTIUPrefs;
|
---|
| 232 | end;
|
---|
| 233 | end;
|
---|
| 234 |
|
---|
| 235 | function AskCosignerForDocument(ADocument: Integer; AnAuthor: Int64): Boolean;
|
---|
| 236 | begin
|
---|
| 237 | Result := Piece(sCallV('TIU REQUIRES COSIGNATURE', [0, ADocument, AnAuthor]), U, 1) = '1';
|
---|
| 238 | end;
|
---|
| 239 |
|
---|
| 240 | function AskCosignerForTitle(ATitle: integer; AnAuthor: Int64): Boolean;
|
---|
| 241 | { returns TRUE if a cosignature is required for a document title and author }
|
---|
| 242 | begin
|
---|
| 243 | Result := Piece(sCallV('TIU REQUIRES COSIGNATURE', [ATitle, 0, AnAuthor]), U, 1) = '1';
|
---|
| 244 | end;
|
---|
| 245 |
|
---|
| 246 | function AskCosignerForNotes: Boolean;
|
---|
| 247 | { returns true if cosigner should be asked when creating a new progress note }
|
---|
| 248 | begin
|
---|
| 249 | if uTIUPrefs = nil then LoadTIUPrefs;
|
---|
| 250 | Result := uTIUPrefs.AskCosigner;
|
---|
| 251 | end;
|
---|
| 252 |
|
---|
| 253 | function AskSubjectForNotes: Boolean;
|
---|
| 254 | { returns true if subject should be asked when creating a new progress note }
|
---|
| 255 | begin
|
---|
| 256 | if uTIUPrefs = nil then LoadTIUPrefs;
|
---|
| 257 | Result := uTIUPrefs.AskNoteSubject;
|
---|
| 258 | end;
|
---|
| 259 |
|
---|
| 260 | function CanCosign(ATitle, ADocType: integer; AUser: Int64): Boolean;
|
---|
| 261 | begin
|
---|
| 262 | if ATitle > 0 then ADocType := 0;
|
---|
| 263 | Result := Piece(sCallV('TIU REQUIRES COSIGNATURE', [ATitle, ADocType, AUser]), U, 1) <> '1';
|
---|
| 264 | end;
|
---|
| 265 |
|
---|
| 266 | procedure DefaultCosigner(var IEN: Int64; var Name: string);
|
---|
| 267 | { returns the IEN (from the New Person file) and Name of this user's default cosigner }
|
---|
| 268 | begin
|
---|
| 269 | if uTIUPrefs = nil then LoadTIUPrefs;
|
---|
| 270 | IEN := uTIUPrefs.DfltCosigner;
|
---|
| 271 | Name := uTIUPrefs.DfltCosignerName;
|
---|
| 272 | end;
|
---|
| 273 |
|
---|
| 274 | function ReturnMaxNotes: Integer;
|
---|
| 275 | begin
|
---|
| 276 | if uTIUPrefs = nil then LoadTIUPrefs;
|
---|
| 277 | Result := uTIUPrefs.MaxNotes;
|
---|
| 278 | if Result = 0 then Result := 100;
|
---|
| 279 | end;
|
---|
| 280 |
|
---|
| 281 | function SortNotesAscending: Boolean;
|
---|
| 282 | { returns true if progress notes should be sorted from oldest to newest (chronological) }
|
---|
| 283 | begin
|
---|
| 284 | if uTIUPrefs = nil then LoadTIUPrefs;
|
---|
| 285 | Result := uTIUPrefs.SortAscending;
|
---|
| 286 | end;
|
---|
| 287 |
|
---|
| 288 | function DfltTIULocation: Integer;
|
---|
| 289 | { returns the IEN of the user defined default progress note title (if any) }
|
---|
| 290 | begin
|
---|
| 291 | if uTIUPrefs = nil then LoadTIUPrefs;
|
---|
| 292 | Result := uTIUPrefs.DfltLoc;
|
---|
| 293 | end;
|
---|
| 294 |
|
---|
| 295 | function DfltTIULocationName: string;
|
---|
| 296 | { returns the name of the user defined default progress note title (if any) }
|
---|
| 297 | begin
|
---|
| 298 | if uTIUPrefs = nil then LoadTIUPrefs;
|
---|
| 299 | Result := uTIUPrefs.DfltLocName;
|
---|
| 300 | end;
|
---|
| 301 |
|
---|
| 302 | { Data Retrieval --------------------------------------------------------------------------- }
|
---|
| 303 |
|
---|
| 304 | procedure ActOnDocument(var AuthSts: TActionRec; IEN: Integer; const ActionName: string);
|
---|
| 305 | var
|
---|
| 306 | x: string;
|
---|
| 307 | begin
|
---|
| 308 | if not (IEN > 0) then
|
---|
| 309 | begin
|
---|
| 310 | AuthSts.Success := True;
|
---|
| 311 | AuthSts.Reason := '';
|
---|
| 312 | Exit;
|
---|
| 313 | end;
|
---|
| 314 | x := sCallV('TIU AUTHORIZATION', [IEN, ActionName]);
|
---|
| 315 | AuthSts.Success := Piece(x, U, 1) = '1';
|
---|
| 316 | AuthSts.Reason := Piece(x, U, 2);
|
---|
| 317 | end;
|
---|
| 318 |
|
---|
| 319 | function AuthorSignedDocument(IEN: Integer): boolean;
|
---|
| 320 | begin
|
---|
| 321 | Result := SCallV('TIU HAS AUTHOR SIGNED?', [IEN, User.DUZ]) = '1';
|
---|
| 322 | end;
|
---|
| 323 |
|
---|
| 324 | function CosignDocument(IEN: Integer): Boolean;
|
---|
| 325 | var
|
---|
| 326 | x: string;
|
---|
| 327 | begin
|
---|
| 328 | x := sCallV('TIU WHICH SIGNATURE ACTION', [IEN]);
|
---|
| 329 | Result := x = 'COSIGNATURE';
|
---|
| 330 | end;
|
---|
| 331 |
|
---|
| 332 | (*function CPTRequiredForNote(IEN: Integer): Boolean;
|
---|
| 333 | begin
|
---|
| 334 | If IEN > 0 then
|
---|
| 335 | Result := sCallV('ORWPCE CPTREQD', [IEN]) = '1'
|
---|
| 336 | else
|
---|
| 337 | Result := False;
|
---|
| 338 | end;*)
|
---|
| 339 |
|
---|
| 340 | procedure ListConsultRequests(Dest: TStrings);
|
---|
| 341 | { lists outstanding consult requests for a patient: IEN^Request D/T^Service^Procedure }
|
---|
| 342 | begin
|
---|
| 343 | CallV('GMRC LIST CONSULT REQUESTS', [Patient.DFN]);
|
---|
| 344 | //MixedCaseList(RPCBrokerV.Results);
|
---|
| 345 | { remove first returned string, it is just a count }
|
---|
| 346 | if RPCBrokerV.Results.Count > 0 then RPCBrokerV.Results.Delete(0);
|
---|
| 347 | SetListFMDateTime('mmm dd,yy hh:nn', TStringList(RPCBrokerV.Results), U, 2);
|
---|
| 348 | Dest.Assign(RPCBrokerV.Results);
|
---|
| 349 | end;
|
---|
| 350 |
|
---|
| 351 | procedure ListNotes(Dest: TStrings; Context: Integer; Early, Late: TFMDateTime;
|
---|
| 352 | Person: int64; OccLim: Integer; SortAscending: Boolean);
|
---|
| 353 | { retrieves existing progress notes for a patient according to the parameters passed in
|
---|
| 354 | Pieces: IEN^Title^FMDateOfNote^Patient^Author^Location^Status^Visit
|
---|
| 355 | Return: IEN^ExDateOfNote^Title, Location, Author^ImageCount^Visit }
|
---|
| 356 | var
|
---|
| 357 | i: Integer;
|
---|
| 358 | x: string;
|
---|
| 359 | SortSeq: Char;
|
---|
| 360 | begin
|
---|
| 361 | if SortAscending then SortSeq := 'A' else SortSeq := 'D';
|
---|
| 362 | //if OccLim = 0 then OccLim := MaxNotesReturned;
|
---|
| 363 | CallV('TIU DOCUMENTS BY CONTEXT',
|
---|
| 364 | [3, Context, Patient.DFN, Early, Late, Person, OccLim, SortSeq]);
|
---|
| 365 | with RPCBrokerV do
|
---|
| 366 | begin
|
---|
| 367 | for i := 0 to Results.Count - 1 do
|
---|
| 368 | begin
|
---|
| 369 | x := Results[i];
|
---|
| 370 | x := Piece(x, U, 1) + U + FormatFMDateTime('mmm dd,yy', MakeFMDateTime(Piece(x, U, 3))) +
|
---|
| 371 | U + Piece(x, U, 2) + ', ' + Piece(x, U, 6) + ', ' + Piece(Piece(x, U, 5), ';', 2) +
|
---|
| 372 | U + Piece(x, U, 11) + U + Piece(x, U, 8) + U + Piece(x, U, 3);
|
---|
| 373 | Results[i] := x;
|
---|
| 374 | end; {for}
|
---|
| 375 | Dest.Assign(Results);
|
---|
| 376 | end; {with}
|
---|
| 377 | end;
|
---|
| 378 |
|
---|
| 379 | procedure ListNotesForTree(Dest: TStrings; Context: Integer; Early, Late: TFMDateTime;
|
---|
| 380 | Person: int64; OccLim: Integer; SortAscending: Boolean);
|
---|
| 381 | { retrieves existing progress notes for a patient according to the parameters passed in
|
---|
| 382 | Pieces: IEN^Title^FMDateOfNote^Patient^Author^Location^Status^Visit
|
---|
| 383 | Return: IEN^ExDateOfNote^Title, Location, Author^ImageCount^Visit }
|
---|
| 384 | var
|
---|
| 385 | SortSeq: Char;
|
---|
| 386 | const
|
---|
| 387 | SHOW_ADDENDA = True;
|
---|
| 388 | begin
|
---|
| 389 | if SortAscending then SortSeq := 'A' else SortSeq := 'D';
|
---|
| 390 | if Context > 0 then
|
---|
| 391 | begin
|
---|
| 392 | CallV('TIU DOCUMENTS BY CONTEXT', [3, Context, Patient.DFN, Early, Late, Person, OccLim, SortSeq, SHOW_ADDENDA]);
|
---|
| 393 | Dest.Assign(RPCBrokerV.Results);
|
---|
| 394 | end;
|
---|
| 395 | end;
|
---|
| 396 |
|
---|
| 397 |
|
---|
| 398 | procedure ListDCSumm(Dest: TStrings);
|
---|
| 399 | { returns the list of discharge summaries for a patient - see ListNotes for pieces }
|
---|
| 400 | var
|
---|
| 401 | i: Integer;
|
---|
| 402 | x: string;
|
---|
| 403 | begin
|
---|
| 404 | CallV('TIU SUMMARIES', [Patient.DFN]);
|
---|
| 405 | with RPCBrokerV do
|
---|
| 406 | begin
|
---|
| 407 | SortByPiece(TStringList(Results), U, 3); // sort on date/time of summary
|
---|
| 408 | for i := 0 to Results.Count - 1 do
|
---|
| 409 | begin
|
---|
| 410 | x := Results[i];
|
---|
| 411 | x := Piece(x, U, 1) + U + FormatFMDateTime('mmm dd,yy', MakeFMDateTime(Piece(x, U, 3)))
|
---|
| 412 | + U + Piece(x, U, 2) + ', ' + Piece(x, U, 6) + ', ' + Piece(Piece(x, U, 5), ';', 2);
|
---|
| 413 | Results[i] := x;
|
---|
| 414 | end; {for}
|
---|
| 415 | Dest.Assign(Results);
|
---|
| 416 | end; {with}
|
---|
| 417 | end;
|
---|
| 418 |
|
---|
| 419 | procedure LoadDocumentText(Dest: TStrings; IEN: Integer);
|
---|
| 420 | { returns the text of a document (progress note, discharge summary, etc.) }
|
---|
| 421 | begin
|
---|
| 422 | CallV('TIU GET RECORD TEXT', [IEN]);
|
---|
| 423 | Dest.Assign(RPCBrokerV.Results);
|
---|
| 424 | end;
|
---|
| 425 |
|
---|
| 426 | procedure LoadDetailText(Dest: TStrings; IEN: Integer); //**KCM**
|
---|
| 427 | begin
|
---|
| 428 | CallV('TIU DETAILED DISPLAY', [IEN]);
|
---|
| 429 | Dest.Assign(RPCBrokerV.Results);
|
---|
| 430 | end;
|
---|
| 431 |
|
---|
| 432 | procedure GetNoteForEdit(var EditRec: TEditNoteRec; IEN: Integer);
|
---|
| 433 | { retrieves internal/external values for progress note fields & loads them into EditRec
|
---|
| 434 | Fields: Title:.01, RefDate:1301, Author:1204, Cosigner:1208, Subject:1701, Location:1205 }
|
---|
| 435 | var
|
---|
| 436 | i, j: Integer;
|
---|
| 437 | //x: string;
|
---|
| 438 |
|
---|
| 439 | function FindDT(const FieldID: string): TFMDateTime;
|
---|
| 440 | var
|
---|
| 441 | i: Integer;
|
---|
| 442 | begin
|
---|
| 443 | Result := 0;
|
---|
| 444 | with RPCBrokerV do for i := 0 to Results.Count - 1 do
|
---|
| 445 | if Piece(Results[i], U, 1) = FieldID then
|
---|
| 446 | begin
|
---|
| 447 | Result := MakeFMDateTime(Piece(Results[i], U, 2));
|
---|
| 448 | Break;
|
---|
| 449 | end;
|
---|
| 450 | end;
|
---|
| 451 |
|
---|
| 452 | function FindExt(const FieldID: string): string;
|
---|
| 453 | var
|
---|
| 454 | i: Integer;
|
---|
| 455 | begin
|
---|
| 456 | Result := '';
|
---|
| 457 | with RPCBrokerV do for i := 0 to Results.Count - 1 do
|
---|
| 458 | if Piece(Results[i], U, 1) = FieldID then
|
---|
| 459 | begin
|
---|
| 460 | Result := Piece(Results[i], U, 3);
|
---|
| 461 | Break;
|
---|
| 462 | end;
|
---|
| 463 | end;
|
---|
| 464 |
|
---|
| 465 | function FindInt(const FieldID: string): Integer;
|
---|
| 466 | var
|
---|
| 467 | i: Integer;
|
---|
| 468 | begin
|
---|
| 469 | Result := 0;
|
---|
| 470 | with RPCBrokerV do for i := 0 to Results.Count - 1 do
|
---|
| 471 | if Piece(Results[i], U, 1) = FieldID then
|
---|
| 472 | begin
|
---|
| 473 | Result := StrToIntDef(Piece(Results[i], U, 2), 0);
|
---|
| 474 | Break;
|
---|
| 475 | end;
|
---|
| 476 | end;
|
---|
| 477 |
|
---|
| 478 | function FindInt64(const FieldID: string): Int64;
|
---|
| 479 | var
|
---|
| 480 | i: Integer;
|
---|
| 481 | begin
|
---|
| 482 | Result := 0;
|
---|
| 483 | with RPCBrokerV do for i := 0 to Results.Count - 1 do
|
---|
| 484 | if Piece(Results[i], U, 1) = FieldID then
|
---|
| 485 | begin
|
---|
| 486 | Result := StrToInt64Def(Piece(Results[i], U, 2), 0);
|
---|
| 487 | Break;
|
---|
| 488 | end;
|
---|
| 489 | end;
|
---|
| 490 |
|
---|
| 491 | function FindVal(const FieldID: string): string;
|
---|
| 492 | var
|
---|
| 493 | i: Integer;
|
---|
| 494 | begin
|
---|
| 495 | Result := '';
|
---|
| 496 | with RPCBrokerV do for i := 0 to Results.Count - 1 do
|
---|
| 497 | if Piece(Results[i], U, 1) = FieldID then
|
---|
| 498 | begin
|
---|
| 499 | Result := Piece(Results[i], U, 2);
|
---|
| 500 | Break;
|
---|
| 501 | end;
|
---|
| 502 | end;
|
---|
| 503 |
|
---|
| 504 | begin
|
---|
| 505 | CallV('TIU LOAD RECORD FOR EDIT', [IEN, '.01;.06;.07;1301;1204;1208;1701;1205;1405;2101;70201;70202']);
|
---|
| 506 | FillChar(EditRec, SizeOf(EditRec), 0);
|
---|
| 507 | with EditRec do
|
---|
| 508 | begin
|
---|
| 509 | Title := FindInt('.01');
|
---|
| 510 | TitleName := FindExt('.01');
|
---|
| 511 | DateTime := FindDT('1301');
|
---|
| 512 | Author := FindInt64('1204');
|
---|
| 513 | AuthorName := FindExt('1204');
|
---|
| 514 | Cosigner := FindInt64('1208');
|
---|
| 515 | CosignerName := FindExt('1208');
|
---|
| 516 | Subject := FindExt('1701');
|
---|
| 517 | Location := FindInt('1205');
|
---|
| 518 | LocationName := FindExt('1205');
|
---|
| 519 | IDParent := FindInt('2101');
|
---|
| 520 | ClinProcSummCode := FindInt('70201');
|
---|
| 521 | ClinProcDateTime := FindDT('70202');
|
---|
| 522 | VisitDate := FindDT('.07');
|
---|
| 523 | PkgRef := FindVal('1405');
|
---|
| 524 | PkgIEN := StrToIntDef(Piece(PkgRef, ';', 1), 0);
|
---|
| 525 | PkgPtr := Piece(PkgRef, ';', 2);
|
---|
| 526 | if Title = TYP_ADDENDUM then Addend := FindInt('.06');
|
---|
| 527 | with RPCBrokerV do
|
---|
| 528 | begin
|
---|
| 529 | for i := 0 to Results.Count - 1 do if Results[i] = '$TXT' then break;
|
---|
| 530 | for j := i downto 0 do Results.Delete(j);
|
---|
| 531 | // -------------------- v19.1 (RV) LOST NOTES?----------------------------
|
---|
| 532 | //Lines := Results; 'Lines' is being overwritten by subsequent Broker calls
|
---|
| 533 | if not Assigned(Lines) then Lines := TStringList.Create;
|
---|
| 534 | Lines.Assign(Results);
|
---|
| 535 | // -----------------------------------------------------------------------
|
---|
| 536 | end;
|
---|
| 537 | end;
|
---|
| 538 | end;
|
---|
| 539 |
|
---|
| 540 | function VisitStrForNote(IEN: Integer): string;
|
---|
| 541 | begin
|
---|
| 542 | Result := sCallV('ORWPCE NOTEVSTR', [IEN]);
|
---|
| 543 | end;
|
---|
| 544 |
|
---|
| 545 | function TitleForNote(IEN: Int64): Integer;
|
---|
| 546 | begin
|
---|
| 547 | Result := StrToIntDef(sCallV('TIU GET DOCUMENT TITLE', [IEN]), 3);
|
---|
| 548 | // with RPCBrokerV do
|
---|
| 549 | // begin
|
---|
| 550 | // ClearParameters := True;
|
---|
| 551 | // RemoteProcedure := 'XWB GET VARIABLE VALUE';
|
---|
| 552 | // Param[0].PType := reference;
|
---|
| 553 | // Param[0].Value := '$G(^TIU(8925,' + IntToStr(IEN) + ',0))';
|
---|
| 554 | // CallBroker;
|
---|
| 555 | // Result := StrToIntDef(Piece(Results[0], U, 1), 3);
|
---|
| 556 | // end;
|
---|
| 557 | end;
|
---|
| 558 |
|
---|
| 559 | function GetPackageRefForNote(NoteIEN: integer): string;
|
---|
| 560 | begin
|
---|
| 561 | Result := sCallV('TIU GET REQUEST', [NoteIEN]);
|
---|
| 562 | end;
|
---|
| 563 |
|
---|
| 564 | function GetConsultIENforNote(NoteIEN: integer): Integer;
|
---|
| 565 | var
|
---|
| 566 | x: string;
|
---|
| 567 | begin
|
---|
| 568 | x := sCallV('TIU GET REQUEST', [NoteIEN]);
|
---|
| 569 | if Piece(x, ';', 2) <> PKG_CONSULTS then
|
---|
| 570 | Result := -1
|
---|
| 571 | else
|
---|
| 572 | Result := StrTOIntDef(Piece(x, ';', 1), -1);
|
---|
| 573 | end;
|
---|
| 574 |
|
---|
| 575 | procedure LockDocument(IEN: Int64; var AnErrMsg: string);
|
---|
| 576 | var
|
---|
| 577 | x: string;
|
---|
| 578 | begin
|
---|
| 579 | x := sCallV('TIU LOCK RECORD', [IEN]);
|
---|
| 580 | if CharAt(x, 1) = '0' then AnErrMsg := '' else AnErrMsg := Piece(x, U, 2);
|
---|
| 581 | end;
|
---|
| 582 |
|
---|
| 583 | procedure UnlockDocument(IEN: Int64);
|
---|
| 584 | begin
|
---|
| 585 | CallV('TIU UNLOCK RECORD', [IEN]);
|
---|
| 586 | end;
|
---|
| 587 |
|
---|
| 588 | function LastSaveClean(IEN: Int64): Boolean;
|
---|
| 589 | begin
|
---|
| 590 | Result := sCallV('TIU WAS THIS SAVED?', [IEN]) = '1';
|
---|
| 591 | end;
|
---|
| 592 |
|
---|
| 593 | function GetTIUListItem(IEN: Int64): string;
|
---|
| 594 | begin
|
---|
| 595 | Result := sCallV('ORWTIU GET LISTBOX ITEM', [IEN]);
|
---|
| 596 | end;
|
---|
| 597 |
|
---|
| 598 | { Data Updates ----------------------------------------------------------------------------- }
|
---|
| 599 |
|
---|
| 600 | (*procedure ClearCPTRequired(IEN: Integer);
|
---|
| 601 | { sets CREDIT STOP CODE ON COMPLETION to NO when no more need to get encounter information }
|
---|
| 602 | begin
|
---|
| 603 | with RPCBrokerV do
|
---|
| 604 | begin
|
---|
| 605 | ClearParameters := True;
|
---|
| 606 | RemoteProcedure := 'TIU UPDATE RECORD';
|
---|
| 607 | Param[0].PType := literal;
|
---|
| 608 | Param[0].Value := IntToStr(IEN);
|
---|
| 609 | Param[1].PType := list;
|
---|
| 610 | with Param[1] do Mult['.11'] := '0'; // **** block removed in v19.1 {RV} ****
|
---|
| 611 | CallBroker;
|
---|
| 612 | end;
|
---|
| 613 | end;*)
|
---|
| 614 |
|
---|
| 615 | procedure DeleteDocument(var DeleteSts: TActionRec; IEN: Integer; const Reason: string);
|
---|
| 616 | { delete a TIU document given the internal entry number, return reason if unable to delete }
|
---|
| 617 | var
|
---|
| 618 | x: string;
|
---|
| 619 | begin
|
---|
| 620 | x := sCallV('TIU DELETE RECORD', [IEN, Reason]);
|
---|
| 621 | DeleteSts.Success := Piece(x, U, 1) = '0';
|
---|
| 622 | DeleteSts.Reason := Piece(x, U, 2);
|
---|
| 623 | end;
|
---|
| 624 |
|
---|
| 625 | function JustifyDocumentDelete(IEN: Integer): Boolean;
|
---|
| 626 | begin
|
---|
| 627 | Result := sCallV('TIU JUSTIFY DELETE?', [IEN]) = '1';
|
---|
| 628 | end;
|
---|
| 629 |
|
---|
| 630 | procedure SignDocument(var SignSts: TActionRec; IEN: Integer; const ESCode: string);
|
---|
| 631 | { update signed status of a TIU document, return reason if signature is not accepted }
|
---|
| 632 | var
|
---|
| 633 | x: string;
|
---|
| 634 | begin
|
---|
| 635 | (* with RPCBrokerV do // temp - to insure sign doesn't go interactive
|
---|
| 636 | begin
|
---|
| 637 | ClearParameters := True;
|
---|
| 638 | RemoteProcedure := 'TIU UPDATE RECORD';
|
---|
| 639 | Param[0].PType := literal;
|
---|
| 640 | Param[0].Value := IntToStr(IEN);
|
---|
| 641 | Param[1].PType := list;
|
---|
| 642 | with Param[1] do Mult['.11'] := '0'; // **** block removed in v19.1 {RV} ****
|
---|
| 643 | CallBroker;
|
---|
| 644 | end; // temp - end*)
|
---|
| 645 | x := sCallV('TIU SIGN RECORD', [IEN, ESCode]);
|
---|
| 646 | SignSts.Success := Piece(x, U, 1) = '0';
|
---|
| 647 | SignSts.Reason := Piece(x, U, 2);
|
---|
| 648 | end;
|
---|
| 649 |
|
---|
| 650 | procedure PutNewNote(var CreatedDoc: TCreatedDoc; const NoteRec: TNoteRec);
|
---|
| 651 | { create a new progress note with the data in NoteRec and return its internal entry number
|
---|
| 652 | load broker directly since there isn't a good way to set up mutilple subscript arrays }
|
---|
| 653 | (*var
|
---|
| 654 | i: Integer;*)
|
---|
| 655 | var
|
---|
| 656 | ErrMsg: string;
|
---|
| 657 | begin
|
---|
| 658 | with RPCBrokerV do
|
---|
| 659 | begin
|
---|
| 660 | ClearParameters := True;
|
---|
| 661 | RemoteProcedure := 'TIU CREATE RECORD';
|
---|
| 662 | Param[0].PType := literal;
|
---|
| 663 | Param[0].Value := Patient.DFN; //*DFN*
|
---|
| 664 | Param[1].PType := literal;
|
---|
| 665 | Param[1].Value := IntToStr(NoteRec.Title);
|
---|
| 666 | Param[2].PType := literal;
|
---|
| 667 | Param[2].Value := ''; //FloatToStr(Encounter.DateTime);
|
---|
| 668 | Param[3].PType := literal;
|
---|
| 669 | Param[3].Value := ''; //IntToStr(Encounter.Location);
|
---|
| 670 | Param[4].PType := literal;
|
---|
| 671 | Param[4].Value := '';
|
---|
| 672 | Param[5].PType := list;
|
---|
| 673 | with Param[5] do
|
---|
| 674 | begin
|
---|
| 675 | //Mult['.11'] := BOOLCHAR[NoteRec.NeedCPT]; // **** removed in v19.1 {RV} ****
|
---|
| 676 | Mult['1202'] := IntToStr(NoteRec.Author);
|
---|
| 677 | Mult['1301'] := FloatToStr(NoteRec.DateTime);
|
---|
| 678 | Mult['1205'] := IntToStr(Encounter.Location);
|
---|
| 679 | if NoteRec.Cosigner > 0 then Mult['1208'] := IntToStr(NoteRec.Cosigner);
|
---|
| 680 | if NoteRec.PkgRef <> '' then Mult['1405'] := NoteRec.PkgRef;
|
---|
| 681 | Mult['1701'] := FilteredString(Copy(NoteRec.Subject, 1, 80));
|
---|
| 682 | if NoteRec.IDParent > 0 then Mult['2101'] := IntToStr(NoteRec.IDParent);
|
---|
| 683 | (* if NoteRec.Lines <> nil then
|
---|
| 684 | for i := 0 to NoteRec.Lines.Count - 1 do
|
---|
| 685 | Mult['"TEXT",' + IntToStr(i+1) + ',0'] := FilteredString(NoteRec.Lines[i]);*)
|
---|
| 686 | end;
|
---|
| 687 | Param[6].PType := literal;
|
---|
| 688 | Param[6].Value := Encounter.VisitStr;
|
---|
| 689 | Param[7].PType := literal;
|
---|
| 690 | Param[7].Value := '1'; // suppress commit logic
|
---|
| 691 | CallBroker;
|
---|
| 692 | CreatedDoc.IEN := StrToIntDef(Piece(Results[0], U, 1), 0);
|
---|
| 693 | CreatedDoc.ErrorText := Piece(Results[0], U, 2);
|
---|
| 694 | end;
|
---|
| 695 | if ( NoteRec.Lines <> nil ) and ( CreatedDoc.IEN <> 0 ) then
|
---|
| 696 | begin
|
---|
| 697 | SetText(ErrMsg, NoteRec.Lines, CreatedDoc.IEN, 1);
|
---|
| 698 | if ErrMsg <> '' then
|
---|
| 699 | begin
|
---|
| 700 | CreatedDoc.IEN := 0;
|
---|
| 701 | CreatedDoc.ErrorText := ErrMsg;
|
---|
| 702 | end;
|
---|
| 703 | end;
|
---|
| 704 | end;
|
---|
| 705 |
|
---|
| 706 | procedure PutAddendum(var CreatedDoc: TCreatedDoc; const NoteRec: TNoteRec; AddendumTo: Integer);
|
---|
| 707 | { create a new addendum for note identified in AddendumTo, returns IEN of new document
|
---|
| 708 | load broker directly since there isn't a good way to set up mutilple subscript arrays }
|
---|
| 709 | (*var
|
---|
| 710 | i: Integer;*)
|
---|
| 711 | var
|
---|
| 712 | ErrMsg: string;
|
---|
| 713 | begin
|
---|
| 714 | with RPCBrokerV do
|
---|
| 715 | begin
|
---|
| 716 | ClearParameters := True;
|
---|
| 717 | RemoteProcedure := 'TIU CREATE ADDENDUM RECORD';
|
---|
| 718 | Param[0].PType := literal;
|
---|
| 719 | Param[0].Value := IntToStr(AddendumTo);
|
---|
| 720 | Param[1].PType := list;
|
---|
| 721 | with Param[1] do
|
---|
| 722 | begin
|
---|
| 723 | Mult['1202'] := IntToStr(NoteRec.Author);
|
---|
| 724 | Mult['1301'] := FloatToStr(NoteRec.DateTime);
|
---|
| 725 | if NoteRec.Cosigner > 0 then Mult['1208'] := IntToStr(NoteRec.Cosigner);
|
---|
| 726 | (* if NoteRec.Lines <> nil then
|
---|
| 727 | for i := 0 to NoteRec.Lines.Count - 1 do
|
---|
| 728 | Mult['"TEXT",' + IntToStr(i+1) + ',0'] := FilteredString(NoteRec.Lines[i]);*)
|
---|
| 729 | end;
|
---|
| 730 | Param[2].PType := literal;
|
---|
| 731 | Param[2].Value := '1'; // suppress commit logic
|
---|
| 732 | CallBroker;
|
---|
| 733 | CreatedDoc.IEN := StrToIntDef(Piece(Results[0], U, 1), 0);
|
---|
| 734 | CreatedDoc.ErrorText := Piece(Results[0], U, 2);
|
---|
| 735 | end;
|
---|
| 736 | if ( NoteRec.Lines <> nil ) and ( CreatedDoc.IEN <> 0 ) then
|
---|
| 737 | begin
|
---|
| 738 | SetText(ErrMsg, NoteRec.Lines, CreatedDoc.IEN, 1);
|
---|
| 739 | if ErrMsg <> '' then
|
---|
| 740 | begin
|
---|
| 741 | CreatedDoc.IEN := 0;
|
---|
| 742 | CreatedDoc.ErrorText := ErrMsg;
|
---|
| 743 | end;
|
---|
| 744 | end;
|
---|
| 745 | end;
|
---|
| 746 |
|
---|
| 747 | procedure PutEditedNote(var UpdatedDoc: TCreatedDoc; const NoteRec: TNoteRec; NoteIEN: Integer);
|
---|
| 748 | { update the fields and content of the note identified in NoteIEN, returns 1 if successful
|
---|
| 749 | load broker directly since there isn't a good way to set up mutilple subscript arrays }
|
---|
| 750 | (*var
|
---|
| 751 | i: Integer;*)
|
---|
| 752 | var
|
---|
| 753 | ErrMsg: string;
|
---|
| 754 | begin
|
---|
| 755 | // First, file field data
|
---|
| 756 | with RPCBrokerV do
|
---|
| 757 | begin
|
---|
| 758 | ClearParameters := True;
|
---|
| 759 | RemoteProcedure := 'TIU UPDATE RECORD';
|
---|
| 760 | Param[0].PType := literal;
|
---|
| 761 | Param[0].Value := IntToStr(NoteIEN);
|
---|
| 762 | Param[1].PType := list;
|
---|
| 763 | with Param[1] do
|
---|
| 764 | begin
|
---|
| 765 | if NoteRec.Addend = 0 then
|
---|
| 766 | begin
|
---|
| 767 | Mult['.01'] := IntToStr(NoteRec.Title);
|
---|
| 768 | //Mult['.11'] := BOOLCHAR[NoteRec.NeedCPT]; // **** removed in v19.1 {RV} ****
|
---|
| 769 | end;
|
---|
| 770 | Mult['1202'] := IntToStr(NoteRec.Author);
|
---|
| 771 | if NoteRec.Cosigner > 0 then Mult['1208'] := IntToStr(NoteRec.Cosigner);
|
---|
| 772 | if NoteRec.PkgRef <> '' then Mult['1405'] := NoteRec.PkgRef;
|
---|
| 773 | Mult['1301'] := FloatToStr(NoteRec.DateTime);
|
---|
| 774 | Mult['1701'] := FilteredString(Copy(NoteRec.Subject, 1, 80));
|
---|
| 775 | if NoteRec.ClinProcSummCode > 0 then Mult['70201'] := IntToStr(NoteRec.ClinProcSummCode);
|
---|
| 776 | if NoteRec.ClinProcDateTime > 0 then Mult['70202'] := FloatToStr(NoteRec.ClinProcDateTime);
|
---|
| 777 | (* for i := 0 to NoteRec.Lines.Count - 1 do
|
---|
| 778 | Mult['"TEXT",' + IntToStr(i+1) + ',0'] := FilteredString(NoteRec.Lines[i]);*)
|
---|
| 779 | end;
|
---|
| 780 | CallBroker;
|
---|
| 781 | UpdatedDoc.IEN := StrToIntDef(Piece(Results[0], U, 1), 0);
|
---|
| 782 | UpdatedDoc.ErrorText := Piece(Results[0], U, 2);
|
---|
| 783 | end;
|
---|
| 784 |
|
---|
| 785 | if UpdatedDoc.IEN <= 0 then //v22.12 - RV
|
---|
| 786 | //if UpdatedDoc.ErrorText <> '' then //v22.5 - RV
|
---|
| 787 | begin
|
---|
| 788 | UpdatedDoc.ErrorText := UpdatedDoc.ErrorText + #13#10 + #13#10 + 'Document #: ' + IntToStr(NoteIEN);
|
---|
| 789 | exit;
|
---|
| 790 | end;
|
---|
| 791 |
|
---|
| 792 | // next, if no error, file document body
|
---|
| 793 | SetText(ErrMsg, NoteRec.Lines, NoteIEN, 0);
|
---|
| 794 | if ErrMsg <> '' then
|
---|
| 795 | begin
|
---|
| 796 | UpdatedDoc.IEN := 0;
|
---|
| 797 | UpdatedDoc.ErrorText := ErrMsg;
|
---|
| 798 | end;
|
---|
| 799 | end;
|
---|
| 800 |
|
---|
| 801 | procedure PutTextOnly(var ErrMsg: string; NoteText: TStrings; NoteIEN: Int64);
|
---|
| 802 | var
|
---|
| 803 | i: Integer;
|
---|
| 804 | begin
|
---|
| 805 | with RPCBrokerV do
|
---|
| 806 | begin
|
---|
| 807 | ClearParameters := True;
|
---|
| 808 | RemoteProcedure := 'TIU UPDATE RECORD';
|
---|
| 809 | Param[0].PType := literal;
|
---|
| 810 | Param[0].Value := IntToStr(NoteIEN);
|
---|
| 811 | Param[1].PType := list;
|
---|
| 812 | for i := 0 to Pred(NoteText.Count) do
|
---|
| 813 | Param[1].Mult['"TEXT",' + IntToStr(Succ(i)) + ',0'] := FilteredString(NoteText[i]);
|
---|
| 814 | Param[2].PType := literal;
|
---|
| 815 | Param[2].Value :='1'; // suppress commit code
|
---|
| 816 | CallBroker;
|
---|
| 817 | if Piece(Results[0], U, 1) = '0' then ErrMsg := Piece(Results[0], U, 2) else ErrMsg := '';
|
---|
| 818 | end;
|
---|
| 819 | end;
|
---|
| 820 |
|
---|
| 821 | procedure SetText(var ErrMsg: string; NoteText: TStrings; NoteIEN: Int64; Suppress: Integer);
|
---|
| 822 | const
|
---|
| 823 | DOCUMENT_PAGE_SIZE = 300;
|
---|
| 824 | TX_SERVER_ERROR = 'An error occurred on the server.' ;
|
---|
| 825 | var
|
---|
| 826 | i, j, page, pages: Integer;
|
---|
| 827 | begin
|
---|
| 828 | // Compute pages, initialize Params
|
---|
| 829 | pages := ( NoteText.Count div DOCUMENT_PAGE_SIZE );
|
---|
| 830 | if (NoteText.Count mod DOCUMENT_PAGE_SIZE) > 0 then pages := pages + 1;
|
---|
| 831 | page := 1;
|
---|
| 832 | InitParams( NoteIEN, Suppress );
|
---|
| 833 | // Loop through NoteRec.Lines
|
---|
| 834 | for i := 0 to NoteText.Count - 1 do
|
---|
| 835 | begin
|
---|
| 836 | j := i + 1;
|
---|
| 837 | //Add each successive line to Param[1].Mult...
|
---|
| 838 | RPCBrokerV.Param[1].Mult['"TEXT",' + IntToStr(j) + ',0'] := FilteredString(NoteText[i]);
|
---|
| 839 | // When current page is filled, call broker, increment page, itialize params,
|
---|
| 840 | // and continue...
|
---|
| 841 | if ( j mod DOCUMENT_PAGE_SIZE ) = 0 then
|
---|
| 842 | begin
|
---|
| 843 | RPCBrokerV.Param[1].Mult['"HDR"'] := IntToStr(page) + U + IntToStr(pages);
|
---|
| 844 | CallBroker;
|
---|
| 845 | if RPCBrokerV.Results.Count > 0 then
|
---|
| 846 | ErrMsg := Piece(RPCBrokerV.Results[0], U, 4)
|
---|
| 847 | else
|
---|
| 848 | ErrMsg := TX_SERVER_ERROR;
|
---|
| 849 | if ErrMsg <> '' then Exit;
|
---|
| 850 | page := page + 1;
|
---|
| 851 | InitParams( NoteIEN, Suppress );
|
---|
| 852 | end; // if
|
---|
| 853 | end; // for
|
---|
| 854 | // finally, file any remaining partial page
|
---|
| 855 | if ( NoteText.Count mod DOCUMENT_PAGE_SIZE ) <> 0 then
|
---|
| 856 | begin
|
---|
| 857 | RPCBrokerV.Param[1].Mult['"HDR"'] := IntToStr(page) + U + IntToStr(pages);
|
---|
| 858 | CallBroker;
|
---|
| 859 | if RPCBrokerV.Results.Count > 0 then
|
---|
| 860 | ErrMsg := Piece(RPCBrokerV.Results[0], U, 4)
|
---|
| 861 | else
|
---|
| 862 | ErrMsg := TX_SERVER_ERROR;
|
---|
| 863 | end;
|
---|
| 864 | end;
|
---|
| 865 |
|
---|
| 866 | procedure InitParams( NoteIEN: Int64; Suppress: Integer );
|
---|
| 867 | begin
|
---|
| 868 | with RPCBrokerV do
|
---|
| 869 | begin
|
---|
| 870 | ClearParameters := True;
|
---|
| 871 | RemoteProcedure := 'TIU SET DOCUMENT TEXT';
|
---|
| 872 | Param[0].PType := literal;
|
---|
| 873 | Param[0].Value := IntToStr(NoteIEN);
|
---|
| 874 | Param[1].PType := list;
|
---|
| 875 | Param[2].PType := literal;
|
---|
| 876 | Param[2].Value := IntToStr(Suppress);
|
---|
| 877 | end;
|
---|
| 878 | end;
|
---|
| 879 |
|
---|
| 880 | { Printing --------------------------------------------------------------------------------- }
|
---|
| 881 |
|
---|
| 882 | function AllowChartPrintForNote(ANote: Integer): Boolean;
|
---|
| 883 | { returns true if a progress note may be printed outside of MAS }
|
---|
| 884 | begin
|
---|
| 885 | Result := (Piece(sCallV('TIU GET DOCUMENT PARAMETERS', [ANote]), U, 9) = '1');
|
---|
| 886 | // or (sCallV('TIU USER IS MEMBER OF CLASS', [User.DUZ, 'MEDICAL INFORMATION SECTION']) = '1');
|
---|
| 887 | // (V16? - RV) New TIU RPC required, per discussion on NOIS MAR-0900-21265
|
---|
| 888 | end;
|
---|
| 889 |
|
---|
| 890 | procedure PrintNoteToDevice(ANote: Integer; const ADevice: string; ChartCopy: Boolean;
|
---|
| 891 | var ErrMsg: string);
|
---|
| 892 | { prints a progress note on the selected device }
|
---|
| 893 | begin
|
---|
| 894 | ErrMsg := sCallV('TIU PRINT RECORD', [ANote, ADevice, ChartCopy]);
|
---|
| 895 | if Piece(ErrMsg, U, 1) = '0' then ErrMsg := '' else ErrMsg := Piece(ErrMsg, U, 2);
|
---|
| 896 | end;
|
---|
| 897 |
|
---|
| 898 | function GetFormattedNote(ANote: Integer; ChartCopy: Boolean): TStrings;
|
---|
| 899 | begin
|
---|
| 900 | CallV('ORWTIU WINPRINT NOTE',[ANote, ChartCopy]);
|
---|
| 901 | Result := RPCBrokerV.Results;
|
---|
| 902 | end;
|
---|
| 903 |
|
---|
| 904 | function GetCurrentSigners(IEN: integer): TStrings;
|
---|
| 905 | begin
|
---|
| 906 | CallV('TIU GET ADDITIONAL SIGNERS', [IEN]);
|
---|
| 907 | MixedCaseList(RPCBrokerV.Results);
|
---|
| 908 | Result := RPCBrokerV.Results ;
|
---|
| 909 | end;
|
---|
| 910 |
|
---|
| 911 | procedure UpdateAdditionalSigners(IEN: integer; Signers: TStrings);
|
---|
| 912 | begin
|
---|
| 913 | CallV('TIU UPDATE ADDITIONAL SIGNERS', [IEN, Signers]);
|
---|
| 914 | end;
|
---|
| 915 |
|
---|
| 916 | function CanChangeCosigner(IEN: integer): boolean;
|
---|
| 917 | begin
|
---|
| 918 | Result := Piece(sCallV('TIU CAN CHANGE COSIGNER?', [IEN]), U, 1) = '1';
|
---|
| 919 | end;
|
---|
| 920 |
|
---|
| 921 | procedure ChangeCosigner(IEN: integer; Cosigner: int64);
|
---|
| 922 | begin
|
---|
| 923 | with RPCBrokerV do
|
---|
| 924 | begin
|
---|
| 925 | ClearParameters := True;
|
---|
| 926 | RemoteProcedure := 'TIU UPDATE RECORD';
|
---|
| 927 | Param[0].PType := literal;
|
---|
| 928 | Param[0].Value := IntToStr(IEN);
|
---|
| 929 | Param[1].PType := list;
|
---|
| 930 | with Param[1] do
|
---|
| 931 | if Cosigner > 0 then
|
---|
| 932 | Mult['1208'] := IntToStr(Cosigner)
|
---|
| 933 | else
|
---|
| 934 | Mult['1208'] := '@';
|
---|
| 935 | CallBroker;
|
---|
| 936 | end;
|
---|
| 937 | end;
|
---|
| 938 |
|
---|
| 939 | // Determine if given note title is allowed more than once per visit. 12/2002-GRE
|
---|
| 940 | function OneNotePerVisit(NoteEIN: Integer; DFN: String; VisitStr: String):boolean;
|
---|
| 941 | var x: string;
|
---|
| 942 | begin
|
---|
| 943 | x := sCallV('TIU ONE VISIT NOTE?', [IntToStr(NoteEIN),DFN,VisitStr]);
|
---|
| 944 | if StrToInt(x) > 0 then
|
---|
| 945 | Result := True //Only one per visit
|
---|
| 946 | else
|
---|
| 947 | Result := False;
|
---|
| 948 | end;
|
---|
| 949 |
|
---|
| 950 | function GetCurrentTIUContext: TTIUContext;
|
---|
| 951 | var
|
---|
| 952 | x: string;
|
---|
| 953 | AContext: TTIUContext;
|
---|
| 954 | begin
|
---|
| 955 | x := sCallV('ORWTIU GET TIU CONTEXT', [User.DUZ]) ;
|
---|
| 956 | with AContext do
|
---|
| 957 | begin
|
---|
| 958 | Changed := True;
|
---|
| 959 | BeginDate := Piece(x, ';', 1);
|
---|
| 960 | FMBeginDate := StrToFMDateTime(BeginDate);
|
---|
| 961 | EndDate := Piece(x, ';', 2);
|
---|
| 962 | FMEndDate := StrToFMDateTime(EndDate);
|
---|
| 963 | Status := Piece(x, ';', 3);
|
---|
| 964 | if (StrToIntDef(Status, 0) < 1) or (StrToIntDef(Status, 0) > 5) then Status := '1';
|
---|
| 965 | Author := StrToInt64Def(Piece(x, ';', 4), 0);
|
---|
| 966 | MaxDocs := StrToIntDef(Piece(x, ';', 5), 0);
|
---|
| 967 | ShowSubject := StrToIntDef(Piece(x, ';', 6), 0) > 0; //TIU PREFERENCE??
|
---|
| 968 | SortBy := Piece(x, ';', 7); //TIU PREFERENCE??
|
---|
| 969 | ListAscending := StrToIntDef(Piece(x, ';', 8), 0) > 0;
|
---|
| 970 | TreeAscending := StrToIntDef(Piece(x, ';', 9), 0) > 0; //TIU PREFERENCE??
|
---|
| 971 | GroupBy := Piece(x, ';', 10);
|
---|
| 972 | SearchField := Piece(x, ';', 11);
|
---|
| 973 | KeyWord := Piece(x, ';', 12);
|
---|
| 974 | Filtered := (Keyword <> '');
|
---|
| 975 | end;
|
---|
| 976 | Result := AContext;
|
---|
| 977 | end;
|
---|
| 978 |
|
---|
| 979 | procedure SaveCurrentTIUContext(AContext: TTIUContext) ;
|
---|
| 980 | var
|
---|
| 981 | x: string;
|
---|
| 982 | begin
|
---|
| 983 | with AContext do
|
---|
| 984 | begin
|
---|
| 985 | SetPiece(x, ';', 1, BeginDate);
|
---|
| 986 | SetPiece(x, ';', 2, EndDate);
|
---|
| 987 | SetPiece(x, ';', 3, Status);
|
---|
| 988 | if Author > 0 then
|
---|
| 989 | SetPiece(x, ';', 4, IntToStr(Author))
|
---|
| 990 | else
|
---|
| 991 | SetPiece(x, ';', 4, '');
|
---|
| 992 | SetPiece(x, ';', 5, IntToStr(MaxDocs));
|
---|
| 993 | SetPiece(x, ';', 6, BOOLCHAR[ShowSubject]); //TIU PREFERENCE??
|
---|
| 994 | SetPiece(x, ';', 7, SortBy); //TIU PREFERENCE??
|
---|
| 995 | SetPiece(x, ';', 8, BOOLCHAR[ListAscending]);
|
---|
| 996 | SetPiece(x, ';', 9, BOOLCHAR[TreeAscending]); //TIU PREFERENCE??
|
---|
| 997 | SetPiece(x, ';', 10, GroupBy);
|
---|
| 998 | SetPiece(x, ';', 11, SearchField);
|
---|
| 999 | SetPiece(x, ';', 12, KeyWord);
|
---|
| 1000 | end;
|
---|
| 1001 | CallV('ORWTIU SAVE TIU CONTEXT', [x]);
|
---|
| 1002 | end;
|
---|
| 1003 |
|
---|
| 1004 | function TIUSiteParams: string;
|
---|
| 1005 | begin
|
---|
| 1006 | if(not uTIUSiteParamsLoaded) then
|
---|
| 1007 | begin
|
---|
| 1008 | uTIUSiteParams := sCallV('TIU GET SITE PARAMETERS', []) ;
|
---|
| 1009 | uTIUSiteParamsLoaded := TRUE;
|
---|
| 1010 | end;
|
---|
| 1011 | Result := uTIUSiteParams;
|
---|
| 1012 | end;
|
---|
| 1013 |
|
---|
| 1014 | // ===================Interdisciplinary Notes RPCs =====================
|
---|
| 1015 |
|
---|
| 1016 | function IDNotesInstalled: boolean;
|
---|
| 1017 | begin
|
---|
| 1018 | Result := True;
|
---|
| 1019 | end;
|
---|
| 1020 |
|
---|
| 1021 | function CanTitleBeIDChild(Title: integer; var WhyNot: string): boolean;
|
---|
| 1022 | var
|
---|
| 1023 | x: string;
|
---|
| 1024 | begin
|
---|
| 1025 | Result := False;
|
---|
| 1026 | x := sCallV('ORWTIU CANLINK', [Title]);
|
---|
| 1027 | if Piece(x, U, 1) = '1' then
|
---|
| 1028 | Result := True
|
---|
| 1029 | else if Piece(x, U, 1) = '0' then
|
---|
| 1030 | begin
|
---|
| 1031 | Result := False;
|
---|
| 1032 | WhyNot := Piece(x, U, 2);
|
---|
| 1033 | end;
|
---|
| 1034 | end;
|
---|
| 1035 |
|
---|
| 1036 | function CanBeAttached(DocID: string; var WhyNot: string): boolean;
|
---|
| 1037 | var
|
---|
| 1038 | x: string;
|
---|
| 1039 | const
|
---|
| 1040 | TX_NO_ATTACH = 'This note appears to be an interdisciplinary parent. Please drag the child note you wish to ' + CRLF +
|
---|
| 1041 | 'attach instead of attempting to drag the parent, or check with IRM or your' + CRLF +
|
---|
| 1042 | 'clinical coordinator.';
|
---|
| 1043 | begin
|
---|
| 1044 | Result := False;
|
---|
| 1045 | if StrToIntDef(DocID, 0) = 0 then exit;
|
---|
| 1046 | x := sCallV('TIU ID CAN ATTACH', [DocID]);
|
---|
| 1047 | if Piece(x, U, 1) = '1' then
|
---|
| 1048 | Result := True
|
---|
| 1049 | else if Piece(x, U, 1) = '0' then
|
---|
| 1050 | begin
|
---|
| 1051 | Result := False;
|
---|
| 1052 | WhyNot := Piece(x, U, 2);
|
---|
| 1053 | end
|
---|
| 1054 | else if Piece(x, U, 1) = '-1' then
|
---|
| 1055 | begin
|
---|
| 1056 | Result := False;
|
---|
| 1057 | WhyNot := TX_NO_ATTACH;
|
---|
| 1058 | end;
|
---|
| 1059 | end;
|
---|
| 1060 |
|
---|
| 1061 | function CanReceiveAttachment(DocID: string; var WhyNot: string): boolean;
|
---|
| 1062 | var
|
---|
| 1063 | x: string;
|
---|
| 1064 | begin
|
---|
| 1065 | x := sCallV('TIU ID CAN RECEIVE', [DocID]);
|
---|
| 1066 | if Piece(x, U, 1) = '1' then
|
---|
| 1067 | Result := True
|
---|
| 1068 | else
|
---|
| 1069 | begin
|
---|
| 1070 | Result := False;
|
---|
| 1071 | WhyNot := Piece(x, U, 2);
|
---|
| 1072 | end;
|
---|
| 1073 | end;
|
---|
| 1074 |
|
---|
| 1075 | function AttachEntryToParent(DocID, ParentDocID: string; var WhyNot: string): boolean;
|
---|
| 1076 | var
|
---|
| 1077 | x: string;
|
---|
| 1078 | begin
|
---|
| 1079 | x := sCallV('TIU ID ATTACH ENTRY', [DocID, ParentDocID]);
|
---|
| 1080 | if StrToIntDef(Piece(x, U, 1), 0) > 0 then
|
---|
| 1081 | Result := True
|
---|
| 1082 | else
|
---|
| 1083 | begin
|
---|
| 1084 | Result := False;
|
---|
| 1085 | WhyNot := Piece(x, U, 2);
|
---|
| 1086 | end;
|
---|
| 1087 | end;
|
---|
| 1088 |
|
---|
| 1089 | function DetachEntryFromParent(DocID: string; var WhyNot: string): boolean;
|
---|
| 1090 | var
|
---|
| 1091 | x: string;
|
---|
| 1092 | begin
|
---|
| 1093 | x := sCallV('TIU ID DETACH ENTRY', [DocID]);
|
---|
| 1094 | if StrToIntDef(Piece(x, U, 1), 0) > 0 then
|
---|
| 1095 | Result := True
|
---|
| 1096 | else
|
---|
| 1097 | begin
|
---|
| 1098 | Result := False;
|
---|
| 1099 | WhyNot := Piece(x, U, 2);
|
---|
| 1100 | end;
|
---|
| 1101 | end;
|
---|
| 1102 |
|
---|
| 1103 | function SubSetOfUserClasses(const StartFrom: string; Direction: Integer): TStrings;
|
---|
| 1104 | begin
|
---|
| 1105 | CallV('TIU USER CLASS LONG LIST', [StartFrom, Direction]);
|
---|
| 1106 | Result := RPCBrokerV.Results;
|
---|
| 1107 | end;
|
---|
| 1108 |
|
---|
| 1109 | function UserDivClassInfo(User: Int64): TStrings;
|
---|
| 1110 | begin
|
---|
| 1111 | CallV('TIU DIV AND CLASS INFO', [User]);
|
---|
| 1112 | Result := RPCBrokerV.Results;
|
---|
| 1113 | end;
|
---|
| 1114 |
|
---|
| 1115 | function UserInactive(EIN: String): boolean;
|
---|
| 1116 | var x: string;
|
---|
| 1117 | begin
|
---|
| 1118 | x:= sCallv('TIU USER INACTIVE?', [EIN]) ;
|
---|
| 1119 | if (StrToInt(x) > 0) then
|
---|
| 1120 | Result := True
|
---|
| 1121 | else
|
---|
| 1122 | Result := False;
|
---|
| 1123 | end;
|
---|
| 1124 |
|
---|
| 1125 | function NoteHasText(NoteIEN: integer): boolean;
|
---|
| 1126 | begin
|
---|
| 1127 | Result := (StrToIntDef(sCallV('ORWTIU CHKTXT', [NoteIEN]), 0) > 0);
|
---|
| 1128 | end;
|
---|
| 1129 |
|
---|
| 1130 | initialization
|
---|
| 1131 | // nothing for now
|
---|
| 1132 |
|
---|
| 1133 | finalization
|
---|
| 1134 | if uNoteTitles <> nil then uNoteTitles.Free;
|
---|
| 1135 | if uTIUPrefs <> nil then uTIUPrefs.Free;
|
---|
| 1136 |
|
---|
| 1137 | end.
|
---|