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

PSO7P529.m

Go to the documentation of this file.
PSO7P529 ;ALB/BI - DEA INITIAL IMPORT ;5/5/21  06:52
 ;;7.0;OUTPATIENT PHARMACY;**529**;DEC 1997;Build 94
 ;External reference to sub-file NEW DEA #S (#200.5321) is supported by DBIA 7000
 ;External reference to DEA NUMBERS file (#8991.9) is supported by DBIA 7002
 Q
 ;
INITLOAD(LIFE) ; -- main entry point for DEA INITIAL IMPORT
 N DEA,FG,NPIEN,NPDATA,NPNAME,DEAIEN,PHANDLE,PSOLDHNDL
 S PSOLDHNDL=$O(^XTMP("PSODEAWB-")) I PSOLDHNDL["PSODEAWB" K ^XTMP(PSOLDHNDL) ; Remove last batch of Exceptions from ^XTMP
 S:'$D(LIFE) LIFE=90
 S PHANDLE=$$INITXTMP("PSODEAWB","DEA INITIAL IMPORT",LIFE)
 S ^TMP($J,"PSODEAWB")=1
 S DEA="A"
 F  S DEA=$O(^VA(200,"PS1",DEA)) Q:DEA=""  D
 . N FILERR,ERRCODE,FG
 . S NPIEN=$O(^VA(200,"PS1",DEA,0))
 . S NPNAME=$$GET1^DIQ(200,NPIEN,.01)
 . D BMES^XPDUTL(DEA_"     "_NPNAME)
 . S SC=$$GET(.FG,DEA)
 . S ERRCODE=SC
 . I 'SC I ERRCODE'[404 D LOG(.FG,NPIEN,PHANDLE,"WEB SERVICE ISSUE") Q
 . I 'SC I $G(ERRCODE)[404 D LOG(.FG,NPIEN,PHANDLE,"DEA# NOT FOUND IN DOJ FILE") Q
 . I $P(FG("name"),",",1)'=$P(NPNAME,",",1) D LOG(.FG,NPIEN,PHANDLE,"NAME MISMATCH") Q
 . I $E($G(FG("businessActivityCode")))'=""&($E($G(FG("businessActivityCode")))'="A")&($E($G(FG("businessActivityCode")))'="C") D LOG(.FG,NPIEN,PHANDLE,"INSTITUTIONAL DEA# REQUIRES INDIVIDUAL DEA SUFFIX") Q
 . I $D(^XTV(8991.9,"B",DEA)) D LOG(.FG,NPIEN,PHANDLE,"DUPLICATE DEA NUMBER") Q
 . K DEAIEN S SC=$$DEAFILE(DEA,NPIEN,PHANDLE,.FG,.DEAIEN) I 'SC  D LOG(.FG,NPIEN,PHANDLE,"DATA FILING ISSUE. "_$P($G(SC),"^",2)) Q
 . D NPFILE(DEA,NPIEN,DEAIEN,.FILERR) I $G(FILERR)'="" D LOG(.FG,NPIEN,PHANDLE,"MIGRATION DATA NOT FILED. "_FILERR) Q
 K ^TMP($J,"PSODEAWB")
 D TMPMSG
 D BMES^XPDUTL("     *******************************************************")
 D BMES^XPDUTL("     The patch post installation process is complete.       ")
 D BMES^XPDUTL("          The DEA data migration was successful.            ")
 D BMES^XPDUTL("     *******************************************************")
 Q
 ;
GET(FG,DEA) ; Function to Get the Remote DEA information, Return in FG.
 N DATA,ERRORS,PATH,REQUEST,RESOURCE,RESPJSON,RESPONSE,SC,SERVER,SERVICE,PSOERR
 Q:$G(DEA)="" "0^No DEA Number Entered."
 S SERVER="PSO DOJ/DEA WEB SERVER"
 S SERVICE="PSO DOJ/DEA WEB SERVICE"
 S RESOURCE=DEA
 ;
 ; Get an instance of the REST request object.
 S REQUEST=$$GETREST^XOBWLIB(SERVICE,SERVER)
 ;
 ; Execute the HTTP Get method.
 S SC=$$GET^XOBWLIB(REQUEST,RESOURCE,.PSOERR,0)
 I 'SC Q "0^General Service Error"_PSOERR.code
 ;
 ; Process the response.
 S RESPONSE=REQUEST.HttpResponse
 S DATA=RESPONSE.Data
 S RESPJSON=""
 F  Q:DATA.AtEnd  Set RESPJSON=RESPJSON_DATA.ReadLine()
 S RESPJSON=$TR(RESPJSON,$C(10),"")
 I RESPJSON="" Q "0^No DEA Found."
 ;
 ; Decode the JSON format into a MUMPS global in FG
 D DECODE^XLFJSON("RESPJSON","FG","ERRORS")
 ;
 ; Default the businessActivitySubcode.
 I $G(FG("businessActivitySubcode"))="" S FG("businessActivitySubcode")=0
 ;
 Q "1^Success"
 ;
LOG(FG,NPIEN,PHANDLE,REASON) ; -- Log import issues
 N CNT,FLD,IENS,TR
 D GETS^DIQ(200,NPIEN,".01;1;8;28;41.99;53.2;53.9","R","TR")
 S IENS=$O(TR(200,""))
 S ^XTMP(PHANDLE,0,0)=$G(^XTMP(PHANDLE,0,0))+1,CNT=^XTMP(PHANDLE,0,0)
 S ^XTMP(PHANDLE,CNT,"LOCAL","DUZ")=NPIEN
 M ^XTMP(PHANDLE,CNT,"WS")=FG,^XTMP(PHANDLE,CNT,"LOCAL")=TR(200,IENS)
 S ^XTMP(PHANDLE,CNT,"Exception")=REASON
 Q
 ;
DEAFILE(DEA,NPIEN,PHANDLE,FG,DEAIEN) ; -- File the import data in DEA NUMBERS FILE #8991.9
 ; POSTAL^XIPUTL used in agreement with Integration Agreement: 3618
 N ED,FDA,IENS,IENROOT,MSGROOT,NPDETOX,SC,XIP,XSTATE,SCH200,SCHFLD,SCHCNT,BAC,SCH200ST,DUPDXDEA
 N DS S DS=$$UP^XLFSTR($G(FG("drugSchedule")))
 S SC="1^SUCCESS"
 S IENS=$S($D(DEAIEN):DEAIEN_",",1:"+1,")
 S FDA(1,8991.9,IENS,.01)=DEA
 S FDA(1,8991.9,IENS,.02)=$G(FG("businessActivityCode"))_$G(FG("businessActivitySubcode")) ; Pointer to file #8991.8
 S BAC=$G(FG("businessActivityCode"))_$G(FG("businessActivitySubcode"))
 S FDA(1,8991.9,IENS,.03)=$S($$DETOXCHK^PSODEAUT(BAC):"X"_$E(DEA,2,9),1:"")    ; DETOX NUMBER
 ;
 ; DETOX DIFFERENCE LOGGING BUT NOT QUITTING
 S NPDETOX=$$GET1^DIQ(200,NPIEN_",",53.11)
 I NPDETOX'="",'$$DETOXCHK^PSODEAUT(BAC) D LOG(.FG,NPIEN,PHANDLE,"DETOX NUMBER "_NPDETOX_" DOESN'T MATCH BUSINESS ACTIVITY CODE.")
 I NPDETOX'="",$$DETOXCHK^PSODEAUT(BAC),NPDETOX'=("X"_$E(DEA,2,9)) D LOG(.FG,NPIEN,PHANDLE,"Existing DETOX "_NPDETOX_" and CALCULATED DETOX "_"X"_$E(DEA,2,9)_" MISMATCH.")
 N CMPDETOX S CMPDETOX=$G(FDA(1,8991.9,IENS,.03))
 I CMPDETOX'="" I $$DETOXDUP^PSODEAUT(DEA,CMPDETOX,.DUPDXDEA) D LOG(.FG,NPIEN,PHANDLE,"Duplicate computed DETOX number "_CMPDETOX_" not filed.") D
 . S FDA(1,8991.9,IENS,.03)=""   ; Don't file duplicate DETOX
 ;
 S FDA(1,8991.9,IENS,.04)=$G(FG("expirationDate"))
 S FDA(1,8991.9,IENS,.06)=1  ; Setting all providers = INPATIENT for initial load.
 S FDA(1,8991.9,IENS,.07)=2  ; Setting all providers = INDIVIDUAL for initial load.
 S FDA(1,8991.9,IENS,1.1)=$G(FG("name"))
 S FDA(1,8991.9,IENS,1.2)=$G(FG("additionalCompanyInfo"))
 S FDA(1,8991.9,IENS,1.3)=$G(FG("address1"))
 S FDA(1,8991.9,IENS,1.4)=$G(FG("address2"))
 S FDA(1,8991.9,IENS,1.5)=$G(FG("city"))
 ;
 ; Special State Processing
 D POSTAL^XIPUTIL($G(FG("zipCode")),.XIP)
 S XSTATE=$G(XIP("STATE"))
 I XSTATE'="" S FDA(1,8991.9,IENS,1.6)=XSTATE ; Pointer to the State File #5.
 ;
 S FDA(1,8991.9,IENS,1.7)=$G(FG("zipCode"))
 ;
 D GETS^DIQ(200,NPIEN_",","55.1:55.6","I","SCH200")
 S SCH200ST=""
 S SCHCNT=0 F SCHFLD=55.1:.1:55.6 S SCHCNT=SCHCNT+SCH200(200,NPIEN_",",SCHFLD,"I")
 S $E(SCH200ST)=$S($G(SCH200(200,NPIEN_",",55.1,"I")):2,1:" ")
 S $E(SCH200ST,2,3)=$S($G(SCH200(200,NPIEN_",",55.2,"I")):"2N",1:"  ")
 S $E(SCH200ST,4)=$S($G(SCH200(200,NPIEN_",",55.3,"I")):3,1:" ")
 S $E(SCH200ST,5,6)=$S($G(SCH200(200,NPIEN_",",55.4,"I")):"3N",1:"  ")
 S $E(SCH200ST,7)=$S($G(SCH200(200,NPIEN_",",55.5,"I")):4,1:" ")
 S $E(SCH200ST,8)=$S($G(SCH200(200,NPIEN_",",55.6,"I")):5,1:" ")
 ;
 D:SCHCNT
 . S FDA(1,8991.9,IENS,2.1)=$S(SCH200(200,NPIEN_",",55.1,"I"):"Y",1:"N")    ; SCHEDULE II NARCOTIC
 . S FDA(1,8991.9,IENS,2.2)=$S(SCH200(200,NPIEN_",",55.2,"I"):"Y",1:"N")    ; SCHEDULE II NON-NARCOTIC
 . S FDA(1,8991.9,IENS,2.3)=$S(SCH200(200,NPIEN_",",55.3,"I"):"Y",1:"N")    ; SCHEDULE III NARCOTIC
 . S FDA(1,8991.9,IENS,2.4)=$S(SCH200(200,NPIEN_",",55.4,"I"):"Y",1:"N")    ; SCHEDULE III NON-NARCOTIC
 . S FDA(1,8991.9,IENS,2.5)=$S(SCH200(200,NPIEN_",",55.5,"I"):"Y",1:"N")    ; SCHEDULE IV
 . S FDA(1,8991.9,IENS,2.6)=$S(SCH200(200,NPIEN_",",55.6,"I"):"Y",1:"N")    ; SCHEDULE V
 . I $TR(SCH200ST," ")'=$TR(DS," ") D LOG(.FG,NPIEN,PHANDLE,"LOCAL SCHEDULES '"_$TR(SCH200ST," ")_"' DON'T MATCH DOJ SCHEDULES '"_$TR(DS," ")_"'")
 ;
 D:'SCHCNT
 . S FDA(1,8991.9,IENS,2.1)=$S(DS["22N":"Y",(DS["2"&(DS'["2N")):"Y",1:"N") ; SCHEDULE II NARCOTIC
 . S FDA(1,8991.9,IENS,2.2)=$S(DS["2N":"Y",1:"N")                          ; SCHEDULE II NON-NARCOTIC
 . S FDA(1,8991.9,IENS,2.3)=$S(DS["33N":"Y",(DS["3"&(DS'["3N")):"Y",1:"N") ; SCHEDULE III NARCOTIC
 . S FDA(1,8991.9,IENS,2.4)=$S(DS["3N":"Y",1:"N")                          ; SCHEDULE III NON-NARCOTIC
 . S FDA(1,8991.9,IENS,2.5)=$S(DS["4":"Y",1:"N")                           ; SCHEDULE IV
 . S FDA(1,8991.9,IENS,2.6)=$S(DS["5":"Y",1:"N")                           ; SCHEDULE V
 . I $TR(DS," ") D LOG(.FG,NPIEN,PHANDLE,"LOCAL SCHEDULES '"_$TR(SCH200ST," ")_"' DON'T MATCH DOJ SCHEDULES '"_$TR(DS," ")_"'")
 ;
 S FDA(1,8991.9,IENS,10.2)="N"  ; LAST UPDATED DATE/TIME
 ;S FDA(1,8991.9,IENS,10.3)=$G(FG("processedDate"))  ; LAST DOJ UPDATE DATE/TIME
 ; LAST DOJ UPDATE DATE/TIME not sent by DOJ - presence indicates DOJ update (not manually entered)
 S FDA(1,8991.9,IENS,10.3)="N"   ; LAST DOJ UPDATE DATE/TIME
 ;
 D UPDATE^DIE("E","FDA(1)","IENROOT","MSGROOT")
 I $D(MSGROOT) S SC="0^DATA NOT FILED. "_$G(MSGROOT("DIERR",1,"TEXT",1)) Q SC
 S DEAIEN=$S($D(IENROOT(1)):IENROOT(1),1:IENS)
 I 'DEAIEN S SC="0^DATA NOT FILED." Q SC
 S FDA(2,8991.9,DEAIEN,10.1)=DUZ D FILE^DIE("","FDA(2)","MSGROOT")
 Q SC
 ;
NPFILE(DEA,NPIEN,DEAIEN,FILERR) ; -- File the DEA NUMBER in the NEW PERSON FILE #200.
 N FDA,IENROOT,MSGROOT
 Q:'$G(NPIEN)  Q:'$G(DEAIEN)
 S FDA(1,200.5321,"+1,"_NPIEN_",",.01)=DEA
 S FDA(1,200.5321,"+1,"_NPIEN_",",.02)=""
 S FDA(1,200.5321,"+1,"_NPIEN_",",.03)=+DEAIEN
 D UPDATE^DIE("","FDA(1)","IENROOT","MSGROOT")
 I $D(MSGROOT) S FILERR=$G(MSGROOT("DIERR",1,"TEXT",1)) I FILERR="" S FILERR="MIGRATION DATA NOT FILED"
 Q
 ;
INITXTMP(NAMESPC,TITLE,LIFE)  ; -- Initialize ^XTMP according to SAC standards.
 N BEGDT,PURGDT
 S BEGDT=$$NOW^XLFDT()
 S PURGDT=$$FMADD^XLFDT(BEGDT,LIFE)
 S NAMESPC=NAMESPC_"-"_BEGDT_"-"_$J
 S ^XTMP(NAMESPC,0)=PURGDT_"^"_BEGDT_"^"_TITLE
 Q NAMESPC
 ;
TMPMSG  ; Send MailMan LOG REPORT
 N CNT,OBJ,PHANDLE,XMSUB,XMDUZ,PSOCNT,PSODASH,EXREAS,PSOXMD,PSOLDXMD
 S $P(PSODASH,"-",80)=""
 S PHANDLE=$O(^XTMP("PSODEAWB"_"-"_($H+1)),-1)
 S PSOXMD=$$INITXTMP("PSOXMD","DEA INITIAL IMPORT",$S($G(LIFE):LIFE,1:90))
 S PSOLDXMD=$O(^XTMP("PSOXMD")) I PSOLDXMD["PSOXMD" K ^XTMP(PSOLDXMD)
 S XMSUB="DEA Migration Exception Report "_$$FMTE^XLFDT(DT,"5DZ"),XMDUZ=.5
 K XMY S NPIEN=0 F  S NPIEN=$O(^XUSEC("PSDMGR",NPIEN)) Q:'+NPIEN  S XMY(NPIEN)=""
 K PSOTEXT  S PSOCNT=0
 N DEAWORK
 F CNT=1:1:$G(^XTMP(PHANDLE,0,0)) D
 . K OBJ M OBJ=^XTMP(PHANDLE,CNT)
 . I CNT>1,($G(DEAWORK)=OBJ("LOCAL","DEA#")) D  Q   ; Create DEA grouping for multiple exceptions on one DEA number
 . . S EXREAS=$$LJ^XLFSTR(OBJ("Exception"),"138T")
 . . N EXREAS1 S EXREAS1=$E(EXREAS,1,68) S EXREAS1=$P(EXREAS1," ",1,$L(EXREAS1," ")-1)
 . . S PSOCNT=PSOCNT+1,^XTMP(PSOXMD,$J,PSOCNT,0)="EXCEPTION: "_$E(EXREAS,1,$L(EXREAS1))    ; 79
 . . I $TR($E(EXREAS,$L(EXREAS1)+1,999)," ","")'="" S PSOCNT=PSOCNT+1,PSOTEXT(PSOCNT)=$E(EXREAS,$L(EXREAS1)+1,150)
 . . S PSOCNT=$G(PSOCNT)+1
 . ;
 . S ^XTMP(PSOXMD,$J,PSOCNT,0)=PSODASH
 . S PSOCNT=PSOCNT+1
 . S ^XTMP(PSOXMD,$J,PSOCNT,0)="PROVIDER NAME: "_$$LJ^XLFSTR(OBJ("LOCAL","NAME"),"35T")_"  "                 ; 52
 . S ^XTMP(PSOXMD,$J,PSOCNT,0)=^XTMP(PSOXMD,$J,PSOCNT,0)_"INITIALS: "_$$LJ^XLFSTR(OBJ("LOCAL","INITIAL"),"5T")_" "     ; 16
 . ;
 . If OBJ("LOCAL","NAME")'=$G(OBJ("WS","name")) D
 .. S PSOCNT=PSOCNT+1
 .. S ^XTMP(PSOXMD,$J,PSOCNT,0)="DOJ PROVIDER NAME: "_$$LJ^XLFSTR($G(OBJ("WS","name")),"35T")                ; 54
 . ;
 . S PSOCNT=PSOCNT+1
 . S ^XTMP(PSOXMD,$J,PSOCNT,0)="TITLE: "_$$LJ^XLFSTR(OBJ("LOCAL","TITLE"),"30T")_"               "           ; 39
 . S ^XTMP(PSOXMD,$J,PSOCNT,0)=^XTMP(PSOXMD,$J,PSOCNT,0)_"DUZ: "_$$LJ^XLFSTR(OBJ("LOCAL","DUZ"),"10T")                 ; 15
 . ;
 . S PSOCNT=PSOCNT+1
 . S ^XTMP(PSOXMD,$J,PSOCNT,0)="NPI: "_$$LJ^XLFSTR(OBJ("LOCAL","NPI"),"10T")_"           "                   ; 27
 . S ^XTMP(PSOXMD,$J,PSOCNT,0)=^XTMP(PSOXMD,$J,PSOCNT,0)_"DEA#: "_$$LJ^XLFSTR(OBJ("LOCAL","DEA#"),"10T")_"          "  ; 27
 . S ^XTMP(PSOXMD,$J,PSOCNT,0)=^XTMP(PSOXMD,$J,PSOCNT,0)_"MAIL CODE: "_$$LJ^XLFSTR(OBJ("LOCAL","MAIL CODE"),"10T")     ; 21
 . ;
 . S PSOCNT=PSOCNT+1,^XTMP(PSOXMD,$J,PSOCNT,0)="REMARKS: "_$$LJ^XLFSTR(OBJ("LOCAL","REMARKS"),"60T")         ; 69
 . ;
 . S EXREAS=$$LJ^XLFSTR(OBJ("Exception"),"138T")
 . N EXREAS1 S EXREAS1=$E(EXREAS,1,68) S EXREAS1=$P(EXREAS1," ",1,$L(EXREAS1," ")-1)
 . S PSOCNT=PSOCNT+1,^XTMP(PSOXMD,$J,PSOCNT,0)="EXCEPTION: "_$E(EXREAS,1,$L(EXREAS1))    ; 79
 . I $TR($E(EXREAS,$L(EXREAS1)+1,999)," ","")'="" S PSOCNT=PSOCNT+1,^XTMP(PSOXMD,$J,PSOCNT,0)=$E(EXREAS,$L(EXREAS1)+1,150)
 . ;
 . S PSOCNT=PSOCNT+1     ;,^XTMP(PSOXMD,$J,PSOCNT,0)=PSODASH
 . S DEAWORK=OBJ("LOCAL","DEA#")
 . ;
 S PSOCNT=PSOCNT+1
 S ^XTMP(PSOXMD,$J,PSOCNT,0)=PSODASH
 S XMY(DUZ)="" N DIFROM S XMTEXT="^XTMP("""_PSOXMD_""","_$J_"," D ^XMD K DIFROM
 K PSOTEXT,XMTEXT
 ;
 Q