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

AGAPIPAT.m

Go to the documentation of this file.
AGAPIPAT ;IHS/DEPM/DMJ/TPF - PATIENT FILE(S) API'S [ 09/21/2006  5:24 PM ]
 ;;7.1;PATIENT REGISTRATION;**2,9,11**;AUG 25, 2005;Build 1
 ;INITIAL SUBROUTINE STUBS WERE WRITTEN BY DON JACKSON AT REQUEST OF JEANETTE
 ;KOMPKOFF. ON 9/28/2006 SANDRA LAHI REASSIGNED THE API TO TIM FRAZIER
 ;
 ;10/11/2006
 ;CALLS FROM DON WERE CHANGED FROM /// DIE CALLS TO DBS (API) CALLS TO
 ;ELIMINATE ALL POSSIBLE INTERACTIVE OUTPUT FROM THE API
 ;
 ;08/20/2010 - AG*7.1*9 - Added PREF/
 ;DISCUSSION IN SAC ON:
 ;TO LIMIT THE CALLER TO CERTAIN PACKAGES USE A REQUIRED PARAMETER OR $ZU(96,9)
 ;TO GET THE NAME OF THE CALLING ROUTINE??
 ;
 ;IHS/OIT/NKD AG*7.1*11 MU2 PREFERRED METHOD
 ;
 ;EACH EDIT SUBROUTINE RETURNS 1 IF THE EDIT WAS SUCCESSFUL - $D(AGERRS) WILL BE 0
 ;OR A 0 IF UNSUCCESSFUL.
 ;IF THE CALL IS TRYING TO DELETE THE FIELD AND THE FIELD IS SET UP IN THE
 ;'REGISTRATION PARAMETER' FILE AS A REQUIRED FIELD FOR THE SITE THEN A MESSAGE
 ;WILL BE RETURNED.
 ;THE CALLER CAN PASS AN .ARRAY TO AGERRS TO RECEIVE ERROR MESSAGES IF ANY. THE
 ;ERROR MESSAGE ARRAY WILL BE CLEARED IMMEDIATELY UPON ENTRY TO THE API CALL
 ;
 ;
 Q
F111(AGDFN,AGVAL,AGERRS) ;EP - edit file 2, field .111 STREET ADDRESS [LINE 1]
 ;W !!,"CALLED BY: ",$ZU(96,9)
 K AGERRS
 ;WHAT ARE CURRENT 'REGISTRATION PARAMETERS' #9009061 SETTINGS FOR SITE
 ;REQUIRED MANDATORY FIELDS
 I $$ISREQ^AGFLDREQ(2,.111) Q:($G(AGVAL)="@")!($G(AGVAL)="") "SITE MANDATORY FIELD REQUIRED"
 N AGFDA,AGIENS
 S AGIENS=$G(AGDFN)_","
 S AGFDA(2,AGIENS,.111)=$G(AGVAL)
 D FILE^DIE("EK","AGFDA","AGERRS")
 I '$D(AGERRS) D UPDATE1^AGED(DUZ(2),AGDFN,1,"")
 Q '$D(AGERRS)
F114(AGDFN,AGVAL,AGERRS) ;EP - edit file 2, field .114 CITY
 K AGERRS
 I $$ISREQ^AGFLDREQ(2,.114) Q:($G(AGVAL)="@")!($G(AGVAL)="") "SITE MANDATORY FIELD REQUIRED"
 N AGFDA,AGIENS
 S AGIENS=$G(AGDFN)_","
 S AGFDA(2,AGIENS,.114)=$G(AGVAL)
 D FILE^DIE("EK","AGFDA","AGERRS")
 I '$D(AGERRS) D UPDATE1^AGED(DUZ(2),AGDFN,1,"")
 Q '$D(AGERRS)
F115(AGDFN,AGVAL,AGERRS) ;EP -edit file 2, field .115 STATE
 K AGERRS
 I $$ISREQ^AGFLDREQ(2,.115) Q:($G(AGVAL)="@")!($G(AGVAL)="") "SITE MANDATORY FIELD REQUIRED"
 N AGFDA,AGIENS
 S AGIENS=$G(AGDFN)_","
 S AGFDA(2,AGIENS,.115)=$G(AGVAL)
 D FILE^DIE("EK","AGFDA","AGERRS")
 I '$D(AGERRS) D UPDATE1^AGED(DUZ(2),AGDFN,1,"")
 Q '$D(AGERRS)
 ;
F116(AGDFN,AGVAL,AGERRS) ;EP - edit file 2, field .116, ZIP CODE
 K AGERRS
 I $$ISREQ^AGFLDREQ(2,.116) Q:($G(AGVAL)="@")!($G(AGVAL)="") "SITE MANDATORY FIELD REQUIRED"
 N AGFDA,AGIENS
 S AGIENS=$G(AGDFN)_","
 S AGFDA(2,AGIENS,.116)=$G(AGVAL)
 D FILE^DIE("EK","AGFDA","AGERRS")
 I '$D(AGERRS) D UPDATE1^AGED(DUZ(2),AGDFN,1,"")
 Q '$D(AGERRS)
 ;
F131(AGDFN,AGVAL,AGERRS) ;EP - edit file 2, field .131 PHONE NUMBER [RESIDENCE]
 K AGERRS
 I $$ISREQ^AGFLDREQ(2,.131) Q:($G(AGVAL)="@")!($G(AGVAL)="") "SITE MANDATORY FIELD REQUIRED"
 N AGFDA,AGIENS
 S AGIENS=$G(AGDFN)_","
 S AGFDA(2,AGIENS,.131)=$G(AGVAL)
 D FILE^DIE("EK","AGFDA","AGERRS")
 I '$D(AGERRS) D UPDATE1^AGED(DUZ(2),AGDFN,1,"")
 Q '$D(AGERRS)
F132(AGDFN,AGVAL,AGERRS) ;EP - edit file 2, field .132 PHONE NUMBER [WORK]
 K AGERRS
 I $$ISREQ^AGFLDREQ(2,.132) Q:($G(AGVAL)="@")!($G(AGVAL)="") "SITE MANDATORY FIELD REQUIRED"
 N AGFDA,AGIENS
 S AGIENS=$G(AGDFN)_","
 S AGFDA(2,AGIENS,.132)=$G(AGVAL)
 D FILE^DIE("EK","AGFDA","AGERRS")
 I '$D(AGERRS) D UPDATE1^AGED(DUZ(2),AGDFN,1,"")
 Q '$D(AGERRS)
F1219(AGDFN,AGVAL,AGERRS) ;EP - edit file 2, field .1219 TEMPORARY PHONE NUMBER
 K AGERRS
 I $$ISREQ^AGFLDREQ(2,.1219) Q:($G(AGVAL)="@")!($G(AGVAL)="") "SITE MANDATORY FIELD REQUIRED"
 N AGFDA,AGIENS
 S AGIENS=$G(AGDFN)_","
 S AGFDA(2,AGIENS,.1219)=$G(AGVAL)
 D FILE^DIE("EK","AGFDA","AGERRS")
 I '$D(AGERRS) D UPDATE1^AGED(DUZ(2),AGDFN,1,"")
 Q '$D(AGERRS)
NIH(AGDFN,AGNUM,AGERRS) ;EP - edit file 9000001 field .35 number in household
 ;NUM=number
 K AGERRS
 I $$ISREQ^AGFLDREQ(9000001,.35) Q:($G(AGNUM)="@")!($G(AGNUM)="") "SITE MANDATORY FIELD REQUIRED"
 N AGFDA,AGIENS
 S AGIENS=$G(AGDFN)_","
 S AGFDA(9000001,AGIENS,.35)=$G(AGNUM)
 D FILE^DIE("EK","AGFDA","AGERRS")
 I '$D(AGERRS) D UPDATE1^AGED(DUZ(2),AGDFN,1,"")
 Q '$D(AGERRS)
THI(AGDFN,AGAMT,AGERRS) ;EP - edit file 9000001, field .36 total household income
 ;AMT=amount
 K AGERRS
 I $$ISREQ^AGFLDREQ(9000001,.36) Q:($G(AGAMT)="@")!($G(AGAMT)="") "SITE MANDATORY FIELD REQUIRED"
 N AGFDA,AGIENS
 S AGIENS=AGDFN_","
 S AGFDA(9000001,AGIENS,.36)=$G(AGAMT)
 D FILE^DIE("EK","AGFDA","AGERRS")
 I '$D(AGERRS) D UPDATE1^AGED(DUZ(2),AGDFN,1,"")
 Q '$D(AGERRS)
ARACE(AGDFN,AGRACE,AGMET,AGERRS) ;EP - add race
 ;AGRACE=race
 ;AGMET=method of collection file 10.3
 K AGERRS
 N AGFDA,AGIENS
 S AGIENS="+1,"_$G(AGDFN)_","
 S AGFDA(2.02,AGIENS,.01)=$G(AGRACE)
 S AGFDA(2.02,AGIENS,.02)=$G(AGMET)
 D UPDATE^DIE("E","AGFDA",,"AGERRS")
 Q '$D(AGERRS)
 ;
 ;THE CALLER WILL NEED TO FIND OUT WHICH ENTRY IN THE MULTIPLE
 ;THEY WISH TO DELETE. THE AGDA IS THE IEN OF THE RACE IN THE 10.3 FILE 
DRACE(AGDFN,AGDA,AGERRS) ;EP - delete race
 K AGERRS
 N AGFDA,AGIENS
 S AGIENS=$G(AGDA)_","_$G(AGDFN)_","
 S AGFDA(2.02,AGIENS,.01)="@"
 D FILE^DIE("EK","AGFDA","AGERRS")
 I '$D(AGERRS) D UPDATE1^AGED(DUZ(2),AGDFN,1,"")
 Q '$D(AGERRS)
 ;
AETH(AGDFN,AGETH,AGMET,AGERRS) ;EP - add ethnicity .06 In file 2
 ;AGETH=ethnicity SEE FILE 10.2
 ;AGMET=method of collection SEE FILE 10.3
 K AGERRS
 N AGFDA,AGIENS
 S AGIENS="+1,"_$G(AGDFN)_","
 S AGFDA(2.06,AGIENS,.01)=$G(AGETH)
 S AGFDA(2.06,AGIENS,.02)=$G(AGMET)
 D UPDATE^DIE("E","AGFDA",,"AGERRS")
 Q '$D(AGERRS)
 ;
DETH(AGDFN,AGDA,AGERRS) ;EP - delete ethnicity
 K AGERRS
 Q:$G(AGDFN)="" "PARAMETER MISSING"
 ;there is only one entry allowed here even though its a mulitple
 ;if the caller does not supply the DA try and find it
 S:$G(AGDA)="" AGDA=$O(^DPT(AGDFN,.06,0))
 Q:AGDA="" "ENTRY NOT FOUND"
 N AGFDA,AGIENS
 S AGIENS=AGDA_","_AGDFN_","
 S AGFDA(2.06,AGIENS,.01)="@"
 D FILE^DIE("EK","AGFDA","AGERRS")
 I '$D(AGERRS) D UPDATE1^AGED(DUZ(2),AGDFN,1,"")
 Q '$D(AGERRS)
 ;
PREF(AGDFN,AGLNG,AGERRS) ;EP - edit file 9000001.86, field .04 PREFERRED LANGUAGE
 ;AG*7.1*9 - API Created
 ;Input:
 ; AGDFN - The Patient's IEN
 ; AGLNG - Preferred Language (pointer to 9999999.99)
 ;
 ;Output:
 ; Function Return - 1 (Success), 0 (Failure)
 ;          AGERRS - Error message/array
 ;          
 N CHK,DA,IENS,AGLANG
 K AGERRS
 S:AGLNG="" AGLNG="@"
 ;
 ;Check to see if PREFERRED LANGUAGE field is required
 I $$ALTREQ^AGFLDREQ(9000001,"PREFERRED LANGUAGE") I ($G(AGLNG)="@") S AGERRS="SITE MANDATORY FIELD REQUIRED" Q 0
 ;
 ;Check if Preferred Language not in the Primary or Other Spoken Language fields
 S CHK=0 I AGLNG'="@" D
 . N DEF,ERROR,IEN,LNG,OLNG,PRM
 . S DEF=$$CLANG^AGED10B(AGDFN)
 . S IEN=$P(DEF,U)              ;IEN of Language multiple
 . S PRM=$P($P(DEF,U,2),":")    ;Primary Language
 . I PRM=AGLNG S CHK=1 Q        ;No Error if Primary equals Preferred
 . ;
 . ;Look in Other Languages
 . D GETS^DIQ(9000001.86,IEN_","_AGDFN_",",".05*","I","OLNG","ERROR")
 . S IEN="" F  S IEN=$O(OLNG("9000001.8605",IEN)) Q:IEN=""  D  Q:CHK=1
 .. S LNG=$G(OLNG("9000001.8605",IEN,".01","I")) Q:LNG=""
 .. I LNG=AGLNG S CHK=1
 ;
 ;Log New Language Entry
 S DA=$$NEWLG^AGED10B(AGDFN)
 S DA(1)=AGDFN
 S IENS=$$IENS^DILF(.DA)
 I CHK=0,AGLNG'="@" S AGLANG(9000001.86,IENS,".02")=AGLNG  ;Set primary if preferred not found
 S AGLANG(9000001.86,IENS,".04")=AGLNG  ;Preferred
 D FILE^DIE("","AGLANG","AGERRS")
 ;
 I '$D(AGERRS) D UPDATE1^AGED(DUZ(2),AGDFN,1,"")
 Q '$D(AGERRS)
 ;
PMETH(AGDFN,AGMETH,AGERRS) ;EP - edit file 9000001 field 4002 PREFERRED REMINDER METHOD
 ;Input:
 ; AGDFN - The patient's IEN
 ; AGMETH - The patient's new Preferred Method of Communication     ;IHS/OIT/NKD AG*7.1*11 MU2 PREFERRED METHOD
 ; 
 ;Output:
 ; Function Return - 1 (Success), 0 (Failure)
 ;          AGERRS - Error message/array
 ;
 N AGFDA,AGIENS,%,%ANS,%D,%H,%I,EXTENT,FIELDNAM,RETURN,XBI
 S:AGMETH="" AGMETH="@"
 K AGERRS
 ;
 ;Entry Validation
 ;IHS/OIT/NKD AG*7.1*11 MU2 PREFERRED METHOD
 ;I AGMETH'="P",AGMETH'="E",AGMETH'="M",AGMETH'="@" S AGERRS="INVALID ENTRY FOR FIELD. EXPECTING 'P', 'E', or 'M'" Q 0
 I (AGMETH'="@")&($$EXTERNAL^DILFD(9000001,4002,,AGMETH)']"") S AGERRS="INVALID ENTRY FOR FIELD." Q 0
 ;
 ;Check to see if PREFERRED REMINDER METHOD field is required
 I $$ISREQ^AGFLDREQ(9000001,4002) I ($G(AGMETH)="@")!($G(AGMETH)="") S AGERRS="SITE MANDATORY FIELD REQUIRED" Q 0
 ;
 S AGIENS=$G(AGDFN)_","
 S AGFDA(9000001,AGIENS,4002)=$G(AGMETH)
 D FILE^DIE("EK","AGFDA","AGERRS")
 ;
 I '$D(AGERRS) D UPDATE1^AGED(DUZ(2),AGDFN,1,"")
 Q '$D(AGERRS)
 ;
EMAIL(AGDFN,AGEMAIL,AGUPDATE,AGERRS) ;EP - edit file 9000001 field 1802 CURRENT EMAIL ADDRESS
 ;Input:
 ; AGDFN - The Patient's IEN
 ; AGEMAIL - The patient's new email address
 ; AGUPDATE (Optional) - 0/Null - Add new email to historical email list, 1 - Do not add email to historical email list
 ; 
 ;Output:
 ; Function Return - 1 (Success), 0 (Failure)
 ;          AGERRS - Error message/array
 ;
 N AGFDA,AGIENS,X,%,%ANS,%D,%H,%I,EXTENT,FIELDNAM,RETURN,XBI
 S:AGEMAIL="" AGEMAIL="@"
 S AGUPDATE=$G(AGUPDATE) S:AGUPDATE'=1 AGUPDATE=0
 K AGERRS
 ;
 ;Entry Validation
 I AGEMAIL'="@" S X=AGEMAIL D EMAIL^AUPNPED I '$D(X) S AGERRS="INVALID EMAIL ADDRESS FORMAT" Q 0
 ;
 ;Check to see if PREFERRED REMINDER METHOD field is required
 I $$ISREQ^AGFLDREQ(9000001,1802) I ($G(AGEMAIL)="@")!($G(AGEMAIL)="") S AGERRS="SITE MANDATORY FIELD REQUIRED" Q 0
 ;
 S AGIENS=$G(AGDFN)_","
 S AGFDA(9000001,AGIENS,1802)=$G(AGEMAIL)
 D FILE^DIE("EK","AGFDA","AGERRS")
 ;
 ;Save into History - Cannot use regular UPDTEMAL^AGUTILS call since it displays text to screen
 I AGEMAIL'="@",'$D(AGERRS),'AGUPDATE D  I $D(AGERRS) Q 0
 . N ADDREC
 . K DA,DIC,DIE,DIR,DR,X,Y
 . S DA(1)=AGDFN
 . S DIC="^AUPNPAT("_DA(1)_",82,"
 . S DIC(0)="L"
 . S X=""""_DT_""""
 . D ^DIC
 . I Y<0 S AGERRS="ERROR UPDATING HISTORICAL EMAIL ADDRESS" Q
 . S ADDREC=+Y
 . K DA,DIC,DIE,DR,X,Y
 . S DA=ADDREC
 . S DA(1)=AGDFN
 . S DIE="^AUPNPAT("_DA(1)_",82,"
 . S DR=".02///^S X=AGEMAIL;"
 . D ^DIE
 . K DA,DIC,DIE,DR,X,Y
 ;
 I '$D(AGERRS) D UPDATE1^AGED(DUZ(2),AGDFN,1,"")
 Q '$D(AGERRS)
 ;
 ;ALLOWED PACKAGES - not used yet
P ;;^SD^BSD^BW^WV^