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

AGUTL.m

Go to the documentation of this file.
AGUTL ;IHS/OIT/NKD - PAT REG UTILITY ROUTINE ; FEBRUARY 10, 2014
 ;;7.1;PATIENT REGISTRATION;**11,12,13,14**;AUG 25, 2005;Build 1
 ;
 ;IHS/OIT/NKD AG*7.1*11 MU2 MULTIPLE RACES
 ;IHS/OIT/NKD AG*7.1*11 MU2 UNKNOWN SEX
 ;IHS/OIT/NKD AG*7.1*11 VAMB
 ;IHS/OIT/NKD AG*7.1*12 INSURER TYPE
 ;IHS/OIT/NKD AG*7.1*13 MBI IMPLEMENTATION
 ;IHS/OIT/NKD AG*7.1*14 MBI PHASE 2
 ;
 Q
RACE(AGPATDFN) ;EP - RETURN LIST OF PATIENT'S RACES (EXTERNAL FORMAT)
 ; # OF RACES^RACE 1^RACE 2^ETC
 ; EX: PT W/0 RACES => "0"
 ; EX: PT W/2 RACES => "2^AMERICAN INDIAN OR ALASKA NATIVE^ASIAN"
 N AGRACE,AGLIST,AGCNT
 D LIST^DIC(2.02,","_AGPATDFN_",","@;.01E","P",,,,,,,"AGRACE")
 S AGLIST=$P(AGRACE("DILIST",0),"^",1)
 F AGCNT=1:1:$P(AGRACE("DILIST",0),"^",1) S AGLIST=AGLIST_"^"_$P(AGRACE("DILIST",AGCNT,0),"^",2)
 Q AGLIST
SEXELIG(AGPATDFN) ;EP - UPDATES PATIENT-SPECIFIC ELIGIBILITY SEX/GENDER FIELDS TO PATIENT'S SEX
 ; MEDICARE/MEDICAID/RAILROAD ELIGIBLE FILES ARE ASSOCIATED WITH A PATIENT
 ; CALLING THIS API WILL UPDATE THE SEX/GENDER FIELDS IN THE ELIGIBLE FILES TO MATCH THE PATIENT'S SEX
 Q:'AGPATDFN
 N AGSEX,AGPTR,AGPTR2
 S AGSEX=$$GET1^DIQ(2,AGPATDFN,.02,"I")
 Q:AGSEX']""
 ; MCR
 S AGPTR=0 F  S AGPTR=$O(^AUPNMCR("B",AGPATDFN,AGPTR)) Q:'AGPTR  D
 . Q:'$D(^AUPNMCR(AGPTR,0))
 . Q:AGPATDFN'=$$GET1^DIQ(9000003,AGPTR,.01,"I")
 . N FDA
 . S AGPTR2=0 F  S AGPTR2=$O(^AUPNMCR(AGPTR,11,AGPTR2)) Q:'AGPTR2  S FDA(9000003.11,AGPTR2_","_AGPTR_",",.08)=AGSEX
 . I $D(FDA) D UPDATE^DIE(,"FDA")
 ; MCD
 S AGPTR=0 F  S AGPTR=$O(^AUPNMCD("B",AGPATDFN,AGPTR)) Q:'AGPTR  D
 . Q:'$D(^AUPNMCD(AGPTR,0))
 . Q:AGPATDFN'=$$GET1^DIQ(9000004,AGPTR,.01,"I")
 . N FDA
 . S FDA(9000004,AGPTR_",",.07)=AGSEX
 . D UPDATE^DIE(,"FDA")
 ; RRE
 S AGPTR=0 F  S AGPTR=$O(^AUPNRRE("B",AGPATDFN,AGPTR)) Q:'AGPTR  D
 . Q:'$D(^AUPNRRE(AGPTR,0))
 . Q:AGPATDFN'=$$GET1^DIQ(9000005,AGPTR,.01,"I")
 . N FDA
 . S AGPTR2=0 F  S AGPTR2=$O(^AUPNRRE(AGPTR,11,AGPTR2)) Q:'AGPTR2  S FDA(9000005.11,AGPTR2_","_AGPTR_",",.08)=AGSEX
 . I $D(FDA) D UPDATE^DIE(,"FDA")
 Q
 ;IHS/OIT/NKD AG*7.1*12 - START OLD CODE
 ;INSTYP(AGIEN) ;EP - RETURN INSURER TYPE CODE
 ;N AGRES
 ;S AGRES=$$GET1^DIQ(9999999.18,AGIEN,.211,"I")
 ;S AGRES=$$GET1^DIQ(9999999.181,AGRES,1,"I")
 ;Q AGRES
 ;IHS/OIT/NKD AG*7.1*12 - END OLD CODE - CODE OPTIMIZATIONS
INSTYP(AGIEN,AGFLAG) ;EP - RETURN INSURER TYPE CODE (DEFAULT) OR NAME (AGFLAG=1)
 S AGIEN=$G(AGIEN,0),AGFLAG=$G(AGFLAG,0) Q:'AGIEN "" Q:'$G(^AUTNINS(AGIEN,3)) "" Q $P($G(^AUTTINTY($G(^AUTNINS(AGIEN,3)),0)),"^",$S(AGFLAG:1,1:2))
 ;IHS/OIT/NKD AG*7.1*13
GETMCR(IEN,EFFDATE)  ;EP - GET MEDICARE ELIGIBILITY NUMBER FOR A RECORD
 ; Call: $$GETMCR^AGUTL(IEN,EFFDATE)
 ;  IEN: Medicare Eligibility record IEN
 ;  EFFDATE: Defaults to TODAY
 ; Returned value:
 ;  Successful (In the following order):
 ;   MBI: If MBI exists as of EFFDATE
 ;   HICN (MEDICARE ELIGIBLE #9000003): MEDICARE NUMBER (#.03)_SUFFIX (#.04)
 ;  Unsuccessful:
 ;   "": If neither MBI nor HICN
 N FILE,DFN S FILE=9000003,IEN=+$G(IEN),EFFDATE=$G(EFFDATE,$$DT^XLFDT),DFN=$$GET1^DIQ(FILE,IEN,.01,"I")
 Q:$$HASMBI(DFN,EFFDATE) $$GETMBI^AUPNMBI(DFN,EFFDATE)
 Q $$HICN(FILE,IEN)
 ;
GETRRE(IEN,EFFDATE)  ;EP - GET RAILROAD ELIGIBILITY NUMBER FOR A RECORD
 ; Call: $$GETRRE^AGUTL(IEN,EFFDATE)
 ;  IEN: Railroad Eligibility record IEN
 ;  EFFDATE: Defaults to TODAY
 ; Returned value:
 ;  Successful (In the following order):
 ;   MBI: If MBI exists as of EFFDATE
 ;   HICN (RAILROAD ELIGIBLE #9000005): PREFIX (#.03)_RAILROAD NUMBER (#.04)
 ;  Unsuccessful:
 ;   "": If neither MBI nor HICN
 N FILE,DFN S FILE=9000005,IEN=+$G(IEN),EFFDATE=$G(EFFDATE,$$DT^XLFDT),DFN=$$GET1^DIQ(FILE,IEN,.01,"I")
 Q:$$HASMBI(DFN,EFFDATE) $$GETMBI^AUPNMBI(DFN,EFFDATE)
 Q $$HICN(FILE,IEN)
 ;
HASMBI(DFN,EFFDATE)  ;EP - CHECK IF PATIENT HAS MBI
 ; Call: $$HASMBI^AGUTL(DFN,EFFDATE)
 ;  EFFDATE: Defaults to TODAY
 ; Returned value:
 ;  Successful: 1
 ;  Unsuccessful: 0
 S DFN=+$G(DFN),EFFDATE=$G(EFFDATE,$$DT^XLFDT) Q:'DFN 0
 Q ''$O(^AUPNPAT(DFN,44,EFFDATE+.000001),-1)
 ;
ISMBI(VAL)  ;EP - CHECK IF THE INPUT IS A VALID MBI
 ; Returned value:
 ;  Successful: MBI (VALIDATED)
 ;  Unsuccessful: 0^SSN  => INPUT MATCHED SSN FORMAT
 ;                0^MCR  => INPUT MATCHED MCR HICN FORMAT
 ;                0^RRE  => INPUT MATCHED RRE HICN FORMAT
 ;                0^ERROR MESSAGE OF MBI FORMAT
 S VAL=$G(VAL)
 Q:VAL?9N "0^SSN"
 Q:VAL?9N.2A "0^MCR"
 Q:VAL?.2A9N "0^RRE"
 Q $$FORMOK^AUPNMBI(VAL)
 ;
HICN(FILE,IEN)  ;EP - RETURNS THE HICN (MEDICARE AND RAILROAD)
 Q ($$GET1^DIQ(FILE,IEN,.03)_$$GET1^DIQ(FILE,IEN,.04))
 ;
EDITMCR(IEN,FLAG)  ;EP - INTERACTIVE EDIT OF MEDICARE NUMBER
 N RES S IEN=+$G(IEN),FLAG=+$G(FLAG)
 D EDITELIG(9000003,IEN)
 I FLAG F  S RES=$$GETMCR(IEN) Q:$L(RES)  D
 . D EDITELIG(9000003,IEN)
 Q
 ;
EDITRRE(IEN,FLAG)  ;EP - INTERACTIVE EDIT OF RAILROAD NUMBER
 N RES S IEN=+$G(IEN),FLAG=+$G(FLAG)
 D EDITELIG(9000005,IEN)
 I FLAG F  S RES=$$GETRRE(IEN) Q:$L(RES)  D
 . D EDITELIG(9000005,IEN)
 Q
 ;
EDITELIG(FILE,IEN)  ;EP - INTERACTIVE EDIT OF HICN AND MBI
 N DFN,POL,RES S FILE=+$G(FILE),IEN=+$G(IEN),DFN=$$GET1^DIQ(FILE,IEN,.01,"I") Q:'DFN
 S POL=$$ASKNUM(FILE,IEN),RES=$$ISMBI(POL)  ;PROMPT USER RESPONSE AND DETERMINE FORMAT
 I 'RES,"^SSN^MCR^RRE^"[(U_$P(RES,U,2)_U) S POL=$S(RES["MCR":$E(POL,1,9),RES["RRE":$E(POL,$L(POL)-8,$L(POL)),1:POL),POL=$$ASKHICN(FILE,IEN,POL)     ;HICN FORMAT
 E  S POL=$$ASKMBI(DFN,POL,$S(FILE=9000003:"MCR",FILE=9000005:"RRE",1:""))  ;MBI FORMAT
 Q
 ;
ASKNUM(FILE,IEN)  ;PROMPT FOR HICN OR MBI AND RETURN USER RESPONSE
 N DIR,X,Y,DFN,DEF
 S IEN=+$G(IEN),FILE=+$G(FILE),DFN=$$GET1^DIQ(FILE,IEN,.01,"I")
 ; INTERACTIVE ENTRY PROMPT
 S DIR(0)="FA^9:11"
 S DIR("A")=$S(FILE=9000003:"MEDICARE",FILE=9000005:"RAILROAD",1:"")_" NUMBER: "
 S DIR("A",1)="The HICN or MBI may be entered at this prompt."
 S DIR("A",2)="  HICN: The "_$S(FILE=9000003:"SUF",FILE=9000005:"PRE",1:"")_"FIX will be prompted for next."
 S DIR("A",3)="   MBI: The EFFECTIVE DATE will be prompted for next."
 S DIR("A",4)=""
 S DIR("A",5)="  CURRENT HICN: "_$$HICN(FILE,IEN)
 S DIR("A",6)="   CURRENT MBI: "_$S($$HASMBI(DFN):$$GETMBI^AUPNMBI(DFN,$$DT^XLFDT),1:"")
 S DIR("A",7)=""
 ; DEFAULT (IF APPLICABLE)
 S DEF=$$HICN(FILE,IEN) S:FILE=9000003 DEF=$E(DEF,1,9) S:FILE=9000005 DEF=$E(DEF,$L(DEF)-8,$L(DEF))
 S:$$HASMBI(DFN) DEF=$$GETMBI^AUPNMBI(DFN,$$DT^XLFDT)
 S:$L(DEF) DIR("B")=DEF
 D ^DIR
 Q $G(X)
 ;
ASKHICN(FILE,IEN,VAL)  ;PROMPT FOR PREFIX/SUFFIX, STORE HICN, AND RETURN HICN
 Q:$D(DTOUT)!$D(DUOUT)!$D(DIROUT) ""
 N DIE,DR,DA
 S IEN=+$G(IEN),FILE=+$G(FILE),VAL=$G(VAL)
 S DIE=$$GET1^DID(FILE,,,"GLOBAL NAME")
 S DR=".03"_$S(FILE=9000003:"////"_VAL,1:"")_";.04"_$S(FILE=9000005:"////"_VAL,1:"")  ; STUFF HICN AND ASK FOR PREFIX/SUFFIX
 S DA=IEN
 D ^DIE
 Q $$HICN(FILE,IEN)
 ;
ASKMBI(IEN,VAL,SRC)  ;VALIDATE MBI, PROMPT FOR EFFECTIVE DATE, STORE ENTRY, RETURN MBI
 Q:$D(DTOUT)!$D(DUOUT)!$D(DIROUT) ""
 N RES,MBI,DIR,EFFDT
 S IEN=+$G(IEN),MBI=$G(VAL),SRC=$G(SRC,"OTH"),RES=$$FORMOK^AUPNMBI(MBI)
 ; VALIDATE MBI FORMAT
 I 'RES W !,$P(RES,U,2),! S DIR(0)="9000001.44,1" D ^DIR S MBI=$G(Y)
 Q:$D(DTOUT)!$D(DUOUT)!$D(DIROUT) ""
 ; ASK FOR EFFECTIVE DATE
 K DIR
 ;S DIR(0)="DA"  ;IHS/OIT/NKD AG*7.1*14 DON'T ALLOW FUTURE DATES
 S DIR(0)="DA^:DT"
 S DIR("A")="EFFECTIVE DATE: "
 ;S DIR("B")=$$FMTE^XLFDT($O(^AUPNPAT(IEN,44,"C",MBI,""),-1),5)  ; DEFAULT TO MOST RECENT DATE IF MBI EXISTS  ;IHS/OIT/NKD AG*7.1*14 DON'T DEFAULT TO FUTURE DATES
 S DIR("B")=$$FMTE^XLFDT($O(^AUPNPAT(IEN,44,"C",MBI,$$DT^XLFDT+.000001),-1),5)  ; DEFAULT TO MOST RECENT DATE IN THE PAST IF MBI EXISTS
 S:'$L(DIR("B")) DIR("B")=$$FMTE^XLFDT($$DT^XLFDT,5)  ; OTHERWISE DEFAULT TO TODAY
 D ^DIR
 Q:$D(DTOUT)!$D(DUOUT)!$D(DIROUT) ""
 S EFFDT=$P(+$G(Y),".")
 ; ADD MBI WITH SOURCE
 Q $$ADDMBI^AUPNMBI(IEN,EFFDT,MBI,SRC)
 ;
 ;IHS/OIT/NKD AG*7.1*14
GETMBIS(IEN,RES,SUB)  ;EP - RETURN FORMATTED LIST OF PATIENT MBI HISTORY
 N TMP S IEN=+$G(IEN),RES=$G(RES),SUB=$G(SUB)
 D LIST^DIC(9000001.44,","_IEN_",","@;.01;1;2;3;4","P","","","","","","","TMP")
 I $L(SUB) M @RES@(SUB)=TMP("DILIST") K @RES@(SUB,0)
 E  M @RES=TMP("DILIST") K @RES@(0)
 Q +TMP("DILIST",0)
 ;