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

AGGPTADD.m

Go to the documentation of this file.
AGGPTADD ;VNGT/HS/ALA-Add new patient ; 19 Apr 2010  12:30 PM
 ;;1.0;PATIENT REGISTRATION GUI;**1**;Nov 15, 2010
 ;
 ;
ADD(DATA,DEF,DFN,PARMS) ; EP - AGG ADD NEW PATIENT
 ; Input
 ;   DEF   = Mini Registration or New Patient
 ;   DFN   = if patient already created, null if new
 ;   PARMS = Parameters
 ; 
 NEW UID,II,AGIEN,PDATA,FILE,LIST,NARRAY,BQ,NAME,VALUE,PFIEN,PTYP,CHIEN,AGI,AGJ,AGWP,PTNAME
 NEW AGGPTLNM,AGGPTFNM,AGGPTMNM,AGGPTSFX,AGGPTSSN,AGGNOSSN,AGGPTHRN,AGGPTDOB,AGGPTSEX,AGGPTMAR
 NEW EXEC,FIELD,TXT,FLAG,WDATA,FILE,SECFILE,AGGPTCOM,AGGPTCDT,ERROR
 S UID=$S($G(ZTSK):"Z"_ZTSK,1:$J)
 S DATA=$NA(^TMP("AGGPTADD",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 FLAG=0 I $G(DFN)="" S FLAG=1
 S @DATA@(II)="I00010RESULT^T00080MESSAGE^I00010DFN"_$C(30)
 S AGIEN=$$FIND1^DIC(9009068.3,"","BX",DEF,"","","ERROR")
 I AGIEN=0 D  Q
 . S II=II+1,@DATA@(II)="-1^RPC Failed: Passed in window name "_DEF_" not found^"_$C(30)
 . S II=II+1,@DATA@(II)=$C(31)
 ;
 S FILE=$P(^AGG(9009068.3,AGIEN,0),U,2),SECFILE=$P(^AGG(9009068.3,AGIEN,0),U,14)
 ;
 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
 ;
 K NARRAY
 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="@"
 . S PFIEN=$O(^AGG(9009068.3,AGIEN,10,"AC",NAME,""))
 . I PFIEN="" S BMXSEC=NAME_" not a valid parameter for this update" Q
 . S PTYP=$P($G(^AGG(9009068.3,AGIEN,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,AGIEN,10,PFIEN,5,"B",VALUE,"")) I CHIEN="" Q
 .. S VALUE=$P(^AGG(9009068.3,AGIEN,10,PFIEN,5,CHIEN,0),U,2)
 . I PTYP="W" K AGGWP D  Q
 .. F AGI=1:1  S AGJ=$P(VALUE,$C(10),AGI) Q:AGJ=""  D
 ... S AGWP(AGI,0)=$$CTRL^AGGUL1(AGJ)
 . S @NAME=VALUE
 . I NAME="AGGPTLNM" S NARRAY("FAMILY")=@NAME
 . I NAME="AGGPTFNM" S NARRAY("GIVEN")=@NAME
 . I NAME="AGGPTMNM" S NARRAY("MIDDLE")=@NAME
 . I NAME="AGGPTSFX" S NARRAY("SUFFIX")=@NAME
 ;
 F TXT="FAMILY","GIVEN","MIDDLE","SUFFIX" I $G(NARRAY(TXT))="" S NARRAY(TXT)=""
 S PTNAME=$$F^XLFNAME1(.NARRAY,"C")
 ;
 I $G(DFN)="" D
 . NEW DIC,DLAYGO,DIADD,X,NWONE
 . S X=PTNAME,DIC="^AUPNPAT(",DIC(0)="MLQ"
 . D ^DIC
 . S DFN=+Y,NWONE=$P(Y,U,3) I NWONE Q
 . K AUPNPAT,AUPNDOB,AUPNDAYS,AUPNDOD,AUPNSEX
 . S DIC="^DPT("
 . K DO,DD D FILE^DICN
 . S DFN=+Y,NWONE=$P(Y,U,3)
 . I NWONE S ^AUPNPAT(DFN,0)=DFN,^AUPNPAT("B",DFN,DFN)=""
 ;
 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,AGIEN,10,"AC",NAME,""))
 . I PFIEN="" S BMXSEC=NAME_" not a valid parameter for this update" Q
 . S FIELD=$P($G(^AGG(9009068.3,AGIEN,10,PFIEN,3)),U,1),SECFLD=$P($G(^AGG(9009068.3,AGIEN,10,PFIEN,3)),U,7)
 . S EXEC=$G(^AGG(9009068.3,AGIEN,10,PFIEN,7))
 . I EXEC'="" X EXEC Q
 . I FIELD="",SECFLD="" Q
 . S PTYP=$P($G(^AGG(9009068.3,AGIEN,10,PFIEN,1)),U,1)
 . I PTYP="C"!(PTYP="K")!(PTYP="T") D  Q
 .. I FIELD'="" S AGGDATAI(FILE,DFN_",",FIELD)=@NAME Q
 .. I SECFLD'="" S AGGDATAI(SECFILE,DFN_",",SECFLD)=@NAME
 . I FIELD'="" S AGGDATA(FILE,DFN_",",FIELD)=@NAME Q
 . I SECFLD'="" S AGGDATA(SECFILE,DFN_",",SECFLD)=@NAME
 ;
 I $D(AGGWP) D
 . NEW FL,FD,IENS,WFLAG
 . 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 WFLAG="" I FL=9000001,FD=1301 S WFLAG="A"
 .... I $D(WDATA) D WP^DIE(FL,IENS,FD,WFLAG,WDATA,"ERROR")
 ;
 I $G(AGGPTSSN)'="" S AGGDATAI(9000001,DFN_",",.23)=$O(^AUTTSSN("B","P",""))
 I $D(AGGDATA) D FILE^DIE("","AGGDATA","ERROR")
 I $D(AGGDATAI) D FILE^DIE("I","AGGDATAI","ERROR")
 K AGGDATA,AGGDATAI
 ;
 ; 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
 ;
 ; Set the Previous community history
 I $G(AGGPTCDT)'="" D COMM(DFN,AGGPTCDT,AGGPTCOM)
 ;
 K AGGWP,AGWP
 S RESULT=1_U
 I $D(ERROR)>0 S RESULT=-1_U_$G(ERROR("DIERR",1,"TEXT",1))
 I $P(RESULT,U,1)'=-1 S RESULT=1_U_U_DFN
 S II=II+1,@DATA@(II)=RESULT_$C(30)
 ;
 ; 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")
 . I FLAG D
 .. D ADD^AGGEXPRT(DFN)
 .. S ^AGPATCH($$NOW^XLFDT(),DUZ(2),DFN)="NEW",$P(^AUPNPAT(DFN,0),U,11)=DUZ
 . I 'FLAG D EDIT^AGGEXPRT(DFN)
 ;
 S NAME=""
 F  S NAME=$O(^AGG(9009068.3,AGIEN,10,"AC",NAME)) Q:NAME=""  K @NAME
 K ERROR
 ;
DONE ;
 S II=II+1,@DATA@(II)=$C(31)
 Q
 ;
NAME(AGGPTLNM,AGGPTFNM,AGGPTMNM,AGGPTSFX) ;EP
 S NARRAY("FAMILY")=$G(AGGPTLNM)
 S NARRAY("GIVEN")=$G(AGGPTFNM)
 S NARRAY("MIDDLE")=$G(AGGPTMNM)
 S NARRAY("SUFFIX")=$G(AGGPTSFX)
 S NAME=$$F^XLFNAME1(.NARRAY,"C")
 Q NAME
 ;
COMM(DFN,AGGPTCDT,AGGPTCOM) ;
 NEW DIC,DA
 I AGGPTCDT'?.N S AGGPTCDT=$$DATE^AGGUL1(AGGPTCDT)
 S DIC("P")=9000001.51,DIC="^AUPNPAT("_DFN_",51,",DIC(0)="QML",(DINUM,X)=AGGPTCDT
 S DA(1)=DFN,DIC("DR")=".02////"_DT_";.03////"_AGGPTCOM K DD,DO D FILE^DICN
 Q