Home   Package List   Routine Alphabetical List   Global Alphabetical List   FileMan Files List   FileMan Sub-Files List   Package Component Lists   Package-Namespace Mapping  
Routine: WVRALINK

WVRALINK.m

Go to the documentation of this file.
WVRALINK ;HCIOFO/FT - RAD/NM-WOMEN'S HEALTH LINK; Oct 18,2022
 ;;1.0;WOMEN'S HEALTH;**3,5,7,9,10,16,18,23,25,24,26,28**;Sep 30, 1998;Build 12
 ;
 ; Reference to ^RADPT in ICR #2480
 ; Reference to ^RAMIS(71 in ICR #2481
 ; Reference to ^RAMIS(71.2 in ICR #2482
 ; Reference to ^DPT( in ICR #10035
 ; Reference to ^%ZTLOAD in ICR #10063
 ; Reference to ^XMD in ICR #10070
 ; Reference to ^XPDUTL in ICR #10141
 ; Reference to ^XUPARAM in ICR #2541
 ; Reference to GETTRMCD^PXRMPRAD in ICR #6808
 ; Reference to $$EARLDATE^PXRMPRAD in ICR #6808
 ; Reference to BLDTARR^PXRMPRAD in ICR #6808
 ;
 ;;  Original routine created by IHS/ANMC/MWR
 ;;* MICHAEL REMILLARD, DDS * ALASKA NATIVE MEDICAL CENTER *
 ;;  CREATE MAMMOGRAM PROCEDURE IN WOMEN'S HEALTH FOR THIS PATIENT.
 ;;  CALLED BY ^RART WHEN A RADIOLOGY REPORT IS VERIFIED.
 ;;  CALLED BY ^RARTE1 WHEN A RADIOLOGY REPORT IS UNVERIFIED.
 ;;  CALLED BY ^WVEXPTRA WHEN EXPORTING HISTORICAL MAMS TO WOMEN'S HEALTH
 ;
 ;---> REQUIRED VARIABLES: DFN  = DFN OF RADIOLOGY PATIENT.
 ;--->                     DATE = INVERSE DATE/TIME OF VISIT.
 ;--->                     CASE = IEN OF RADIOLOGY EXAM (CASE).
 ;
 ;---> OPTIONAL VARIABLE:  WVNEWP = TOTAL NEW WH PATIENTS ADDED.
 ;--->                     WVMCNT = TOTAL NEW MAMS PROCEDURES ADDED.
 ;--->                     THESE IF CALLED FROM ^WVEXPTRA ROUTINE.
 ;
 ;---> GENERATED VARIBLES:
 ;---> WVPROC = IEN OF RADIOLOGY PROCEDURE (FILE #71), THEN IT
 ;--->          GETS CHANGED TO WOMEN'S HEALTH PROCEDURE TYPE
 ;--->                                   (FILE #790.2).
 ;---> WVLOC  = WARD/CLINIC/LOCATION (FILE #44).
 ;---> WVDATE = DATE OF THE PROCEDURE.
 ;---> WVPROV = ORDERING PROVIDER.
 ;---> WVMOD  = LEFT OR RIGHT, IF IT'S A UNILATERAL MAMMOGRAM.
 ;---> WVDX   = RADIOLOGY DIAGNOSTIC CODE.
 ;---> WVBWDX = WOMEN'S HEALTH RESULT/DIAGNOSIS.
 ;
CREATE(DFN,DATE,CASE) ;
 Q:'+$$VERSION^XPDUTL("WV")
 Q:($G(DFN)']"")!($G(DATE)']"")!($G(CASE)']"")
 N ZTDESC,ZTDTH,ZTIO,ZTRTN,ZTSAVE
 S:'$D(DUZ)#2 DUZ=.5
 S:'+$G(DUZ(2)) DUZ(2)=$$KSP^XUPARAM("INST")
 S ZTRTN="CREATEQ^WVRALINK",ZTDESC="WV CREATE MAMMOGRAM ENTRY"
 S ZTSAVE("DFN")="",ZTSAVE("DATE")="",ZTSAVE("CASE")=""
 S ZTIO="",ZTDTH=$H
 D ^%ZTLOAD
 Q
CREATEH(DFN,DATE,CASE,STATUS) ; Entry from ^WVEXPTRA which looks for exams
 ; created before the WH package was installed.
 Q:($G(DFN)']"")!($G(DATE)']"")!($G(CASE)']"")!($G(STATUS)']"")
 ;
CREATEQ ; Queue data entry creation. Called from CREATE above
 N CLOSED,CODES,EARLDATE,ERROR,MATCH,TEMPDATE,TERMIEN,TERMSTAT
 N WVPROC,WVLOC,WVDATE,WVDR,WVPROV,WVMOD,WVDX,WVBWDX,WVLEFT,WVRIGHT
 N WVCASE,WVCPT,WVERR,WVCREDIT,WVEXAM0,WVTERM,WVZSTAT,WVADDEOC,WVDIV
 ;---> QUIT IF RADIOLOGY DATA IS NOT DEFINED OR ="".
 I $D(ZTQUEUED) S ZTREQ="@"
 S CLOSED=0
 Q:'$D(^RADPT(DFN,"DT",DATE,"P",CASE,0))
 ;
 ;---> QUIT IF THIS PROCEDURE DOES NOT HAVE A MAM CPT CODE.
 ;---> QUIT IF THIS PROCEDURE DOES NOT HAVE AN ULTRASOUND CPT CODE.
 ;---> WVEXAM0=ZERO NODE OF RADIOLOGY EXAM.
 ;AGP pull division from radiology data default to DUZ(2) is none found in radiology
 S WVDIV=$$GETRADDIV(DFN,DATE,CASE)
 I WVDIV=0,DUZ(2)>0 S WVDIV=DUZ(2)
 S WVEXAM0=^RADPT(DFN,"DT",DATE,"P",CASE,0)
 S WVCPT=$$GET1^DIQ(71,$P(WVEXAM0,U,2),9,"") Q:WVCPT=""
 ;check reminder terms
 S WVADDEOC=0
 S MATCH=0
 S TERMIEN=0 F  S TERMIEN=$O(^WV(790.2,"RT",TERMIEN)) Q:TERMIEN'>0!($G(WVPROC)'="")  D
 .K CODES
 .D GETTRMCD^PXRMPRAD(TERMIEN,.CODES,.WVTERM,.ERROR)
 .I $G(ERROR)'="" Q
 .I $D(CODES(WVCPT)) S MATCH=1
 .;S WVPROC=$O(^WV(790.2,"RT",TERMIEN,""))
 .I MATCH=0,$D(WVTERM("E","RAMIS(71,",$P(WVEXAM0,U,2))) S MATCH=1
 .I MATCH=1 D
 ..S WVPROC=$O(^WV(790.2,"RT",TERMIEN,""))
 ..S EARLDATE=$$EARLDATE^PXRMPRAD(.WVTERM)
 ..S TEMPDATE=9999999-$P(DATE,".")
 ..I EARLDATE>0,TEMPDATE<EARLDATE S CLOSED=1
 ;check old style of specific CPT code
 I +$G(WVPROC)'>0 D
 .S WVCPT=$$GET1^DIQ(71,$P(WVEXAM0,U,2),9,"I") Q:WVCPT=""
 .S WVPROC=$O(^WV(790.2,"AC",WVCPT,0)) ;cpt code x-ref to get 790.2 ien
 Q:+$G(WVPROC)'>0  ;cpt code is not tracked in 790.2
 Q:$P($G(^WV(790.2,+WVPROC,0)),U,5)'="R"  ;cpt is not rad/nm procedure
 Q:$P($G(^DPT(DFN,0)),U,2)'="F"  ;not female
 ;
 ;---> QUIT IF NO WOMEN'S HEALTH SITE PARAMETER FILE ON THIS MACHINE.
 ;     OR NO DEFAULT CASE MANAGER
 Q:'$D(^WV(790.02,WVDIV))
 Q:'$P($G(^WV(790.02,WVDIV,0)),U,2)
 ;
 ;---> IF NOT CALLED FROM ^WVEXPTRA (i.e., STATUS is undefined) CHECK
 ;---> SITE PARAMETER AND QUIT IF "IMPORT MAMMOGRAMS FROM RADIOLOGY"
 ;---> IS NOT SET TO "YES". CHECK VETERAN STATUS AND ELIGIBILITY CODE.
 N Y S Y=^WV(790.02,WVDIV,0)
 I '$D(STATUS) Q:'$P(Y,U,10)
 I '$D(STATUS) Q:'$$VNVEC^WVRALIN1()  ;vet/non-vet/eligibility code check
 ;
 ;---> SET WVZSTAT =THE STATUS (OPEN OR CLOSED) IN WOMEN'S HEALTH.
 ;---> THAT MAMMOGRAMS SHOULD RECEIVE WHEN COPIED OVER FROM RADIOLOGY.
 I $G(WVZSTAT)="" S WVZSTAT=$P(Y,U,23) S:WVZSTAT="" WVZSTAT="o"
 I $G(STATUS)]"" S WVZSTAT=$G(STATUS) ;status selected in ^WVEXPTRA
 I CLOSED=1 S WVZSTAT="c"
 ;
 D COPY(WVEXAM0)
 ;
EXIT ;EP
 K I,N,X
 Q
 ;
COMPARE(WVPROC) ;
 N NAME,RESULT,TERMIEN,TERMARR,X
 S RESULT=0
 S TERMIEN=+$P($G(^WV(790.2,WVPROC,3)),U)
 I TERMIEN=0 Q RESULT
 S NAME=$$GET1^DIQ(811.5,TERMIEN_",",.01)
 I NAME="" Q RESULT
 D BLDTARR^PXRMPRAD(.TERMARR)
 S X=0 F  S X=$O(TERMARR(X)) Q:X'>0!(RESULT=1)  D
 .I TERMARR(X)=NAME S RESULT=1
 Q RESULT
 ;
COPY(Y) ;EP
 ;---> COPY MAM PROCEDURE DATA FROM RADIOLOGY TO WOMEN'S HEALTH.
 ;---> VARIABLE DFN=PATIENT
 ;---> LOCATION=DUZ(2)
 ;---> WARD/CLINIC/LOCATION
 N FDA,IENS,NUM,WVACCESS,WVIEN,WVIEN1,X,WVPVDX
 S WVLOC=$P(Y,U,8)
 ;
 S WVPVDX=0
 ;---> WVDATE=DATE OF THE PROCEDURE.
 S WVDATE=$P($P(^RADPT(DFN,"DT",DATE,0),U),".")
 ;
 ;---> RECONSTRUCT THE FULL CASE# FOR THIS RAD PROCEDURE.
 ;---> THIS IS USED AS A LINK (XREF) BETWEEN THE RADIOLOGY PROCEDURE
 ;---> AND THE WOMEN'S HEALTH PROCEDURE.
 S WVCASE=$E(WVDATE,4,7)_$E(WVDATE,2,3)_"-"_$P(Y,U)
 ;---> CHECK TO BE SURE THE CASE# XREF IS REALLY DOWN THERE.
 S:'$D(^RADPT("ADC",WVCASE,DFN,DATE,CASE)) WVCASE="UNKNOWN"
 ;
 ;AGP TODO begin store off previous diagnosis into new multiple when when a verify report is resent
 ;comment out the Q: command and remove the comments until AGP TODO END
 ;---> capture previous info to be moved to the prev diagnosis multiple
 ;---> QUIT IF THIS PROCEDURE HAS ALREADY BEEN SENT TO WOMEN'S HEALTH.
 ;Q:$D(^WV(790.1,"E",WVCASE))
 I $D(^WV(790.1,"E",WVCASE)) D  Q
 .S WVIEN1=$O(^WV(790.1,"E",WVCASE,""))
 .S WVACCESS=$P($G(^WV(790.1,WVIEN1,0)),U)
 .S WVPVDX=$P($G(^WV(790.1,WVIEN1,0)),U,5)
 .S WVZSTAT=$P($G(^WV(790.1,WVIEN1,0)),U,14)
 .I WVPVDX=0!(WVIEN1=0)!(WVACCESS="") Q
 .S WVDX=$P(Y,U,13) I WVDX="" Q
 .S WVBWDX=""
 .I +WVDX I $D(^WV(790.32,"C",WVDX)) S WVBWDX=$O(^WV(790.32,"C",WVDX,0))
 .I WVPVDX=WVBWDX Q
 .K WVERR
 .S IENS="+2,"_WVIEN1_","
 .S FDA(790.1,WVIEN1_",",.01)=WVACCESS
 .S FDA(790.1,WVIEN1_",",.05)=$S(WVBWDX="":"@",1:WVBWDX)
 .I WVZSTAT'="" S FDA(790.1,WVIEN1_",",.14)=WVZSTAT
 .S FDA(790.24,IENS,.01)=WVPVDX
 .S FDA(790.24,IENS,1)=$$NOW^XLFDT()
 .D UPDATE^DIE("","FDA","","WVERR")
 .K WVERR
 .D ADD^PXRMEOC(DFN,$$NOW^XLFDT(),+WVIEN1_";WV(790.1,",1,0,"BREAST CARE",.WVERR)
 .I '$D(WVERR) Q
 .S NUM=0
 .S NUM=NUM+1,^TMP("PXRMXMZ",$J,NUM,0)="Error adding Women's Health Procedure to the patient episode file."
 .D BLDMSG^WVRPCGF1(DFN,"ERROR Updating Episode of Care File.",.NUM)
 ;AGP TODO END
 ;
 ;---> REQUESTING PROVIDER/ORDERING PROVIDER
 S WVPROV=$P(Y,U,14)
 ;
 ;---> IF UNILATERAL, ATTEMPT TO PICK UP LEFT OR RIGHT MODIFIER.
 I WVPROC=26 D
 .I $D(^RADPT(DFN,"DT",DATE,"P",CASE,"M",0)) D
 ..N N S N=0
 ..F  S N=$O(^RADPT(DFN,"DT",DATE,"P",CASE,"M",N)) Q:'N  D
 ...S WVMOD=$P(^RADPT(DFN,"DT",DATE,"P",CASE,"M",N,0),U)
 ...S WVMOD=$$GET1^DIQ(71.2,WVMOD,.01,"I")
 ...I "LEFTleft"[WVMOD S WVLEFT=1
 ...I "RIGHTright"[WVMOD S WVRIGHT=1
 ..Q:$D(WVLEFT)&($D(WVRIGHT))
 ..I $D(WVLEFT) S WVMOD="l" Q
 ..I $D(WVRIGHT) S WVMOD="r" Q
 ;
 ;---> IF THERE'S A DIAGNOSTIC CODE, ATTEMPT TO PICK UP DIAGNOSIS.
 ;---> USE "WV DIAGNOSTIC CODE TRANSLATION" FILE #790.32.
 S WVDX=$P(Y,U,13)
 I +WVDX I $D(^WV(790.32,"C",WVDX)) S WVBWDX=$O(^WV(790.32,"C",WVDX,0))
 ;
 ;---> GET CREDIT METHOD.
 S WVCREDIT=$P(Y,U,26)
 ;
PATIENT ;---> IF PATIENT ISN'T IN WOMEN'S HEALTH DATABASE, ADD HER.
 S WVERR=1
 I '$D(^WV(790,DFN,0)) D
 .D AUTOADD^WVPATE(DFN,DUZ(2),.WVERR)
 .I $D(WVNEWP) S:WVERR WVNEWP=WVNEWP+1
 Q:WVERR<0
 D FIND^WVRALIN1 ;check for 'unlinked' entry in File 790.1
 Q:$D(^WV(790.1,"E",WVCASE))  ;quit if link was made in WVRALIN1
PROC ;---> CREATE MAMMOGRAM PROCEDURE IN WV PROCEDURE FILE #790.1.
 ;
 S WVDR=".02////"_DFN_";.04////"_WVPROC
 S WVDR=WVDR_";.05////"_$G(WVBWDX)_";.07////"_WVPROV
 S WVDR=WVDR_";.09////"_$G(WVMOD)_";.1////"_DUZ(2)_";.11////"_WVLOC
 S WVDR=WVDR_";.12////"_WVDATE_";.14////"_WVZSTAT_";.15////"_WVCASE
 S WVDR=WVDR_";.18////.5;.19////"_DT_";.34////"_$G(DUZ(2))_";.35////"_WVCREDIT
 ;
 D NEW2^WVPROC(DFN,WVPROC,WVDATE,WVDR,"","",.WVERR)
 I $D(WVMCNT) S:WVERR>-1 WVMCNT=WVMCNT+1
 Q:WVERR<0  ;procedure not added
 Q:$D(WVMCNT)  ;mass import of Rad/NM exams
 I +$G(Y)>0,$$COMPARE(WVPROC)>0,WVPVDX=0 D
 .K WVERR
 .D ADD^PXRMEOC(DFN,$$NOW^XLFDT(),+Y_";WV(790.1,",1,0,"BREAST CARE",.WVERR)
 .I '$D(WVERR) Q
 .S NUM=0
 .S NUM=NUM+1,^TMP("PXRMXMZ",$J,NUM,0)="Error adding Women's Health Procedure to the patient episode file."
 .D BLDMSG^WVRPCGF1(DFN,"ERROR Updating Episode of Care File.",.NUM)
 ;Q:$P($G(^WV(790.02,+DUZ(2),0)),U,23)="c"  ;Status=closed
 I (WVCPT=76856)!(WVCPT=76830)!(WVCPT=76645) D  Q  ;not breast related
 .D MAIL^WVRADWP(DFN,+Y,WVPROC,WVPROV) ;iens for patient, accession, procedure, provider/requestor
 .Q
 D CPRS^WVSNOMED(69,DFN,"",WVPROV,"Mammogram results available.",DATE_"~"_CASE)
 Q
 ;
 ;
DELETE(DFN,DATE,CASE) ;EP
 ;---> MODIFY WOMEN'S HEALTH PROCEDURE TO REFLECT CHANGE.
 ;---> CALLED FROM RARTE1 (DELETE A REPORT AND UNVERIFY A REPORT).
 ;
 Q:'+$$VERSION^XPDUTL("WV")
 Q:'$D(DFN)!('$D(DATE))!('$D(CASE))
 N ZTDESC,ZTDTH,ZTIO,ZTRTN,ZTSAVE
 S ZTRTN="DELETEQ^WVRALINK",ZTDESC="WV MAMMOGRAM RPT CHANGE"
 S ZTSAVE("DFN")="",ZTSAVE("DATE")="",ZTSAVE("CASE")=""
 S ZTIO="",ZTDTH=$H
 ;D DELETEQ^WVRALINK
 D ^%ZTLOAD
 Q
DELETEQ ; Modify WV entry when mammogram report is unverified or deleted
 Q:'$D(^RADPT(DFN,"DT",DATE,"P",CASE,0))
 N WVIEN,WVDATE,WVCASE,WVCMGR,WVLOOP,WVMSG,WVPROV
 N XMDUZ,XMSUB,XMTEXT,XMY ;send mail message to case manager
 I $D(ZTQUEUED) S ZTREQ="@"
 ;
 ;---> WVDATE=DATE OF PROCEDURE.
 S WVDATE=$P($P(^RADPT(DFN,"DT",DATE,0),U),".")
 S WVCASE=$P(^RADPT(DFN,"DT",DATE,"P",CASE,0),U)
 ;
 ;---> WVCASE=RECONSTRUCTED CASE# OF PROCEDURE.
 S WVCASE=$E(WVDATE,4,7)_$E(WVDATE,2,3)_"-"_WVCASE
 ;---> QUIT IF NO CASE# XREF IN WOMEN'S HEALTH PROCEDURE FILE.
 Q:'$D(^WV(790.1,"E",WVCASE))
 ;
 S WVIEN=$O(^WV(790.1,"E",WVCASE,0))
 Q:'$D(^WV(790.1,WVIEN,0))
 ;AGP TODO remove auto open a WH procedure when a report is unverified or deleted
 ;commented out D RADMON^WVPROC
 ;D RADMOD^WVPROC(WVIEN) ;update wh status to "open"
 S WVPROV=+$$GET1^DIQ(790.1,WVIEN,.07,"I") ;get provider/requestor
 S WVCMGR=+$$GET1^DIQ(790,DFN,.1,"I") ;get case manager
 S:WVCMGR XMY(WVCMGR)=""
 ; if no case manager, then get default case manager(s)
 I 'WVCMGR S WVLOOP=0 F  S WVLOOP=$O(^WV(790.02,WVLOOP)) Q:'WVLOOP  D
 .S WVCMGR=$$GET1^DIQ(790.02,WVLOOP,.02,"I")
 .S:WVCMGR XMY(WVCMGR)=""
 .Q
 Q:$O(XMY(0))'>0  ;no case manager(s)
 S:WVPROV XMY(WVPROV)=""
 S XMDUZ=.5 ;message sender
 S XMSUB="RAD/NM Rpt for WH patient is UNVERIFIED/DELETED"
 S WVMSG(1)="        Patient: "_$P($G(^DPT(DFN,0)),U,1)_" (SSN: "_$$SSN^WVUTL1(DFN)_")"
 S WVMSG(2)=" WH Accession #: "_$P($G(^WV(790.1,+WVIEN,0)),U,1)
 S WVMSG(3)="  RAD/NM Case #: "_WVCASE
 S WVMSG(4)=" "
 S WVMSG(5)="NOTE: THIS PROCEDURE HAS BEEN ALTERED IN RADIOLOGY/NM."
 S WVMSG(6)="Follow-up is required in the WOMEN'S HEALTH package!"
 S XMTEXT="WVMSG("
 D ^XMD
 Q
 ;
GETRADDIV(DFN,DATE,CASE) ;
 N LOC,RADIV,RALOC,RESULT,WVDTNODE,X0
 S RESULT=0
 ;check the radiology division 
 S WVDTNODE=$G(^RADPT(DFN,"DT",DATE,0))
 S RADIV=+$P(WVDTNODE,U,3)
 I RADIV>0 S RESULT=+$P($G(^RA(79,RADIV,0)),U)
 I RESULT>0 Q RESULT
 ;last check is for the imaging location type
 S RALOC=+$P(WVDTNODE,U,4)
 I RALOC=0 Q RESULT
 S LOC=+$P($G(^RA(79.1,LOC,0)),U)
 I LOC=0 Q RESULT
 S RESULT=$$GETLOCDIV(LOC)
 Q RESULT
 ;
GETLOCDIV(LOC) ;
 N RESULT
 S RESULT=0
 S RESULT=$P($G(^SC(+LOC,0)),U,4)
 I RESULT>0 Q RESULT
 S RESULT=$$INS4LOC^VSITCK1(LOC)
 Q RESULT