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

BQIRGADD.m

Go to the documentation of this file.
BQIRGADD ;PRXM/HC/ALA-Save patient register data ; 16 Nov 2007  1:18 PM
 ;;2.1;ICARE MANAGEMENT SYSTEM;;Feb 07, 2011
 ;
EN(DATA,BQIREG,BQIDFN,BQIEN,BQITYP,PARMS) ; EP - BQI SAVE REGISTER DATA
 ; Input parameters
 ;   BQIREG - Register or sub-register name
 ;   BQIDFN - Patient IEN
 ;   BQIEN  - Record IEN, if one was passed out to GUI
 ;   BQITYP - What is to happen to the record (A=Add, E=Edit, D=Delete)
 ;   PARMS  - Parameters and their values
 ;
 NEW UID,II,ADD,BN,BQ,VFIEN,BQWP,PDATA,NAME,VALUE,PFIEN,PTYPE,RVIEN,FILE,FIELD
 NEW BQQI,BQIDATA,BQIASRG,SUB,RGDATA,XREF,SUBREG,GLBREF,GLBNOD,DA,DIK,BKMSTAT
 NEW BQFLD,BQJ,BWDATA,DFIELD,DFILE,NWIENS
 S UID=$S($G(ZTSK):"Z"_ZTSK,1:$J)
 S DATA=$NA(^TMP("BQIRGADD",UID))
 K @DATA
 ;
 S II=0
 NEW $ESTACK,$ETRAP S $ETRAP="D ERR^BQIRGADD D UNWIND^%ZTER" ; SAC 2006 2.2.3.3.2
 S @DATA@(II)="I00010RESULT^T01024MSG"_$C(30)
 ;
 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
 ;
 I $G(PARMS)="",BQITYP'="D" Q
 I BQIREG="" S BMXSEC="RPC Call Failed: Register not passed in." Q
 S VFIEN=$O(^BQI(90506.3,"B",BQIREG,""))
 I VFIEN="" S BMXSEC="RPC Call Failed: "_BQIREG_" does not exist." Q
 K BQWP
 F BQ=1:1:$L(PARMS,$C(28)) D
 . S PDATA=$P(PARMS,$C(28),BQ) Q:PDATA=""
 . S NAME=$P(PDATA,"=",1),VALUE=$P(PDATA,"=",2,99)
 . I VALUE="" S VALUE="@"
 . I NAME="BKMWHOM" Q
 . S PFIEN=$O(^BQI(90506.3,VFIEN,10,"AC",NAME,""))
 . S PTYP=$P(^BQI(90506.3,VFIEN,10,PFIEN,1),U,1)
 . I PTYP="D",VALUE'="@" S VALUE=$$DATE^BQIUL1(VALUE)
 . ;I PTYP="T" S VALUE="`"_VALUE
 . S RVIEN=$O(^BQI(90506.1,"B",NAME,"")) I RVIEN="" Q
 . S DFILE=$P(^BQI(90506.1,RVIEN,0),U,5)
 . S DFIELD=$P(^BQI(90506.1,RVIEN,0),U,6)
 . I PTYP="W" D  Q
 .. I VALUE="@" S BQIDATA(DFILE,DFIELD)=VALUE Q
 .. F BQQI=1:1  S BQJ=$P(VALUE,$C(10),BQQI) Q:BQJ=""  D
 ... S BQWP(DFILE,DFIELD,BQQI)=BQJ
 . I DFIELD'=".001" S BQIDATA(DFILE,DFIELD)=VALUE
 ;
 ; Check for register or subregister
 S BQIASRG=""
 S SUB=$P(^BQI(90506.3,VFIEN,0),U,8)
 I SUB'="" D
 . S BQIREG=$P(^BQI(90506.3,SUB,0),U,1)
 . S HFIL=$P(^BQI(90506.3,SUB,0),U,10)
 . S HFLD=$P(^BQI(90506.3,SUB,0),U,11)
 . S HFIL=$P(^BQI(90506.3,VFIEN,0),U,10)
 . S HFLD=$P(^BQI(90506.3,VFIEN,0),U,11)
 S BQIASRG=$O(^BQI(90507,"B",BQIREG,""))
 I BQIASRG'="" D
 . S RGDATA=^BQI(90507,BQIASRG,0)
 . S FILE=$P(RGDATA,U,7),XREF=$P(RGDATA,U,6)
 . S ADD=$G(^BQI(90507,BQIASRG,2))
 . I $G(SUBREG)="" S SUBREG=$P(RGDATA,U,9)
 . S GLBREF=$$ROOT^DILFD(FILE,"")_XREF_")"
 . S GLBNOD=$$ROOT^DILFD(FILE,"",1)
 . I GLBNOD="" Q
 ;
 ; If the register global doesn't exist, quit
 I '$D(@GLBNOD@(0)) Q
 ;
 ;  If the patient is not already in the register, add them else update their record
 S BKMDFN=BQIDFN,HFIL=$G(HFIL,""),HFLD=$G(HFLD,"")
 X ADD
 ;
DONE ;
 S II=II+1,@DATA@(II)=$C(31)
 Q
 ;
SAV(BQIUPD,IENS) ;EP - Set the data
 ;
 K BQIWP
 S BQFIL=""
 F  S BQFIL=$O(BQIDATA(BQFIL)) Q:BQFIL=""  D
 . S BQFLD=""
 . F  S BQFLD=$O(BQIDATA(BQFIL,BQFLD)) Q:BQFLD=""  D
 .. S BQIUPD(BQFIL,IENS,BQFLD)=BQIDATA(BQFIL,BQFLD)
 ;
 I $D(BQWP),SUB="" D WP(IENS)
 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
 ;
WP(WIENS) ;EP - Set up word-processing array
 S BQFIL=""
 F  S BQFIL=$O(BQWP(BQFIL)) Q:BQFIL=""  D
 . S BQFLD=""
 . F  S BQFLD=$O(BQWP(BQFIL,BQFLD)) Q:BQFLD=""  D
 .. S BQN=""
 .. F  S BQN=$O(BQWP(BQFIL,BQFLD,BQN)) Q:BQN=""  D
 ... S BQIWP(BQFIL,WIENS,BQFLD,BQN)=BQWP(BQFIL,BQFLD,BQN)
 Q
 ;
AST(BQDFN) ;EP - Add patient to Asthma Register
 NEW DINUM,X,DIC,DLAYGO,DA,DR,DIE
 S (DINUM,X)=BQDFN,DIC(0)="L",DIC="^BATREG("
 S DIC("DR")=".02///U",DLAYGO=90181.01,DIADD=1
 K DO,DD D FILE^DICN K DINUM,DLAYGO,DIADD
 S DA=+Y I DA=-1 Q
 S DIE=DIC
 S DR=".05///^S X=$$LASTAV^BATU(BQIDFN,1);.06///^S X=$$LASTAV^BATU(BQIDFN,2);.08///^S X=$$NAPT^BQIULPT(BQIDFN);.09///^S X=DT;.11///^S X=DUZ"
 D ^DIE
 Q
 ;
HMS(BKMDFN,BQIEN,SUB,HFIL,HFLD) ; EP - Add patient to HMS register w/ status
 ; Taken from ACC^BKMVCD
 ; Replaced interactive messages with BMXSEC
 ; 
 ; Input parameters:
 ; BKMDFN - patient ien
 ; BQIEN  - record IENs
 ;
 ;
 NEW BKMOK,BKMHIV,BKMIEN,BKMREG,BKMVUP
 S BQIEN=$G(BQIEN,"")
 I BQIEN'="" S BKMIENS=BQIEN
 ;
 I BQIEN="" D
 . S BKMHIV=$$HIVIEN^BKMIXX3()
 . I BKMHIV="" S BMXSEC="RPC Call Failed: There is no HMS register defined." Q
 . S BKMIEN=$$BKMIEN^BKMIXX3(BKMDFN)   ; BKMIEN and BKMREG used by BKMVAUD
 . I BKMIEN="" S BKMIEN=$$ADDPAT^BKMVCD(BKMDFN) ; Create entry in iCare registry for pat
 . I BKMIEN="" S BMXSEC="RPC Call Failed: An entry for the patient could not be created in the iCare registry." Q
 . S BKMREG=$$BKMREG^BKMIXX3(BKMIEN)
 . I BKMREG="" S BKMREG=$$ADDREG^BKMVCD(BKMIEN,BKMHIV) ; Create HMS register entry for pat
 . I BKMREG="" S BMXSEC="RPC Call Failed: An entry for the patient could not be created in the HMS register." Q
 . S BKMIENS=BKMREG_","_BKMIEN_","
 . ;
 . ; Add audit entry for the NEW rec
 . ;D NEW^BKMVAUDN(BKMIEN,BKMREG,DUZ)
 ;
 ; If BQITYP is delete
 I BQITYP="D" D  Q
 . NEW IENS
 . I SUB="" D  Q
 .. S IENS=BQIEN,BQIUPD(FILE,IENS,.01)="@" D FILE^DIE("","BQIUPD","ERROR")
 .. I $D(ERROR)>0 S II=II+1,@DATA@(II)=-1_U_$G(ERROR("DIERR",1,"TEXT",1))_$C(30) Q
 .. S II=II+1,@DATA@(II)=1_U_$C(30)
 . I SUB'="" D
 .. D FIELD^DID(HFIL,HFLD,"","SPECIFIER","HARRAY")
 .. S SBFIL=$G(HARRAY("SPECIFIER"))
 .. S SBFIL=$$STRIP^XLFSTR(SBFIL,"ABCDEFGHIJKLMNOPQRSTUVWXYZ")
 .. I $$GET1^DIQ(SBFIL,BQIEN,$S(SBFIL=90451.03:4,SBFIL=90451.145:.04,1:3),"I")'=DUZ D  Q
 ... S II=II+1,@DATA@(II)="-1^User is not owner, cannot edit"_$C(30)
 .. S IENS=BQIEN,BQIUPD(SBFIL,BQIEN,.01)="@" D FILE^DIE("","BQIUPD","ERROR")
 .. ;S IENS=BQIEN,BQIUPD(SBFIL,IENS,.01)="@" D FILE^DIE("","BQIUPD","ERROR")
 .. I $D(ERROR)>0 S II=II+1,@DATA@(II)=-1_U_$G(ERROR("DIERR",1,"TEXT",1))_$C(30) K ERROR Q
 .. S II=II+1,@DATA@(II)=1_U_$C(30)
 ;
 K BQIUPD
 ;
 ; Build multiple record
 I SUB'="" D  Q:$D(ERROR)>0
 . K FDA,ERROR,BQQIEN
 . I BQITYP="D" Q
 . I BQITYP="A" S IENS="+1,"_BKMIENS
 . I BQITYP="E" S IENS=BQIEN
 . D SAV(.FDA,IENS)
 . S SBFIL=$O(FDA("")) I SBFIL="" Q
 . S FDA(SBFIL,IENS,$S(SBFIL=90451.03:4,SBFIL=90451.145:.04,1:3))=DUZ
 . S FDA(SBFIL,IENS,$S(SBFIL=90451.03:5,SBFIL=90451.145:.05,1:4))=$$NOW^XLFDT()
 . D UPDATE^DIE("","FDA","BQQIEN","ERROR")
 . I $D(ERROR) S II=II+1,@DATA@(II)=-1_U_$G(ERROR("DIERR",1,"TEXT",1))_$C(30) K ERROR Q
 . K FDA,BQIDATA
 . I $D(BQWP)>0 D
 .. I BQITYP="A" S NWIENS=$G(BQQIEN(1))_","_BKMIENS
 .. I BQITYP="E" S NWIENS=BKMIENS
 .. D WP(NWIENS)
 .. S BWDATA=$NA(BQIWP(SBFIL,NWIENS,20))
 .. D WP^DIE(SBFIL,NWIENS,20,"",BWDATA,"ERROR")
 . ;I $G(BKMSTAT)="" S BKMSTAT=$$GET1^DIQ(90451.01,BKMIENS,.5,"I")
 . ;I $G(BKMSTAT)="" S BKMSTAT="A"
 . I $D(ERROR) S II=II+1,@DATA@(II)=-1_U_$G(ERROR("DIERR",1,"TEXT",1))_$C(30) K ERROR Q
 ;
 I SUB'="" D
 . S BKMIEN=$$BKMIEN^BKMIXX3(BKMDFN)
 . S BKMREG=$$BKMREG^BKMIXX3(BQIDFN)
 . ;I $G(BKMIENS)'="" S BKMIENS=BKMREG_","_BKMIEN_","
 ;
 I $L(BKMIENS,",")=4 D
 . I $G(BKMSTAT)="" Q
 . S BQIUPD(90451.01,$P(BKMIENS,",",2,4),.02)=$$NOW^XLFDT()
 . S BQIUPD(90451.01,$P(BKMIENS,",",2,4),.025)=DUZ
 . I $G(BKMSTAT)'="" S BQIUPD(90451.01,$P(BKMIENS,",",2,4),.5)=$G(BKMSTAT)
 . I $G(BQIUPD(90451.01,$P(BKMIENS,",",2,4),.5))="" K BQIUPD(90451.01,$P(BKMIENS,",",2,4),.5)
 . S BQIUPD(90451.01,$P(BKMIENS,",",2,4),.75)=$$NOW^XLFDT()
 . S BQIUPD(90451.01,$P(BKMIENS,",",2,4),.8)=DUZ
 I $L(BKMIENS,",")<4 D
 . I $G(BKMSTAT)="" Q
 . S BQIUPD(90451.01,BKMIENS,.02)=$$NOW^XLFDT()
 . S BQIUPD(90451.01,BKMIENS,.025)=DUZ
 . I $G(BKMSTAT)'="" S BQIUPD(90451.01,BKMIENS,.5)=$G(BKMSTAT)
 . I $G(BQIUPD(90451.01,BKMIENS,.5))="" K BQIUPD(90451.01,BKMIENS,.5)
 . S BQIUPD(90451.01,BKMIENS,.75)=$$NOW^XLFDT()
 . S BQIUPD(90451.01,BKMIENS,.8)=DUZ
 ;
 K ERROR
 D SAV(.BQIUPD,BKMIENS)
 I $D(BQIUPD) D FILE^DIE("","BQIUPD","ERROR")
 K BQIUPD
 ;
 I $D(ERROR) D  Q
 . S II=II+1,@DATA@(II)=-1_U_$G(ERROR("DIERR",1,"TEXT",1))_$C(30)
 ;
 I $D(BQIWP)>0 D
 . S IENS=""
 . F  S IENS=$O(BQIWP(90451.01,IENS)) Q:IENS=""  D
 .. S BQFLD=""
 .. F  S BQFLD=$O(BQIWP(90451.01,IENS,BQFLD)) Q:BQFLD=""  D
 ... S BWDATA=$NA(BQIWP(90451.01,IENS,BQFLD))
 ... D WP^DIE(90451.01,IENS,BQFLD,"",BWDATA,"ERROR")
 I $D(ERROR)>0 S II=II+1,@DATA@(II)=-1_U_$G(ERROR("DIERR",1,"TEXT",1))_$C(30) Q
 ;
 S II=II+1,@DATA@(II)=1_U_$C(30)
 ; Make sure that HIV Case Manager added to DSPM
 S BKMCMGR=$$GET1^DIQ(90451.01,BKMIENS,6.5,"I")
 I BKMCMGR="" S BKMCMGR="@"
 D AEDAP^BDPAPI(BKMDFN,BKMCMGR,"HIV CASE MANAGER",.RESULT)
 S BKMPRV=$$GET1^DIQ(90451.01,BKMIENS,6,"I")
 I BKMPRV="" S BKMPRV="@"
 D AEDAP^BDPAPI(BKMDFN,BKMPRV,"HIV PROVIDER",.RESULT)
 ; Set the user last edited and date/time last edited
 NEW BKMIEN,BKMREG,IENS
 S BKMIEN=$P(BKMIENS,",",2),BKMREG=$P(BKMIENS,",",1)
 I $G(BKMIEN)'="",$G(BKMREG)'="",$G(DUZ)'="" D
 . ; Set the data via FileMan API
 . K FDA
 . S IENS="+1,"_BKMREG_","_BKMIEN_","
 . S FDA(90451.05,IENS,.01)=$$NOW^XLFDT()     ; DATE/TIME
 . S FDA(90451.05,IENS,1)=DUZ     ; EVENT USER (File 200)
 . D UPDATE^DIE("","FDA","")
 . K FDA,%DT,X,Y
 ;D POST^BKMVAUD ; End audit log
 Q