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

AGAPIS.m

Go to the documentation of this file.
AGAPIS ;IHS/SD/TPF - PATIENT REGISTRATION ELIGIBLITY API CALL
 ;;7.1;PATIENT REGISTRATION;**2,12**;AUG 25, 2005;Build 1
 ;
 ;IHS/OIT/NKD AG*7.1*12 INSURER TYPE
 ;
 W !,"DO NOT CALL FROM ROOT!"
 Q
 ;
 ;GENERAL LOGIC:
 ;
 ;USING THE "EFF" CROSS REFERENCE IN THE "CATEGORY PRIORITIZING" FILE
 ;#9000035 FIND ALL PRIORITIZED CATEGORIES FOR THE PATIENT DFN (AGGIEN)
 ;WHICH ARE EFFECTIVE (EFFECTIVE DATE OF PRIORITY (#.06) ) AS
 ;OF THE DATE OF SERVICE (AGGDOS).
 ;
 ;NEXT, ELIMINATE ANY ENTRIES IN THE ELIGIBILITY FILE WHICH ARE FOUND TO
 ;BE NON-ACTIVE GIVEN THE DATE OF SERVICE (AGGDOS). THE DATE OF SERVICE
 ;IS COMPARED TO THE 'BEGIN' AND ENDING DATES OF COVERAGE FOUND IN THE
 ;APPROPRIATE ELIGIBLITY FILE.
 ;
 ;IF THE ELIGIBILITY ENTRY IS FOUND TO BE ACTIVE THEN THE CATEGORY AND
 ;ELIGIBILITY DATA IS ADDED TO THE RETURNED ARRAY
 ;OR STRING IF AGGBMX=1.
 ;
 ;THE RETURNED ARRAY HAS THE FOLLOWING BASIC STRUCTURE:
 ; 
 ;     AGGXY(CATEGORY,PRIORITY,INSURER POINTER,File #, fda iens,
 ;                      Field#/Field Name, [Internal/External])=DATA
 ; 
 ;THE SUBSCRIPT STRUCTURE BEYOND THE INSURER POINTER (THIRD SUBSCRIPT) IS
 ;IN THE FORM OF A STANDARD FDA ARRAY RETURNED BY THE FIELMAN DBS API
 ;$$GETS^DIQ() Data Retriever AND IS DEPENDENT UPON THE FLAGS PASSED VIA
 ;PARAMETER AGGFLAG. SEE "VA FILEMAN V. 22.0 PROGRAMMER MANUAL"
 ;PAGE 2-186 FOR DETAILS ON WHAT THE FLAGS MEAN. KEEP IN MIND THE
 ;RETURNED ARRAY'S STRUCTURE CHANGES DEPENDING ON THE FLAGS BEING PASSED.
 ;NOTE: THE 'INSURER POINTER' SUBSCRIPT FOR THE GUARANTOR WILL BE THE
 ;GLOBAL RFERENCE TO THE ACTUAL GUARANTOR
 ;  E.G.
 ;  AGGXY("T",1,"AUPNPAT(5571,0)","9000003.1","97,",".01","E")="GEGNUN,DELORES M"
 ;
 ;IN THE CASE ABOVE, THE GUARANTOR IS THE PATIENT. THE GUARANTOR
 ;AS OF THIS PATCH CAN BE A PATIENT, AN INSURER OR AN EMPLOYER
 ;
 ;IF AGGBMX=1 THEN THE BMXNet STRING IS RETURNED. IT'S FORMAT IS THE
 ;SAME AS THE BMXNet STRUCTURE FOR STATIC TABLES. SEE PAGES 8-9 OF THE
 ;"BMXNet ADO.NET Data Access and Connectivity Utilities for RPMS User
 ;Manual" FOR A DESCRIPTION OF THIS STRUCTURE.
 ;
 ;PARAMETERS:
 ;AGGXY   = RETURNED DATA ARRAY OR STRING
 ;AGGIEN  = PATIENT'S DFN. if null error message returned
 ;AGGDOS  = DATE OF SERVICE
 ;          If null, AGGDOS=DT
 ;   
 ;AGGFLAG = STANDARD FLAGS FOR GETS^DIQ  CALL
 ;           "I" = INTERNAL
 ;           "E" = EXTERNAL VALUES (DEFAULT)
 ;           "N" = DON'T RETURN NULL VALUES
 ;           "R" = RESOLVE FILE NUMBERS TO NAMES
 ;   
 ;           if null the default is "E"
 ;   
 ;AGGCAT  = A ^ DELIMITED STRING CONTAINING THE CATEGORIES REQUESTED
 ;          'M' FOR MEDICAL;
 ;          'D' FOR DENTAL;
 ;          'O' FOR OPTOMETRY;
 ;          'R' FOR PHARMACY;
 ;          'P' FOR MENTAL HEALTH;
 ;          'A' FOR AUTO ACCIDENT/TORT;    This is the same
 ;                                         as third party liability
 ;          'W' FOR WORKMAN'S COMP;
 ;  
 ;          E.G.  ^M^A^W^
 ;  
 ;          WILL RETURN MEDICAL,AUTO ACCIDENT AND WORKMEN'S COM
 ;          CATEGORIES.
 ;          if null the default is ALL CATEGORIES
 ;  
 ;AGGBMX  = IF 1 THEN DATA IS RETURNED IN BMXNET FORMAT
 ;          IF 0 THEN DATA IS RETURNED IN ARRAY FORMAT DESCRIBED ABOVE
 ;          if null the default is 0
 ;  
 ;IF NO EFFECTIVE SEQUENCE CATEGORIES ARE FOUND:
 ;  1) THE BMXNET CALLER WIL RECEIVE THE COLUMN SCHEMA WITH NO RECORDS
 ;     E.G. AGGXY="T00004CATEGORY^N000030PRIORITY^N000030INSURER^
 ;              N000030FILE_NUMBER^F000030FDA_IENS^F000050FIELD^
 ;              F000080DATA^"
 ;  
 ;  2) AGGXY WILL BE UNDEFINED FOR A NON BMXNET CALLER
 ;     D GETELIG^AGAPIS(.LJF,10416,DT,"ER","",0)   
GETELIG(AGGXY,AGGIEN,AGGDOS,AGGFLAG,AGGCAT,AGGBMX) ;PEP - API ENTRY FOR ACTIVE INSURANCE COVERAGE
 N PATIEN,RECORD,FLD,AGGDATA,AGGRET,AGGRETMP,CATPRIOR
 I '$D(^AUPNPAT(AGGIEN))!'$D(^DPT(AGGIEN)) S AGGXY="T00040ERROR"_$C(30)_"Patient not in either PATIENT or VA PATIENT file"_$C(30)_$C(31) Q
 I $G(AGGCAT)'="" D
 .I $E(AGGCAT)'=U S AGGCAT=U_AGGCAT
 .I $E(AGGCAT,$L(AGGCAT))'=U S AGGCAT=AGGCAT_U
 I $G(AGGIEN)="",$G(AGGBMX) S AGGXY="T00040ERROR"_$C(30)_"No patient IEN"_$C(30)_$C(31) Q
 I $G(AGGIEN)="" K AGGXY Q
 S:$G(AGGBMX)="" AGGBMX=0
 S:$G(AGGDOS)="" AGGDOS=DT
 S:$G(AGGCAT)'="" AGGCAT=$$UPPER(AGGCAT)
 S:AGGFLAG'="" AGGFLAG=$$UPPER(AGGFLAG)
 S:$G(AGGCAT)="" AGGCAT=$$GETCODES()
 S:$G(AGGFLAG)="" AGGFLAG="E"
 S AGGRETMP=""
 ;GO THROUGH THE CATEGORIES AND GRAB ONLY THOSE SELECTED IN AGGCAT
 S CAT=""
 F  S CAT=$O(^AUPNICP("EFF",AGGIEN,CAT)) Q:CAT=""  D
 .Q:AGGCAT'[(U_CAT_U)
 .S EFFDT=$O(^AUPNICP("EFF",AGGIEN,CAT,AGGDOS+.01),-1)
 .Q:EFFDT=""
 .S RECORD=""
 .F  S RECORD=$O(^AUPNICP("EFF",AGGIEN,CAT,EFFDT,RECORD)) Q:RECORD=""  D
 ..K AGGDATA,AGGERR
 ..;GET DATA FROM 'CATEGORY PRIORITIZING' FILE
 ..D GETS^DIQ(9000035,RECORD,"*","I","AGGDATA","AGGERR")
 ..I $D(AGGERR) Q
 ..M AGGRETMP=AGGDATA
 ;GO GET INSURANCE ELIGIBILITY
 K CATPRIOR
 D GETINS(.AGGRETMP,.CATPRIOR)
 D DELOBSOL(.CATPRIOR)   ;DELETE OBSOLETE FIELDS MARKED WITH '*' IN NAME
 ;HERE WE SHOULD HAVE A LIST OF ALL ACTIVE SEQ. ELIGIBILITIES SORTED IN CATPRIOR
 I 'AGGBMX M AGGXY=CATPRIOR D CLEAN Q
 ;OTHERWISE SEND BACK A BMX RECORD SET
 D BMXHDR(.HDR)
 D BMXSET(.CATPRIOR,.AGGXY)
 S AGGXY=HDR_$C(30)_AGGXY_$C(30)
 D CLEAN
 Q
 ;GET ELIGIBLITY INFO AND SORT BY CATEGORY,PRIORITY AND INSURER
GETINS(AGGELIG,CATPRIOR) ;
 S RECORD=""
 ;SORT THE CATEGORIZED ENTRIES BY CATEGORY AND PRIORITY
 F  S RECORD=$O(AGGELIG(9000035,RECORD)) Q:RECORD=""  D
 .S RECPTR=$G(AGGELIG(9000035,RECORD,".15","I"))
 .S INSPTR=$G(AGGELIG(9000035,RECORD,".03","I"))
 .S PRIORITY=$G(AGGELIG(9000035,RECORD,".05","I"))
 .S CATEGORY=$G(AGGELIG(9000035,RECORD,.04,"I"))
 .S COVTYPE=$G(AGGELIG(9000035,RECORD,.07,"I"))
 .S CATPRIOR(CATEGORY,PRIORITY,INSPTR)=RECPTR_"|"_COVTYPE
 ;
 ;NOW GET THE ELIGIBILITY DATA
 S CATEGORY=""
 F  S CATEGORY=$O(CATPRIOR(CATEGORY)) Q:CATEGORY=""  D
 .S PRIORITY=""
 .F  S PRIORITY=$O(CATPRIOR(CATEGORY,PRIORITY)) Q:PRIORITY=""  D
 ..S INSPTR=""
 ..S INSPTR=$O(CATPRIOR(CATEGORY,PRIORITY,INSPTR)) Q:INSPTR=""  D
 ...K AGGERR,AGGDATA
 ...;GET INSURER TYPE FROM INSURER FILE
 ...I $P(CATPRIOR(CATEGORY,PRIORITY,INSPTR),"|",2)="G" D
 ....S INSTYPE="GUARANTOR"
 ...;E  S INSTYPE=$$GET1^DIQ(9999999.18,INSPTR,.21,"E","AGGINS","AGGERR")
 ...E  S INSTYPE=$$INSTYP^AGUTL(INSPTR,1)  ;IHS/OIT/NKD AG*7.1*12
 ...S RECPTR=$P(CATPRIOR(CATEGORY,PRIORITY,INSPTR),"|")
 ...S COVTYPE=$P(CATPRIOR(CATEGORY,PRIORITY,INSPTR),"|",2)
 ...I INSPTR=1,(COVTYPE'="D") D GETRRAB^AGAPIS1(.CATPRIOR) Q  ;RAILROAD RETIRMENT A & B
 ...I INSPTR=2,(COVTYPE'="D") D GETMCRAB^AGAPIS1(.CATPRIOR) Q  ;MEDICARE A & B
 ...I INSPTR=3 D GETMCD^AGAPIS1(.CATPRIOR) Q  ;MEDICAID
 ...I INSPTR=1,(COVTYPE="D") D GETRRD^AGAPIS1(.CATPRIOR) Q  ;RAILROAD RETIREMENT PART D
 ...I INSPTR=2,(COVTYPE="D") D GETMCRD^AGAPIS1(.CATPRIOR) Q  ;MEDICARE PART D
 ...I INSTYPE="MCR PART D",(COVTYPE="D") D GETMCRD^AGAPIS1(.CATPRIOR) Q  ;MEDICARE PART D
 ...I INSTYPE="GUARANTOR" D GETGUAR^AGAPIS1(.CATPRIOR) Q
 ...I INSTYPE="THIRD PARTY LIABILITY" D GETTPL^AGAPIS1(.CATPRIOR) Q
 ...I INSTYPE="WORKMEN'S COMP." D WCOMP^AGAPIS1(.CATPRIOR) Q
 ...;ALL OTHERS SHOULD BE PRIVATE INSURANCE
 ...D GETPRVT^AGAPIS1(.CATPRIOR)
 ...K AGGDATA,AGGERR
 Q
CLEAN ;
 K AGCODES,AGGRET,AGGDATA,AGGFLAG,AGGFILE,FIELDTYP,AGGHDR,AGGZERO
 K RECORD,AGCODES,AGGRETMP,AGCDSTR,CAT,CATEGORY,COVTYPE,EFFDT,INSPTR,INSTYPE,POLHPTR
 K PRIORITY,RECPTR,TPRECPTR,SBRECPTR,FILENO,DATA,FIELDS,FDAIENS,AGGINS,AGGPOLH
 K X,Y,HDR,AGGFIELD
 Q
 ;CREATE BMXNET COLUMN HEADER FOR BMX RECORD SET
BMXHDR(HDR) ;
 S HDR="T00004CATEGORY"_U
 S HDR=HDR_"N000030PRIORITY"_U
 S HDR=HDR_"N000030INSURER"_U
 S HDR=HDR_"N000030FILE_NUMBER"_U
 S HDR=HDR_"F000030FDA_IENS"_U
 S HDR=HDR_"F000050FIELD"_U
 S HDR=HDR_"F000080DATA"
 Q HDR
 ;CREATE BMXNET RECORD SET TO SEND BACK TO CLIENT
BMXSET(CATPRIOR,AGGXY) ;
 N AGGRET
 S AGGRET=""
 S CATEGORY=""
 F  S CATEGORY=$O(CATPRIOR(CATEGORY)) Q:CATEGORY=""  D
 .S PRIORITY=""
 .F  S PRIORITY=$O(CATPRIOR(CATEGORY,PRIORITY)) Q:PRIORITY=""  D
 ..S INSPTR=""
 ..F  S INSPTR=$O(CATPRIOR(CATEGORY,PRIORITY,INSPTR)) Q:INSPTR=""  D
 ...S FILENO=""
 ...F  S FILENO=$O(CATPRIOR(CATEGORY,PRIORITY,INSPTR,FILENO)) Q:FILENO=""  D
 ....S FDAIENS=""
 ....F  S FDAIENS=$O(CATPRIOR(CATEGORY,PRIORITY,INSPTR,FILENO,FDAIENS)) Q:FDAIENS=""  D
 .....S FIELD=""
 .....F  S FIELD=$O(CATPRIOR(CATEGORY,PRIORITY,INSPTR,FILENO,FDAIENS,FIELD)) Q:FIELD=""  D
 ......S DATA=$G(CATPRIOR(CATEGORY,PRIORITY,INSPTR,FILENO,FDAIENS,FIELD))
 ......S:DATA="" DATA=$G(CATPRIOR(CATEGORY,PRIORITY,INSPTR,FILENO,FDAIENS,FIELD,"I"))
 ......S:DATA="" DATA=$G(CATPRIOR(CATEGORY,PRIORITY,INSPTR,FILENO,FDAIENS,FIELD,"E"))
 ......S AGGRET=AGGRET_CATEGORY_U_PRIORITY_U_INSPTR_U_FILENO_U_FDAIENS_U_FIELD_U_DATA_$C(30)
 ......;W !,AGGRET
 M AGGXY=AGGRET
 Q
GETCODES() ;
 S AGZERO=$G(^DD(9000035,.04,0)),AGCDSTR=$P(AGZERO,U,3)
 S AGCODES=U
 F PIECE=1:1 Q:$P($P(AGCDSTR,";",PIECE),":")=""  S AGCODES=AGCODES_$S($P($P(AGCDSTR,";",PIECE),":")="A":"T",1:$P($P(AGCDSTR,";",PIECE),":"))_U
 K AGZERO,PIECE
 Q AGCODES
UPPER(STR) ;EP - CHANGE LOWER TO UPPER
 Q $TR(STR,"abcdefghijklmnopqrstuvwxyz","ABCDEFGHIJKLMNOPQRSTUVWXYZ")
TYPE(TYPE) ;SET FIELDTYPE TO T(TEXT),N(UMERIC),I(NTEGER) OR D(ATE)
 Q:TYPE["D" "D"
 Q:TYPE["N" "N"
 Q:TYPE["P" "I"
 Q "F"
SPECIAL(STR) ;CHANGE SPECIAL CHARS TO NULL
 Q $TR(STR,"'""!@#$%^&*():;<>?/\|,.`~[]{}-+=","")
 ;DELETE OBSOLETE FIELDS
DELOBSOL(CATPRIOR) ;
 S CATEGORY=""
 F  S CATEGORY=$O(CATPRIOR(CATEGORY)) Q:CATEGORY=""  D
 .S PRIORITY=""
 .F  S PRIORITY=$O(CATPRIOR(CATEGORY,PRIORITY)) Q:PRIORITY=""  D
 ..S INSPTR=""
 ..F  S INSPTR=$O(CATPRIOR(CATEGORY,PRIORITY,INSPTR)) Q:INSPTR=""  D
 ...S FILENO=""
 ...F  S FILENO=$O(CATPRIOR(CATEGORY,PRIORITY,INSPTR,FILENO)) Q:FILENO=""  D
 ....S FDAIENS=""
 ....F  S FDAIENS=$O(CATPRIOR(CATEGORY,PRIORITY,INSPTR,FILENO,FDAIENS)) Q:FDAIENS=""  D
 .....S FIELD=""
 .....F  S FIELD=$O(CATPRIOR(CATEGORY,PRIORITY,INSPTR,FILENO,FDAIENS,FIELD)) Q:FIELD=""  D
 ......D FIELD^DID(FILENO,FIELD,"","LABEL","AGGFIELD","AGGERR")
 ......I AGGFIELD("LABEL")["*" K CATPRIOR(CATEGORY,PRIORITY,INSPTR,FILENO,FDAIENS,FIELD)
 Q