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

BKMSTIDS.m

Go to the documentation of this file.
BKMSTIDS ;VNGT/HS/ALA-STI Incidences ; 20 Jun 2011  4:41 PM
 ;;2.2;HIV MANAGEMENT SYSTEM;**1**;Apr 01, 2015;Build 17
 ;
EN(BKMDFN,RPSDT,RPEDT,BKTYPE,BKARRAY,BKSTIY,MUL) ; PEP
 ; Input parameters
 ;   BKMDFN  - Patient internal entry number
 ;   RPSDT   - Report start date in FileMan date format
 ;   RPEDT   - Report end date in FileMan date format
 ;   BKTYPE  - Type of STI data, defaults to 'Key'
 ;   BKARRAY - Array to return raw data
 ;   BKSTIY  - Array to return data by totals
 ;   MUL     - Multiple HIV events okay if 1 (default is 0 or no)
 ;
 NEW DIR,Y,X,DTOUT,DUOUT,DFN,SEX,SSN,PTNAME,AGE,AUPNDAYS,AUPNDOB
 NEW AUPNPAT,AUPNDOD,AUPNSEX,SIEN,STINM,STI,NIN,DDATA,RSTI,NSTI,RSTINM
 NEW RSTNM,RSIEN,NSIEN,NRSCR,HVDFL,BKTYPE,NCT,NSCR,RFL,SCREEN,LR,NTSCR
 NEW TOT,BKIN,BKN,HSCR,POP,INC,SDAT,STYP,BKBDT,BKEDT,CT,BKMARRAY,BSN
 NEW TOTIN,INCD,INCS,TOTNS,TOTRF,TOTSD,RC,TVALN,QFL,SSCREEN,BKSTY,BN
 NEW ZARRAY,NDEN,NNUM,TOTGD,TOTGN,FLAG,COLDTM,CPT,DAT,PRNM,TXN,TYP,NREF,TOTGR
 NEW HNUM,IHVDFL,NKREF,RDT,RF,NKNUM,NKSTY,MTYP
 ;
 S BKTYPE=$G(BKTYPE,"KEY"),HVDFL=0,AUPNPAT=BKMDFN,MUL=$G(MUL,0)
 K BKARRAY,BKSTIN,BKSTIY S QFL=0
 ;S BKBDT=$$FMADD^XLFDT(RPSDT,-60),BKEDT=$$FMADD^XLFDT(RPSDT,300)
 S BKBDT=$$FMADD^XLFDT(RPSDT,-(30.4167*2)),BKEDT=$$FMADD^XLFDT(RPSDT,300)
 D EN^BKMSTI(AUPNPAT,BKBDT,BKEDT,BKTYPE,.BKARRAY,.HVDFL)
 I '$D(BKARRAY) S BKSTIY(0)=0 Q
 I $D(BKARRAY) D
 . NEW STI
 . S STI=""
 . F  S STI=$O(BKARRAY(STI)) Q:STI=""  D  Q:QFL
 .. I $G(BKARRAY(STI,"DEN"))'=0 S QFL=1 Q
 I 'QFL K BKARRAY S BKSTIY(0)=0 Q
 D INC
 ;  clean up extras values not needed
 S INC=0,HNUM=0
 F  S INC=$O(BKSTIN(INC)) Q:INC=""  D
 . S STYP="",NDEN(INC)=0,NNUM(INC)=0,QFL=0
 . F  S STYP=$O(BKSTIN(INC,STYP)) Q:STYP=""  D
 .. I STYP="HIV" S HNUM=HNUM+1
 .. S SDAT="",CT=0
 .. F  S SDAT=$O(BKSTIN(INC,STYP,SDAT)) Q:SDAT=""  D
 ... S CT=CT+1
 ... I CT>1 K BKSTIN(INC,STYP,SDAT)
 ... I 'MUL,HNUM>1,STYP="HIV" K BKSTIN(INC,STYP,SDAT)
 ;
CMP ; Compile raw data
 S INC=0
 F  S INC=$O(BKSTIN(INC)) Q:INC=""  D
 . K REC,NBREC,NREC
 . S TOTIN=0
 . S TYP="" F  S TYP=$O(BKSTIN(INC,TYP)) Q:TYP=""  D
 .. S DAT=""
 .. F  S DAT=$O(BKSTIN(INC,TYP,DAT)) Q:DAT=""  D
 ... S BKN=$O(^BKM(90454,"D",TYP,""))
 ... S BKSTIY(INC,TYP,0)=1_"^^^^"_$$FMTE^XLFDT(DAT,"2Z")_" "_BKSTIN(INC,TYP,DAT),TOTIN=TOTIN+1
 ... S BN=0
 ... F  S BN=$O(^BKM(90454,BKN,10,BN)) Q:'BN  D
 .... S BSN=$P(^BKM(90454,BKN,10,BN,0),"^",1)
 .... S BKSTY=$P(^BKM(90454,BSN,0),"^",3),HVDFL=0
 .... I $D(BKSTIY(INC,BKSTY))>0 Q
 .... I $D(BKSTIN(INC,BKSTY))>0 Q
 .... I BKSTY="HIV" D
 ..... NEW HKDATE,HEDATE,HSRDT
 ..... S HKDATE="",HEDATE=DAT
 ..... S HVDFL=$$HIVS^BKMRMDR(.BKMDFN,.HKDATE,.HEDATE)
 ..... I +HVDFL=1 D
 ...... I HVDFL["POV" S BKSTIY(INC,BKSTY)="0^0^^"_$P(HVDFL,U,2),IHVDFL=1 Q
 ...... S HSRDT=$$FMADD^XLFDT(BKBDT,-(30.4167*1))
 ...... I $P(HVDFL,U,3)<HSRDT D
 ....... I $G(BKARRAY(TYP,"NUM",BKSTY,DAT))="" S BKSTIY(INC,BKSTY)="1^0^^" Q
 ....... S BKSTIY(INC,BKSTY)=$G(BKARRAY(TYP,"NUM",BKSTY,DAT))
 ...... S BKSTIY(INC,BKSTY)="1^1^^"_$P(HVDFL,U,2)
 ..... ;I +HVDFL=1 S IHVDFL=1 Q
 ..... I +HVDFL=0 S BKSTIY(INC,BKSTY)=$G(BKARRAY(TYP,"NUM",BKSTY,DAT))
 .... I +HVDFL=1 Q
 .... S BKSTIY(INC,BKSTY)=1
 .... I $G(BKARRAY(TYP,"NUM",BKSTY,DAT))'="" D
 ..... S $P(BKSTIY(INC,BKSTY),"^",2)=1
 ..... S $P(BKSTIY(INC,BKSTY),"^",4)=$P(BKARRAY(TYP,"NUM",BKSTY,DAT),"^",2)
 .... I $G(BKARRAY(TYP,"REF",BKSTY,DAT))'="" D
 ..... ;S $P(BKSTIY(INC,BKSTY),"^",2)=1
 ..... S $P(BKSTIY(INC,BKSTY),"^",3)=1
 ..... I $G(BKARRAY(TYP,"NUM",BKSTY,DAT))="" S $P(BKSTIY(INC,BKSTY),"^",4)=$P(BKARRAY(TYP,"REF",BKSTY,DAT),"^",1)
 ..... I $G(BKARRAY(TYP,"NUM",BKSTY,DAT))'="" S $P(BKSTIY(INC,BKSTY),"^",3)=0
 .. D NG(INC,TYP)
 . S BKSTIY(INC,0)=TOTIN
 ;
 S TOTIN=0,TOTNS=0,TOTSD=0,TOTRF=0,TOTGD=0,TOTGN=0,TOTGR=0
 S INC=0
 F  S INC=$O(BKSTIY(INC)) Q:INC=""  D
 . S TOTIN=TOTIN+$P(BKSTIY(INC,0),U,1)
 . ;S TOTGD=TOTGD+NDEN(INC),TOTGN=TOTGN+NNUM(INC)
 . S TOTGD=TOTGD+1,TOTGN=TOTGN+NNUM(INC),TOTGR=TOTGR+NREF(INC)
 . S TYP=0 F  S TYP=$O(BKSTIY(INC,TYP)) Q:TYP=""  D
 .. I $G(BKSTIY(INC,TYP,0))'="" Q
 .. S TOTNS=TOTNS+$P(BKSTIY(INC,TYP),U,1)
 .. S TOTSD=TOTSD+$P(BKSTIY(INC,TYP),U,2)
 .. S TOTRF=TOTRF+$P(BKSTIY(INC,TYP),U,3)
 ;
 S BKSTIY(0)=TOTIN_U_TOTNS_U_TOTSD_U_TOTRF_U_TOTGD_U_TOTGN_U_TOTGR
 K BKSTIN
 ;TOTIN = Total number of incidences
 ;TOTNS = Total number of screenings needed
 ;TOTSD = Total number of screenings done
 ;TOTRF = Total number of refusals
 ;TOTGD = Total number of 'grouped' denominators
 ;TOTGN = Total number of 'grouped' numerators
 ;TOTGR = Total number of 'grouped' refusals
 Q
 ;
INC ;EP - Determine multiple incidences
 NEW TYP,DAT,INC,PDAT,NXDT,NTYP,DTDIF,NM
 K MBKARAY,BKSTIN
 S TYP=""
 F  S TYP=$O(BKARRAY(TYP)) Q:TYP=""  D
 . S DAT=""
 . F  S DAT=$O(BKARRAY(TYP,"DEN",DAT)) Q:DAT=""  D
 .. S MBKARAY(DAT,TYP)=BKARRAY(TYP,"DEN",DAT)
 .. S NNUM=0,NM=""
 .. F  S NM=$O(BKARRAY(TYP,"NUM",NM)) Q:NM=""  I $G(BKARRAY(TYP,"NUM",NM))'=0 S NNUM=NNUM+1
 .. S ZARRAY("ZN",DAT,TYP)=NNUM
 .. S RF=""
 .. F  S RF=$O(BKARRAY(TYP,"REF",RF)) Q:RF=""  S RDT="" F  S RDT=$O(BKARRAY(TYP,"REF",RF,RDT)) Q:RDT=""  S ZARRAY("ZR",RDT,RF)=0
 ;
 S INC=0,DAT="",PDAT=""
 F  S DAT=$O(MBKARAY(DAT)) Q:DAT=""  D
 . S INC=INC+1 D SDT(DAT) K MBKARAY(DAT)
 . ;S DTDIF=$$FMADD^XLFDT(DAT,60)
 . S DTDIF=$$FMADD^XLFDT(DAT,(30.4167*2))
 . S NXDT=DAT F  S NXDT=$O(MBKARAY(NXDT)) Q:NXDT=""  D
 .. I NXDT<DTDIF D
 ... S MTYP=$O(BKSTIN(INC,""))
 ... D SDT(NXDT)
 ... K MBKARAY(NXDT)
 Q
 ;
SDT(VDT) ;EP - Same date, multiple types
 S TYP=""
 F  S TYP=$O(MBKARAY(VDT,TYP)) Q:TYP=""  D
 . I $G(MTYP)'="",MTYP=TYP Q
 . I $G(MTYP)'="",MTYP'=TYP S INC=INC+1
 . S BKSTIN(INC,TYP,VDT)=MBKARAY(VDT,TYP)
 Q
 ;
NG(NIN,NTYP) ;
 NEW BKN,BN,BSN,NKSTY,NKNUM,NKREF
 S BKN=$O(^BKM(90454,"D",NTYP,""))
 S BN=0,NKNUM=0,NKREF=0
 I $G(IHVDFL)=1 S NKNUM=1
 F  S BN=$O(^BKM(90454,BKN,10,BN)) Q:'BN  D
 . S BSN=$P(^BKM(90454,BKN,10,BN,0),"^",1)
 . S NKSTY=$P(^BKM(90454,BSN,0),"^",3)
 . S NKNUM=$P($G(BKSTIY(NIN,NKSTY)),"^",2)+NKNUM
 . S NKREF=$P($G(BKSTIY(NIN,NKSTY)),"^",3)+NKREF
 S NNUM(NIN)=$S(NKNUM=3:1,1:0)
 S NREF(NIN)=$S(NKREF>0&((NKREF+NKNUM)=3):1,1:0)
 Q