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

BQITD031.m

Go to the documentation of this file.
  1. BQITD031 ;PRXM/HC/ALA-CVD Known Definition ; 19 Jun 2006 5:01 PM
  1. ;;2.1;ICARE MANAGEMENT SYSTEM;;Feb 07, 2011
  1. ; Utilities called by BQITD03
  1. ;
  1. Q
  1. ;
  1. AMI(DFN,GLOB,TMREF,DXOK) ; EP - Process AMI date logic
  1. ;
  1. ; Within any two year period, at least two diagnoses of [whatever] and
  1. ; at least 90 days between first and last diagnosis (Revised logic definition)
  1. ;
  1. ; Input
  1. ; DFN - patient whose AMI diagnoses are being examined
  1. ; GLOB - Global where data is to be stored
  1. ; Structure:
  1. ; GLOB(DFN,"CRITERIA",criteria or taxonomy,visit or problem ien)=date/time
  1. ; TMREF - Global used to temporarily store diagnoses that may meet the
  1. ; AMI logic and, if so, will be stored in GLOB
  1. ; DXOK - If set to '1', patient meets the AMI logic for CVD Known - value
  1. ; may be returned (if called by PAT subroutine)
  1. ; Variables
  1. ; NOK - If set to '1', no diagnoses remaining that will meet the date logic
  1. ; LDX - Most recent diagnosis that meets the AMI criteria
  1. ; FDX - Other diagnosis that must be compared to LDX to determine if they
  1. ; meet the date logic
  1. ; STOP - Set to '1' if the date range exceeds the two year maximum so new
  1. ; value for LDX must be found
  1. ; VTYP - Visit type - either 'V' for visit or 'P' for problem
  1. N NOK,STOP,LDX,FDX,DX
  1. I $G(@TMREF@(DFN))<2 K @TMREF@(DFN) Q
  1. S DXOK=0,NOK=0
  1. F D Q:DXOK!NOK K @TMREF@(DFN,LDX)
  1. . S LDX=$O(@TMREF@(DFN,"A"),-1) I LDX="" S NOK=1 Q
  1. . S STOP=0,FDX=LDX
  1. . F S FDX=$O(@TMREF@(DFN,FDX),-1) Q:FDX="" D Q:DXOK!STOP
  1. .. I $$TYP(DFN,LDX,TMREF)="P",$$TYP(DFN,FDX,TMREF)="P" Q
  1. .. I $$FMDIFF^XLFDT(LDX,FDX,1)'<731 S STOP=1 Q ; More than 2 years apart
  1. .. I $$FMDIFF^XLFDT(LDX,FDX,1)>89 S DXOK=1 D
  1. ... ; Delete remaining entries from temporary file
  1. ... S DX=""
  1. ... F S DX=$O(@TMREF@(DFN,DX)) Q:DX="" I DX'=LDX,DX'=FDX K @TMREF@(DFN,DX)
  1. ; Update global with criteria
  1. I DXOK D
  1. . M @GLOB@(DFN)=@TMREF@(DFN)
  1. . NEW IEN,FREF,EXDT
  1. . S VSDT="",EXDT=""
  1. . F S VSDT=$O(@TMREF@(DFN,VSDT)) Q:VSDT="" D
  1. .. S TIEN="" F S TIEN=$O(@TMREF@(DFN,VSDT,TIEN)) Q:TIEN="" D
  1. ... S VISIT=$P(@TMREF@(DFN,VSDT,TIEN),U,2),VTYP=$P(@TMREF@(DFN,VSDT,TIEN),U,1)
  1. ... S IEN=$P(@TMREF@(DFN,VSDT,TIEN),U,4),FREF=$P(@TMREF@(DFN,VSDT,TIEN),U,5)
  1. ... I VTYP="V" S @GLOB@(DFN,"CRITERIA",TAX,VTYP,VISIT,IEN)=VSDT_U_EXDT_U_IEN_U_FREF
  1. ... I VTYP="P" S @GLOB@(DFN,"CRITERIA",TAX,VTYP,VISIT)=VSDT_U_EXDT
  1. Q
  1. ;
  1. IHD(DFN,GLOB,TMREF,DXOK) ; EP - Process IHD/Multiple Known CVD date logic
  1. ;
  1. ; Within any five year period, at least three diagnoses of [whatever] and
  1. ; at least 90 days between first and last diagnosis (Revised logic definition)
  1. ; Input
  1. ; DFN - patient whose IHD diagnoses are being examined
  1. ; GLOB - Global where data is to be stored
  1. ; Structure:
  1. ; GLOB(DFN,"CRITERIA",criteria or taxonomy,visit or problem ien)=date/time
  1. ; TMREF - Global used to temporarily store diagnoses that may meet the
  1. ; IHD logic and, if so, will be stored in GLOB
  1. ; DXOK - If set to '1', patient meets the IHD logic for CVD Known - value
  1. ; may be returned (if called by PAT subroutine)
  1. ; Variables
  1. ; NOK - If set to '1', no diagnoses remaining that will meet the date logic
  1. ; LDX - Most recent diagnosis that meets the IHD criteria
  1. ; LDX1 - Next recent diagnosis that meets the IHD criteria
  1. ; FDX - Third diagnosis that must be compared to LDX to determine if they
  1. ; meet the date logic
  1. ; STOP - Set to '1' if the date range exceeds the two year maximum so new
  1. ; value for LDX must be found
  1. ; VTYP - Visit type - either 'V' for visit or 'P' for problem
  1. N NOK,STOP,LDX,LDX1,FDX,DX
  1. I $G(@TMREF@(DFN))<3 K @TMREF@(DFN) Q
  1. S DXOK=0,NOK=0
  1. F D Q:DXOK!NOK K @TMREF@(DFN,LDX)
  1. . S LDX=$O(@TMREF@(DFN,"A"),-1) I LDX="" S NOK=1 Q
  1. . S LDX1=$O(@TMREF@(DFN,LDX),-1) I LDX1="" S NOK=1 Q
  1. . ; Only one problem can be included
  1. . I $$TYP(DFN,LDX,TMREF)="P",$$TYP(DFN,LDX1,TMREF)="P" D I LDX1="" S NOK=1 Q
  1. .. F S LDX1=$O(@TMREF@(DFN,LDX1),-1) Q:LDX1="" I $$TYP(DFN,LDX1,TMREF)="V" Q
  1. . S STOP=0,FDX=LDX1
  1. . F S FDX=$O(@TMREF@(DFN,FDX),-1) Q:FDX="" D Q:DXOK!STOP
  1. .. I $$TYP(DFN,LDX,TMREF)="P"!($$TYP(DFN,LDX1,TMREF)="P"),$$TYP(DFN,FDX,TMREF)="P" Q
  1. .. I $$FMDIFF^XLFDT(LDX,FDX,1)'<1826 S STOP=1 Q ; More than 5 years apart
  1. .. I $$FMDIFF^XLFDT(LDX,FDX,1)>89 S DXOK=1 D
  1. ... ; Delete remaining entries from temporary file
  1. ... S DX=""
  1. ... F S DX=$O(@TMREF@(DFN,DX)) Q:DX="" I DX'=LDX,DX'=LDX1,DX'=FDX K @TMREF@(DFN,DX)
  1. I DXOK D
  1. . M @GLOB@(DFN)=@TMREF@(DFN)
  1. . NEW IEN,FREF,EXDT
  1. . S VSDT="",EXDT=""
  1. . F S VSDT=$O(@TMREF@(DFN,VSDT)) Q:VSDT="" D
  1. .. S TIEN="" F S TIEN=$O(@TMREF@(DFN,VSDT,TIEN)) Q:TIEN="" D
  1. ... S VISIT=$P(@TMREF@(DFN,VSDT,TIEN),U,2),VTYP=$P(@TMREF@(DFN,VSDT,TIEN),U,1)
  1. ... S IEN=$P(@TMREF@(DFN,VSDT,TIEN),U,4),FREF=$P(@TMREF@(DFN,VSDT,TIEN),U,5)
  1. ... S TAX=$P(@TMREF@(DFN,VSDT,TIEN),U,6)
  1. ... I VTYP="V" S @GLOB@(DFN,"CRITERIA",TAX,VTYP,VISIT,IEN)=VSDT_U_EXDT_U_IEN_U_FREF
  1. ... I VTYP="P" S @GLOB@(DFN,"CRITERIA",TAX,VTYP,VISIT)=VSDT_U_EXDT
  1. Q
  1. ;
  1. IHDSM(DFN,GLOB,TMREF,DXOK) ; EP - Process IHD same day date logic
  1. ;
  1. ; 3 different instances of IHD on same day
  1. ; Input
  1. ; DFN - patient whose IHD diagnoses are being examined
  1. ; GLOB - Global where data is to be stored
  1. ; Structure:
  1. ; GLOB(DFN,"CRITERIA",criteria or taxonomy,visit or problem ien)=date/time
  1. ; TMREF - Global used to temporarily store diagnoses that may meet the
  1. ; IHD logic and, if so, will be stored in GLOB
  1. ; DXOK - If set to '1', patient meets the IHD logic for CVD Known - value
  1. ; may be returned (if called by PAT subroutine)
  1. ; Variables
  1. ; VSDT - Visit date
  1. ; TIEN - Diagnosis internal entry number
  1. ; CT - Count of diagnoses for a date
  1. ; VCT - Count of diagnoses associated with a visit
  1. ; STOP - Set to '1' if the date range exceeds the two year maximum so new
  1. ; value for LDX must be found
  1. ; VTYP - Visit type - either 'V' for visit or 'P' for problem
  1. ; VST - Array of visits to be included in the criteria
  1. ; PVST - If there are only 2 visit dxs, set to the problem to be included
  1. ;
  1. N VSDT,TIEN,CT,VCT,VISIT,VTYP,VST,PVST,PRM,VPRM
  1. I $G(@TMREF@(DFN))<3 K @TMREF@(DFN) Q
  1. S DXOK=0,VSDT="",VPRM=""
  1. F S VSDT=$O(@TMREF@(DFN,VSDT),-1) Q:VSDT="" D Q:DXOK
  1. . S STOP=0,TIEN="",CT=0,VCT=0,PVST="" K VST
  1. . F S TIEN=$O(@TMREF@(DFN,VSDT,TIEN)) Q:TIEN="" D Q:VPRM
  1. .. I $P(@TMREF@(DFN,VSDT,TIEN),U,7) S VPRM=1,VST(TIEN)="",CT=1,VCT=1
  1. . Q:'VPRM S TIEN=""
  1. . F S TIEN=$O(@TMREF@(DFN,VSDT,TIEN)) Q:TIEN="" I '$D(VST(TIEN)) D
  1. .. S CT=CT+1
  1. .. ; There must be three different diagnoses
  1. .. ; and of these three only one can be a problem
  1. .. ; One diagnosis must be a primary (PRM)
  1. .. S VTYP=$P(@TMREF@(DFN,VSDT,TIEN),U),PRM=$P(@TMREF@(DFN,VSDT,TIEN),U,7)
  1. .. I VTYP="V" S VCT=VCT+1 I CT'>3 S VST(TIEN)=""
  1. .. I VTYP="P",PVST="" S PVST=TIEN
  1. .. I CT'<3,VCT'<2 S DXOK=1
  1. . I DXOK D DEL(VSDT,CT,VCT,PVST,.VST)
  1. ; Update global with criteria
  1. ; VSDT is the date for which there are 3 different diagnoses
  1. ;
  1. I DXOK D
  1. . M @GLOB@(DFN,VSDT)=@TMREF@(DFN,VSDT)
  1. . NEW IEN,FREF,EXDT
  1. . S TIEN="",EXDT=""
  1. . F S TIEN=$O(@TMREF@(DFN,VSDT,TIEN)) Q:TIEN="" D
  1. .. S VISIT=$P(@TMREF@(DFN,VSDT,TIEN),U,2),VTYP=$P(@TMREF@(DFN,VSDT,TIEN),U,1)
  1. .. S IEN=$P(@TMREF@(DFN,VSDT,TIEN),U,4),FREF=$P(@TMREF@(DFN,VSDT,TIEN),U,5)
  1. .. I VTYP="V" S @GLOB@(DFN,"CRITERIA","Ischemic Heart Disease (3 diff)",VTYP,VISIT,IEN)=VSDT_U_EXDT_U_IEN_U_FREF
  1. .. I VTYP="P" S @GLOB@(DFN,"CRITERIA","Ischemic Heart Disease (3 diff)",VTYP,VISIT)=VSDT_U_EXDT
  1. Q
  1. ;
  1. TYP(DFN,DX,TMREF) ; EP - Return 'V' or 'P' to identify type of visit
  1. ; Input
  1. ; DFN - Patient
  1. ; DX - Diagnosis internal entry number
  1. ; TMREF - Temporary array of diagnoses
  1. ; Variables
  1. ; LTYP - Either 'V' for visit or 'P' for problem
  1. N LIEN,LTYP
  1. S LTYP="P"
  1. S LIEN=""
  1. F S LIEN=$O(@TMREF@(DFN,DX,LIEN)) Q:LIEN="" D Q:LTYP="V"
  1. . S LTYP=$P(@TMREF@(DFN,DX,LIEN),U)
  1. Q LTYP
  1. ;
  1. DEL(VSDT,CT,VCT,PVST,VST) ; EP - Delete diagnoses from temporary file
  1. ; If more than three diagnoses on same day, remove extras
  1. ; preferentially keeping visit diagnoses over problem diagnoses
  1. ; and retaining a maximum of one problem diagnosis
  1. ;
  1. ; Input
  1. ; VSDT - Visit date
  1. ; CT - Count of diagnoses for a date
  1. ; VCT - Count of diagnoses associated with a visit
  1. ; PVST - If there are problem dxs, set to the first problem ien
  1. ; VST - array of visit iens; if there are more than three only the
  1. ; first three are included
  1. ;
  1. I CT=3 Q ; If only 3 diagnoses we're done
  1. I VCT'<3 D Q ; keep three visit diagnoses and remove the rest
  1. . S TIEN=""
  1. . F S TIEN=$O(@TMREF@(DFN,VSDT,TIEN)) Q:TIEN="" D
  1. .. I '$D(VST(TIEN)) K @TMREF@(DFN,VSDT,TIEN)
  1. ; keep the problem and two visit diagnoses and remove the rest
  1. S TIEN=""
  1. F S TIEN=$O(@TMREF@(DFN,VSDT,TIEN)) Q:TIEN="" D
  1. . I '$D(VST(TIEN)),TIEN'=PVST K @TMREF@(DFN,VSDT,TIEN)
  1. Q
  1. PRB ; EP - Check Problem File for instance of taxonomy
  1. ; Called by BQITD03
  1. ;
  1. ; PVIEN - Taxonomy entry
  1. ; TPGLOB - Problem file temporary global reference
  1. ;
  1. NEW IEN,PGREF,PFREF,DFN,VSDTM
  1. ; Go through the problem file, starting with the most recent entry
  1. S IEN="",PGREF="^AUPNPROB",PFREF=9000011,PROB=0
  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. . ; get the date of the problem, since not all dates exist, the
  1. . ;
  1. . ; Check class - if Family ignore
  1. . I $$GET1^DIQ(PFREF,IEN,.04,"I")="F" Q
  1. . ; hierarchy is 'DATE ENTERED', and then 'DATE LAST MODIFIED'.
  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. . S @TPGLOB@(DFN,VSDTM,PVIEN)="P"_U_IEN
  1. . S $P(@TPGLOB@(DFN,VSDTM,PVIEN),U,6)=TAX
  1. . S @TPGLOB@(DFN)=$G(@TPGLOB@(DFN))+1
  1. Q
  1. ;
  1. PPRB ;EP - Check Problem File for instance of a patient
  1. ; Called by BQITD03
  1. ; Input Parameters
  1. ; DFN - Patient record
  1. ; TPGLOB - Temporary global
  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
  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. . S @TPGLOB@(DFN,VSDTM,TIEN)="P"_U_PVIEN
  1. . S $P(@TPGLOB@(DFN,VSDTM,TIEN),U,6)=TAX
  1. . S @TPGLOB@(DFN)=$G(@TPGLOB@(DFN))+1
  1. Q