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

DGPTDD.m

Go to the documentation of this file.
DGPTDD ;ALB/LD - DD CALLS FOR PTF (#45) FILE;Nov 20, 2020@09:44
 ;;5.3;Registration;**58,932,1020,1076**;Aug 13, 1993;Build 4
 ;
 ; DD calls for the Suffix and Transferring Suffix fields of PTF
 ; file (#45).
 ;
ACTIVE(X,Y,DGADM) ; Suffix active during patient's admission date?
 ;
 ;         DGEFDT  -- Suffix Effective Date
 ;         DGEFIEN -- Suffix Effective Date IEN
 ;        DGSUFPTR -- Suffix pointer from Station Type file
 ;
 ;  INPUT:     X   --  Suffix
 ;             Y   --  Station Type Number
 ;         DGADM   --  PTF IEN (use to get 2nd piece which is
 ;                              admission date or use DT if null)
 ; OUTPUT: DGACT   --  Active during admission date? (1=YES,0=NO)
 ;
 N DGACT,DGEFDT,DGEFIEN,DGFL,DGSUFPTR,DGI
 S (DGACT,DGEFIEN,DGEFDT,DGFL,DGSUFPTR)=0
 F DGI=0:0 S DGI=$O(^DIC(45.81,+$G(Y),"S","B",DGI)) Q:'DGI!$G(DGFL)  D
 .I $P($G(^DIC(45.68,DGI,0)),U)=$G(X) S DGSUFPTR=DGI,DGFL=1
 I $D(^DGPT(+$G(DGADM),0)) S DGADM=+$P(^(0),U,2)
 S DGADM=$S(+$G(DGADM)>0:-DGADM,1:-DT) S:$P(DGADM,".",2) DGADM=$P(DGADM,".") S DGADM=DGADM_.2359
 S DGEFDT=+$O(^DIC(45.68,DGSUFPTR,"E","AEFF",DGADM))
 I -(DGEFDT)'>0 S DGEFDT=+$O(^DIC(45.68,DGSUFPTR,"E","B",DGEFDT)),DGEFDT=-DGEFDT
 S DGEFIEN=$O(^DIC(45.68,DGSUFPTR,"E","AEFF",DGEFDT,DGEFIEN))
 S DGACT=$P($G(^DIC(45.68,+DGSUFPTR,"E",+DGEFIEN,0)),U,2)
 Q +$G(DGACT)
 ;
ACTLST(DGADM) ;    List of active suffixes
 ;
 ;          DGEFFDT -- Suffix Effective Date
 ;         DGEFFIEN -- Suffix Effective Date IEN
 ;
 ;  INPUT:     DGADM  --  PTF IEN (use to get 2nd piece which is
 ;                                 admission date or use DT if null)
 ; OUTPUT:     List of active suffixes during admission date
 ;
 N DGCTR,DGEFFDT,DGEFFIEN,DGI,DGOUT,DGST,DGX,DGY
 S (DGEFFDT,DGOUT)=0,DGCTR=1
 I $D(^DGPT(+$G(DGADM),0)) S DGADM=+$P(^(0),U,2)
 S DGADM=$S(+$G(DGADM)>0:-DGADM,1:-DT) S:$P(DGADM,".",2) DGADM=$P(DGADM,".")
 F DGST=0:0 S DGST=$O(^DIC(45.81,"B",DGST)) Q:'DGST  D
 .F DGI=0:0 S DGI=$O(^DIC(45.81,DGST,"S","B",DGI)) Q:'DGI  D
 ..S DGEFFDT=+$O(^DIC(45.68,DGI,"E","AEFF",DGADM))
 ..I -(DGEFFDT)'>0 S DGEFFDT=$O(^DIC(45.68,DGI,"E","B",DGEFFDT)),DGEFFDT=-DGEFFDT
 ..S DGEFFIEN=0,DGEFFIEN=$O(^DIC(45.68,DGI,"E","AEFF",DGEFFDT,DGEFFIEN))
 ..S:$P($G(^DIC(45.68,DGI,"E",+DGEFFIEN,0)),U,2)=1 ^TMP("ACTSUFF",$J,DGCTR)=$P($G(^DIC(45.68,DGI,0)),U)_U_$P($G(^DIC(45.81,DGST,0)),U,2),DGCTR=DGCTR+1
 W @IOF,"Choose From:",!
 F DGX=0:0 S DGX=$O(^TMP("ACTSUFF",$J,DGX)) Q:'DGX!($G(DGOUT))  D
 .I $Y>(IOSL-5) D NEXTSCR
 .W:'$G(DGOUT) !,$P($G(^TMP("ACTSUFF",$J,DGX)),U),?15,$P($G(^TMP("ACTSUFF",$J,DGX)),U,2)
 K ^TMP("ACTSUFF")
 Q
NEXTSCR ;
 F DGY=$Y:1:(IOSL-4) W !
 S DIR(0)="E" D ^DIR K DIR I $D(DIRUT)!($D(DUOUT)) S DGOUT=1 K DIRUT,DTOUT,DUOUT G NEXTSCRQ
 W @IOF,"Choose From:",!
NEXTSCRQ ;
 Q
 ;=============================================
 ;QUEUE DATA CHANGE MESSAGES WHEN AN ICD
 ;DIAGNOSIS CODE IS RECORDED, EDITED OR DELETED
NOTIFY(OLDVAL,NEWVAL,DA,FILE,TYPE,ACTION) ;
 ;ALLOW THE SET CALL TO STORE THE DATA WHEN EDITING AN ENTRY
 ;DO NOT EXECUTE DURING A PRE-/POST-INSTALL OF THE RELATED INDEXES
 I (($G(ACTION)="KILL")&($G(NEWVAL(1))'=""))!($G(XPDNM)'="") Q
 N IEN,DFN,RECTYPE,SUB,NAME,NODE,EXISTS,FIELD,GTYPE,CLEAR,STATION,VAIN,VAERR
 N INST
 S IEN=$$IENS^DILF(.DA) Q:+IEN<1
 S IEN("TOP")=$P(IEN,",",$L(IEN,",")-1),TYPE=$G(TYPE)
 I TYPE="DISCHARGE" S DFN=$G(NEWVAL(1)),RECTYPE=$G(NEWVAL(2)),SUB=2
 I (TYPE="MOVEMENT")!(TYPE="SERVICE") D
 .S DFN=$P($G(^DGPT(IEN("TOP"),0)),U)
 .S RECTYPE=$P($G(^DGPT(IEN("TOP"),0)),U,11),SUB=1
 .I TYPE="MOVEMENT" Q
 .I +$G(OLDVAL(3))=0,$G(NEWVAL(3))=1 S CLEAR="NEWVAL"
 .I $G(OLDVAL(3))=1,+$G(NEWVAL(3))=0,'$$ALLCLEAR(.NEWVAL) S CLEAR="OLDVAL"
 .I $G(CLEAR)'="" D
 ..F  S SUB=$O(@CLEAR@(SUB)) Q:'+SUB  S @CLEAR@(SUB)=""
 ..S SUB=0
 ..K CLEAR
 .K OLDVAL(3),NEWVAL(3)
 I TYPE="SERVICE46",$G(NEWVAL(2))>0 D
 .S DFN=$P($G(^DGPT(NEWVAL(2),0)),U)
 .S RECTYPE=$P($G(^DGPT(NEWVAL(2),0)),U,11),SUB=2,IEN("TOP")=NEWVAL(2)
 .I $G(OLDVAL(11))="",$G(NEWVAL(11))>0 S CLEAR="NEWVAL"
 .I $G(OLDVAL(11))>0,$G(NEWVAL(11))="",'$$ALLCLEAR(.NEWVAL) S CLEAR="OLDVAL"
 .I $G(CLEAR)'="" D
 ..F  S SUB=$O(@CLEAR@(SUB)) Q:'+SUB  S @CLEAR@(SUB)=""
 ..S SUB=1
 ..K CLEAR
 .K OLDVAL(11),NEWVAL(11)
 ;SKIP UNKNOWN TYPE AND CENSUS RECORDS (RECTYPE=2)
 I (+$G(DFN)<1)!($G(RECTYPE)="")!($G(RECTYPE)=2)!('$D(SUB)) Q
 S NAME="DG PTF ICD NOTIFIER",NODE=$$GETNODE(NAME,FILE,IEN("TOP"))
 F  S SUB=$O(OLDVAL(SUB)) Q:'+SUB  D
 .I OLDVAL(SUB)=NEWVAL(SUB) Q
 .S FIELD=$$GETFIELD(TYPE,SUB) Q:FIELD=""
 .S EXISTS=$D(^XTMP(NAME,NODE,TYPE,FIELD))
 .S EXISTS("NEW")=$G(^XTMP(NAME,NODE,TYPE,FIELD,"NEW"))
 .S EXISTS("OLD")=$G(^XTMP(NAME,NODE,TYPE,FIELD,"OLD"))
 .;NEW RECORD/FIELD VALUE DELETED BEFORE NOTIFICATION SENT
 .I EXISTS,EXISTS("NEW")=$G(OLDVAL(SUB)),$G(NEWVAL(SUB))="",EXISTS("OLD")="" D  Q
 ..K ^XTMP(NAME,NODE,TYPE,FIELD)
 .I 'EXISTS S ^XTMP(NAME,NODE,TYPE,FIELD,"OLD")=$G(OLDVAL(SUB))
 .S ^XTMP(NAME,NODE,TYPE,FIELD,"NEW")=$G(NEWVAL(SUB))
 S CLEAR=1,CLEAR("ALL")=1
 F GTYPE="DISCHARGE","MOVEMENT","SERVICE","SERVICE46"  D
 .I $D(^XTMP(NAME,NODE,GTYPE)) D
 ..S SUB="" F  S SUB=$O(^XTMP(NAME,NODE,GTYPE,SUB)) Q:SUB=""!('CLEAR)  D
 ...I SUB'="IENS" S CLEAR=0,CLEAR("ALL")=0
 ..I CLEAR K ^XTMP(NAME,NODE,GTYPE)
 ..E  S CLEAR=1
 I CLEAR("ALL") D  Q
 .K ^XTMP(NAME,NODE),^XTMP(NAME,"B",FILE,IEN("TOP"))
 .I $O(^XTMP(NAME,0))="" K ^XTMP(NAME)
 S ^XTMP(NAME,NODE,TYPE,"IENS")=IEN
 S ^XTMP(NAME,NODE,"DFN")=DFN
 S ^XTMP(NAME,NODE,"INTEREST DATE")=$P($G(^DGPT(IEN("TOP"),0)),U,2)
 S ^XTMP(NAME,NODE,"OCCURRED DATE")=$$NOW^XLFDT
 S ^XTMP(NAME,NODE,"FILE")=FILE
 D INP^VADPT
 Q:+$G(VAERR)
 I +$G(VAIN(2))>0 S ^XTMP(NAME,NODE,"PRIMARY PROVIDER")=+VAIN(2)
 I +$G(VAIN(11))>0 S ^XTMP(NAME,NODE,"ATTENDING PHYSICIAN")=+VAIN(11)
 I +$G(VAIN(4))>0 D
 .S INST=+$P($G(^DIC(42,+VAIN(4),0)),U,11) Q:INST=0
 .S INST=+$P($G(^DG(40.8,INST,0)),U,7) Q:INST=0
 I +$G(VAIN(4))=0 D
 .S INST=+$P($G(^DGPT(IEN("TOP"),0)),U,3) Q:INST=0
 .D F4^XUAF4(INST,.STATION) Q:$P($G(STATION),U,1)=0
 .S INST=$P(STATION,U,1)
 I +$G(INST)>0 S ^XTMP(NAME,NODE,"INSTITUTION")=INST
 S ^XTMP(NAME,"B",FILE,IEN("TOP"))=NODE
 Q
ALLCLEAR(DATA) ;RETURN TRUE IF ALL NODES ARE EMPTY
 N RETURN,SUB
 S RETURN=1
 S SUB="" F  S SUB=$O(DATA(SUB)) Q:(SUB="")!('RETURN)  D
 .I $G(DATA(SUB))'="" S RETURN=0
 Q RETURN
GETNODE(NAME,FILE,IEN) ;RETURN A FREE NODE IN NOTIFIER DATA
 N RETURN
 S RETURN=$G(^XTMP(NAME,"B",FILE,IEN))
 I RETURN="" F  S RETURN=$J_" "_$$NOW^XLFDT Q:'$D(^XTMP(NAME,RETURN))  H 1
 S ^XTMP(NAME,0)=$$FMADD^XLFDT(DT,5)_U_DT_U_"PTF ICD NOTIFIER DATA"
 Q RETURN
GETFIELD(TYPE,SUB) ;RETURN SUBSCRIPT FIELD NAME
 N RETURN,NUMBER
 S RETURN=""
 I TYPE="DISCHARGE" D
 .I SUB=3 S RETURN="PDX" Q
 .I SUB>3,SUB<28 S NUMBER=SUB-3,RETURN="SDX"_$S(NUMBER<10:"0",1:"")_NUMBER Q
 .I SUB=28 S RETURN="PDX-P1986"
 I TYPE="MOVEMENT" D
 .I SUB>1,SUB<27 S NUMBER=SUB-1,RETURN="DX"_$S(NUMBER<10:"0",1:"")_NUMBER
 I TYPE="SERVICE",SUB=2 S RETURN="PDX"
 I TYPE="SERVICE46" D
 .I SUB=3 S RETURN="PDX" Q
 .I SUB>3,SUB<11 S NUMBER=SUB-3,RETURN="SDX"_$S(NUMBER<10:"0",1:"")_NUMBER
 Q RETURN
 ;
 ;=============================================
 ;QUEUE DATA CHANGE MESSAGES WHEN AN ICD
 ;PROCEDURE CODE IS RECORDED, EDITED OR DELETED
NOTIFYP(OLDVAL,NEWVAL,DA,FILE,TYPE,ACTION) ; 
 ;ALLOW THE SET CALL TO STORE THE DATA WHEN EDITING AN ENTRY
 ;DO NOT EXECUTE DURING A PRE-/POST-INSTALL OF THE RELATED INDEXES
 I (($G(ACTION)="KILL")&($G(NEWVAL(1))'=""))!($G(XPDNM)'="") Q
 N IEN,DFN,RECTYPE,SUB,NAME,NODE,EXISTS,FIELD,GTYPE,CLEAR,STATION,INST
 S IEN=$$IENS^DILF(.DA) Q:+IEN<1
 S IEN("TOP")=$P(IEN,",",$L(IEN,",")-1),TYPE=$G(TYPE)
 I TYPE="DISCHARGE" S DFN=$G(NEWVAL(1)),RECTYPE=$G(NEWVAL(2)),SUB=2
 I (TYPE="PROCEDURE")!(TYPE="SURGERY") D
 . S DFN=$P($G(^DGPT(IEN("TOP"),0)),U)
 . S RECTYPE=$P($G(^DGPT(IEN("TOP"),0)),U,11),SUB=1
 ; SKIP UNKNOWN TYPE AND CENSUS RECORDS (RECTYPE=2)
 I (+$G(DFN)<1)!($G(RECTYPE)="")!($G(RECTYPE)=2)!('$D(SUB)) Q
 ;
 S NAME="DG PTF ICD OP NOTIFIER",NODE=$$GETNODE(NAME,FILE,IEN("TOP"))
 F  S SUB=$O(OLDVAL(SUB)) Q:'+SUB  D
 . I OLDVAL(SUB)=NEWVAL(SUB) Q
 . S FIELD=$$GETFLD(TYPE,SUB) Q:FIELD=""
 . S EXISTS=$D(^XTMP(NAME,NODE,TYPE,FIELD))
 . S EXISTS("NEW")=$G(^XTMP(NAME,NODE,TYPE,FIELD,"NEW"))
 . S EXISTS("OLD")=$G(^XTMP(NAME,NODE,TYPE,FIELD,"OLD"))
 . ;NEW RECORD/FIELD VALUE DELETED BEFORE NOTIFICATION SENT
 . I EXISTS,EXISTS("NEW")=$G(OLDVAL(SUB)),$G(NEWVAL(SUB))="",EXISTS("OLD")="" D  Q
 .. K ^XTMP(NAME,NODE,TYPE,FIELD)
 . I 'EXISTS S ^XTMP(NAME,NODE,TYPE,FIELD,"OLD")=$G(OLDVAL(SUB))
 . S ^XTMP(NAME,NODE,TYPE,FIELD,"NEW")=$G(NEWVAL(SUB))
 ;
 S CLEAR=1,CLEAR("ALL")=1
 F GTYPE="DISCHARGE","PROCEDURE","SURGERY"  D
 . I $D(^XTMP(NAME,NODE,GTYPE)) D
 .. S SUB="" F  S SUB=$O(^XTMP(NAME,NODE,GTYPE,SUB)) Q:SUB=""!('CLEAR)  D
 ... I SUB'="IENS" S CLEAR=0,CLEAR("ALL")=0
 .. I CLEAR K ^XTMP(NAME,NODE,GTYPE)
 .. E  S CLEAR=1
 I CLEAR("ALL") D  Q
 . K ^XTMP(NAME,NODE),^XTMP(NAME,"B",FILE,IEN("TOP"))
 . I $O(^XTMP(NAME,0))="" K ^XTMP(NAME)
 ;
 S ^XTMP(NAME,NODE,TYPE,"IENS")=IEN
 S ^XTMP(NAME,NODE,"DFN")=DFN
 S ^XTMP(NAME,NODE,"INTEREST DATE")=$P($G(^DGPT(IEN("TOP"),0)),U,2)
 S ^XTMP(NAME,NODE,"OCCURRED DATE")=$$NOW^XLFDT
 S ^XTMP(NAME,NODE,"FILE")=FILE
 S INST=+$P($G(^DGPT(IEN("TOP"),0)),U,3) I INST'=0 D
 . D F4^XUAF4(INST,.STATION) Q:$P($G(STATION),U,1)=0
 . S INST=$P(STATION,U,1)
 I +$G(INST)>0 S ^XTMP(NAME,NODE,"INSTITUTION")=INST
 S ^XTMP(NAME,"B",FILE,IEN("TOP"))=NODE
 Q
 ;
GETFLD(TYPE,SUB) ;RETURN SUBSCRIPT FIELD NAME
 N RETURN,NUMBER
 S RETURN=""
 I TYPE="DISCHARGE" D
 . S NUMBER=SUB-2,RETURN="OPC"_$S(NUMBER<10:"0",1:"")_NUMBER Q
 I TYPE="PROCEDURE" D
 . S NUMBER=SUB-1,RETURN="OPC"_$S(NUMBER<10:"0",1:"")_NUMBER
 I TYPE="SURGERY" D
 . S NUMBER=SUB-1,RETURN="OPC"_$S(NUMBER<10:"0",1:"")_NUMBER
 Q RETURN