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

BQITDGN.m

Go to the documentation of this file.
  1. BQITDGN ;PRXM/HC/ALA-General Taxonomy Diagnosis Category ; 10 Apr 2006 6:53 PM
  1. ;;2.1;ICARE MANAGEMENT SYSTEM;;Feb 07, 2011
  1. Q
  1. ;
  1. POP(BQARY,TGLOB,KEEP) ; EP -- By population
  1. ;
  1. ;Description
  1. ; Finds all patients who meet the criteria passed in array BQARY
  1. ;Input
  1. ; BQARY - Array of taxonomies and other information
  1. ; Format: BQARY(#)=TAX^TYPE^NIT^TMFRAME^FREF^PLFLG^SAME
  1. ; TGLOB - Global where data is to be stored and passed back
  1. ; to calling routine
  1. ; Structure:
  1. ; TGLOB(DFN,"CRITERIA",criteria or taxonomy,visit or problem ien)=date/time
  1. ;Variables
  1. ; TAX - Taxonomy name
  1. ; NIT - Number of iterations
  1. ; TMFRAME - Time frame of check, this is a relative date (T-12M)
  1. ; FREF - File Number reference
  1. ; PLFLG - Active Problem flag
  1. ; SAME - Check flag for instance on same date
  1. ; GREF - Global reference
  1. ; TREF - Taxonomy temp reference
  1. ; TPGLOB - Temporary global reference for Problem File instances
  1. ; KEEP - Keep the temporary global when passed from another logic definition
  1. ; EXDT - Expiration date
  1. ; DTDIF - difference between the start and end dates of the timeframe
  1. ; STDT - Start date of the timeframe
  1. ; ENDT - End date of the timeframe
  1. ; PRIM - Clinical ranking e.g. primary diagnosis only or primary/secondary.
  1. ; SERV - Visit service categories
  1. ;
  1. NEW N,TAX,NIT,TMFRAME,FREF,GREF,TREF,STDT,GLOBAL,IEN,TIEN,VISIT,VSDTM,ENDT
  1. NEW TPGLOB,SAME,EXDT,DTDIF,TPRGL,PRIM,SERV,VSERV
  1. S KEEP=$G(KEEP,0)
  1. S TPGLOB=$NA(^TMP("TEMP",UID))
  1. ; if KEEP is zero (do not keep any previous data passed), clean out the temporary
  1. ; global
  1. I 'KEEP K @TPGLOB
  1. ; For each defined taxonomy set up into an array from File 90506.2
  1. I $D(@BQARY) D
  1. . S N=0 F S N=$O(@BQARY@(N)) Q:'N D
  1. .. D PROC
  1. .. S DFN=0
  1. .. F S DFN=$O(@TPGLOB@(DFN)) Q:'DFN D
  1. ... I '$D(@TGLOB@(DFN)) M @TGLOB@(DFN)=@TPGLOB@(DFN)
  1. .. ;
  1. .. I 'KEEP K @TPGLOB
  1. .. Q
  1. I $D(@TPGLOB) K @TPGLOB
  1. I $D(@TREF) K @TREF
  1. I $D(@TPRGL) K @TPRGL
  1. K DFN,PLFLG,GLBL,PC,STDT
  1. Q
  1. ;
  1. PROC ;Process each entry
  1. S TAX=$P(@BQARY@(N),U,1),NIT=$P(@BQARY@(N),U,3)
  1. S TMFRAME=$P(@BQARY@(N),U,4),FREF=$P(@BQARY@(N),U,5)
  1. S PLFLG=+$P(@BQARY@(N),U,6),SAME=+$P(@BQARY@(N),U,7)
  1. S PRIM=+$P(@BQARY@(N),U,8),SERV=$P(@BQARY@(N),U,9)
  1. S EXDT="",DTDIF=""
  1. I TMFRAME'="" D
  1. . S ENDT=$$DATE^BQIUL1(TMFRAME),STDT=$$DT^XLFDT()
  1. . S DTDIF=$$FMDIFF^XLFDT(STDT,ENDT,1)
  1. S GREF=$$ROOT^DILFD(FREF,"",1)
  1. S TPRGL=$NA(^TMP("TPRBLM",UID)) K @TPRGL
  1. ; Build the taxonomy reference
  1. S TREF=$NA(^TMP("BQITAX",UID))
  1. K @TREF
  1. D BLD^BQITUTL(TAX,TREF)
  1. ; For each entry in the taxonomy reference
  1. S TIEN="" F S TIEN=$O(@TREF@(TIEN)) Q:TIEN="" D
  1. . ; If problem flag, check the problem file for any instances of
  1. . ; the taxonomy entry
  1. . I PLFLG D PRB(TIEN,TPRGL) Q
  1. ; For each entry in the appropriate file (GREF), starting with most recent
  1. ; look for patients with instances for each taxonomy entry
  1. S DFN=""
  1. F S DFN=$O(@TPRGL@(DFN)) Q:DFN="" M @TGLOB@(DFN)=@TPRGL@(DFN)
  1. S TIEN=""
  1. F S TIEN=$O(@TREF@(TIEN)) Q:TIEN="" D
  1. . S IEN=""
  1. . F S IEN=$O(@GREF@("B",TIEN,IEN),-1) Q:IEN="" D
  1. .. ; if a bad record (no zero node), quit
  1. .. I $G(@GREF@(IEN,0))="" Q
  1. .. ; get patient record
  1. .. S DFN=$$GET1^DIQ(FREF,IEN,.02,"I") Q:DFN=""
  1. .. ; if the patient already has a problem instance, quit
  1. .. ;I $D(@TPRGL@(DFN))>0,$D(@TGLOB@(DFN)) M @TGLOB@(DFN)=@TPRGL@(DFN) Q
  1. .. I $D(@TGLOB@(DFN)) Q
  1. .. ; get the visit information
  1. .. S VISIT=$$GET1^DIQ(FREF,IEN,.03,"I") Q:VISIT=""
  1. .. ; if the visit is deleted, quit
  1. .. I $$GET1^DIQ(9000010,VISIT,.11,"I")=1 Q
  1. .. ; check clinical ranking if diagnosis (9000010.07)
  1. .. I FREF=9000010.07,PRIM I $P(@GREF@(IEN,0),U,12)'="P" S MFL=0 D Q:'MFL
  1. ... I $O(@GREF@("AD",VISIT,""))=IEN S MFL=1
  1. .. ; check clinical ranking if procedure (9000010.18 or 9000010.08)
  1. .. I (FREF=9000010.18)!(FREF=9000010.08)&(PRIM) I $P(@GREF@(IEN,0),U,7)'="P" S MFL=0 D Q:'MFL
  1. ... I $O(@GREF@("AD",VISIT,""))=IEN S MFL=1
  1. .. S VSDTM=$$GET1^DIQ(9000010,VISIT,.01,"I")\1 Q:VSDTM=0
  1. .. ; if there is a specified timeframe for the visit and the
  1. .. ; visit date doesn't fall within that timeframe, quit
  1. .. I $G(TMFRAME)'="",VSDTM<ENDT Q
  1. .. ; if service categories, check the visit for the service category
  1. .. S VSERV=$$GET1^DIQ(9000010,VISIT,.07,"I")
  1. .. I $G(SERV)'="",SERV'[VSERV Q
  1. .. ; if the SAME day flag is zero then the value cannot be on the same day
  1. .. ; if there is already a value for this date, quit
  1. .. I 'SAME,$D(@TPGLOB@(DFN,"VISIT",VSDTM)) Q
  1. .. ; if the patient has already met the number of interations, quit
  1. .. I $G(@TPGLOB@(DFN))'<NIT Q
  1. .. ; set the qualifying criteria for this patient and diagnostic category
  1. .. I DTDIF'="" S EXDT=$$FMADD^XLFDT(VSDTM,DTDIF)
  1. .. S @TPGLOB@(DFN,"CRITERIA",TAX,"V",VISIT,IEN)=VSDTM
  1. .. S $P(@TPGLOB@(DFN,"CRITERIA",TAX,"V",VISIT,IEN),U,3)=IEN_U_FREF
  1. .. I EXDT'="" S $P(@TPGLOB@(DFN,"CRITERIA",TAX,"V",VISIT,IEN),U,2)=EXDT
  1. .. S @TPGLOB@(DFN,"VISIT",VSDTM)=""
  1. .. S @TPGLOB@(DFN)=$G(@TPGLOB@(DFN))+1
  1. S DFN=""
  1. F S DFN=$O(@TPGLOB@(DFN)) Q:DFN="" D
  1. . K @TPGLOB@(DFN,"VISIT")
  1. . I @TPGLOB@(DFN)<NIT K @TPGLOB@(DFN)
  1. Q
  1. ;
  1. PAT(BQARY,TGLOB,PTDFN,KEEP) ; EP -- By patient
  1. ;Description
  1. ; Checks if a patient meets the criteria
  1. ;Input
  1. ; BQARY - Array of taxonomies and other information
  1. ; DFN - patient internal entry number
  1. ;
  1. S KEEP=$G(KEEP,0)
  1. NEW TPGLOB
  1. S TPGLOB=$NA(^TMP("TEMP",UID))
  1. I 'KEEP K @TPGLOB
  1. NEW N,TAX,NIT,TMFRAME,FREF,GREF,TREF,STDT,GLOBAL,IEN
  1. NEW TIEN,VISIT,VSDTM,SAME,PROB,TPRGL,PRIM,SERV,VSERV
  1. S N=0 F S N=$O(@BQARY@(N)) Q:'N D
  1. . D PROCP
  1. . I '$D(@TGLOB@(PTDFN)) M @TGLOB@(PTDFN)=@TPGLOB@(PTDFN)
  1. . I 'KEEP K @TPGLOB
  1. . Q
  1. K @TPGLOB@(PTDFN,"VISIT")
  1. I '$D(@TGLOB@(PTDFN)),$G(@TPGLOB@(PTDFN))<NIT K @TPGLOB Q 0
  1. D FIL Q 1
  1. ;
  1. FIL ;
  1. M @TGLOB@(PTDFN,"CRITERIA")=@TPGLOB@(PTDFN,"CRITERIA")
  1. S @TGLOB@(PTDFN)=$G(@TGLOB@(PTDFN))+$G(@TPGLOB@(PTDFN))
  1. Q
  1. ;
  1. PROCP ; Process one patient
  1. S TAX=$P(@BQARY@(N),U,1),NIT=$P(@BQARY@(N),U,3)
  1. S TMFRAME=$P(@BQARY@(N),U,4),FREF=$P(@BQARY@(N),U,5)
  1. S PLFLG=+$P(@BQARY@(N),U,6),SAME=+$P(@BQARY@(N),U,7)
  1. S PRIM=+$P(@BQARY@(N),U,8),SERV=$P(@BQARY@(N),U,9)
  1. S EXDT="",DTDIF=""
  1. I TMFRAME'="" D
  1. . S ENDT=$$DATE^BQIUL1(TMFRAME),STDT=$$DT^XLFDT()
  1. . S DTDIF=$$FMDIFF^XLFDT(STDT,ENDT,1)
  1. S GREF=$$ROOT^DILFD(FREF,"",1),TREF=$NA(^TMP("BQITAX",UID))
  1. K @TREF
  1. S TPRGL=$NA(^TMP("TPRBLM",UID)) K @TPRGL
  1. D BLD^BQITUTL(TAX,TREF)
  1. I PLFLG D PPRB(PTDFN,TPRGL) I $D(@TPRGL@(PTDFN))>0,'$D(@TGLOB@(PTDFN)) M @TGLOB@(PTDFN)=@TPRGL@(PTDFN) Q
  1. S IEN=""
  1. F S IEN=$O(@GREF@("AC",PTDFN,IEN),-1) Q:'IEN D
  1. . S TIEN=$$GET1^DIQ(FREF,IEN,.01,"I") I TIEN="" Q
  1. . I '$D(@TREF@(TIEN)) Q
  1. . S VISIT=$$GET1^DIQ(FREF,IEN,.03,"I") I VISIT="" Q
  1. . I $$GET1^DIQ(9000010,VISIT,.11,"I")=1 Q
  1. . ; check clinical ranking if diagnosis (9000010.07)
  1. . I FREF=9000010.07,PRIM I $P(@GREF@(IEN,0),U,12)'="P" S MFL=0 D Q:'MFL
  1. .. I $O(@GREF@("AD",VISIT,""))=IEN S MFL=1
  1. . I (FREF=9000010.18)!(FREF=9000010.08)&(PRIM) I $P(@GREF@(IEN,0),U,7)'="P" S MFL=0 D Q:'MFL
  1. .. I $O(@GREF@("AD",VISIT,""))=IEN S MFL=1
  1. . S VSDTM=$$GET1^DIQ(9000010,VISIT,.01,"I")\1 I VSDTM=0 Q
  1. . I $G(TMFRAME)'="",VSDTM<ENDT Q
  1. . ; if service categories, check the visit for the service category
  1. . S VSERV=$$GET1^DIQ(9000010,VISIT,.07,"I")
  1. . I $G(SERV)'="",SERV'[VSERV Q
  1. . ; if the SAME day flag is zero then the value cannot be on the same day
  1. . ; if there is already a value for this date, quit
  1. . I 'SAME,$D(@TPGLOB@(PTDFN,"VISIT",VSDTM)) Q
  1. . I $G(@TPGLOB@(PTDFN))'<NIT Q
  1. . I DTDIF'="" S EXDT=$$FMADD^XLFDT(VSDTM,DTDIF)
  1. . S @TPGLOB@(PTDFN,"CRITERIA",TAX,"V",VISIT,IEN)=VSDTM
  1. . S $P(@TPGLOB@(PTDFN,"CRITERIA",TAX,"V",VISIT,IEN),U,3)=IEN_U_FREF
  1. . I EXDT'="" S $P(@TPGLOB@(PTDFN,"CRITERIA",TAX,"V",VISIT,IEN),U,2)=EXDT
  1. . S @TPGLOB@(PTDFN,"VISIT",VSDTM)=""
  1. . S @TPGLOB@(PTDFN)=$G(@TPGLOB@(PTDFN))+1
  1. K @TPGLOB@(PTDFN,"VISIT")
  1. I $G(@TPGLOB@(PTDFN))<NIT K @TPGLOB@(PTDFN)
  1. Q
  1. ;
  1. PRB(PVIEN,BQTGLB) ;EP - Check Problem File for instance of taxonomy
  1. ; Input
  1. ; PVIEN - Taxonomy entry
  1. ; TPGLOB - Problem file temporary global reference
  1. NEW IEN,PGREF,PFREF
  1. ; Go through the problem file, starting with the most recent entry
  1. S IEN="",PGREF="^AUPNPROB",PFREF=9000011
  1. F S IEN=$O(@PGREF@("B",PVIEN,IEN),-1) Q:IEN="" D
  1. . ; get the patient record
  1. . S DFN=$$GET1^DIQ(PFREF,IEN,.02,"I") I DFN="" Q
  1. . ; if there is already a problem instance for this patient, quit
  1. . I $G(@BQTGLB@(DFN))=1 Q
  1. . ; get the date of the problem, since not all dates exist, the
  1. . ; hierachy is 'DATE OF ONSET', 'DATE ENTERED', and then 'DATE LAST MODIFIED'.
  1. . ;
  1. . ; Check class - if Family ignore
  1. . I $$GET1^DIQ(PFREF,IEN,.04,"I")="F" Q
  1. . S VSDTM=$$PROB^BQIUL1(IEN)\1 Q:VSDTM=0
  1. . ; if there is a specified timeframe for the instance and the
  1. . ; problem date doesn't fall within that timeframe, quit
  1. . I $G(TMFRAME)'="",VSDTM<ENDT Q
  1. . ; if the problem is not an 'active' one, quit
  1. . I $$GET1^DIQ(PFREF,IEN,.12,"I")'="A" Q
  1. . ; set the qualifying criteria for this patient and diagnostic category
  1. . I DTDIF'="" S EXDT=$$FMADD^XLFDT(VSDTM,DTDIF)
  1. . S @BQTGLB@(DFN,"CRITERIA",TAX,"P",IEN)=VSDTM
  1. . I EXDT'="" S $P(@BQTGLB@(DFN,"CRITERIA",TAX,"P",IEN),U,2)=EXDT
  1. . S @BQTGLB@(DFN)=$G(@BQTGLB@(DFN))+1
  1. Q
  1. ;
  1. PPRB(DFN,BQTGLB) ;EP - Check Problem File for instance of a patient
  1. NEW PGREF,PFREF,PVIEN,VSDTM
  1. S PGREF="^AUPNPROB",PFREF=9000011,PROB=0
  1. S PVIEN=""
  1. F S PVIEN=$O(@PGREF@("AC",DFN,PVIEN),-1) Q:PVIEN="" D Q:PROB
  1. . S TIEN=$$GET1^DIQ(PFREF,PVIEN,.01,"I") I TIEN="" Q
  1. . I '$D(@TREF@(TIEN)) Q
  1. . ; Check class - if Family ignore
  1. . I $$GET1^DIQ(PFREF,PVIEN,.04,"I")="F" Q
  1. . I $$GET1^DIQ(PFREF,PVIEN,.12,"I")'="A" Q
  1. . S VSDTM=$$PROB^BQIUL1(PVIEN)\1 Q:VSDTM=0
  1. . I $G(TMFRAME)'="",VSDTM<ENDT Q
  1. . I '$D(@BQTGLB@(DFN,PVIEN,VSDTM)) D
  1. .. S @BQTGLB@(DFN,PVIEN,VSDTM)=$G(@BQTGLB@(DFN,PVIEN,VSDTM))+1
  1. .. I DTDIF'="" S EXDT=$$FMADD^XLFDT(VSDTM,DTDIF)
  1. .. S @BQTGLB@(DFN,"CRITERIA",TAX,"P",PVIEN)=VSDTM
  1. .. I EXDT'="" S $P(@BQTGLB@(DFN,"CRITERIA",TAX,"P",PVIEN),U,2)=EXDT
  1. .. S @BQTGLB@(DFN)=$G(@BQTGLB@(DFN))+1
  1. .. S PROB=1
  1. Q