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

AGGMLUPD.m

Go to the documentation of this file.
AGGMLUPD ;VNGT/HS/ALA-Multiple record update ; 20 May 2010  1:41 PM
 ;;1.0;PATIENT REGISTRATION GUI;**1**;Nov 15, 2010
 ;
 ;
UPD(DATA,DEF,PROC,RIEN,MIEN,PARMS) ; EP - AGG UPDATE A MULTIPLE RECORD
 ; Input
 ;   DEF   - Definition Name
 ;   RIEN  - Record IEN
 ;   MIEN  - Multiple IEN
 ;   PROC  - 'A' to add, 'E' to edit, 'D' to delete
 ;   PARMS - Parameters
 ;
 NEW UID,II,BN,LIST,PDATA,NAME,VALUE,VFIEN,FILE,PTYP,CHIEN,FIELD,EXEC,GLBRT,SECFLD,BQ
 NEW AGGDATA,ERROR,RESULT,AGGINT,IENS,X,DA,DIC,SUB,SECFILE,SUBFIL,SUBFLD,WHERE,NOD,REF
 NEW PFIEN,Y
 S UID=$S($G(ZTSK):"Z"_ZTSK,1:$J)
 S DATA=$NA(^TMP("AGGPTUPD",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 @DATA@(II)="I00010RESULT^T01024ERROR"_$C(30)
 ;
 S MIEN=$G(MIEN,"") S:MIEN=0 MIEN=""
 S VFIEN=$O(^AGG(9009068.3,"B",DEF,""))
 I VFIEN="" S BMXSEC="RPC Call Failed: "_DEF_" Definition does not exist." Q
 S FILE=$P(^AGG(9009068.3,VFIEN,0),U,2),SECFILE=$P(^AGG(9009068.3,VFIEN,0),U,14)
 S SUB=$P(^AGG(9009068.3,VFIEN,0),U,7)
 I SUB D
 . S SUBFIL=$P(^AGG(9009068.3,VFIEN,0),U,10),SUBFLD=$P(^AGG(9009068.3,VFIEN,0),U,11)
 . S WHERE=$P(^DD(SUBFIL,SUBFLD,0),U,4),REF=$P(^DD(SUBFIL,SUBFLD,0),U,2),NOD=$P(WHERE,";",1)
 ;
 ; Get previous data
 I $G(RIEN)'="",$G(MIEN)'="" D
 . S DA(1)=RIEN,DA=MIEN,IENS=$$IENS^DILF(.DA)
 . NEW FLD,LIST
 . S FLD="",LIST="" F  S FLD=$O(^AGG(9009068.3,VFIEN,10,"AD",FLD)) Q:FLD=""  S LIST=LIST_FLD_";"
 . S LIST=$$TKO^AGGUL1(LIST,";")
 . D GETS^DIQ(FILE,IENS,LIST,"I","AGGINT")
 . NEW FLD,LIST
 . S FLD="",LIST="" F  S FLD=$O(^AGG(9009068.3,VFIEN,10,"AG",FLD)) Q:FLD=""  S LIST=LIST_FLD_";"
 . D GETS^DIQ(SECFILE,IENS,LIST,"I","AGGINT")
 ;
 S PARMS=$G(PARMS,"")
 I PARMS="" D
 . S LIST="",BN=""
 . F  S BN=$O(PARMS(BN)) Q:BN=""  S LIST=LIST_PARMS(BN)
 . K PARMS
 . S PARMS=LIST
 . K LIST
 ;
 F BQ=1:1:$L(PARMS,$C(28)) D  Q:$G(BMXSEC)'=""
 . S PDATA=$P(PARMS,$C(28),BQ) Q:PDATA=""
 . S NAME=$P(PDATA,"=",1),VALUE=$P(PDATA,"=",2,99)
 . ;I VALUE="" S VALUE="@"
 . ;I VALUE="" Q
 . S PFIEN=$O(^AGG(9009068.3,VFIEN,10,"AC",NAME,""))
 . I PFIEN="" S BMXSEC=NAME_" not a valid parameter for this update" Q
 . S PTYP=$P($G(^AGG(9009068.3,VFIEN,10,PFIEN,1)),U,1)
 . I PTYP="D" S VALUE=$$DATE^AGGUL1(VALUE)
 . ;I PTYP="T" S VALUE=VALUE
 . I PTYP="C"!(PTYP="K") D
 .. I VALUE="" Q
 .. S CHIEN=$O(^AGG(9009068.3,VFIEN,10,PFIEN,5,"B",VALUE,"")) I CHIEN="" Q
 .. S VALUE=$P(^AGG(9009068.3,VFIEN,10,PFIEN,5,CHIEN,0),U,2)
 . I PTYP="W" D  Q
 .. F AGI=1:1  S AGJ=$P(VALUE,$C(10),AGI) Q:AGJ=""  D
 ... S AGWP(AGI,0)=$$CTRL^AGGUL1(AGJ)
 . S FIELD=$P($G(^AGG(9009068.3,VFIEN,10,PFIEN,3)),U,1),SECFLD=$P($G(^AGG(9009068.3,VFIEN,10,PFIEN,3)),U,7)
 . I $G(IENS)'="" D
 .. I FIELD'="",$G(AGGINT(FILE,IENS,FIELD,"I"))'="",VALUE="" S VALUE="@"
 .. I SECFLD'="",$G(AGGINT(SECFILE,IENS,SECFLD,"I"))'="",VALUE="" S VALUE="@"
 . S @NAME=VALUE I FIELD=".01"!(SECFLD=".01") S X=VALUE
 ;
 I PROC="D" D  G FIN
 . I FILE'="" S AGGDATA(FILE,IENS,.01)="@"
 . I SECFILE'="" S AGGDATA(SECFILE,IENS,.01)="@"
 . S RESULT=1
 ;
 I $G(IENS)="",PROC="A" D  I DA=-1 S RESULT="-1^"_"Unable to create new record" D PRB(RESULT) Q
 . NEW DIC,DLAYGO
 . S GLBRT=$$ROOT^DILFD(SUBFIL,"",0)
 . S DIC(0)="L",DLAYGO="L",DA(1)=RIEN,DIC=GLBRT_DA(1)_","_NOD_","
 . K DO,DD D FILE^DICN
 . S DA=+Y I DA=-1 Q
 . S IENS=$$IENS^DILF(.DA)
 ;
 F BQ=1:1:$L(PARMS,$C(28)) D  Q:$G(BMXSEC)'=""
 . S PDATA=$P(PARMS,$C(28),BQ) Q:PDATA=""
 . S NAME=$P(PDATA,"=",1)
 . S PFIEN=$O(^AGG(9009068.3,VFIEN,10,"AC",NAME,""))
 . I PFIEN="" S BMXSEC=NAME_" not a valid parameter for this update" Q
 . S FIELD=$P($G(^AGG(9009068.3,VFIEN,10,PFIEN,3)),U,1),SECFLD=$P($G(^AGG(9009068.3,VFIEN,10,PFIEN,3)),U,7)
 . S EXEC=$G(^AGG(9009068.3,VFIEN,10,PFIEN,7))
 . I EXEC'="" X EXEC Q
 . I FIELD="",SECFLD="" Q
 . S PTYP=$P($G(^AGG(9009068.3,VFIEN,10,PFIEN,1)),U,1)
 . I PTYP="C"!(PTYP="T")!(PTYP="K") D  Q
 .. I FIELD'="" S AGGDATAI(FILE,IENS,FIELD)=@NAME Q
 .. I SECFLD'="" S AGGDATAI(SECFILE,IENS,SECFLD)=@NAME
 . I FIELD'="" S AGGDATA(FILE,IENS,FIELD)=@NAME Q
 . I SECFLD'="" S AGGDATA(SECFILE,IENS,SECFLD)=@NAME
 ;
 S RESULT=1_U
 ;
 I $D(AGGWP) D
 . NEW FL,FD,IENS,FLAG
 . S FL=""
 . F  S FL=$O(AGGWP(FL)) Q:FL=""  D
 .. S IENS=""
 .. F  S IENS=$O(AGGWP(FL,IENS)) Q:IENS=""  D
 ... S FD=""
 ... F  S FD=$O(AGGWP(FL,IENS,FD)) Q:FD=""  D
 .... S FLAG=""
 .... ;I FL=9000001,FD=1301 S FLAG="A"
 .... I $D(WDATA) D WP^DIE(FL,IENS,FD,FLAG,WDATA,"ERROR")
 ;
FIN ;
 K AGGWP,AGWP
 I $D(ERROR)>0 S RESULT=-1_U_$G(ERROR("DIERR",1,"TEXT",1))
 K ERROR
 I $D(AGGDATA)>0 D FILE^DIE("","AGGDATA","ERROR")
 I $D(AGGDATAI)>0 D FILE^DIE("I","AGGDATAI","ERROR")
 I $D(ERROR)>0 S RESULT=-1_U_$G(ERROR("DIERR",1,"TEXT",1))
 I $P(RESULT,U,1)'=-1 S RESULT=1_U
 S II=II+1,@DATA@(II)=RESULT_$C(30)
 K AGGDATA,AGGDATAI
 ;
 I $P(RESULT,U,1)=1 D
 . I $G(DEF)="Other Tribe" D EDIT^AGGEXPRT(RIEN)
 S NAME=""
 F  S NAME=$O(^AGG(9009068.3,VFIEN,10,"AC",NAME)) Q:NAME=""  I $G(@NAME)'="" K @NAME
 ;
DONE ;
 S II=II+1,@DATA@(II)=$C(31)
 Q
 ;
ERR ;
 D ^%ZTER
 NEW Y,ERRDTM
 S Y=$$NOW^XLFDT() X ^DD("DD") S ERRDTM=Y
 S BMXSEC="Recording that an error occurred at "_ERRDTM
 I $D(II),$D(DATA) S II=II+1,@DATA@(II)=$C(31)
 Q
 ;
PRB(RESULT) ;
 S II=II+1,@DATA@(II)=RESULT_$C(30)
 S II=II+1,@DATA@(II)=$C(31)
 Q