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

AGGPTDMG.m

Go to the documentation of this file.
AGGPTDMG ;VNGT/HS/ALA-Patient Registration Special Updates  ; 16 Apr 2010  9:08 AM
 ;;1.0;PATIENT REGISTRATION GUI;;Nov 15, 2010
 ;
 ;
MANY(DATA,DEF,XREF,DFN) ; EP -- AGG BUILD WINDOW MANY
 ; Input
 ;   DEF  - AGG Window Name
 ;   XREF - Cross-reference ID for the patient (DFN)
 ;   DFN  - Patient IEN
 ; Description - Returns many records at a top level for one patient
 ;
 NEW UID,II,AGIEN,AGCN,AGDATA,FLD,TYPE,CODE,DEXEC,ARRAY,AN,DQTY,VAL,VALUE,HEADR,HDATA,FILE,FL,FD
 NEW VHD,J,K,LEN,LG,LN,ECHR,HDR,IEN,IENS
 S UID=$S($G(ZTSK):"Z"_ZTSK,1:$J)
 S DATA=$NA(^TMP("AGGPTDMG",UID))
 K @DATA
 S II=0
 NEW $ESTACK,$ETRAP S $ETRAP="D ERR^AGGWDISP D UNWIND^%ZTER" ; SAC 2006 2.2.3.3.2
 ;
 S AGIEN=$$FIND1^DIC(9009068.3,"","BX",DEF,"","","ERROR")
 I AGIEN=0 S BMXSEC="RPC Failed: Passed in window name "_DEF_" not found" Q
 ;
 S FILE=$P(^AGG(9009068.3,AGIEN,0),U,2)
 S GLBREF=$$ROOT^DILFD(FILE,"",1),RESULT=""
 S IEN="",HEADR=""
 F  S IEN=$O(@GLBREF@(XREF,DFN,IEN)) Q:IEN=""  D
 . S HEADR="",HDATA="",IENS=IEN_","
 . D REC(IENS)
 . S @DATA@(0)=HEADR_$C(30)
 . S II=II+1,@DATA@(II)=HDATA_$C(30)
 I HEADR="" D
 . D HDR
 . S @DATA@(0)=HEADR_$C(30)
 S II=II+1,@DATA@(II)=$C(31)
 Q
 ;
MUL(DATA,DEF,NOD,RIEN,MIEN) ; EP -- AGG BUILD WINDOW MULTIPLE
 ; Input
 ;   DEF  - AGG Window Name
 ;   XREF - Cross-reference ID for the patient (DFN)
 ;   RIEN - Record IEN (could be DFN)
 ;   MIEN - Specific multiple IEN
 ; Description - Returns many records at a top level for one patient
 ;
 NEW UID,II,AGIEN,AGCN,AGDATA,FLD,TYPE,CODE,DEXEC,ARRAY,AN,DQTY,VAL,VALUE,HEADR,HDATA,FILE,FL,FD
 NEW VHD,J,K,LEN,LG,LN,ECHR,HDR,VAL1,VAL2,SBFIL
 S UID=$S($G(ZTSK):"Z"_ZTSK,1:$J)
 S DATA=$NA(^TMP("AGGPTMUL",UID))
 K @DATA
 S II=0
 NEW $ESTACK,$ETRAP S $ETRAP="D ERR^AGGWDISP D UNWIND^%ZTER" ; SAC 2006 2.2.3.3.2
 ;
 S AGIEN=$$FIND1^DIC(9009068.3,"","BX",DEF,"","","ERROR")
 I AGIEN=0 S BMXSEC="RPC Failed: Passed in window name "_DEF_" not found" Q
 ;
 S FILE=$P(^AGG(9009068.3,AGIEN,0),U,2),SBFIL=$P(^AGG(9009068.3,AGIEN,0),U,10)
 S GLBREF=$$ROOT^DILFD(SBFIL,"",1),RESULT="",HEADR=""
 I $G(MIEN)'="" D  Q
 . S HEADR="",HDATA=""
 . NEW DA,IENS
 . S DA(1)=RIEN,DA=MIEN,IENS=$$IENS^DILF(.DA),IEN=MIEN
 . D REC(IENS)
 . S @DATA@(0)=HEADR_$C(30)
 . S II=II+1,@DATA@(II)=HDATA_$C(30)
 . S II=II+1,@DATA@(II)=$C(31)
 ;
 S IEN=0
 F  S IEN=$O(@GLBREF@(RIEN,NOD,IEN)) Q:'IEN  D
 . S HEADR="",HDATA=""
 . NEW DA,IENS
 . S DA(1)=RIEN,DA=IEN,IENS=$$IENS^DILF(.DA)
 . D REC(IENS)
 . S @DATA@(0)=HEADR_$C(30)
 . S II=II+1,@DATA@(II)=HDATA_$C(30)
 I HEADR="" D
 . D HDR
 . S @DATA@(0)=HEADR_$C(30)
 S II=II+1,@DATA@(II)=$C(31)
 Q
 ;
REC(IENS) ; Each Record
 S AGCN=0
 F  S AGCN=$O(^AGG(9009068.3,AGIEN,10,AGCN)) Q:'AGCN  D
 . I $P(^AGG(9009068.3,AGIEN,10,AGCN,0),U,11)'="" Q
 . S AGDATA=$G(^AGG(9009068.3,AGIEN,10,AGCN,0))
 . S FLD=$P($G(^AGG(9009068.3,AGIEN,10,AGCN,3)),U,1)
 . S TYPE=$P($G(^AGG(9009068.3,AGIEN,10,AGCN,1)),U,1)
 . S CODE=$P(AGDATA,U,7),HDR=$P(AGDATA,U,2)
 . S DEXEC=$G(^AGG(9009068.3,AGIEN,10,AGCN,8))
 . I FLD="",DEXEC="" Q
 . I TYPE="M" S VALUE=""
 . I TYPE="T" D
 .. I DEXEC'="" D  Q
 ... S VAL=""
 ... S DQTY="I" X DEXEC S VAL=VALUE_$C(28)
 ... S DQTY="E" X DEXEC S VAL=VAL_VALUE
 .. S VALUE=$$GET1^DIQ(FILE,IENS,FLD,"I")_$C(28)_$$GET1^DIQ(FILE,IENS,FLD,"E")
 . I (TYPE="C")!(TYPE="K") D
 .. I DEXEC'="" D  Q
 ... S VAL=""
 ... I DEXEC'["DQTY" X DEXEC Q
 ... S DQTY="I" X DEXEC S VAL=VALUE_$C(28)
 ... S DQTY="E" X DEXEC S VALUE=VAL_VALUE
 .. I FLD'="" D  Q
 ... S VAL1=$$GET1^DIQ(FILE,IENS,FLD,"I") I VAL1="" Q
 ... S VAL2=$O(^AGG(9009068.3,AGIEN,10,AGCN,5,"C",VAL1,"")) I VAL2="" Q
 ... S VAL2=$P(^AGG(9009068.3,AGIEN,10,AGCN,5,VAL2,0),U,1)
 ... S VALUE=VAL1_$C(28)_VAL2
 .. S VAL1=$$GET1^DIQ(SECFILE,IENS,SECFLD,"I") I VAL1="" Q
 .. S VAL2=$O(^AGG(9009068.3,AGIEN,10,AGCN,5,"C",VAL1,"")) I VAL2="" Q
 .. S VAL2=$P(^AGG(9009068.3,AGIEN,10,AGCN,5,VAL2,0),U,1)
 .. S VALUE=VAL1_$C(28)_VAL2
 . I TYPE="X"!(TYPE="N") D
 .. NEW TYPE
 .. I DEXEC'="" X DEXEC Q
 .. I FLD=.001 S VALUE=IEN Q
 .. S VALUE=$$GET1^DIQ(FILE,IENS,FLD,"E")
 . I TYPE="D" D
 .. I DEXEC'="" X DEXEC Q
 .. S VALUE=$$GET1^DIQ(FILE,IENS,FLD,"I"),VALUE=$$FMTE^AGGUL1(VALUE)
 . I TYPE="W" D
 .. NEW FL,FD
 .. K ARRAY S VALUE=""
 .. I DEXEC'="" X DEXEC
 .. I DEXEC="" D GETS^DIQ(FILE,IENS,FLD,"E","ARRAY")
 .. S FL=$O(ARRAY("")) I FL="" Q
 .. S FD=$O(ARRAY(FL,IENS,"")) I FD="" Q
 .. S AN=0,TXT=ARRAY(FL,IENS,FD,"E") I TXT="" Q
 .. K @TXT@("E")
 .. F  S AN=$O(@TXT@(AN)) Q:AN=""  S VALUE=VALUE_@TXT@(AN)_$C(10)
 . S HEADR=HEADR_HDR_"^"
 . S HDATA=HDATA_VALUE_"^"
 S HEADR=$$TKO^AGGUL1(HEADR,"^"),HDATA=$$TKO^AGGUL1(HDATA,"^")
 Q
 ;
HDR ;
 S AGCN=0
 F  S AGCN=$O(^AGG(9009068.3,AGIEN,10,AGCN)) Q:'AGCN  D
 . I $P(^AGG(9009068.3,AGIEN,10,AGCN,0),U,11)'="" Q
 . S HDR=$P($G(^AGG(9009068.3,AGIEN,10,AGCN,0)),U,2)
 . S HEADR=HEADR_HDR_"^"
 S HEADR=$$TKO^AGGUL1(HEADR,"^")
 Q
 ; 
RACE(DATA,DFN) ; EP -- AGG PATIENT RACE
 ; Input
 ;    DFN    - Patients DFN or internal entry number
 ;
 NEW UID,II,HDR,BN,RACE,METH
 S UID=$S($G(ZTSK):"Z"_ZTSK,1:$J)
 S DATA=$NA(^TMP("AGGPTRCE",UID))
 K @DATA
 ;
 S II=0
 ;
 NEW $ESTACK,$ETRAP S $ETRAP="D ERR^AGGPTUPD D UNWIND^%ZTER" ; SAC 2006 2.2.3.3.2
 ;
 S HDR="I00010AGGRDA^T00030AGRACE^T00030AGRMET"_$C(30)
 S @DATA@(II)=HDR
 S BN=0
 F  S BN=$O(^DPT(DFN,.02,BN)) Q:'BN  D
 . NEW DA,IENS
 . S DA(1)=DFN,DA=BN,IENS=$$IENS^DILF(.DA)
 . S RACE=$$GET1^DIQ(2.02,IENS,.01,"I")_$C(28)_$$GET1^DIQ(2.02,IENS,.01,"E")
 . S METH=$$GET1^DIQ(2.02,IENS,.02,"I")_$C(28)_$$GET1^DIQ(2.02,IENS,.02,"E")
 . S II=II+1,@DATA@(II)=BN_U_RACE_U_METH_$C(30)
 ;
DONE ;
 S II=II+1,@DATA@(II)=$C(31)
 Q
 ;
ETHN(DFN,FLD) ; EP - Patient's Ethnicity
 NEW BN,VAL
 S BN=0,VAL=""
 F  S BN=$O(^DPT(DFN,.06,BN)) Q:'BN  D
 . NEW DA,IENS
 . S DA(1)=DFN,DA=BN,IENS=$$IENS^DILF(.DA)
 . S VAL=$$GET1^DIQ(2.06,IENS,FLD,"I")_$C(28)_$$GET1^DIQ(2.06,IENS,FLD,"E")
 Q VAL
 ;
RCE(DFN,FLD) ; EP - Patient's Race
 NEW BN,VAL
 S BN=0,VAL=""
 F  S BN=$O(^DPT(DFN,.02,BN)) Q:'BN  D
 . NEW DA,IENS
 . S DA(1)=DFN,DA=BN,IENS=$$IENS^DILF(.DA)
 . S VAL=$$GET1^DIQ(2.02,IENS,FLD,"I")_$C(28)_$$GET1^DIQ(2.02,IENS,FLD,"E")
 Q VAL
 ;
SEQ(DEF,DFN) ;EP - Sequence number
 NEW AGINSN1,AGINS,AGCAT,SEQ,QFL,AGN,INSNM,INSPTR
 D EP^AGINS
 D LOADCAT^AGCAT
 S INSNM=$$UP^XLFSTR(DEF)
 S INSPTR=$$FIND1^DIC(9999999.18,"","BX",INSNM,"","","ERROR")
 I $G(RIEN)="" S RIEN=DFN
 S SEQ="",QFL=0
 F  S SEQ=$O(AGINSNN(SEQ)) Q:SEQ=""  D  Q:QFL
 . I $P($G(AGINSNN(SEQ)),U,2)=INSPTR,$P($G(AGINSNN(SEQ)),U,11)[RIEN S QFL=1 Q
 . S AGN=""
 . F  S AGN=$O(AGINSNN(SEQ,AGN)) Q:AGN=""  D  Q:QFL
 .. I $P(AGINSNN(SEQ,AGN),U,2)=INSPTR,$P(AGINSNN(SEQ,AGN),U,11)[RIEN S QFL=1
 . I DEF="Private Insurance" S INSPTR=$$GET1^DIQ(9000006.11,IENS,.01,"I")
 . I $P($G(AGINSNN(SEQ)),U,2)=INSPTR,$P($G(AGINSNN(SEQ)),U,11)[RIEN S QFL=1 Q
 . S AGN=""
 . F  S AGN=$O(AGINSNN(SEQ,AGN)) Q:AGN=""  D  Q:QFL
 .. I $P(AGINSNN(SEQ,AGN),U,2)=INSPTR,$P(AGINSNN(SEQ,AGN),U,11)[RIEN S QFL=1
 K AGINSN1,AGINS,AGCAT,AGINSNN
 Q SEQ
 ;
 NEW SEQ,SFLD
 S SEQ=""
 S SFLD=$S(FILE=9000006.11:.01,1:.02)
 S INSPTR=$$GET1^DIQ(FILE,IENS,SFLD,"I")
 I $G(DFN)="" S DFN=RIEN
 I '$D(^AUPNICP("C",DFN)) Q SEQ
 S SIEN="",QFL=0
 F  S SIEN=$O(^AUPNICP("C",DFN,SIEN)) Q:SIEN=""!(QFL)  D
 . I $P(^AUPNICP(SIEN,0),U,14)'[IENS Q
 . I $P(^AUPNICP(SIEN,0),U,3)=INSPTR S SEQ=$P(^AUPNICP(SIEN,0),U,5)
 Q SEQ