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

BQICEADD.m

Go to the documentation of this file.
BQICEADD ;GDHD/HCS/ALA-CMET Add Event ; 09 Jan 2017  9:12 AM
 ;;2.6;ICARE MANAGEMENT SYSTEM;;Jul 07, 2017;Build 72
 ;
EN(DATA,DFN,PARMS) ;EP -- BQI ADD NEW EVENT
 NEW CIEN
 NEW ARLDTM
 ;S ARLDTM=$$NOW^XLFDT()
 ;S ^ARLPARMS("BQICEADD",ARLDTM,"DFN")=DFN
 ;S ^ARLPARMS("BQICEADD",ARLDTM,"PARMS")=$G(PARMS)
 S UID=$S($G(ZTSK):"Z"_ZTSK,1:$J)
 S DATA=$NA(^TMP("BQICEADD",UID))
 S MORE=$G(MORE,1)
 K @DATA
 S II=0
 NEW $ESTACK,$ETRAP S $ETRAP="D ERR^BQICEADD D UNWIND^%ZTER" ; SAC 2006 2.2.3.3.2
 ;
 S @DATA@(II)="I00010RESULT^I00010QUEUED_CMET_IEN"_$C(30)
 ;
 ; Get the parameters
 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
 ;
 ; Parse the visit parameters
 K APCDALVR
 F BQ=1:1:$L(PARMS,$C(28)) D
 . NEW VFIEN,PTYP
 . S VFIEN=$$FIND1^DIC(90506.3,"","MX","CMET Add Event","","","ERROR")
 . S PDATA=$P(PARMS,$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=""
 . S PTYP=$P($G(^BQI(90506.3,VFIEN,10,PFIEN,1)),U,1)
 . ;I "AD"[$P(^BQI(90506.3,VFIEN,10,PFIEN,1),U,1) S VALUE=$$DATE^BQIUL1(VALUE)
 . I PTYP="A"!(PTYP="D") S VALUE=$$DATE^BQIUL1(VALUE)
 . I PTYP="W" D  Q
 .. K BTPWP D WP(VALUE)
 . S @NAME=VALUE
 ;
 F BQ=1:1:$L(PARMS,$C(28)) D
 . NEW VFIEN
 . S VFIEN=$$FIND1^DIC(90506.3,"","MX","PCC Visit","","","ERROR")
 . S PDATA=$P(PARMS,$C(28),BQ) Q:PDATA=""
 . S NAME=$P(PDATA,"=",1),VALUE=$P(PDATA,"=",2,99)
 . I VALUE="" Q
 . I NAME="APCCDATE" S @NAME=VALUE
 . 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:$$OLOC())
 S APCDALVR("APCDTYPE")=$G(APCDALVR("APCDTYPE"),"I")
 S APCDALVR("APCDCAT")=$G(APCDALVR("APCDCAT"),"E")
 S APCDALVR("APCDCLN")=$G(CLN,"OTHER")
 S APCDDATE=$$DATE^BQIUL1(APCCDATE)
 I $G(MORE)'="" S APCDALVR("APCDAUTO")=1
 S APCDALVR("APCDOPT")=$$FIND1^DIC(19,"","BX","BQIRPC","","","ERROR")
 ;
 ;  Create visit and then update other Vfiles
 D EN^APCDALV
 ; Check for error
 I '$G(APCDALVR("APCDAFLG")) S VISIT=$G(APCDALVR("APCDVSIT"))
 E  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
 S VFIEN=$O(^BTPW(90621.1,"D",EVTYPE,"")),FRIL=VFIEN
 S VFILE=$$GET1^DIQ(90621.1,VFIEN_",",.02,"E")
 S FREF=$$GET1^DIQ(90621.1,VFIEN_",",.02,"I")
 S APCDALVR("APCDATMP")="[APCDALVR "_FREF_" (ADD)]"
 I EVTYPE="CPT" S APCDALVR("APCDTCPT")=$P(^ICPT(IVALIEN,0),"^",1),APCDALVR("APCDTUN")=1,APCDALVR("APCDTPN")=$$ENARR()
 I EVTYPE="POV" S APCDALVR("APCDTPOV")=$P(^ICD9(IVALIEN,0),"^",1),APCDALVR("APCDTNQ")=$$ENARR(),APCDALVR("APCDTPS")="PRIMARY"
 I EVTYPE="LAB" S APCDALVR("APCDTLAB")=IVALIEN,APCDALVR("APCDTLPV")=$$ENARR(),APCDALVR("APCDTCSF")="RESULTED"
 I EVTYPE="PROCEDURE" S APCDALVR("APCDTPRC")=$P(^ICD0(IVALIEN,0),"^",1),APCDALVR("APCDTNQ")=$$ENARR(),APCDALVR("APCDTPP")="YES"
 ;
 ; Create V files
 D EN^APCDALVR
 ; Check for error
 I '$G(APCDALVR("APCDAFLG")) S RESULT=1
 E  S RESULT=-1
 ; Cleanup
 K APCDALVR
 I RESULT=1 D
 . S GREF=$$ROOT^DILFD(FREF,"",1)
 . S RIEN=$O(@GREF@("AD",VISIT,""))
 . D CM
 ;
 I RESULT=-1 D
 . NEW DA,DIK
 . S DIK="^AUPNVSIT(",DA=VISIT D ^DIK
 ;
DONE ;
 S II=II+1,@DATA@(II)=RESULT_U_$G(CIEN)_$C(30)
 S II=II+1,@DATA@(II)=$C(31)
 K AGE,APCCDATE,APCDDATE,APCDANE,APCDLOC,APCDLOC,BQ,DA,DFN,DOB,EVIEN,EVNAME,EVTYPE,FREF,FRIL,IENS
 K GREFF,II,IVALIEN,MORE,NAME,PARMS,PDATA,PFIEN,RESULT,RIEN,SEX,SSN,VALUE,VFIEN,VFILE,VISIT,VSDTM
 K ^UTILITY($J)
 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("BQICEADD",UID))
 S II=II+1,@DATA@(II)=$C(31)
 Q
 ;
CM ;EP
 NEW DIC,DLAYGO,X,Y,BTPUPD
 S DIC="^BTPWQ(",DIC(0)="LMNZ",DLAYGO=90629,DIC("P")=DLAYGO
 S X=EVIEN
 K DO,DD D FILE^DICN
 S CIEN=+Y
 D UPD(CIEN)
 D CHK
 Q
 ;
UPD(CIEN) ;
 S VSDTM=$P(^AUPNVSIT(VISIT,0),"^",1),IENS=CIEN_","
 S BTPUPD(90629,IENS,.02)=DFN,BTPUPD(90629,IENS,.03)=VSDTM
 S BTPUPD(90629,IENS,.04)=VISIT,BTPUPD(90629,IENS,.05)=RIEN
 S BTPUPD(90629,IENS,.06)=FRIL,BTPUPD(90629,IENS,.07)=$$NOW^XLFDT()
 S BTPUPD(90629,IENS,.09)=$G(WHIEN),BTPUPD(90629,IENS,.1)=$G(RARPT)
 S BTPUPD(90629,IENS,.15)=$G(ACCN)
 S BTPUPD(90629,IENS,.08)="P",BTPUPD(90629,IENS,.12)="Add Manual Event"
 S BTPUPD(90629,IENS,.13)=$$CAT^BTPWPDSP(EVIEN,1),BTPUPD(90629,IENS,.11)=$$NOW^XLFDT()
 S BTPUPD(90629,IENS,.16)=$$GET1^DIQ(9000010,VISIT_",",.06,"I")
 S BTPUPD(90629,IENS,1.02)=$G(BTPWPFND)
 D FILE^DIE("","BTPUPD","ERROR")
 I $D(BTPWP) D WP^DIE(90629,IENS,4,"","BTPWP","ERROR") K BTPWP
 Q
 ;
CHK ; Check to supercede previously existing record
 NEW PIEN,BTPUPD
 S PIEN=""
 F  S PIEN=$O(^BTPWQ("AD",DFN,PIEN)) Q:PIEN=""  D
 . I $P(^BTPWQ(PIEN,0),U,1)'=EVIEN Q
 . I PIEN=CIEN Q
 . I VSDTM>$P(^BTPWQ(PIEN,0),U,3) Q
 . I $P(^BTPWQ(PIEN,0),U,8)="P" D
 .. S BTPUPD(90629,PIEN_",",.08)="S"
 .. D FILE^DIE("","BTPUPD","ERROR")
 ;
 ; Check for possible match with future followup
 NEW TIEN
 S TIEN=""
 F  S TIEN=$O(^BTPWP("AE",DFN,"F",TIEN)) Q:TIEN=""  D
 . I $P(^BTPWP(TIEN,0),U,1)'=EVIEN Q
 . S BTPUPD(90629,CIEN_",",1.01)=TIEN
 . D FILE^DIE("","BTPUPD","ERROR")
 Q
 ;
OLOC() ;EP - Other location
 NEW PRMN,DOM,DIV
 S PRMN=$O(^XTV(8989.51,"B","BEHOENCX OTHER LOCATION",""))
 S DOM=$P(^XTV(8989.3,1,0),"^",1)
 S DIV=$G(DUZ(2))
 S APCDLOC=DIV
 S IEN=$O(^XTV(8989.5,"AC",PRMN,DIV_";DIC(4,","")),APCDLOC=^XTV(8989.5,"AC",PRMN,DIV_";DIC(4,",IEN)
 I IEN="" S IEN=$O(^XTV(8989.5,"AC",PRMN,DOM_";DIC(4.2,","")),APCDLOC=^XTV(8989.5,"AC",PRMN,DOM_";DIC(4.2,",IEN)
 Q APCDLOC
 ;
ENARR() ;EP - Event Narrative
 NEW TEXT
 ;I $G(APCDLOC)="" S APCDLOC=$G(APCDALVR("APCDLOC"))
 ;I APCDLOC'="" S TEXT="Event "_EVNAME_" done at "_$P(^DIC(4,APCDLOC,0),"^",1)_" location"
 S TEXT="CMET manually entered event"
 Q TEXT
 ;
WP(X) ;EP - Process comment
 NEW DIWL,DIWR,BQN
 K ^UTILITY($J,"W")
 S DIWL=1,DIWR=70
 D ^DIWP
 S BQN=""
 F  S BQN=$O(^UTILITY($J,"W",1,BQN)) Q:BQN=""  S BTPWP(BQN)=^UTILITY($J,"W",1,BQN,0)
 Q