| 1 | RA45PST2 ;Hines OI/GJC - Post-init 'B', patch 45 ;10/10/03  06:32 | 
|---|
| 2 | VERSION ;;5.0;Radiology/Nuclear Medicine;**45**;Mar 16, 1998 | 
|---|
| 3 | ; | 
|---|
| 4 | ENQ2 ;The second process must be tasked off that will identify all the | 
|---|
| 5 | ;non-parent Rad/Nuc Med orderable items (OI) in file 101.43 checking | 
|---|
| 6 | ;them to see if barium, oral cholecystogram or unspecified contrast | 
|---|
| 7 | ;media happen to be associated contrasts. | 
|---|
| 8 | ; | 
|---|
| 9 | ;If no associations move onto the next OI and check for CMs | 
|---|
| 10 | ; | 
|---|
| 11 | ;If yes, update the procedure in file 71; add barium, oral | 
|---|
| 12 | ;cholecystografic or unspecified contrast media to the CONTRAST MEDIA | 
|---|
| 13 | ;(#125) multiple in file 71. All successful and unsuccessful updates | 
|---|
| 14 | ;will be presented to the user in the form of an email message. | 
|---|
| 15 | ;(Failure to update occurs when a record cannot be locked) | 
|---|
| 16 | ; | 
|---|
| 17 | ;Finally, the Rad/Nuc Med Procedure (71) file will be synchronized with | 
|---|
| 18 | ;the Orderable Items (101.43) file. | 
|---|
| 19 | ; | 
|---|
| 20 | ;Note: since parent procedure records resident in the OI file prior | 
|---|
| 21 | ;to RA*5*45 did not have CM associations synchronizing files 101.43 & | 
|---|
| 22 | ;71 will occur just before processing is finished. | 
|---|
| 23 | ; | 
|---|
| 24 | S:$D(ZTQUEUED) ZTREQ="@" S RAX="",(RACT,ZTSTOP)=0 | 
|---|
| 25 | F  S RAX=$O(^ORD(101.43,"S.XRAY",RAX)) Q:RAX=""  D  Q:ZTSTOP | 
|---|
| 26 | .S RAY=0 F  S RAY=$O(^ORD(101.43,"S.XRAY",RAX,RAY)) Q:'RAY  D | 
|---|
| 27 | ..S RAOIRA=$G(^ORD(101.43,RAY,"RA")),RAOICM=$P(RAOIRA,U) Q:RAOICM="" | 
|---|
| 28 | ..S RAOIPT=$P(RAOIRA,U,2) Q:("^B^P^")[("^"_RAOIPT_"^") | 
|---|
| 29 | ..;parents have no descendents in 101.43 & broads have no CPTs quit | 
|---|
| 30 | ..S RAOI=$G(^ORD(101.43,RAY,0)),RAOI(2)=$P(RAOI,U,2) | 
|---|
| 31 | ..Q:$P(RAOI(2),";",2)'="99RAP"  ;just to be on the safe side... | 
|---|
| 32 | ..;update file 71 with CM data, lock the record if lock fails quit | 
|---|
| 33 | ..;record will not be updated in this case | 
|---|
| 34 | ..L +^RAMIS(71,+RAOI(2)):30 | 
|---|
| 35 | ..I '$T D SETMP(+RAOI(2),$E($P(RAOI,U),1,40),"",RAOICM,"*failed*",1) Q | 
|---|
| 36 | ..F RAI=1:1:$L(RAOICM) D FILECM(+RAOI(2),$E(RAOICM,RAI),RAI) | 
|---|
| 37 | ..L -^RAMIS(71,+RAOI(2)) ;unlock | 
|---|
| 38 | ..;identify those records in file 71 that have been updated; the | 
|---|
| 39 | ..;user will be made aware of rad/nuc med procedure updates via email | 
|---|
| 40 | ..S RAMIS(0)=$G(^RAMIS(71,+RAOI(2),0)),RAPNAME=$P(RAMIS(0),U) | 
|---|
| 41 | ..S RACT=RACT+1 S:RACT#200=0 ZTSTOP=$$S^%ZTLOAD() | 
|---|
| 42 | ..S RACPT=$P($$CPT^ICPTCOD($P(RAMIS(0),U,9)),U),RACPT=$S(RACPT=-1:"none",1:RACPT) | 
|---|
| 43 | ..D SETMP(+RAOI(2),$E(RAPNAME,1,40),RACPT,RAOICM,"*done*",1) | 
|---|
| 44 | ..Q | 
|---|
| 45 | .Q | 
|---|
| 46 | ; | 
|---|
| 47 | ;if the user stopped this process via TaskMan (TM) inform the user | 
|---|
| 48 | D:ZTSTOP=1 STOP | 
|---|
| 49 | ; | 
|---|
| 50 | ;if there has been data updated, let the user know through an email | 
|---|
| 51 | ;even if the user stopped the task via TaskMan (TM) | 
|---|
| 52 | I +$O(^TMP("RA PROC UPDATE 45",$J,0)) D MAILQ2^RA45PST(1,"RA*5*45: Update Rad/NM CM definitions from Ord. Item CM definitions") | 
|---|
| 53 | ; | 
|---|
| 54 | ;user stopped the process, do not proceed kill variables and quit | 
|---|
| 55 | I ZTSTOP=1 D KILLQ2 Q | 
|---|
| 56 | ; | 
|---|
| 57 | ;make sure the all from file 71 get updated in file 101.43; ZTSTOP | 
|---|
| 58 | ;exists and is set to zero. | 
|---|
| 59 | ;RAO7MFN takes care of: skipping broad procedures, skipping inactive | 
|---|
| 60 | ;procedures, & flagging parent procedure with contrasts if a non-broad | 
|---|
| 61 | ;descendent has contrasts. | 
|---|
| 62 | S (RACT,RAY)=0 K ^TMP("RA PROC UPDATE 45",$J) | 
|---|
| 63 | F  S RAY=$O(^RAMIS(71,RAY)) Q:'RAY  D  Q:ZTSTOP | 
|---|
| 64 | .S RAMIS(0)=$G(^RAMIS(71,RAY,0)),RAPNAME=$E($P(RAMIS(0),U),1,40) | 
|---|
| 65 | .S RASTAT=+$G(^RAMIS(71,RAY,"I")),RASTAT=$S(RASTAT=0:1,RASTAT>DT:1,1:0) | 
|---|
| 66 | .S RAPTY=$P(RAMIS(0),U,6),RAPTY=$S(RAPTY="P":"(p)",1:"") | 
|---|
| 67 | .S RACPTB=$P($$CPT^ICPTCOD($P(RAMIS(0),U,9)),U),RACPTB=$S(RACPTB=-1:"none",1:RACPTB),RAPNAME=RAPNAME_RAPTY | 
|---|
| 68 | .;build Rad/Nuc Med procedure file based contrast media string | 
|---|
| 69 | .S (I,RACM)="" | 
|---|
| 70 | .F  S I=$O(^RAMIS(71,RAY,"CM","B",I)) Q:I=""  S RACM=RACM_I | 
|---|
| 71 | .; | 
|---|
| 72 | .;update file 71 with CM data; attempt lock, if lock fails quit | 
|---|
| 73 | .;record will not be updated if a lock attempt fails | 
|---|
| 74 | .K I S RACT=RACT+1 S:RACT#50=0 ZTSTOP=$$S^%ZTLOAD() | 
|---|
| 75 | .Q:ZTSTOP  L +^RAMIS(71,RAY):30 | 
|---|
| 76 | .I '$T D SETMP(RAY,RAPNAME,RACPTB,RACM,"*failed*",2) Q | 
|---|
| 77 | .D PROC^RAO7MFN(0,71,"1^"_RASTAT,RAY_"^"_RAPNAME) | 
|---|
| 78 | .;1st parameter (param) indicates a single procedure update; 2nd param | 
|---|
| 79 | .;indicates the file being edited (RAD/NUC MED PROCEDURE); 3rd param | 
|---|
| 80 | .;indicates the 'before & after' status of the procedure after an | 
|---|
| 81 | .;edit event ('before' status always active to guarantee unconditional | 
|---|
| 82 | .;OI file updates); 4th param indicates the IEN (1st piece) and name | 
|---|
| 83 | .;(2nd piece) of the procedure in file 71 | 
|---|
| 84 | .L -^RAMIS(71,RAY) ;unlock... | 
|---|
| 85 | .D SETMP(RAY,RAPNAME,RACPTB,RACM,"*done*",2) | 
|---|
| 86 | .Q | 
|---|
| 87 | ; | 
|---|
| 88 | ;if the user stopped this process via TaskMan (TM) inform the user | 
|---|
| 89 | D:ZTSTOP=1 STOP | 
|---|
| 90 | ; | 
|---|
| 91 | ;if there has been data updated, let the user know through an email | 
|---|
| 92 | I +$O(^TMP("RA PROC UPDATE 45",$J,0)) D MAILQ2^RA45PST(2,"RA*5*45: Synch up the Rad/Nuc Med Procedure & Orderable Item files") | 
|---|
| 93 | ; | 
|---|
| 94 | KILLQ2 ;kill & quit | 
|---|
| 95 | K RACM,RACT,RACPT,RACPTB,RAI,RAMIS,RAOI,RAOICM,RAOIPT,RAOIRA,RAPNAME | 
|---|
| 96 | K RAPTY,RASTAT,RAX,RAY,ZTSTOP,^TMP("RA PROC UPDATE 45",$J) | 
|---|
| 97 | Q | 
|---|
| 98 | ; | 
|---|
| 99 | FILECM(RAIEN,RACM,RAI) ;Files contrast medium into the CONTRAST MEDIA (#125) | 
|---|
| 100 | ;field in the RAD/NUC MED PROCEDURE (#71) file. Set the 'CONTRAST MEDIA | 
|---|
| 101 | ;USED' field (20) to 'Y'es on the initial pass into FILECM (when RAI=1) | 
|---|
| 102 | ;Input | 
|---|
| 103 | ; RAIEN=IEN of rad/nuc med procedure in file 71 | 
|---|
| 104 | ;  RACM=I (Iodinated ionic); N (Iodinated non-ionic); L (Gadolinium); | 
|---|
| 105 | ;       C (Oral Cholecystographic); G (Gastrografin); B (Barium); | 
|---|
| 106 | ;       M (unspecified contrast media) | 
|---|
| 107 | ;   RAI=position of a particular character in a data string | 
|---|
| 108 | ; | 
|---|
| 109 | Q:$D(^RAMIS(71,RAIEN,"CM","B",RACM))\10  ;prevents duplicate records | 
|---|
| 110 | K RAFDA S RAD1=+$O(^RAMIS(71,RAIEN,"CM",$C(32)),-1)+1 | 
|---|
| 111 | S:RAI=1 RAFDA(71,RAIEN_",",20)="Y" | 
|---|
| 112 | S RAFDA(71.0125,"+"_RAD1_","_RAIEN_",",.01)=RACM | 
|---|
| 113 | D UPDATE^DIE("","RAFDA") K RAD1,RAFDA | 
|---|
| 114 | Q | 
|---|
| 115 | ; | 
|---|
| 116 | SETMP(SUB,NME,CPT,CMU,MSG,FMT) ;set the ^TMP("RA PROC UPDATE 45",$J) global | 
|---|
| 117 | ;with procedure information | 
|---|
| 118 | ;input: SUB=IEN of Rad/Nuc Med Procedure (Orderable Item ID fld value) | 
|---|
| 119 | ;       NME=procedure name | 
|---|
| 120 | ;       CPT=procedure CPT | 
|---|
| 121 | ;       CMU=contrast media (see RACM definition for FILECM subroutine) | 
|---|
| 122 | ;       MSG=indicator *done* or *failed* | 
|---|
| 123 | ;       FMT=format for data in email(column position 80 chars wide max) | 
|---|
| 124 | N I,RAX,RAY S $P(RAY," ",81)="",RAX="" | 
|---|
| 125 | F I=1:1:$L(CMU) S RAX=RAX_$E(CMU,I)_$S($L(CMU)>I:",",1:"") | 
|---|
| 126 | S $E(RAY,1,8)=$G(MSG),$E(RAY,10,50)=$G(NME) | 
|---|
| 127 | S:FMT=1 $E(RAY,52,59)=$G(CPT) | 
|---|
| 128 | S:FMT=2 $E(RAY,55,60)=$G(CPT) | 
|---|
| 129 | S:FMT=1 $E(RAY,60,70)=$G(RAX) | 
|---|
| 130 | S:FMT=2 $E(RAY,65,77)=$G(RAX) | 
|---|
| 131 | S ^TMP("RA PROC UPDATE 45",$J,SUB)=RAY | 
|---|
| 132 | Q | 
|---|
| 133 | ; | 
|---|
| 134 | STOP ;inform the user that the task has been stopped | 
|---|
| 135 | S ^TMP("RA PROC UPDATE 45",$J,$$SUB())="RA*5*45's Orderable Items-Rad/Nuc Med Proc. synchronization has been terminated prematurely" | 
|---|
| 136 | Q | 
|---|
| 137 | ; | 
|---|
| 138 | SUB() ;return the next available subscript (arithmetic progression) | 
|---|
| 139 | Q +$O(^TMP("RA PROC UPDATE 45",$J,$C(32)),-1)+1 | 
|---|
| 140 | ; | 
|---|