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

BKMVFAPI.m

Go to the documentation of this file.
BKMVFAPI ;PRXM/HC/ALA - Autopopulate Code for iCare ; 15 Nov 2005  5:46 PM
 ;;2.1;HIV MANAGEMENT SYSTEM;;Feb 07, 2011
 ;
 Q
 ;
EN(GLBREF,BKMDEC) ;EP - Entry point
 ;
 ;Description
 ;  Find all the patients that would meet the HMS autopopulate logic
 ;Input
 ;  GLBREF - Global reference where the data will be filed (^TMP("name",$j)
 ;  BKMDEC - Include deceased patients
 ;
 NEW REGISTER
 S REGISTER=$$HIVIEN^BKMIXX3()
 I REGISTER="" S BMXSEC="There is no HMS register defined." Q
 ;
 ;if we have to check for valid user
 ;I '$$VALID^BKMIXX3(DUZ) S BMXSEC="You are not a valid HMS user." Q
 ;
DXN ; Check the ICD9 Diagnosis taxonomies
 K ^TMP("BKMARRAY",$J),^TMP("BKMPOP",$J)
 D BLDTAX^BKMIXX5("BGP HIV/AIDS DXS","^TMP(""BKMARRAY"",$J)")
 S DXN="" F  S DXN=$O(^TMP("BKMARRAY",$J,DXN)) Q:DXN=""  D
 . S LIEN="" F  S LIEN=$O(^AUPNVPOV("B",DXN,LIEN)) Q:LIEN=""  D
 .. S DFN=$P(^AUPNVPOV(LIEN,0),U,2)
 .. I DFN="" Q
 .. I 'BKMDEC,$$GET1^DIQ(2,DFN,.351,"I")'="" Q
 .. I '$$HRN^BKMVUTL(DFN) Q
 .. D NPAT(DFN)
 . ;
 . S LIEN="" F  S LIEN=$O(^AUPNPROB("B",DXN,LIEN)) Q:LIEN=""  D
 .. S DFN=$P(^AUPNPROB(LIEN,0),U,2) I DFN="" Q
 .. I 'BKMDEC,$$GET1^DIQ(2,DFN,.351,"I")'="" Q
 .. I '$$HRN^BKMVUTL(DFN) Q
 .. D NPAT(DFN)
 ;
 K DXN,LIEN
 ;
MED ; Check the medication taxonomies
 K ^TMP("BKMARRAY",$J)
 D BLDTAX^BKMIXX5("BKMV NRTI MED NDCS","^TMP(""BKMARRAY"",$J)")
 S MED="" F  S MED=$O(^TMP("BKMARRAY",$J,MED)) Q:MED=""  D FMD("BKMV NRTI MED NDCS")
 D BLDTAX^BKMIXX5("BKMV NRTI MEDS","^TMP(""BKMARRAY"",$J)")
 S MED="" F  S MED=$O(^TMP("BKMARRAY",$J,MED)) Q:MED=""  D FMD("BKMV NRTI MEDS")
 D BLDTAX^BKMIXX5("BKMV NNRTI MED NDCS","^TMP(""BKMARRAY"",$J)")
 S MED="" F  S MED=$O(^TMP("BKMARRAY",$J,MED)) Q:MED=""  D FMD("BKMV NNRTI MED NDCS")
 D BLDTAX^BKMIXX5("BKMV NNRTI MEDS","^TMP(""BKMARRAY"",$J)")
 S MED="" F  S MED=$O(^TMP("BKMARRAY",$J,MED)) Q:MED=""  D FMD("BKMV NNRTI MEDS")
 D BLDTAX^BKMIXX5("BKMV PI MED NDCS","^TMP(""BKMARRAY"",$J)")
 S MED="" F  S MED=$O(^TMP("BKMARRAY",$J,MED)) Q:MED=""  D FMD("BKMV PI MED NDCS")
 D BLDTAX^BKMIXX5("BKMV PI MEDS","^TMP(""BKMARRAY"",$J)")
 S MED="" F  S MED=$O(^TMP("BKMARRAY",$J,MED)) Q:MED=""  D FMD("BKMV PI MEDS")
 D BLDTAX^BKMIXX5("BKMV EI MED NDCS","^TMP(""BKMARRAY"",$J)")
 S MED="" F  S MED=$O(^TMP("BKMARRAY",$J,MED)) Q:MED=""  D FMD("BKMV EI MED NDCS")
 D BLDTAX^BKMIXX5("BKMV EI MEDS","^TMP(""BKMARRAY"",$J)")
 S MED="" F  S MED=$O(^TMP("BKMARRAY",$J,MED)) Q:MED=""  D FMD("BKMV EI MEDS")
 K ^TMP($J,"BKMVMEDS")
 ;  
LAB ;  Check the lab, CPT, and LOINC codes in the Lab V-File.
 ;
 ;  Build the lab tests from taxonomies to check
 K ^TMP("BKMARRAY",$J),^TMP("BKMCPT",$J)
 D BLDTAX^BKMIXX5("BGP HIV TEST TAX","^TMP(""BKMARRAY"",$J)")
 S LAB="" F  S LAB=$O(^TMP("BKMARRAY",$J,LAB)) Q:LAB=""  D FLB("BGP HIV TEST TAX")
 K ^TMP("BKMARRAY",$J)
 D BLDTAX^BKMIXX5("BGP HIV TEST LOINC CODES","^TMP(""BKMARRAY"",$J)")
 S LAB="" F  S LAB=$O(^TMP("BKMARRAY",$J,LAB)) Q:LAB=""  D FLB("BGP HIV TEST LOINC CODES")
 K ^TMP("BKMARRAY",$J)
 D BLDTAX^BKMIXX5("BGP CPT HIV TESTS","^TMP(""BKMCPT"",$J)")
 S CPT="" F  S CPT=$O(^TMP("BKMCPT",$J,CPT)) Q:CPT=""  D
 . S BCPTR=0 F  S BCPTR=$O(^BLRCPT(BCPTR)) Q:'BCPTR  D
 .. I $D(^BLRCPT(BCPTR,11,"B",CPT)) S LAB=$P($G(^BLRCPT(BCPTR,1)),U,1) I LAB'="" S ^TMP("BKMARRAY",$J,LAB)=$P(^LAB(60,LAB,0),U,1)
 K ^TMP("BKMCPT",$J),CPT,BCPTR
 S LAB="" F  S LAB=$O(^TMP("BKMARRAY",$J,LAB)) Q:LAB=""  D FLB("BGP CPT HIV TESTS")
 ;  
XIT ;KILL LOCALS AND EXIT
 D ^XBFMK
 K DIR,REGISTER,BKM,FOUND,LOINC,MED,VMEDIEN,Y,ZTDESC,ZTIO,ZTSAVE
 K STATUS,ZTRTN,ZTSK,AIDX,AIEN,AOK,DXN,HIDX,HIEN,LIEN,QFL,VISDTM,VISIT
 K ^TMP("BKMPOP",$J),^TMP("BKMARRAY",$J),^TMP("BKMTST",$J)
 K ^TMP("BKMAIDS",$J),^TMP("BKMHIV",$J),^TMP("BKMCD4",$J)
 K DCT,DIAGCAT,HAIDSDT,IAIDSDT,RDATE,LAB,RDA,SBFILE,SUBFIL,XCNP,IGNORE
 K BKCIEN,BKMIEN,BKMPOPDT,DFN,ERR,ERROR,BCPTR,CPT,ENTRY,BKMDEC
 Q
 ;
FMD(MTAX) ; Find Medications
 NEW LIEN
 S LIEN="" F  S LIEN=$O(^AUPNVMED("B",MED,LIEN)) Q:LIEN=""  D
 . S DFN=$P(^AUPNVMED(LIEN,0),U,2)
 . I DFN="" Q
 . I 'BKMDEC,$$GET1^DIQ(2,DFN,.351,"I")'="" Q
 . I '$$HRN^BKMVUTL(DFN) Q
 . S ^TMP($J,"BKMVMEDS",DFN)=$G(^TMP($J,"BKMVMEDS",DFN))+1
 . Q
 S DFN="" F  S DFN=$O(^TMP($J,"BKMVMEDS",DFN)) Q:DFN=""  D
 . I $G(^TMP($J,"BKMVMEDS",DFN))>1 D NPAT(DFN)
 K ^TMP($J,"BKMVMEDS",DFN),^TMP("BKMARRAY",$J)
 K DFN,MTAX
 Q
 ;
FLB(LTAX) ; Find Lab tests
 NEW LIEN
 S LIEN="" F  S LIEN=$O(^AUPNVLAB("B",LAB,LIEN)) Q:LIEN=""  D
 . S DFN=$P(^AUPNVLAB(LIEN,0),U,2)
 . I DFN="" Q
 . I 'BKMDEC,$$GET1^DIQ(2,DFN,.351,"I")'="" Q
 . I '$$HRN^BKMVUTL(DFN) Q
 . S RESULT=$$GET1^DIQ(9000010.09,LIEN,.04,"E") Q:RESULT=""
 . I $$POSITIVE^BKMVF32(RESULT) D NPAT(DFN)
 K LIEN,LTAX,RESULT,DFN
 Q
 ;
NPAT(DFN) ;
 S @GLBREF@(DFN,0)=""
 Q