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

PXKENCOUNTER.m

Go to the documentation of this file.
PXKENCOUNTER ;SLC/PKR - Builds an array of all encounter data. ;11/22/2021
 ;;1.0;PCE PATIENT CARE ENCOUNTER;**217**;Aug 12, 1996;Build 134
 Q
 ;
COEVENT(VISITIEN) ;Add to the ^TMP("PXKCO",$J, array the
 ;already exisiting encounter data. This is for the PXK VISIT
 ;DATA event.
 I $G(VISITIEN)'>0 Q  ;PX/183
 I '$D(^AUPNVSIT(VISITIEN)) Q
 N CSTPIEN,IND,MODIFIER,NODE,NUMM,NUMP,NUMS,PRV,PRVLIST,PS,TEMP,TMPSUB,VFIEN
 S TMPSUB="PXKCO"
 ;Credit Stop Visits
 S CSTPIEN=""
 F  S CSTPIEN=$O(^AUPNVSIT("AD",VISITIEN,CSTPIEN)) Q:CSTPIEN=""  D
 . I "SC"'[$P($G(^AUPNVSIT(CSTPIEN,150)),"^",3) Q
 . S NODE=""
 . F  S NODE=$O(^AUPNVSIT(CSTPIEN,NODE)) Q:(NODE'=+NODE)  D
 .. S ^TMP(TMPSUB,$J,VISITIEN,"CSTP",CSTPIEN,NODE,"AFTER")=^AUPNVSIT(CSTPIEN,NODE)
 .. S ^TMP(TMPSUB,$J,VISITIEN,"CSTP",CSTPIEN,NODE,"BEFORE")=^AUPNVSIT(CSTPIEN,NODE)
 ;
 ;V CPT
 S VFIEN=""
 F  S VFIEN=$O(^AUPNVCPT("AD",VISITIEN,VFIEN)) Q:VFIEN=""  D
 . S NODE=""
 . F  S NODE=$O(^AUPNVCPT(VFIEN,NODE)) Q:(NODE'=+NODE)  D
 .. I NODE=801 Q
 ..;Modifiers.
 .. I NODE=1 D
 ... S IND=0
 ... F  S IND=+$O(^AUPNVCPT(VFIEN,NODE,IND)) Q:IND=0  D
 .... S MODIFIER=^AUPNVCPT(VFIEN,NODE,IND,0)
 .... S ^TMP(TMPSUB,$J,VISITIEN,"CPT",VFIEN,NODE,"AFTER",MODIFIER)=""
 .... S ^TMP(TMPSUB,$J,VISITIEN,"CPT",VFIEN,NODE,"BEFORE",MODIFIER)=""
 .. E  D
 ... S ^TMP(TMPSUB,$J,VISITIEN,"CPT",VFIEN,NODE,"AFTER")=^AUPNVCPT(VFIEN,NODE)
 ... S ^TMP(TMPSUB,$J,VISITIEN,"CPT",VFIEN,NODE,"BEFORE")=^AUPNVCPT(VFIEN,NODE)
 ;
 ;V EXAM
 S VFIEN=""
 F  S VFIEN=$O(^AUPNVXAM("AD",VISITIEN,VFIEN)) Q:VFIEN=""  D
 . S NODE=""
 . F  S NODE=$O(^AUPNVXAM(VFIEN,NODE)) Q:(NODE'=+NODE)  D
 .. I NODE=801 Q
 .. S ^TMP(TMPSUB,$J,VISITIEN,"XAM",VFIEN,NODE,"AFTER")=^AUPNVXAM(VFIEN,NODE)
 .. S ^TMP(TMPSUB,$J,VISITIEN,"XAM",VFIEN,NODE,"BEFORE")=^AUPNVXAM(VFIEN,NODE)
 ;
 ;V HF
 S VFIEN=""
 F  S VFIEN=$O(^AUPNVHF("AD",VISITIEN,VFIEN)) Q:VFIEN=""  D
 . S NODE=""
 . F  S NODE=$O(^AUPNVHF(VFIEN,NODE)) Q:(NODE'=+NODE)  D
 .. I NODE=801 Q
 .. S ^TMP(TMPSUB,$J,VISITIEN,"HF",VFIEN,NODE,"AFTER")=^AUPNVHF(VFIEN,NODE)
 .. S ^TMP(TMPSUB,$J,VISITIEN,"HF",VFIEN,NODE,"BEFORE")=^AUPNVHF(VFIEN,NODE)
 ;
 ;V ICR
 S VFIEN=""
 F  S VFIEN=$O(^AUPNVICR("AD",VISITIEN,VFIEN)) Q:VFIEN=""  D
 . S NODE=""
 . F  S NODE=$O(^AUPNVICR(VFIEN,NODE)) Q:(NODE'=+NODE)  D
 .. I NODE=801 Q
 .. S ^TMP(TMPSUB,$J,VISITIEN,"ICR",VFIEN,NODE,"AFTER")=^AUPNVICR(VFIEN,NODE)
 .. S ^TMP(TMPSUB,$J,VISITIEN,"ICR",VFIEN,NODE,"BEFORE")=^AUPNVICR(VFIEN,NODE)
 ;
 ;V IMM
 S VFIEN=""
 F  S VFIEN=$O(^AUPNVIMM("AD",VISITIEN,VFIEN)) Q:VFIEN=""  D
 . S NODE=""
 . F  S NODE=$O(^AUPNVIMM(VFIEN,NODE)) Q:(NODE'=+NODE)  D
 .. I NODE=801 Q
 ..;Fields that are multiples.
 .. I (NODE=2)!(NODE=3)!(NODE=11) D
 ... S IND=0
 ... F  S IND=+$O(^AUPNVIMM(VFIEN,NODE,IND)) Q:IND=0  D
 .... S TEMP=^AUPNVIMM(VFIEN,NODE,IND,0)
 .... S ^TMP(TMPSUB,$J,VISITIEN,"IMM",VFIEN,NODE,"AFTER",IND)=TEMP
 .... S ^TMP(TMPSUB,$J,VISITIEN,"IMM",VFIEN,NODE,"BEFORE",IND)=TEMP
 .. E  D
 ... S ^TMP(TMPSUB,$J,VISITIEN,"IMM",VFIEN,NODE,"AFTER")=^AUPNVIMM(VFIEN,NODE)
 ... S ^TMP(TMPSUB,$J,VISITIEN,"IMM",VFIEN,NODE,"BEFORE")=^AUPNVIMM(VFIEN,NODE)
 ;
 ;V PED
 S VFIEN=""
 F  S VFIEN=$O(^AUPNVPED("AD",VISITIEN,VFIEN)) Q:VFIEN=""  D
 . S NODE=""
 . F  S NODE=$O(^AUPNVPED(VFIEN,NODE)) Q:(NODE'=+NODE)  D
 .. I NODE=801 Q
 .. S ^TMP(TMPSUB,$J,VISITIEN,"PED",VFIEN,NODE,"AFTER")=^AUPNVPED(VFIEN,NODE)
 .. S ^TMP(TMPSUB,$J,VISITIEN,"PED",VFIEN,NODE,"BEFORE")=^AUPNVPED(VFIEN,NODE)
 ;
 ;V POV
 S VFIEN=""
 F  S VFIEN=$O(^AUPNVPOV("AD",VISITIEN,VFIEN)) Q:VFIEN=""  D
 . S NODE=""
 . F  S NODE=$O(^AUPNVPOV(VFIEN,NODE)) Q:(NODE'=+NODE)  D
 .. I NODE=801 Q
 .. S ^TMP(TMPSUB,$J,VISITIEN,"POV",VFIEN,NODE,"AFTER")=^AUPNVPOV(VFIEN,NODE)
 .. S ^TMP(TMPSUB,$J,VISITIEN,"POV",VFIEN,NODE,"BEFORE")=^AUPNVPOV(VFIEN,NODE)
 ;
 ;V PROVIDER
 S VFIEN=""
 F  S VFIEN=$O(^AUPNVPRV("AD",VISITIEN,VFIEN)) Q:VFIEN=""  D
 . S NODE=""
 . F  S NODE=$O(^AUPNVPRV(VFIEN,NODE)) Q:(NODE'=+NODE)  D
 .. I NODE=801 Q
 .. I NODE=0 D
 ... S TEMP=^AUPNVPRV(VFIEN,NODE),PRV=$P(TEMP,U,1),PS=$P(TEMP,U,4)
 ...;Primary/Secondary is a required field but it is possible for it
 ...;to be missing.
 ... I PS="" S PS="M"
 ... S PRVLIST(PRV,"CNT")=$G(PRVLIST(PRV,"CNT"))+1
 ... S PRVLIST(PRV,PS,"CNT")=$G(PRVLIST(PRV,PS,"CNT"))+1
 ... S PRVLIST(PRV,PS,PRVLIST(PRV,"CNT"))=VFIEN
 .. S ^TMP(TMPSUB,$J,VISITIEN,"PRV",VFIEN,NODE,"AFTER")=^AUPNVPRV(VFIEN,NODE)
 .. S ^TMP(TMPSUB,$J,VISITIEN,"PRV",VFIEN,NODE,"BEFORE")=^AUPNVPRV(VFIEN,NODE)
 ;Remove duplicates.
 S PRV=""
 F  S PRV=$O(PRVLIST(PRV)) Q:PRV=""  D
 . I PRVLIST(PRV,"CNT")=1 Q
 . S NUMM=+$G(PRVLIST(PRV,"M","CNT"))
 . S NUMP=+$G(PRVLIST(PRV,"P","CNT"))
 . S NUMS=+$G(PRVLIST(PRV,"S","CNT"))
 .;Remove any entries that are missing the Primary/Secondary designation.
 . I NUMM>0 F IND=1:1:NUMM S VFIEN=PRVLIST(PRV,"M",IND) K ^TMP(TMPSUB,$J,VISITIEN,"PRV",VFIEN)
 .;If this provider is listed as primary more than once, delete the other primaries. 
 . I NUMP>1 D
 .. F IND=2:1:NUMP S VFIEN=PRVLIST(PRV,"P",IND) K ^TMP(TMPSUB,$J,VISITIEN,"PRV",VFIEN)
 ..;If this provider is a primary, delete all its secondaries and missing.
 . I NUMP>0 D
 .. F IND=1:1:NUMS S VFIEN=PRVLIST(PRV,"S",IND) K ^TMP(TMPSUB,$J,VISITIEN,"PRV",VFIEN)
 .. S NUMS=0
 .;If this provider is not primary, only keep the first secondary.
 . I NUMS>1 D
 .. F IND=2:1:NUMS D
 ... S VFIEN=PRVLIST(PRV,"S",IND)
 ... K ^TMP(TMPSUB,$J,VISITIEN,"PRV",VFIEN)
 ;
 ;V SC
 S VFIEN=""
 F  S VFIEN=$O(^AUPNVSC("AD",VISITIEN,VFIEN)) Q:VFIEN=""  D
 . S NODE=""
 . F  S NODE=$O(^AUPNVSC(VFIEN,NODE)) Q:(NODE'=+NODE)  D
 .. I NODE=801 Q
 .. S ^TMP(TMPSUB,$J,VISITIEN,"SC",VFIEN,NODE,"AFTER")=^AUPNVSC(VFIEN,NODE)
 .. S ^TMP(TMPSUB,$J,VISITIEN,"SC",VFIEN,NODE,"BEFORE")=^AUPNVSC(VFIEN,NODE)
 ;
 ;V SKIN
 S VFIEN=""
 F  S VFIEN=$O(^AUPNVSK("AD",VISITIEN,VFIEN)) Q:VFIEN=""  D
 . S NODE=""
 . F  S NODE=$O(^AUPNVSK(VFIEN,NODE)) Q:(NODE'=+NODE)  D
 .. I NODE=801 Q
 .. S ^TMP(TMPSUB,$J,VISITIEN,"SK",VFIEN,NODE,"AFTER")=^AUPNVSK(VFIEN,NODE)
 .. S ^TMP(TMPSUB,$J,VISITIEN,"SK",VFIEN,NODE,"BEFORE")=^AUPNVSK(VFIEN,NODE)
 ;
 ;V TRT
 S VFIEN=""
 F  S VFIEN=$O(^AUPNVTRT("AD",VISITIEN,VFIEN)) Q:VFIEN=""  D
 . S NODE=""
 . F  S NODE=$O(^AUPNVTRT(VFIEN,NODE)) Q:(NODE'=+NODE)  D
 .. I NODE=801 Q
 .. S ^TMP(TMPSUB,$J,VISITIEN,"TRT",VFIEN,NODE,"AFTER")=^AUPNVTRT(VFIEN,NODE)
 .. S ^TMP(TMPSUB,$J,VISITIEN,"TRT",VFIEN,NODE,"BEFORE")=^AUPNVTRT(VFIEN,NODE)
 Q
 ;
ENCEVENT(VISITIEN,DONTKILL) ;Create the ^TMP("PKRENC",$J, array of all the
 ;information about one encounter.
 ;Parameters:
 ;  VISITIEN  Pointer to the Visit (#9000010)
 ;  DONOTKILL is 1 if the output array is not to be killed before used
 ;            and 0 or null if the array is to be killed (cleaned out)
 ;
 ;  The encounter is returned in the array
 ;    ^TMP("PXKENC",$J,pointer to visit)
 ;
 I $G(VISITIEN)'>0 Q  ;PX/183
 I '$D(^AUPNVSIT(VISITIEN)) Q
 N CSTPIEN,IND,NODE,NUMM,NUMP,NUMS,PRV,PRVLIST,PS,TEMP,TMPSUB,VFIEN
 S TMPSUB="PXKENC"
 K:'$G(DONTKILL) ^TMP(TMPSUB,$J)
 ;Visit and Credit Stop Visits
 S NODE=""
 F  S NODE=$O(^AUPNVSIT(VISITIEN,NODE)) Q:(NODE'=+NODE)  D
 . S ^TMP(TMPSUB,$J,VISITIEN,"VST",VISITIEN,NODE)=^AUPNVSIT(VISITIEN,NODE)
 S CSTPIEN=""
 F  S CSTPIEN=$O(^AUPNVSIT("AD",VISITIEN,CSTPIEN)) Q:CSTPIEN=""  D
 . I "SC"'[$P($G(^AUPNVSIT(CSTPIEN,150)),"^",3) Q
 . S NODE=""
 . F  S NODE=$O(^AUPNVSIT(CSTPIEN,NODE)) Q:(NODE'=+NODE)  D
 .. S ^TMP(TMPSUB,$J,VISITIEN,"CSTP",CSTPIEN,NODE)=^AUPNVSIT(CSTPIEN,NODE)
 ;
 ;V CPT
 S VFIEN=""
 F  S VFIEN=$O(^AUPNVCPT("AD",VISITIEN,VFIEN)) Q:VFIEN=""  D
 . S NODE=""
 . F  S NODE=$O(^AUPNVCPT(VFIEN,NODE)) Q:(NODE'=+NODE)  D
 .. I NODE=801 Q
 ..;Modifiers.
 .. I NODE=1 D
 ... S ^TMP(TMPSUB,$J,VISITIEN,"CPT",VFIEN,NODE,0)=^AUPNVCPT(VFIEN,NODE,0)
 ... S IND=0
 ... F  S IND=+$O(^AUPNVCPT(VFIEN,NODE,IND)) Q:IND=0  D
 .... S ^TMP(TMPSUB,$J,VISITIEN,"CPT",VFIEN,NODE,IND,0)=^AUPNVCPT(VFIEN,NODE,IND,0)
 .. E  S ^TMP(TMPSUB,$J,VISITIEN,"CPT",VFIEN,NODE)=^AUPNVCPT(VFIEN,NODE)
 ;
 ;V EXAM
 S VFIEN=""
 F  S VFIEN=$O(^AUPNVXAM("AD",VISITIEN,VFIEN)) Q:VFIEN=""  D
 . S NODE=""
 . F  S NODE=$O(^AUPNVXAM(VFIEN,NODE)) Q:(NODE'=+NODE)  D
 .. I NODE=801 Q
 .. S ^TMP(TMPSUB,$J,VISITIEN,"XAM",VFIEN,NODE)=^AUPNVXAM(VFIEN,NODE)
 ;
 ;V HF
 S VFIEN=""
 F  S VFIEN=$O(^AUPNVHF("AD",VISITIEN,VFIEN)) Q:VFIEN=""  D
 . S NODE=""
 . F  S NODE=$O(^AUPNVHF(VFIEN,NODE)) Q:(NODE'=+NODE)  D
 .. I NODE=801 Q
 .. S ^TMP(TMPSUB,$J,VISITIEN,"HF",VFIEN,NODE)=^AUPNVHF(VFIEN,NODE)
 ;
 ;V ICR
 S VFIEN=""
 F  S VFIEN=$O(^AUPNVICR("AD",VISITIEN,VFIEN)) Q:VFIEN=""  D
 . S NODE=""
 . F  S NODE=$O(^AUPNVICR(VFIEN,NODE)) Q:(NODE'=+NODE)  D
 .. I NODE=801 Q
 .. S ^TMP(TMPSUB,$J,VISITIEN,"ICR",VFIEN,NODE)=^AUPNVICR(VFIEN,NODE)
 ;
 ;V IMM
 S VFIEN=""
 F  S VFIEN=$O(^AUPNVIMM("AD",VISITIEN,VFIEN)) Q:VFIEN=""  D
 . S NODE=""
 . F  S NODE=$O(^AUPNVIMM(VFIEN,NODE)) Q:(NODE'=+NODE)  D
 .. I NODE=801 Q
 ..;Fields that are multiples.
 .. I (NODE=2)!(NODE=3)!(NODE=11) D
 ... S ^TMP(TMPSUB,$J,VISITIEN,"IMM",VFIEN,NODE,0)=^AUPNVIMM(VFIEN,NODE,0)
 ... S IND=0
 ... F  S IND=+$O(^AUPNVIMM(VFIEN,NODE,IND)) Q:IND=0  D
 .... S ^TMP(TMPSUB,$J,VISITIEN,"IMM",VFIEN,NODE,IND,0)=^AUPNVIMM(VFIEN,NODE,IND,0)
 .. E  S ^TMP(TMPSUB,$J,VISITIEN,"IMM",VFIEN,NODE)=^AUPNVIMM(VFIEN,NODE)
 ;
 ;V PED
 S VFIEN=""
 F  S VFIEN=$O(^AUPNVPED("AD",VISITIEN,VFIEN)) Q:VFIEN=""  D
 . S NODE=""
 . F  S NODE=$O(^AUPNVPED(VFIEN,NODE)) Q:(NODE'=+NODE)  D
 .. I NODE=801 Q
 .. S ^TMP(TMPSUB,$J,VISITIEN,"PED",VFIEN,NODE)=^AUPNVPED(VFIEN,NODE)
 ;
 ;V POV
 S VFIEN=""
 F  S VFIEN=$O(^AUPNVPOV("AD",VISITIEN,VFIEN)) Q:VFIEN=""  D
 . S NODE=""
 . F  S NODE=$O(^AUPNVPOV(VFIEN,NODE)) Q:(NODE'=+NODE)  D
 .. I NODE=801 Q
 .. S ^TMP(TMPSUB,$J,VISITIEN,"POV",VFIEN,NODE)=^AUPNVPOV(VFIEN,NODE)
 ..;Check for bad Provider Narrative Category pointer.
 .. I (NODE=802),(^AUPNVPOV(VFIEN,NODE)'>0) S ^TMP(TMPSUB,$J,VISITIEN,"POV",VFIEN,NODE)=""
 ;
 ;V PROVIDER
 S VFIEN=""
 F  S VFIEN=$O(^AUPNVPRV("AD",VISITIEN,VFIEN)) Q:VFIEN=""  D
 . S NODE=""
 . F  S NODE=$O(^AUPNVPRV(VFIEN,NODE)) Q:(NODE'=+NODE)  D
 .. I NODE=801 Q
 .. S ^TMP(TMPSUB,$J,VISITIEN,"PRV",VFIEN,NODE)=^AUPNVPRV(VFIEN,NODE)
 .. I NODE=0 D
 ... S TEMP=^AUPNVPRV(VFIEN,NODE),PRV=$P(TEMP,U,1),PS=$P(TEMP,U,4)
 ...;Primary/Secondary is a required field but it is possible for it
 ...;to be missing.
 ... I PS="" S PS="M"
 ... S PRVLIST(PRV,"CNT")=$G(PRVLIST(PRV,"CNT"))+1
 ... S PRVLIST(PRV,PS,"CNT")=$G(PRVLIST(PRV,PS,"CNT"))+1
 ... S PRVLIST(PRV,PS,PRVLIST(PRV,PS,"CNT"))=VFIEN
 ;Remove duplicates.
 S PRV=""
 F  S PRV=$O(PRVLIST(PRV)) Q:PRV=""  D
 . I PRVLIST(PRV,"CNT")=1 Q
 . S NUMM=+$G(PRVLIST(PRV,"M","CNT"))
 . S NUMP=+$G(PRVLIST(PRV,"P","CNT"))
 . S NUMS=+$G(PRVLIST(PRV,"S","CNT"))
 .;Remove any entries that are missing the Primary/Secondary designation.
 . I NUMM>0 F IND=1:1:NUMM S VFIEN=PRVLIST(PRV,"M",IND) K ^TMP(TMPSUB,$J,VISITIEN,"PRV",VFIEN)
 .;If this provider is listed as primary more than once, delete the other primaries. 
 . I NUMP>1 D
 .. F IND=2:1:NUMP S VFIEN=PRVLIST(PRV,"P",IND) K ^TMP(TMPSUB,$J,VISITIEN,"PRV",VFIEN)
 ..;If this provider is a primary, delete all its secondaries and missing.
 . I NUMP>0 D
 .. F IND=1:1:NUMS S VFIEN=PRVLIST(PRV,"S",IND) K ^TMP(TMPSUB,$J,VISITIEN,"PRV",VFIEN)
 .. S NUMS=0
 .;If this provider is not primary, only keep the first secondary.
 . I NUMS>1 D
 .. F IND=2:1:NUMS D
 ... S VFIEN=PRVLIST(PRV,"S",IND)
 ... K ^TMP(TMPSUB,$J,VISITIEN,"PRV",VFIEN)
 ;
 ;V SC
 S VFIEN=""
 F  S VFIEN=$O(^AUPNVSC("AD",VISITIEN,VFIEN)) Q:VFIEN=""  D
 . S NODE=""
 . F  S NODE=$O(^AUPNVSC(VFIEN,NODE)) Q:(NODE'=+NODE)  D
 .. I NODE=801 Q
 .. S ^TMP(TMPSUB,$J,VISITIEN,"SC",VFIEN,NODE)=^AUPNVSC(VFIEN,NODE)
 ;
 ;V SKIN
 S VFIEN=""
 F  S VFIEN=$O(^AUPNVSK("AD",VISITIEN,VFIEN)) Q:VFIEN=""  D
 . S NODE=""
 . F  S NODE=$O(^AUPNVSK(VFIEN,NODE)) Q:(NODE'=+NODE)  D
 .. I NODE=801 Q
 .. S ^TMP(TMPSUB,$J,VISITIEN,"SK",VFIEN,NODE)=^AUPNVSK(VFIEN,NODE)
 ;
 ;V TRT
 S VFIEN=""
 F  S VFIEN=$O(^AUPNVTRT("AD",VISITIEN,VFIEN)) Q:VFIEN=""  D
 . S NODE=""
 . F  S NODE=$O(^AUPNVTRT(VFIEN,NODE)) Q:(NODE'=+NODE)  D
 .. I NODE=801 Q
 .. S ^TMP(TMPSUB,$J,VISITIEN,"TRT",VFIEN,NODE)=^AUPNVTRT(VFIEN,NODE)
 Q
 ;