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

AGGPTUPD.m

Go to the documentation of this file.
AGGPTUPD ;VNGT/HS/ALA-Update Patient Data ; 16 Apr 2010  9:08 AM
 ;;1.0;PATIENT REGISTRATION GUI;**1**;Nov 15, 2010
 ;
UPD(DATA,DEF,DFN,PARMS) ; EP - AGG UPDATE PATIENT
 ; Input
 ;   DEF   - Definition Name
 ;   DFN   - Patient IEN
 ;   PARMS - Parameters
 NEW UID,II,BN,LIST,PDATA,NAME,VALUE,VFIEN,FILE,PTYP,CHIEN,FIELD,EXEC,OTHPARM
 NEW AGGDATA,ERROR,RESULT,AGGINT,WDATA,AGGPTEML
 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^T01024OTHER_PARMS"_$C(30)
 ;
 S OTHPARM=""  ;Initialize OTHER_PARMS return value
 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)
 ;
 ; Get previous data
 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,DFN_",",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,DFN_",",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 NAME="DFN",VALUE="" Q
 . ;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)
 . ;
 . I $G(AGGPTCDT)'="" S AGGPTCDT=$$DATE^AGGUL1(AGGPTCDT)
 . 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 FIELD'="",$G(AGGINT(FILE,DFN_",",FIELD,"I"))'="",VALUE="" S VALUE="@"
 . I SECFLD'="",$G(AGGINT(SECFILE,DFN_",",SECFLD,"I"))'="",VALUE="" S VALUE="@"
 . ;I FIELD'="",$G(AGGINT(FILE,DFN_",",FIELD,"I"))'="",VALUE=$G(AGGINT(FILE,DFN_",",FIELD,"I")) Q
 . ;I SECFLD'="",$G(AGGINT(SECFILE,DFN_",",SECFLD,"I"))'="",VALUE=$G(AGGINT(SECFILE,DFN_",",SECFLD,"I")) Q
 . S @NAME=VALUE
 ;
 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 NAME="AGGECREL"!(NAME="AGGNKREL")!(NAME="AGGPTVET") D  Q
 .. I FIELD'="" D HRDST(FILE,DFN,FIELD,@NAME) Q
 .. I SECFLD'="" D HRDST(SECFILE,DFN,SECFLD,@NAME)
 . I PTYP="C"!(PTYP="T")!(PTYP="K") D  Q
 .. I FIELD'="",$G(@NAME)'="",$G(@NAME)'=$G(AGGINT(FILE,DFN_",",FIELD,"I")) D  Q
 ... I @NAME'="@" S AGGDATAI(FILE,DFN_",",FIELD)=@NAME Q
 ... S AGGDATA(FILE,DFN_",",FIELD)=@NAME
 .. I SECFLD'="",$G(@NAME)'="",$G(@NAME)'=$G(AGGINT(SECFILE,DFN_",",SECFLD,"I")) D  Q
 ... I @NAME'="@" S AGGDATAI(SECFILE,DFN_",",SECFLD)=@NAME Q
 ... S AGGDATA(SECFILE,DFN_",",SECFLD)=@NAME
 . I FIELD'="",$G(@NAME)'="",$G(@NAME)'=$G(AGGINT(FILE,DFN_",",FIELD,"I")) S AGGDATA(FILE,DFN_",",FIELD)=@NAME Q
 . I SECFLD'="",$G(@NAME)'="",$G(@NAME)'=$G(AGGINT(SECFILE,DFN_",",SECFLD,"I")) S AGGDATA(SECFILE,DFN_",",SECFLD)=@NAME
 ;
 I $G(AGGPTCOM)'="" D
 . S AGGDATA(9000001,DFN_",",1118)=$P(^AUTTCOM(AGGPTCOM,0),U,1)
 . ; Set the Previous community history
 . I $G(AGGPTCDT)'="" D COMM^AGGPTADD(DFN,AGGPTCDT,AGGPTCOM)
 I $G(AGGPTEML)'="" D EML^AGGUL1(DFN)
 ;
 ; Set the HRN
 I '$D(ERROR) D
 . NEW DIE,DR,DA
 . I $G(AGGPTHRN)="" Q
 . S DIE="^AUPNPAT(",DA=DFN
 . S DR="4101///"_"`"_DUZ(2)
 . S DR(2,9000001.41)=".02///"_AGGPTHRN
 . D ^DIE
 ;
 S RESULT=1_U_U_$G(OTHPARM)
 ;
 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")
 ;
 K AGGWP,AGWP
 I $D(ERROR)>0 S RESULT=-1_U_$G(ERROR("DIERR",1,"TEXT",1))_U_$G(OTHPARM)
 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))_U_$G(OTHPARM)
 I $P(RESULT,U,1)'=-1 S RESULT=1_U_U_$G(OTHPARM)
 ;
 ; Set last date updated and updated by
 I $P(RESULT,U,1)=1 D
 . S AGGDATAI(9000001,DFN_",",.03)=DT,AGGDATAI(9000001,DFN_",",.12)=DUZ
 . D FILE^DIE("I","AGGDATAI","ERROR")
 . D EDIT^AGGEXPRT(DFN)
 . I $$DECEASED^AGEDERR2(DFN) D ADDPAT^BIPATE(DFN,DUZ(2),,$P($G(^DPT(DFN,.35)),U),"d")
 ;
 S II=II+1,@DATA@(II)=RESULT_$C(30)
 K AGGDATA,AGGDATAI
 S NAME=""
 F  S NAME=$O(^AGG(9009068.3,VFIEN,10,"AC",NAME)) Q:NAME=""  K @NAME
 ;
DONE ;
 S II=II+1,@DATA@(II)=$C(31)
 Q
 ;
ETHN(AGDFN,AGETH,AGMETH) ;EP - Update Ethnicity
 NEW OK,ERROR
 ; First delete the entry
 S OK=$$DETH^AGAPIPAT(AGDFN,"",.ERROR)
 ;I OK="ENTRY NOT FOUND" S OK=0
 I AGETH="@"!(AGETH="") S RESULT=1_U Q
 S:AGMETH]"" AGMETH=$P(^DIC(10.3,AGMETH,0),U,1)
 S AGETH=$P(^DIC(10.2,AGETH,0),U,1)
 ; If no errors, OK=0, then add the new ethnicity
 S OK=$$AETH^AGAPIPAT(AGDFN,AGETH,AGMETH,.ERROR)
 I $D(ERROR)>0 S RESULT=-1_U_$G(ERROR("DIERR",1,"TEXT",1)) Q
 S RESULT=1_U
 Q
 ;
SRACE(AGDFN,AGRACE,AGRMET) ;EP - Update Race
 NEW OK,ERROR,AGGRDA,RACE,MET
 I $G(AGRMET)="" S MET="UNKNOWN"
 ; First delete the entry
 S AGGRDA=0
 F  S AGGRDA=$O(^DPT(AGDFN,.02,AGGRDA)) Q:'AGGRDA  D DRACE^AGAPIPAT(AGDFN,AGGRDA,.ERROR)
 ;
 I AGRACE="@"!(AGRACE="") S RESULT=1_U Q
 S RACE=$P(^DIC(10,AGRACE,0),U,1)
 ;S MET=$P(^DIC(10.3,AGRMET,0),U,1)
 D ARACE^AGAPIPAT(AGDFN,RACE,MET,.ERROR)
 ;
 I $D(ERROR)>0 S RESULT=-1_U_$G(ERROR("DIERR",1,"TEXT",1))
 S RESULT=1_U
 Q
 ;
RACE(DATA,DFN,TYPE,AGGRDA,AGRACE,AGRMET,PARMS) ; EP -- BQI UPDATE PAT RACE
 ; Updates for multiple races
 ;Input Parameters
 ;  DFN    - Patient internal entry number
 ;  TYPE   - 'A' to add or 'D' to delete
 ;  AGGRDA - Race record IEN needed in order to delete
 ;  AGRACE - Race value
 ;  AGRMET - Method of Collection value
 ;  PARMS  - List of parameters
 ;  
 NEW UID,II,ERROR,RESULT
 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 @DATA@(II)="I00010RESULT^T01024MSG"_$C(30)
 ;
 S RESULT=1_U
 ;
 I TYPE="D" D DRACE^AGAPIPAT(DFN,AGGRDA,.ERROR)
 ;
 I TYPE="A" D
 . NEW RACE,MET
 . S RACE=$P(^DIC(10,AGRACE,0),U,1)
 . S MET=$P(^DIC(10.3,AGRMET,0),U,1)
 . D ARACE^AGAPIPAT(DFN,RACE,MET,.ERROR)
 ;
 I $D(ERROR)>0 S RESULT=-1_U_$G(ERROR("DIERR",1,"TEXT",1))
 S II=II+1,@DATA@(II)=RESULT_$C(30)
 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
 ;
HRDST(FILE,DA,FIELD,VALUE) ; EP - Hard set data because they have triggers on them
 NEW CROOT,WHERE,NOD,PEC
 S CROOT=$$ROOT^DILFD(FILE,"",1)
 S WHERE=$$GET1^DID(FILE,FIELD,"","GLOBAL SUBSCRIPT LOCATION")
 I WHERE="" Q
 S NOD=$P(WHERE,";",1),PEC=$P(WHERE,";",2)
 S $P(@CROOT@(DA,NOD),U,PEC)=$S(VALUE'="@":VALUE,1:"")
 Q