source: Scheduling/trunk/m/BSDX26.m@ 1176

Last change on this file since 1176 was 1161, checked in by Sam Habiel, 14 years ago

Added LGPL license to routines

File size: 4.7 KB
Line 
1BSDX26 ; IHS/OIT/HMW - WINDOWS SCHEDULING RPCS ; 4/28/11 10:24am
2 ;;1.5;BSDX;;Apr 28, 2011
3 ; Licensed under LGPL
4 ; Change History:
5 ; 3101023 - UJO/SMH - Addition of restartable transaction; relocation of tx.
6 ; --> Thanks to Zach Gonzalez and Rick Marshall
7 ; 3101205 - UJO/SMH - Extensive refactoring.
8 ;
9 ; Error Reference:
10 ; -1: Appt ID is not a number
11 ; -2: Appt IEN is not in ^BSDXAPPT
12 ; -3: FM Failure to file WP field in ^BSDXAPPT
13 ;
14EDITAPTD(BSDXY,BSDXAPTID,BSDXNOTE) ;EP
15 ;Entry point for debugging
16 ;
17 D DEBUG^%Serenji("EDITAPT^BSDX26(.BSDXY,BSDXAPTID,BSDXNOTE)")
18 Q
19UT ; Unit Tests
20 ; Test 1: Make sure this damn thing works
21 N ZZZ
22 N %H S %H=$H
23 N NOTE S NOTE="New Note "_%H
24 D EDITAPT(.ZZZ,188,NOTE)
25 I ^BSDXAPPT(188,1,1,0)'=NOTE W "ERROR",! B
26 ; Test 2: Test Errors -1 and -2
27 N ZZZ
28 N NOTE S NOTE="Nothing important"
29 D EDITAPT(.ZZZ,"BLAHBLAH",NOTE)
30 I +^BSDXTMP($J,1)'=-1 W "ERROR IN -1",! B
31 D EDITAPT(.ZZZ,298734322,NOTE)
32 I +^BSDXTMP($J,1)'=-2 W "ERROR IN -2",! B
33 ; Test 4: M Error
34 N bsdxdie S bsdxdie=1
35 D EDITAPT(.ZZZ,188,NOTE)
36 I +^BSDXTMP($J,1)'=-100 W "ERROR IN -100",! B
37 k bsdxdie
38 ; Test 5: Trestart
39 N bsdxrestart S bsdxrestart=1
40 N %H S %H=$H
41 N NOTE S NOTE="New Note "_%H
42 D EDITAPT(.ZZZ,188,NOTE)
43 I ^BSDXAPPT(188,1,1,0)'=NOTE W "ERROR in TRESTART",! B
44 ; Test 6: for Hosp Location Update
45 N DATE S DATE=$$NOW^XLFDT()
46 S DATE=$E(DATE,1,12) ; Just get minutes b/c of HL file input transform
47 D APPADD^BSDX07(.ZZZ,DATE,DATE+.001,3,"Dr Office",30,"Old Note",1)
48 N APPID S APPID=+$P(^BSDXTMP($J,1),U)
49 D EDITAPT(.ZZZ,APPID,"New Note")
50 I ^BSDXAPPT(APTID,1,1,0)'="New Note" W "Error in HL Section",! B
51 I $P(^SC(2,"S",DATE,1,1,0),U,4)'="New Note" W "Error in HL Section",! B
52 QUIT
53 ;
54EDITAPT(BSDXY,BSDXAPTID,BSDXNOTE) ;EP Edit appointment (only note text can be edited)
55 ; Called by RPC: BSDX EDIT APPOINTMENT
56 ;
57 ; Edits Appointment Text in BSDX APPOINTMENT file & Hosp Location (44) file
58 ;
59 ; Parameters:
60 ; - BSDXY: Global Return (RPC must be set to Global Array)
61 ; - BSDXAPTID: Appointment IEN in BSDX APPOINTMENT
62 ; - BSDXNOTE: New note
63 ;
64 ; Return:
65 ; ADO.net Recordset having 1 field: ERRORID
66 ; If Okay: -1; otherwise, positive integer with message
67 ;
68 ; Return Array; set Return and clear array
69 S BSDXY=$NA(^BSDXTMP($J))
70 K ^BSDXTMP($J)
71 ; ET
72 N $ET S $ET="G ETRAP^BSDX26"
73 ; Set up basic DUZ variables
74 D ^XBKVAR
75 ; Counter
76 N BSDXI S BSDXI=0
77 ; Header Node
78 S ^BSDXTMP($J,BSDXI)="T00100ERRORID"_$C(30)
79 ; Restartable txn for GT.M. Restored vars are Params + BSDXI.
80 TSTART (BSDXY,BSDXAPTID,BSDXNOTE,BSDXI):T="BSDX EDIT APPOINTMENT^BSDX26"
81 ;
82 ;;;test for error inside transaction. See if %ZTER works
83 I $G(bsdxdie) S X=1/0
84 ;;;test
85 ;;;test for TRESTART
86 I $G(bsdxrestart) K bsdxrestart TRESTART
87 ;;;test
88 ;
89 ; Validate Appointment ID
90 I '+BSDXAPTID D ERR(BSDXI,"-1~BSDX26: Invalid Appointment ID") QUIT
91 I '$D(^BSDXAPPT(BSDXAPTID,0)) D ERR(BSDXI,"-2~BSDX26: Invalid Appointment ID") QUIT
92 ; Put the WP in decendant fields from the root to file as a WP field
93 S BSDXNOTE(.5)=BSDXNOTE,BSDXNOTE=""
94 I $D(BSDXNOTE(0)) S BSDXNOTE(.5)=BSDXNOTE(0) K BSDXNOTE(0)
95 N BSDXMSG ; Message in case of error in filing.
96 I $D(BSDXNOTE(.5)) D
97 . D WP^DIE(9002018.4,BSDXAPTID_",",1,"","BSDXNOTE","BSDXMSG")
98 I $D(BSDXMSG) D ERR(BSDXI,"-3~BSDX26: Fileman failure to file data into 9002018.4") QUIT
99 ;
100 ; Now file in file 44:
101 N PTIEN S PTIEN=$$GET1^DIQ(9002018.4,BSDXAPTID,".05","I") ; Patient IEN
102 N HLIEN S HLIEN=$$GET1^DIQ(9002018.4,BSDXAPTID,".07:.04","I") ; HL Location IEN pointed to by Resource ID
103 N DATE S DATE=+^BSDXAPPT(BSDXAPTID,0) ; Date of APPT
104 N BSDXRES S BSDXRES=0 ; Result
105 ; Update Note only if we have a linked hospital location.
106 I HLIEN S BSDXRES=$$UPDATENOTE^BSDXAPI(PTIEN,HLIEN,DATE,BSDXNOTE(.5))
107 ; If we get an error (denoted by -1 in BSDXRES), return error to client
108 I BSDXRES<0 D ERR(BSDXI,"-4~BSDX26: BSDXAPI reports an error: "_BSDXRES) QUIT
109 ;Return Recordset
110 TCOMMIT
111 S BSDXI=BSDXI+1
112 S ^BSDXTMP($J,BSDXI)="-1"_$C(30)
113 S BSDXI=BSDXI+1
114 S ^BSDXTMP($J,BSDXI)=$C(31)
115 QUIT
116 ;
117ERR(BSDXI,BSDXERR) ;Error processing
118 S BSDXI=BSDXI+1
119 S BSDXERR=$TR(BSDXERR,"^","~")
120 I $TL>0 TROLLBACK
121 S ^BSDXTMP($J,BSDXI)=BSDXERR_$C(30)
122 S BSDXI=BSDXI+1
123 S ^BSDXTMP($J,BSDXI)=$C(31)
124 QUIT
125 ;
126ETRAP ;EP Error trap entry
127 N $ET S $ET="D ^%ZTER HALT" ; Emergency Error Trap
128 I $TL>0 TROLLBACK
129 D ^%ZTER
130 S $EC=""
131 I '$D(BSDXI) N BSDXI S BSDXI=0
132 D ERR(BSDXI,"-100~BSDX26 Error: "_$G(%ZTERZE))
133 Q
Note: See TracBrowser for help on using the repository browser.