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

BQINOTR.m

Go to the documentation of this file.
BQINOTR ;GDIT/HS/ALA-Reminder Notification Log ; 03 Jan 2013  12:21 PM
 ;;2.7;ICARE MANAGEMENT SYSTEM;**1**;Dec 19, 2017;Build 12
 ;
LOG(DFN,NTYP,TIUP,IMML,PWHN,REM,PROV) ;PEP - Log a notification entry
 ; Input
 ;   DFN  - Patient IEN
 ;   NTYP - Notification Type LETTER, EMAIL, PHONE
 ;   TIUP - TIU note pointer
 ;   IMML - Immunization letter pointer
 ;   PWHN - Patient Wellness Handout pointer (no longer needed)
 ;   REM  - Reminder (IMMUNIZATIONS if from immunization package)
 ;   PROV - Provider
 ;
 NEW DDATA
 S DDATA=$P($G(^DD(90509.4,.02,0)),U,3)
 I DDATA[":MAIL" D
 . I NTYP="LETTER" S NTYP="MAIL"
 NEW DIC,DIE,X,DLAYGO,IEN,Y,PTPF,BQIUPD,BQIEXT,RMM,D
 S DIC="^BQI(90509.4,",DIE=DIC,X=DFN
 S DLAYGO=90509.4,DIC(0)="L",DIC("P")=DLAYGO
 K DO,DD D FILE^DICN
 S IEN=+Y I Y=-1 Q
 S PTPF=$$GET1^DIQ(9000001,DFN_",",4002,"E")
 S BQIUPD(90509.4,IEN_",",.05)=DUZ,BQIUPD(90509.4,IEN_",",.04)=$$NOW^XLFDT()
 S BQIEXT(90509.4,IEN_",",.02)=PTPF,BQIEXT(90509.4,IEN_",",.03)=NTYP
 S BQIUPD(90509.4,IEN_",",.06)=$G(TIUP),BQIUPD(90509.4,IEN_",",.07)=$G(PWHN)
 S BQIUPD(90509.4,IEN_",",.09)=$G(REM),BQIUPD(90509.4,IEN_",",.08)=$G(PROV)
 I REM="IMMUNIZATIONS" D IMM(DFN)
 I REM'="",REM'="IMMUNIZATIONS" D DUE(DFN,REM)
 I $D(BQIEXT) D FILE^DIE("E","BQIEXT","ERROR")
 I $D(BQIUPD) D FILE^DIE("","BQIUPD","ERROR")
 Q
 ;
IMM(BIDFN) ;EP - Expand immunization reminders
 NEW FRN,IT,RCDUE,OVDUE,REMDUE
 D IMM^BQIRMIZ(BIDFN)
 I '$D(^BQI(90509.4,IEN,1,0)) S ^BQI(90509.4,IEN,1,0)="^90509.41^^"
 S FRN=""
 F  S FRN=$O(^BIPDUE("B",BIDFN,FRN)) Q:FRN=""  D
 . S IT=$P(^BIPDUE(FRN,0),"^",2)
 . S RCDUE=$P(^BIPDUE(FRN,0),"^",4),OVDUE=$P(^(0),"^",5)
 . S REMDUE=$S(RCDUE'="":RCDUE,1:OVDUE)
 . S BTYP=$P(^AUTTIMM(IT,0),"^",2)
 . NEW DA,IENS
 . S DA(1)=IEN,X=BTYP,DIC="^BQI(90509.4,"_DA(1)_",1,",DIC(0)="L",DLAYGO=90509.41
 . D ^DIC S DA=+Y
 . S IENS=$$IENS^DILF(.DA),BQIUPD(90509.41,IENS,.02)=REMDUE
 I $D(BQIUPD) D FILE^DIE("","BQIUPD","ERROR")
 Q
 ;
DUE(BQDFN,REM) ;EP - Reminders from ICARE PATIENT file
 NEW RN,DUE
 S RN=$O(^BQIPAT(BQDFN,40,"B",REM,"")) I RN="" Q
 S DUE=$P(^BQIPAT(BQDFN,40,RN,0),U,4)
 S BQIUPD(90509.4,IEN_",",.1)=DUE
 Q
 ;
COMP(BQDFN,REM) ;EP - Set completion
 NEW RN,DUE,RMN,BQIUPD,NNIEN,IMN,LIMM,IMIEN,NDUE
 S RN=$O(^BQIPAT(BQDFN,40,"B",REM,"")) I RN'="" D
 . S DUE=$P(^BQIPAT(BQDFN,40,RN,0),U,4),LIMM=$P(^(0),U,2)
 . ;
 . S RMN=$O(^BQI(90509.4,"C",BQDFN,REM,""),-1) I RMN="" Q
 . S NDUE=$$GET1^DIQ(90509.4,RMN_",",.1,"I")
 . I DUE'="",NDUE'=DUE D
 .. I LIMM'="",LIMM>NDUE S BQIUPD(90509.4,RMN_",",.11)=LIMM
 ;
 I $D(BQIUPD) D FILE^DIE("I","BQIUPD","ERROR")
 I '$D(^BQI(90509.4,"C",BQDFN,"IMMUNIZATIONS")) Q
 ;
 S NNIEN=""
 F  S NNIEN=$O(^BQI(90509.4,"C",BQDFN,"IMMUNIZATIONS",NNIEN)) Q:NNIEN=""  D
 . S RMM=""
 . F  S RMM=$O(^BQI(90509.4,NNIEN,1,"B",RMM)) Q:RMM=""  D
 .. S RMN=$O(^BQI(90509.4,NNIEN,1,"B",RMM,""))
 .. S IMNM=$P(^BQI(90509.4,NNIEN,1,RMN,0),"^",1),DUE=$P(^(0),"^",2)
 .. S IMIEN=$O(^AUTTIMM("AC",IMNM,"")) I IMIEN="" Q
 .. S LIMM=$$LIMM^BQIREM(BQDFN,IMIEN),LIMM=$P(LIMM,"^",1)
 .. NEW DA,IENS
 .. S DA(1)=NNIEN,DA=RMN,IENS=$$IENS^DILF(.DA)
 .. I LIMM>DUE S BQIUPD(90509.41,IENS,.03)=LIMM
 I $D(BQIUPD) D FILE^DIE("I","BQIUPD","ERROR")
 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(BQII),$D(DATA) S BQII=BQII+1,@DATA@(BQII)=$C(31)
 Q
 ;
UPD(DATA,OWNR,PLIEN,BQINOTT,TIUDA,REMCODE,DFN) ; EP - BQI UPDATE REMINDER NOTIFY
 NEW UID
 S UID=$S($G(ZTSK):"Z"_ZTSK,1:$J)
 S DATA=$NA(^TMP("BQINOTUP",UID))
 K @DATA
 ;
 S BQII=0
 NEW $ESTACK,$ETRAP S $ETRAP="D ERR^BQINOTR D UNWIND^%ZTER" ; SAC 2006 2.2.3.3.2
 S @DATA@(BQII)="I00010RESULT^T01024MSG"_$C(30)
 S BQINOTT=$G(BQINOTT,""),TIUDA=$G(TIUDA,""),REMCODE=$G(REMCODE,"")
 I $G(OWNR),$G(PLIEN) D
 . S PRN=$O(^BQICARE(OWNR,1,PLIEN,10,"B","PROV","")) I PRN="" S PROV="" Q
 . S PROV=$P(^BQICARE(OWNR,1,PLIEN,10,PRN,0),U,3)
 K ERROR
 D LOG(DFN,BQINOTT,TIUDA,$G(IMML),$G(PWHN),REMCODE,PROV)
 S RESULT=1_U
 I $D(ERROR)>0 S RESULT=-1_U_$G(ERROR("DIERR","1","TEXT","1"))
 S BQII=BQII+1,@DATA@(BQII)=RESULT_$C(30)
 S BQII=BQII+1,@DATA@(BQII)=$C(31)
 Q
 ;
REF(DATA,OWNR,PLIEN,REMCODE,DFN) ;EP - BQI REFRESH REMINDER NOTIFY
 NEW UID
 S UID=$S($G(ZTSK):"Z"_ZTSK,1:$J)
 S DATA=$NA(^TMP("BQINOTRF",UID))
 K @DATA
 S HEADR="I00010DFN^",VALUE=DFN_U
 ;
 S BQII=0
 NEW $ESTACK,$ETRAP S $ETRAP="D ERR^BQINOTR D UNWIND^%ZTER" ; SAC 2006 2.2.3.3.2
 S GIEN=0,CRN=$O(^BQI(90506.5,"C","RE","")),RIEN=REMCODE
 F  S GIEN=$O(^BQI(90506.5,CRN,10,GIEN)) Q:'GIEN  D
 . S DIS=$P(^BQI(90506.5,CRN,10,GIEN,0),U,5),STVCD=$P(^(0),U,1)
 . I $P(^BQI(90506.5,CRN,10,GIEN,0),U,9)=1 S IFL=1 Q
 . S BQDTFRM=$P(^BQI(90506.5,CRN,10,GIEN,0),U,8) S:BQDTFRM="" BQDTFRM="S"
 . S RES=$$FND^BQICMUTL(CRN,GIEN,DFN)
 . I 'RES S HDR="T00025"_STVCD,VAL="" Q
 . I DIS="" S HDR="T00025"_STVCD,VAL=RES
 . I DIS="D" D
 .. S HDR="T00025"_STVCD
 .. S VAL=$S(BQDTFRM="S":$$FMTE^BQIUL1($P(RES,U,2)),1:$$FMTMDY^BQIUL1($P(RES,U,2)))
 . I DIS="R" S HDR="T00025"_STVCD,VAL=$P(RES,U,2)
 . I DIS="B" D
 .. S HDR="T00025"_STVCD
 .. S VAL=$S(BQDTFRM="S":$$FMTE^BQIUL1($P(RES,U,2)),1:$$FMTMDY^BQIUL1($P(RES,U,2)))_" "_$P(RES,U,3)
 . S HEADR=HEADR_HDR_U
 . S VALUE=VALUE_VAL_U
 S HEADR=$$TKO^BQIUL1(HEADR,"^")
 S VALUE=$$TKO^BQIUL1(VALUE,"^")
 ;
 S @DATA@(BQII)=HEADR_$C(30)
 S BQII=BQII+1,@DATA@(BQII)=VALUE_$C(30)
 S BQII=BQII+1,@DATA@(BQII)=$C(31)
 Q
 ;
LNOT(BQIDFN) ;EP - Get the last patient's notification information
 NEW DATE,NIEN,TYPE,IEN
 I $O(^BQI(90509.4,"D",BQIDFN,""))="" Q ""
 S DATE=$O(^BQI(90509.4,"D",BQIDFN,""),-1) I DATE="" Q ""
 S NIEN=$O(^BQI(90509.4,"D",BQIDFN,DATE,""),-1) I NIEN="" Q ""
 S TYPE=$P($G(^BQI(90509.4,NIEN,0)),"^",9) I TYPE="" Q ""
 I TYPE["IMMUNIZATION" Q $$FMTE^XLFDT(DATE,"5Z")_" ("_TYPE_")"
 I TYPE="PWH" Q $$FMTE^XLFDT(DATE,"5Z")_" (Patient Wellness)"
 S IEN=""
 I TYPE["_" S IEN=$O(^BQI(90506.1,"B",TYPE,IEN))
 I IEN'="" S TYPE=$P(^BQI(90506.1,IEN,0),"^",3)
 Q $$FMTE^XLFDT(DATE,"5Z")_$S(TYPE'="":" ("_TYPE_")",1:"")
 ;
LIMM(BQIDFN) ;EP - Get the last immunization notification for a patient
 NEW TYPE,NIEN,DATE
 S TYPE="IMMUNIZATIONS"
 I $O(^BQI(90509.4,"C",BQIDFN,"IMMUNIZATIONS",""))="" Q ""
 S NIEN=$O(^BQI(90509.4,"C",BQIDFN,"IMMUNIZATIONS",""),-1) I NIEN="" Q ""
 S DATE=$P(^BQI(90509.4,NIEN,0),"^",4)\1
 Q $$FMTE^XLFDT(DATE,"5Z")