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

BKMSTID1.m

Go to the documentation of this file.
BKMSTID1 ;PRXM/HC/ALA-STI Display ; 20 Mar 2007  2:23 PM
 ;;2.1;HIV MANAGEMENT SYSTEM;;Feb 07, 2011
 ;
EN(BKMDFN,RPSDT,RPEDT,BKTYPE,BKARRAY,BKSTIY) ;
 ; 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
 ;
 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,QFL,SSCREEN
 NEW TOT,BKIN,BKN,HSCR,POP,INC,SDAT,STYP,BKBDT,BKEDT,CT,BKMARRAY
 NEW TOTIN,INCD,INCS
 ;
 S BKTYPE=$G(BKTYPE,"KEY"),HVDFL=0,AUPNPAT=BKMDFN
 K BKARRAY,BKSTIN,BKSTIY S QFL=0
 S BKBDT=$$FMADD^XLFDT(RPSDT,-60),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
 F  S INC=$O(BKSTIN(INC)) Q:INC=""  D
 . S STYP=""
 . F  S STYP=$O(BKSTIN(INC,STYP)) Q:STYP=""  D
 .. 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)
 ;
 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 RC=""
 ... F  S RC=$O(BKARRAY(TYP,"NUM",RC)) Q:RC=""  D
 .... I +$G(BKSTIN(INC,TYP,DAT,RC))=0 D
 ..... I $D(BKSTIN(INC,RC)) Q
 ..... I HVDFL,RC="HIV" Q
 ..... S BKSTIN(INC,TYP,DAT,RC)=$G(BKARRAY(TYP,"NUM",RC,DAT))
 ..... ;S:BKSTIN(INC,TYP,DAT,RC)="" BKSTIN(INC,TYP,DAT,RC)=0
 ... ;
 ... S RC=""
 ... F  S RC=$O(BKARRAY(TYP,"REF",RC)) Q:RC=""  D
 .... I +$G(BKSTIN(INC,TYP,DAT,RC))=0 D
 ..... I $D(BKSTIN(INC,RC)) Q
 ..... I HVDFL,RC="HIV" Q
 ..... S BKSTIN(INC,TYP,DAT,RC)=$S($G(BKARRAY(TYP,"REF",RC,DAT))="":0,1:1_U_$G(BKARRAY(TYP,"REF",RC,DAT)))
 ..... I $G(BKARRAY(TYP,"REF",RC,DAT))'="" S REF(BKARRAY(TYP,"REF",RC,DAT))=""
 ..... ;S:BKSTIN(INC,TYP,DAT,RC)="" BKSTIN(INC,TYP,DAT,RC)=0
 ;
 S INC=0
 F  S INC=$O(BKSTIN(INC)) Q:INC=""  D
 . S TYP="" F  S TYP=$O(BKSTIN(INC,TYP)) Q:TYP=""  D
 .. S $P(BKSTIY(INC,0),U,1)=$P($G(BKSTIY(INC,0)),U,1)+1
 .. S DAT="" F  S DAT=$O(BKSTIN(INC,TYP,DAT)) Q:DAT=""  D
 ... S INCD=$$FMTE^XLFDT(DAT,"2Z")_" "_BKSTIN(INC,TYP,DAT)
 ... S $P(BKSTIY(INC,TYP,0),U,1)=$P($G(BKSTIY(INC,TYP,0)),U,1)+1
 ... S $P(BKSTIY(INC,TYP,0),U,5)=INCD
 ... ;S $P(BKSTIY(INC,0),U,5)=$P(BKSTIY(INC,0),U,5)_INCD_"; "
 ... S RC="" F  S RC=$O(BKSTIN(INC,TYP,DAT,RC)) Q:RC=""  D
 .... S BKSTIY("Z",INC,RC,DAT)=BKSTIN(INC,TYP,DAT,RC)
 .... Q
 ;
 K NS,SD,RF
 S INC=0
 F  S INC=$O(BKSTIY(INC)) Q:INC=""  D
 . S RC=""
 . F  S RC=$O(BKSTIY("Z",INC,RC)) Q:RC=""  D
 .. S DAT=""
 .. F  S DAT=$O(BKSTIY("Z",INC,RC,DAT)) Q:DAT=""  D
 ... S NS(INC,RC)=$G(NS(INC,RC))+1
 ... I $P(BKSTIY("Z",INC,RC,DAT),U,1)=1 S SD(INC,RC)=$G(SD(INC,RC))+1,INCD(INC,RC)=$G(INCD(INC,RC))_$P(BKSTIY("Z",INC,RC,DAT),U,2)_"; "
 ... I $P(BKSTIY("Z",INC,RC,DAT),U,2)["REF " S RF(INC,RC)=$G(RF(INC,RC))+1
 ... S:$G(SD(INC,RC))="" SD(INC,RC)=0
 ... S:$G(RF(INC,RC))="" RF(INC,RC)=0
 ;
 K BKSTIY("Z")
 ;
 S INC=0
 F  S INC=$O(NS(INC)) Q:INC=""  D
 . S RC=""
 . F  S RC=$O(NS(INC,RC)) Q:RC=""  D
 .. S $P(BKSTIY(INC,RC),U,1)=NS(INC,RC)
 ;
 S INC=0
 F  S INC=$O(SD(INC)) Q:INC=""  D
 . S RC=""
 . F  S RC=$O(SD(INC,RC)) Q:RC=""  D
 .. S $P(BKSTIY(INC,RC),U,2)=SD(INC,RC)
 ;
 S INC=0
 F  S INC=$O(RF(INC)) Q:INC=""  D
 . S RC=""
 . F  S RC=$O(RF(INC,RC)) Q:RC=""  D
 .. S $P(BKSTIY(INC,RC),U,3)=RF(INC,RC)
 ;
 S INC=0
 F  S INC=$O(INCD(INC)) Q:INC=""  D
 . S RC=""
 . F  S RC=$O(INCD(INC,RC)) Q:RC=""  D
 .. S $P(BKSTIY(INC,RC),U,4)=INCD(INC,RC)
 ;
 S TOTIN=0,TOTNS=0,TOTSD=0,TOTRF=0
 S INC=0
 F  S INC=$O(BKSTIY(INC)) Q:INC=""  D
 . S TOTIN=TOTIN+$P(BKSTIY(INC,0),U,1)
 . S TYP=0 F  S TYP=$O(BKSTIY(INC,TYP)) Q:TYP=""  D
 .. I $G(BKSTIY(INC,TYP,0))'="" Q
 .. ;F TI=1:1:3 S:$P(BKSTIY(INC,TYP),U,TI)="" $P(BKSTIY(INC,TYP),U,TI)=0
 .. 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
 K BKARRAY,BKSTIN
 Q
 ;
INC ;EP - Determine multiple incidences
 NEW TYP,DAT,INC,PDAT,NXDT,NTYP,DTDIF
 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 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 NXDT=DAT F  S NXDT=$O(MBKARAY(NXDT)) Q:NXDT=""  D
 .. I NXDT<DTDIF D
 ... 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
 . S BKSTIN(INC,TYP,VDT)=MBKARAY(VDT,TYP)
 Q