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

BQIVFADD.m

Go to the documentation of this file.
BQIVFADD ;PRXM/HC/ALA-Add new Vfile entry ; 09 Apr 2007  5:48 PM
 ;;2.2;ICARE MANAGEMENT SYSTEM;;Jul 28, 2011;Build 37
 Q
 ;
EN(DATA,DFN,VFILE,MORE,VPARMS,EPARMS) ;EP -- BQI ADD NEW VFILE ENTRY
 ;
 ;Input
 ;  DFN    - Patient's IEN
 ;  VFILE  - Vfile add new entry to
 ;  MORE   - More entries for the same date
 ;  VPARMS - Visit parameters
 ;  EPARMS - Event parameters
 ;
 NEW UID,II,VFIEN,LIST,BQ,PFIEN,PRFLD,PRVAL,CLN,APCDPAT,CHIEN,PDATA,TBFIL
 NEW APCDDATE,APCDTCPT,QUALIF
 S UID=$S($G(ZTSK):"Z"_ZTSK,1:$J)
 S DATA=$NA(^TMP("BQIVFADD",UID)),MORE=$G(MORE)
 K @DATA
 S II=0
 NEW $ESTACK,$ETRAP S $ETRAP="D ERR^BQIVFADD D UNWIND^%ZTER" ; SAC 2006 2.2.3.3.2
 ;
 S @DATA@(II)="I00010RESULT"_$C(30)
 ;
 S VFILE=$G(VFILE,"") I VFILE="" S BMXSEC="No Vfile selected" Q
 ;
 ; Get the visit parameters
 S VPARMS=$G(VPARMS,"")
 I VPARMS="" D
 . S LIST="",BN=""
 . F  S BN=$O(VPARMS(BN)) Q:BN=""  S LIST=LIST_VPARMS(BN)
 . K VPARMS
 . S VPARMS=LIST
 . K LIST
 ;
 ;Get the PCC event parameters
 S EPARMS=$G(EPARMS,"")
 I EPARMS="" D
 . S LIST="",BN=""
 . F  S BN=$O(EPARMS(BN)) Q:BN=""  S LIST=LIST_EPARMS(BN)
 . K EPARMS
 . S EPARMS=LIST
 . K LIST
 ;
 ; Parse the visit parameters
 K APCDALVR
 F BQ=1:1:$L(VPARMS,$C(28)) D
 . NEW VFIEN
 . S VFIEN=$$FIND1^DIC(90506.3,"","MX","PCC Visit","","","ERROR")
 . S PDATA=$P(VPARMS,$C(28),BQ) Q:PDATA=""
 . S NAME=$P(PDATA,"=",1),VALUE=$P(PDATA,"=",2,99)
 . I VALUE="" Q
 . S PFIEN=$O(^BQI(90506.3,VFIEN,10,"AC",NAME,"")) Q:PFIEN=""
 . I "AD"[$P(^BQI(90506.3,VFIEN,10,PFIEN,1),U,1) S VALUE=$$DATE^BQIUL1(VALUE)
 . I $P(^BQI(90506.3,VFIEN,10,PFIEN,1),U,1)="C" D
 .. S CHIEN=$O(^BQI(90506.3,VFIEN,10,PFIEN,5,"B",VALUE,"")) I CHIEN="" Q
 .. S VALUE=$P(^BQI(90506.3,VFIEN,10,PFIEN,5,CHIEN,0),U,2)
 . S APCDALVR(NAME)=VALUE
 S APCDALVR("APCDPAT")=DFN,APCDPAT=DFN
 S APCDALVR("APCDANE")="",APCDALVR("AUPNTALK")=""
 S APCDALVR("APCDLOC")=$S($G(APCDALVR("APCDLOC"))'="":APCDALVR("APCDLOC"),1:DUZ(2))
 S APCDALVR("APCDTYPE")=$G(APCDALVR("APCDTYPE"),"I")
 S APCDALVR("APCDCAT")=$G(APCDALVR("APCDCAT"),"E")
 S APCDALVR("APCDCLN")=$G(CLN,"")
 I $G(MORE)'="" S APCDALVR("APCDAUTO")=1
 ;
 ;  Create visit and then update other Vfiles
 D EN^APCDALV
 ; Check for error
 I '$G(APCDALVR("APCDAFLG")) S VISIT=$G(APCDALVR("APCDVSIT"))
 I $G(APCDALVR("APCDAFLG"))=2 S RESULT=-1 G DONE
 ; 
 ; If there is an outside provider, set it separately
 I $G(APCDALVR("APCDTOPR"))'="" D
 . S BQIUPD(9000010,VISIT_",",1210)=$G(APCDALVR("APCDTOPR"))
 . D FILE^DIE("","BQIUPD","ERROR")
 . K BQIUPD
 ;
 ; Determine the input template for the event
 I VFILE=9000010.01 S VFIEN=$O(^BQI(90506.3,"B","Measurement",""))
 E  S VFIEN=$$FIND1^DIC(90506.3,"","M",VFILE,"","","ERROR")
 S VFILE=$$GET1^DIQ(90506.3,VFIEN_",",.02,"E")
 S APCDALVR("APCDATMP")="[APCDALVR "_VFILE_" (ADD)]"
 ;
 ; Parse the event parameters
  F BQ=1:1:$L(EPARMS,$C(28)) D
 . S PDATA=$P(EPARMS,$C(28),BQ) Q:PDATA=""
 . S NAME=$P(PDATA,"=",1),VALUE=$P(PDATA,"=",2,99)
 . I VALUE="" Q
 . S PFIEN=$O(^BQI(90506.3,VFIEN,10,"AC",NAME,""))
 . I "AD"[$P(^BQI(90506.3,VFIEN,10,PFIEN,1),U,1) S VALUE=$$DATE^BQIUL1(VALUE)
 . I $P(^BQI(90506.3,VFIEN,10,PFIEN,1),U,1)="C" D
 .. S CHIEN=$O(^BQI(90506.3,VFIEN,10,PFIEN,5,"B",VALUE,"")) I CHIEN="" Q
 .. S VALUE=$P(^BQI(90506.3,VFIEN,10,PFIEN,5,CHIEN,0),U,2)
 . S APCDALVR(NAME)=VALUE
 . S @NAME=VALUE
 . I NAME="VITDTM" S APCDALVR("APCDTCDT")=$G(@NAME)
 ;
 ;Check fields for pointers
 S PRFLD=""
 F  S PRFLD=$O(^BQI(90506.3,VFIEN,10,"AC",PRFLD)) Q:PRFLD=""  D
 . I $G(APCDALVR(PRFLD))="" Q
 . S PFIEN=$O(^BQI(90506.3,VFIEN,10,"AC",PRFLD,""))
 . S PTYP=$P(^BQI(90506.3,VFIEN,10,PFIEN,1),U,1)
 . I PTYP'="T" Q
 . S PRVAL=APCDALVR(PRFLD)
 . I PRFLD="APCDTPRV" Q
 . S APCDALVR(PRFLD)="`"_PRVAL
 ;
 ; Check for code set versioning
 ;I VFILE=9000010.18 D
 ;. I $G(APCDDATE)="" S APCDDATE=$P(^AUPNVSIT(VISIT,0),U,1)\1
 ;. I $G(APCDTCPT)'="" D CPT^BQIVFVAL(APCDDATE,APCDTCPT)
 ;. I RESULT=1 S APCDALVR("DIFGLINE")=1
 ;. I $$PATCH^XPDUTL("BJPC*2.0*1") K APCDALVR("DIFGLINE")
 ;
 ; Create V files
 D EN^APCDALVR
 ; Check for error
 I '$G(APCDALVR("APCDAFLG")) S RESULT=1
 I $G(APCDALVR("APCDAFLG"))=2 S RESULT=-1
 ;
 I $G(QUALIF)'="",VFILE=9000010.01,RESULT=1 S IEN=$G(APCDALVR("APCDADFN")) D QLF
 ;
 ; Cleanup
 K APCDALVR
 ;
DONE ;
 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 $G(II)="" S II=0
 I $G(UID)="" S UID=$S($G(ZTSK):"Z"_ZTSK,1:$J)
 I $G(DATA)="" S DATA=$NA(^TMP("BQIVFADD",UID))
 S II=II+1,@DATA@(II)=$C(31)
 Q
 ;
QLF ; Update Qualifiers
 I $G(^AUPNVMSR(IEN,5,0))="" S ^AUPNVMSR(IEN,5,0)="^9000010.015PA^^"
 NEW DIC,DA,X,BJ
 S DA(1)=IEN
 S DLAYGO=9000010.015,DIC="^AUPNVMSR("_DA(1)_",5,",DIC("P")=DLAYGO,DIC(0)="L"
 F BJ=1:1 S X=$P(QUALIF,$C(29),BJ) Q:X=""  K DO,DD D FILE^DICN
 Q