source: BMXNET_RPMS_dotNET_UTILITIES-BMX/branch/BMX41000/routines/BMXADOF.m@ 1589

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

Mumps Routines 4 BMX4

File size: 11.5 KB
Line 
1BMXADOF ; IHS/CIHA/GIS - RPC CALL FOR EXTENDED FUNCTIONALITY OF BMXNet UTILITIES ; 4/6/11 12:52pm
2 ;;4.1000;BMX;;Apr 17, 2011
3 ; THIS IS THE ADO RECORDSET FILER: ADO -> FILEMAN
4 ; VISIT FILE UPDATES REPRESENT A SPECIAL CASE HTAT IS MANAGED IN BMXADOF1
5 ; INCLUDES TRANSACTION CONTROLS
6 ;
7 ;
8 ;
9 N DAS,FILE,DATA,OUT S DAS=7,FILE=19707.82,DATA="2.02|120/83" D FILE(.OUT,FILE,DAS,DATA) W !,OUT Q
10 ;
11FILED(OUT,FILE,DAS,DATA) ; RPC CALL: UNIVERSAL FILEMAN RECORD UPDATER UTILITY
12 ; D DEBUG^%Serenji("FILED^BMXADOF(.OUT,FILE,DAS,DATA)") ; DEBUGGER ENTRY POINT
13 Q
14 ;
15FILEX(OUT,FILE,DAS,DATA) ; EP - RPC CALL: INSURES THAT BMXIEN IS VALID - MOJO ONLY
16 I '$L($G(DATA)) D
17 . S DATA="",%=""
18 . F S %=$O(DATA(%)) Q:'% S DATA=DATA_DATA(%) ; CONVERT DATA ARRAY INTO A DATA STRING
19 . Q
20 I '$L(DATA) Q
21 I DATA["999|" S DAS=+$P(DATA,"999|",2) I 'DAS S DAS="" ; FORCE NEW ENTRY
22 D FILE(.OUT,FILE,$G(DAS),DATA)
23 Q
24 ;
25FILE(OUT,FILE,DAS,DATA) ;EP - RPC CALL: UNIVERSAL FILEMAN RECORD UPDATER UTILITY
26 ;
27 ; OUT = OUTBOUND MESSAGE RETURNED TO CALLINING APP. 'OK'=SUCCESSFUL TRANSACTION, 'OK|5' NEW RECORD DAS=5 ADDED
28 ; IF TRANSACTION FAILS, AN ERROR MESSAGE IS PASSED
29 ; FILE = VALID FILEMAN FILE OR SUB-FILE NUMBER - WHERE UPDATE IS TO OCCUR
30 ; DAS = THE DA STRING - TYPICALLY THE FILE INTERNAL ENTRY NUMBER OF THE RECORD TO BE UPDATED
31 ; IF THIS IS A SUB-FILE, DAS MUST BE PRECEDED BY PARENT DAS(S) IN COMMA SEPARATED STRING - TOP TO BOTTOM ORDER
32 ; DAS MAY BE PRECEDED BY '+' = ALL FIELDS ARE MANDATORY (REQD FOR TRANSACTION) OR '-' = DELETE THIS ENTRY
33 ; IF DAS STRING = NULL OR = '+', THIS MEANS ADD A NEW RECORD WITH DATA SUPPLIED IN DATA PARAMETER
34 ; EXAMPLES OF DAS STRINGS: '1' (EDIT RECORD #1), '5,2,-7' (DELETE RECORD #7 IN 3RD LEVEL SUBFILE)
35 ; DATA = DATA STRING OR ARRAY REFERENCE. DATA CAN BE PASSED USING THE .PARAM SYNTAX
36 ; DATA STRING FORMAT: FIELD#|VALUE_$C(30)_FIELD#|VALUE_$C(30)_...FIELD#|VALUE_$C(30)
37 ; $C(30) [AKA EOR] IS THE DATA ELEMENT SEPARATOR
38 ; $C(30) IS USED AS THE DATA DELIMITER BECAUSE OTHER CHARACTERS LIKE '^' COULD APPEAR IN THE VALUE PIECE!
39 ; EA FIELD# MAY BE PRECEED BY '+' = MANDATORY (REQD FOR TRANSACTION) OR '-' = DELETE THE VALUE OF THIS FIELD
40 ; EXAMPLE: ".03|1/5/46"_EOR_"-.02|"_EOR_"+.09|139394444"_EOR NOTE -.02| IS SAME AS .02|@ OR .02|
41 ; '+' IN FRONT OF THE DAS IS THE SAME AS PUTTING A '+' IN FRONT OF EVERY FIELD# IN THE DATA STRING
42 ;
43 ;;;;;DEBUG CODE!!!!
44 S ^ZSAM("FILE")=FILE
45 S ^ZSAM("DAS")=DAS
46 S ^ZSAM("DATA")=DATA
47 ;;;;;DEBUG CODE!!!!
48 ;
49 ;
50 N VENDUZ,VUZ
51 M VENDUZ=DUZ S VUZ=$C(68,85,90)
52 N OREF,CREF,DIC,DIE,DA,DR,X,Y,%,I,FLD,CNT,FNO,VAL,@VUZ,TFLG,DFLG,TOT,UFLG,XTFLG,GTFLG,GDFLG,LVLS,IENS
53 I $G(FILE)=9000010 N AUPNPAT,AUPNDOB,AUPNDOD,AUPNVSIT,AUPNTALK,APCDOVRR S (APCDOVRR,AUPNTALK)=1 ; THE VISIT FILE IS UPDATED IN THIS TRANSACTION
54 X ("M "_$C(68,85,90)_"=VENDUZ S "_$C(68,85,90)_"(0)="_$C(34,64,34)) K VENDUZ ; ELININATES PERMISSION PROBLEMS
55 S OUT="",FLD="",GTFLG=0,GDFLG=0
56 S X="MERR^BMXADOF",@^%ZOSF("TRAP") ; SET MUMPS ERROR TRAP
57 I '$D(^DD(+$G(FILE))) S OUT="Invalid file number" Q ; FILE # MUST BE VALID
58 S DAS=$G(DAS) I $E(DAS)="," S DAS=$E(DAS,2,99) ; ACCURATE IF NON SUB-FILE DAS STRING DOSN'T CONTAIN A ","
59 S LVLS=$L(DAS,",")
60 S %=FILE F CNT=1:1 S %=$G(^DD(%,0,"UP")) I '% Q ; COUNT FILE/SUB-FILE LEVELS IN THE DATA DICTIONARY
61 I LVLS'=CNT S OUT="Invalid DAS string" Q ; LEVELS IN DAS STRING MUST MATCH LEVELS IN THE DATA DICTIONARY
62 I $E(DAS)="-" S DAS=$E(DAS,2,99),GDFLG=1 ; GLOBAL DELETE FLAG
63 I $E(DAS)="+" S DAS=$E(DAS,2,99),GTFLG=1 ; GLOBAL TRANSACTION FLAG, ROLLBACK IF ANY FIELD FAILS TO UPDATE
64 I LVLS>1 F I=1:1:LVLS D I DAS="ERR" S OUT="Invalid DAS string" Q ; MAKE DAS ARRAY. MIRRORS THE DA() ARRAY
65 . I I=LVLS S DAS=$P(DAS,",",I) Q ; SET DAS OF SUBFILE
66 . S %=$P(DAS,",",I) I '% S DAS="ERR" Q
67 . S DAS(LVLS-I)=% ; SET DAS(S) OF PARENT FILE(S). LIKE DA(), THE LARGER THE DAS SUBSCRIPT, THE HIGHER THE LEVEL
68 . Q
69 I DAS="ERR" S OUT="Update cancelled. Invalid DAS string" Q
70 I DAS="Add"!(DAS="ADD") S DAS=""
71 S %=$E(DAS) I %="-" S GDFLG=1,DAS=$E(DAS,2,99) ; YET ANOTHER WAY TO SET GLOBAL DELETE FLAG
72 S %=$$REF(FILE,.DAS) ; GET OPEN REF, CLOSED REF, AND IENS STRING
73 S OREF=$P(%,"|"),CREF=$P(%,"|",2),IENS=$P(%,"|",3) I $L(OREF),$L(CREF)
74 E S OUT="Update cancelled. Invalid file definition/global reference" Q ; ERROR REPORT
75 I DAS,'$D(@CREF@(DAS)) S OUT="Update cancelled. Invalid DAS" Q ; IF THERE IS AN DAS, IT MUST BE VALID
76 I '$G(DAS),FILE=9000010,'$$VVAR^BMXADOF2(DATA) Q ; VISIT FILE ADD REQUIRES THAT SPECIAL VARIABLES BE PRESENT AND VALID
77 I 'GDFLG,DAS,DATA[".01|@" S GDFLG=1 ; ALTERNATE WAY TO SET GLOBAL DELETE FLAG: REMOVE .01 FIELD
78 I GDFLG,'DAS S OUT="Deletion cancelled. Missing DAS" Q ; CAN'T DO DELETE WITHOUT AN DAS
79 I GDFLG D DIK(OREF,DAS) S OUT="Record deleted|"_DAS Q ; DELETE AND QUIT
80 S UFLG=$S($G(DAS):"E",1:"A") ; SET UPDATE FLAG: ADD OR EDIT
81 I '$L($G(DATA)) D I '$L($G(DATA)) S OUT="Update cancelled. Missing/invalid data string" Q ; COMPRESS DATA ARRAY INTO A SINGLE STRING
82 . S DATA="",%=""
83 . F S %=$O(DATA(%)) Q:'% S DATA=DATA_DATA(%) ; CONVERT DATA ARRAY INTO A DATA STRING
84 . Q
85 S %=$L(DATA) S %=$E(DATA,%-1,%) D ; CHECK FOR PROPER TERMINATION OF DATA STRING
86 . I %=$C(30,31) Q ; PROPER TERMINATION
87 . I $E(%,2)=$C(30) S DATA=DATA_$C(31) Q
88 . I $E(%,2)=$C(31) S DATA=$E(DATA,1,$L(DATA-1))_$C(30,31)
89 . S DATA=DATA_$C(30,31)
90 . Q
91 S TOT=$L(DATA,$C(30)) I 'TOT S OUT="Update cancelled. Missing data string" Q
92SPEC S DATA=$$SPEC^BMXADOFS(FILE,DATA,UFLG) ; BASED ON FILE IEN, SPECIAL MODS MAY BE MADE TO THE DATA STRING
93 S TOT=$L(DATA,$C(30)) I 'TOT S OUT="Update cancelled. SPEC analysis failed." Q
94 F CNT=1:1:TOT S %=$P(DATA,$C(30),CNT) I $L(%) S DATA(CNT)=% ; BUILD PRIMARY FIELD ARRAY
95 S %=$G(DATA(1)) I %=""!(%=$C(31)) S OUT="Update cancelled. Missing data string" Q
96 S %=DATA(CNT) I %[$C(31) S %=$P(%,$C(31),1),DATA(CNT)=% ; STRIP OFF END OF FILE MARKER
97 F CNT=1:1:TOT S X=$G(DATA(CNT)) I $L(X) D ; BUILD SECONDARY FIELD ARRAY
98 . S TFLG=0,DFLG=0
99 . I $E(X)="+" S TFLG=1,X=$E(X,2,999),$P(FLD,U)=1
100 . I $E(X)="-" S DFLG=1,X=$E(X,2,999)
101 . S FNO=$P(X,"|"),VAL=$P(X,"|",2)
102 . I '$D(^DD(FILE,+$G(FNO),0)) S:$L(OUT) OUT=OUT_"~" S OUT=OUT_FNO_"|Invalid field number" Q
103 . I DFLG,VAL'="" S:$L(OUT) OUT=OUT_"~" S OUT=OUT_FNO_"|Invalid deletion syntax" Q ; CANT DELETE IF A VALUE IS SENT
104 . I VAL="@" S DFLG=1 ; SYNC DFLG AND VAL
105 . S FLD(FNO)=VAL_U_TFLG_U_DFLG
106 . I FNO=.01,TFLG S $P(FLD,U,2)=1
107 . Q
108 I $P($G(FLD(.01)),U,3),UFLG="A" S OUT="Record deletion cancelled. Missing DAS" Q ; CAN'T DELETE A RECORD WITHOUT A VALID DAS
109 I $P($G(FLD(.01)),U,3)!($G(GDFLG)) S UFLG="D" ; DELETION
110DELREC I UFLG="D" D DIK(OREF,DAS) S OUT="OK" Q ; DELETE THE RECORD
111 I UFLG="A",'$L($P($G(FLD(.01)),U)) S OUT="Record addition cancelled. Missing .01 field" Q ; CAN'T ADD A RECORD WITHOUT A VALID .01 FIELD
112DINUM I UFLG="A",$G(^DD(FILE,.01,0))["DINUM=X" D ; IF DINUM'D RECORD EXISTS, SWITCH TO MOD MODE
113 . S %=FLD(.01)
114 . I $E(%)="`" S %=+$E(%,2,99)
115 . I '$D(@CREF@(%,0)) Q ; OK TO ADD BRAND NEW RECORD BUT EXISTING RECORDS MUST BE EDITED
116 . K FLD(.01)
117 . S DAS=%,UFLG="E"
118 . Q
119ADDREC I UFLG="A" D ADD(OREF) Q ; ADD A NEW ENTRY TO A FILE
120EDITREC I UFLG="E" D EDIT(OREF,DAS) Q ; EDIT AN EXISTING RECORD
121 Q
122 ;
123DIK(DIK,DA) ; DELETE A RECORD
124 ; PATCHED BY GIS 9/28/04 TO FIX PROBLEMS WITH SUBFILE DELETION
125 I '$G(DAS(1)) G DIK1 ; CHECK FOR SUBFILE DELETION
126 N DA,IENS,I,DIK
127 I '$G(FILE) Q
128 S I=0,IENS=DAS_","
129 M DA=DAS
130 F S I=$O(DAS(I)) Q:'I S IENS=IENS_DAS(I)_","
131 S DIK=$$ROOT^DILFD(FILE,IENS) I '$L(DIK) Q
132DIK1 D ^DIK
133 D ^XBFMK
134 Q
135 ;
136ADD(DIC) ; ADD A NEW ENTRY TO A FILE
137 N X,Y,%,DA,DN,UP,SB,DNODE,ERR
138 S X=$P($G(FLD(.01)),U) I '$L(X) S OUT="Unable to add a new record" Q
139 S X=$$POINT(FILE,.01,X) ; ADD ACCENT GRAV IF NECESSARY
140 S X=""""_X_"""" ; FORCE A NEW ENTRY
141 S DIC(0)="L"
142 I $O(DAS(0)) D I $G(ERR) S Y=-1 G AFAIL ; GET DIC("P") IF NECESSARY
143 . S %=0 F S %=$O(DAS(%)) Q:'% S DA(%)=DAS(%) ; CREATE THE DA ARRAY
144 . S UP=$G(^DD(FILE,0,"UP")) I 'UP S ERR=1 Q
145 . S SB=$O(^DD(UP,"SB",FILE,0)) I 'SB S ERR=1 Q
146 . S DIC("P")=$P($G(^DD(UP,SB,0)),U,2) I '$L(DIC("P")) S ERR=1 Q
147 . S DN=DIC_"1,0)" I $D(DN) Q
148 . S @DN=(U_DIC("P")_U_U) ; CREATE THE DICTIONARY NODE
149 . Q
150ADIC D ^DIC
151AFAIL I Y=-1 S OUT="Unable to add a new record" G AX
152 I $O(FLD(0)) D EDIT(DIC,+Y) Q
153 S OUT="OK"_"|"_+Y
154AX D ^XBFMK
155 Q
156 ;
157EDIT(DIE,DA) ; EDIT AN EXISTING RECORD
158 N DR,RFLG,ERR,FNO,VAL,TFLG,RESULT,MSG,DIERR,DISYS,SF,APCDALVR
159 S FNO=0,DR="",APCDALVR=""
160 I UFLG="A" S OUT="OK New record added|"_DA
161 F S FNO=$O(FLD(FNO)) Q:'FNO S X=FLD(FNO) I $L(X) D I $G(RFLG) Q ; CHECK EA FIELD AND BUILD THE DR STRING AND ERROR STRING
162 . S VAL(FNO)=$P(X,U),TFLG=$P(X,U,2) I '$L(VAL(FNO)) Q
163 . S SF=$$WP(FILE,FNO)
164 . I SF D WORD(FILE,DA,FNO,CREF,VAL(FNO)) Q ; WORD PROCESSING FIELDS MANAGED SEPARATELY
165 . S VAL(FNO)=$$POINT(FILE,FNO,VAL(FNO)) ; ADD ACCENT GRAV IF NECESSARY
166 . K ERR,RESULT
167 . I VAL(FNO)="@"!(VAL(FNO)="") S RESULT="@"
168 . I FNO=.01,UFLG="A" S:$E(VAL(.01))="`" VAL(.01)=$E(VAL(.01),2,999) Q ; NO NEED TO EDIT THE .01 FIELD OF A RECORD THAT HAS JUST BEEN CREATED
169 . I FILE\1=9000010,$L($P(FILE,".",2))=2,UFLG="E",(FNO=.02!(FNO=.03)) Q ; CAN'T EDIT EXISTING PT AND VISIT FIELDS OF V FILES
170 . I FILE\1=9000010,$L($P(FILE,".",2))=2,UFLG="A",FNO=.03,VAL(.03)?1"`"1.N S %=+$E(VAL(.03),2,99) I $D(^AUPNVSIT(%,0)) S RESULT=% G E1
171 . I FILE=9000011,FNO=.07,VAL(.07)?1.N S RESULT=VAL(.07) G E1 ; THE VALIDITY CHECK FAILS - SO BYPASS THIS
172CHK . I VAL(FNO)'="@" D CHK^DIE(FILE,FNO,"",VAL(FNO),.RESULT,.ERR)
173E1 . I RESULT=U D Q
174 .. S MSG=$G(ERR("DIERR",1,"TEXT",1),"Failed FileMan data validation")
175 .. I $L(OUT) S OUT=OUT_"~"
176 .. I TFLG!GTFLG S RFLG=1,OUT=FNO_"|"_MSG Q
177 .. S OUT=OUT_FNO_"|"_MSG
178 .. Q
179 . S VAL(FNO)=RESULT
180 . I $L(DR) S DR=DR_";"
181 . I RESULT="@" S DR=DR_FNO_"////@" Q ; DELETE THIS VALUE
182 . S DR=DR_FNO_"////^S X=VAL("_FNO_")" ; BUILD DR STRING
183 . Q
184 I $G(RFLG) D:UFLG="A" DIK(DIE,DA) S OUT="Record update cancelled"_"|"_OUT G EX ; TRANSACTION ROLLBACK FLAG IS SET, ENTRY DELETED (ADD MODE) OR UPDATE CANCELLED (EDIT MODE)
185 S %=0 F S %=$O(DAS(%)) Q:'% S DA(%)=DAS(%) ; JUST IN CASE THIS IS A MILTIPLE, CREATE THE DA ARRAY
186DIE L +@CREF@(DA):2 I $T D ^DIE L -@CREF@(DA) G:OUT["valid" EX S OUT="OK" S:UFLG="A" OUT=OUT_"|"_DA G EX ; SUCCESS!!!!
187 S OUT="Update cancelled. File locked" ; FILE LOCKED. UNABLE TO UPDATE
188 I $L(FLD),UFLG="A" D DIK(DIE,DA) ; ROLLBACK THE NEW RECORD
189EX D ^XBFMK ; CLEANUP
190 Q
191 ;
192REF(FILE,DAS) ; GIVEN A FILE/SUBFILE NUMBER & DAS ARRAY, RETURN THE FM GLOBAL REFERENCE INFO: OREF|CREF|IENS
193 N OREF,CREF,IENS,I,X
194 S IENS=$$IENS^DILF(.DAS) I '$L(IENS) Q ""
195 S OREF=$$ROOT^DILFD(FILE,IENS) I '$L(OREF) Q ""
196 S CREF=$$CREF^DILF(OREF) I '$L(CREF) Q ""
197 Q (OREF_"|"_CREF_"|"_IENS)
198 ;
199POINT(FILE,FNO,VAL) ; ADD ACCENT GRAV IF NECESSARY
200 I $E(VAL)="`" Q VAL
201 I $P($G(^DD(FILE,FNO,0)),U,2)["P",VAL=+VAL,VAL\1=VAL S VAL="`"_VAL
202 Q VAL
203 ;
204WP(FILE,FLD) ; RETURN THE SUBFILE NUMBER IF IT IS A WORD PROCESSING FIELD
205 N SF,DTYPE
206 S SF=$P($G(^DD(+$G(FILE),+$G(FLD),0)),U,2) I 'SF Q 0
207 S DTYPE=$P($G(^DD(SF,.01,0)),U,2)
208 I DTYPE["W" Q SF
209 Q 0
210 ;
211WORD(FILE,DA,FLD,CREF,VAL) ; SUFF TEXT ENTRY INTO THE WP MULTIPLE FIELD
212 N SS,TOT,A,B,I
213 S SS=+$P($G(^DD(FILE,FLD,0)),U,4) I SS="" Q
214 I VAL="@"!(VAL="") K @CREF@(DA,SS) Q ; DELETE THE WP RECORD: REMOVE DICTIONARY NODE AND DATA
215 S TOT=0
216 F Q:'$L(VAL) D
217 . S A=$E(VAL,1,80),VAL=$E(VAL,81,999999) ; PEEL OFF AN 80 CHARACTER DATA BLOCK FROM THE FRONT OF THE TEXT STRING
218 . I $L(A) S TOT=TOT+1,B(TOT)=A ; BUILD THE TEMP ARRAY
219 . Q
220 I '$D(B(1)) Q ; NOTHING TO STORE SO QUIT
221 S @CREF@(DA,SS,0)="^^"_TOT_U_TOT_U_DT ; SET DICTIONARY NODE
222 F I=1:1:TOT S @CREF@(DA,SS,I,0)=B(I) ; SET DATA NODES
223 Q
224 ;
225MERR ; MUMPS ERROR TRAP
226 N ERR,X
227 X ("S X=$"_"ZE")
228 S ERR="M ERROR: "_X
229 S OUT=ERR
230 Q
231 ;
Note: See TracBrowser for help on using the repository browser.