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

AGMPHLEU.m

Go to the documentation of this file.
AGMPHLEU ; IHS/SD/TPF - HLO MPI A28 MISSING ICN BACKGROUND TASKS ;    
 ;;7.2;IHS PATIENT REGISTRATION;**1,3,6**;MAY 20, 2010;Build 23
 ;
 ;RTN RUNS IN BACKGROUND AND TRAVERSES VA PATIENT FILE
 ;ANY RECORDS WITH FIELD ANY RECORDS WIH ONLY A LOCAL ICN
 ;OR MISSING AN EUID AN ATTEMPT WILL BE MADE TO DO ANOTHER
 ;EXACT MATCH QUERY A28 IN THE SAME WAY AS DONE IN THE 'ADD; OPTION
START ;EP - START UP MISSING AND LOCAL ID TASK
 D MISSEUID
 Q
 ;
MISSEUID ;EP - PROCESS MISSING EUID
 N DFNIEN,MISSING,ADDED,ERRORS,TMPDUZ2,NONORF,MERGED,LOCKED,NOCHART,QUEUED,PICN,TICN,DELAY,MAX,DA,CNT
 S TMPDUZ2=DUZ(2)
 S (MISSING,ADDED,ERRORS,NONORF,MERGED,LOCKED,NOCHART,QUEUED)=0
 ;05/30/2013 - KJH - TFS8081 - Update the ^XTMP global used to store temporary info about the MISSING ICN TASK.
 S ^XTMP("AGMPICN",0)=$$FMADD^XLFDT(DT,58)_U_DT_U_"AGMP MPI MISSING ICN TSK"
 S DELAY=+$G(^XTMP("AGMPICN","DELAY")) I DELAY=0 S DELAY=14 ;If not set, use 14 day minimum between attempts to get an ICN for a patient.
 S MAX=+$G(^XTMP("AGMPICN","MAX")) I MAX=0 S MAX=5000 ;If not set, use 5000 as the maximum number of attempts.
 ;06/07/2013 - DMB - TFS8081 - If running in foreground, let user pick maximum number of records to extract
 I '$D(ZTQUEUED) D  I MAX=-1 Q
 . N DIR,X,Y,DTOUT,DUOUT,DIRUT,DIROUT
 . W !!,"Enter the maximum number of messages you would like to create.  If you want to"
 . W !,"send messages for all active charts for all patients who are currently missing"
 . W !,"an ICN, enter 9999999",!
 . S DIR(0)="NA^1:9999999:0",DIR("A")="Maximum number of messages to send? ",DIR("B")=MAX
 . D ^DIR
 . I +Y<1 S MAX=-1 Q
 . S MAX=Y
 S DFNIEN=0
 ;05/30/2013 - KJH - TFS8081 - Update the MISSING ICN TASK to use the TREATING FACILITY LIST.
 F CNT=0:1 S DFNIEN=$O(^DPT(DFNIEN)) Q:'DFNIEN  D
 .I $D(^DPT(DFNIEN,-9)) S MERGED=MERGED+1 Q  ;DON'T ATTEMPT FOR MERGED RECORDS
 .I $$DEMOPAT^AGMPHLU(DFNIEN) Q  ; 9/13/2017 - GCD - CR 7713 - Don't upload demo patients.
 .S PICN=$$GET1^DIQ(2,DFNIEN_",",991.01,"E") ;PATIENT INTEGRATION CONTROL NUMBER
 .;W !,DFNIEN
 .;TRY A LOCK. IF CAN'T LOCK PATIENT, RECORD BEING BUILT??
 .L +^DPT(DFNIEN):5 I '$T S LOCKED=LOCKED+1 Q
 .L -^DPT(DFNIEN)
 .I '$D(ZTQUEUED),CNT#1000=0 W "."
 .I '$O(^AUPNPAT(DFNIEN,41,0)) S NOCHART=NOCHART+1 Q
 .S DUZ(2)=0
 .F  S DUZ(2)=$O(^AUPNPAT(DFNIEN,41,DUZ(2))) Q:DUZ(2)=""  D
 ..;W !,?5,$S($P($G(^AGFAC(DUZ(2),0)),U,21)'="":$P($G(^AGFAC(DUZ(2),0)),U,21),1:"UNDEFINED")
 ..I $P($G(^AGFAC(DUZ(2),0)),U,21)'="Y" D  Q  ;ONLY "OFFICAL REGISTERING FACILITIES"
 ...S NONORF=NONORF+1
 ..S DA=$O(^DGCN(391.91,"AINST",DUZ(2),DFNIEN,"")),TICN=""
 ..I DA S TICN=$$GET1^DIQ(391.91,DA_",",9999999.02,"E")  ;TREATING FACILITY INTEGRATION CONTROL NUMBER
 ..;05/30/2013 - KJH - TFS8081 - Add code to try to prevent system from attempting to resend a request until at least 7 days have passed.
 ..I PICN]"",TICN]"",PICN=TICN K ^XTMP("AGMPICN",DFNIEN,DUZ(2)) Q  ; OK. Does not need to be tracked.
 ..S MISSING=MISSING+1
 ..I $G(^XTMP("AGMPICN",DFNIEN,DUZ(2)))+DELAY>+$H S QUEUED=QUEUED+1 Q  ;Wait at least 'DELAY' days before trying again.
 ..;06/11/2013 - DMB - TFS8081 - Only add to queue if under the maximum number of attempts per execution
 ..I ADDED<MAX D ATTEMPT(DFNIEN,.ADDED,.ERRORS)
 S DUZ(2)=TMPDUZ2  ;RESTORE DUZ(2) TO TASKER
 I '$D(ZTQUEUED) D
 .W !,"PATIENT LOCKED: ",LOCKED
 .W !,"PATIENT MERGED: ",MERGED
 .W !,"NO CHARTS FOR PATIENT: ",NOCHART
 .W !,"ORF IS OFF FOR LOCATION/STATION: ",NONORF
 .W !!,"ICN MISSING FROM PATIENT/STATION: ",MISSING
 .W !,"ALREADY ON QUEUE: ",QUEUED
 .W !,"ERRORS: ",ERRORS
 .W !,"MESSAGES QUEUED: ",ADDED I ADDED>MAX W "   *** Per execution maximum of ",MAX," exceeeded ***"
 Q
 ;
ATTEMPT(DFN,ADDED,ERRORS) ;EP - TRY TO ADD PTS WITH MISSING EUIDs
 D CREATMSG^AGMPIHLO(DFN,"A28","",.SUCCESS)  ;DO THE A28
 I 'SUCCESS D  Q
 .S ERRORS=ERRORS+1
 .S ERR="CANNOT CREATE A28 DURING 'AGMP MPI MISSING ICN TSK'"
 .D NOTIF^AGMPIHLO(DFN,ERR)
 ;06/11/2013 - DMB - TFS8081 - If successful, update counter and add to the temporary global
 S ADDED=ADDED+1
 S ^XTMP("AGMPICN",DFNIEN,DUZ(2))=+$H
 ;05/29/2013 - KJH - TFS8109 - This was causing an extra message to be sent to EDR.
 ;S X="AG REGISTER A PATIENT",DIC=101,INDA=DFN
 ;D EN^XQOR
 Q
 ;CREATE OUTGOING BATCH
BATCHOUT() ;EP - THIS ENTRY POINT WILL COLLECT A28 MESSAGE FOR PTS WITH MISSING ICNS
 N MSG,PARMS,SEG,WHOTO,DFN,QUIT,BATCH,HLMP,HLMSTATE
 S BATCH=1
 S HLPM("MESSAGE TYPE")="ADT"
 S HLPM("EVENT")="A28"
 S HLPM("VERSION")=2.4
 S HLPM("FIELD SEPARATOR")="^"
 S HLPM("ENCODING CHARACTERS")="~|\&"
 S HL1("ECH")=HLPM("ENCODING CHARACTERS")
 S COMP=$E(HL1("ECH"))
 S HL1("FS")=HLPM("FIELD SEPARATOR")
 S HL1("ECH")="~|\&"
 S HL1("FS")="^"
 S HL1("Q")=""
 S HL1("VER")=2.4
 I '$$NEWBATCH^HLOAPI(.HLPM,.HLMSTATE,.ERR) D  Q 0
 .D NOTIF^AGMPIHLO(0,"Unable to create batch."_$S($D(ERR):" ERR:"_$G(ERR),1:""))
 S (DFNIEN,QUIT)=0
 F  S DFNIEN=$O(^DPT(DFNIEN)) Q:'DFNIEN!(QUIT)  D
 .Q:$$GET1^DIQ(2,DFNIEN_",",991.01,"E")  ;INTEGRATION CONTROL NUMBER
 .Q:$D(^DPT(DFNIEN,-9))  ;DON'T ATTEMPT FOR MERGED RECORDS
 .I $$DEMOPAT^AGMPHLU(DFNIEN) Q  ; 9/13/2017 - GCD - CR 7713 - Don't upload demo patients.
 .;IF NO ICN THEN TRY A LOCK, IF CAN'T LOCK PATIENT RECORD BEING BUILT??
 .L +^DPT(DFNIEN):5 I '$T Q
 .L -^DPT(DFNIEN)
 .D
 ..I '$$ADDMSG^HLOAPI(.HLMSTATE,.HLPM,.ERR) D  Q
 ...S QUIT=1
 ...D NOTIF^AGMPIHLO(0,"UNABLE TO ADD MESSAGE TO BATCH."_$S($D(ERR):" ERR:"_$G(ERR),1:""))
 ..M HLST=HLMSTATE
 ..D EVN^AGMPIHLO(HLPM("EVENT"))
 ..I '$D(ERR) D PID^AGMPIHL1(DFNIEN)
 ..I '$D(ERR) D ZPD^AGMPIHL1(DFNIEN)
 ..I $D(ERR) D NOTIF^AGMPIHLO(0,"UNABLE TO ADD MSG TO BATCH."_$S($D(ERR):" ERR:"_$G(ERR),1:""))
 ..;D VTQ(DFNIEN,.SEG,.MSG)
 ..;I '$$ADDSEG^HLOAPI(.MSG,.SEG,.ERR) Q
 ..;D RDF(DFNIEN,.SEG,.MSG)
 ..;I '$$ADDSEG^HLOAPI(.MSG,.SEG,.ERR) Q
 Q:QUIT 0
 ;B "S+"
 D SET
 ; 05/24/2013 - KJH - TFS8008 - Remove extraneous locks on the HLO globals.
 I '$$SENDONE^HLOAPI1(.MSG,.APPARMS,.WHO,.ERR) D  Q 0
 .D NOTIF^AGMPIHLO(0,"UNABLE TO SEND BATCH."_$S($D(ERR):" ERR:"_$G(ERR),1:""))
 K BATCH
 Q 1
 ;
SET ;EP - INIT VARS FOR BATCH
 S APPARMS("SENDING APPLICATION")="RPMS-MPI"
 S APPARMS("ACCEPT ACK TYPE")="AL"  ;Commit ACK type
 ;S APPARMS("ACCEPT ACK TYPE")="NE"  ;(FIELD 15) Commit ACK type ;TPF - CHANGED TO THIS BECASUE OF "SE" ERRORS APPARMS("APP ACK RESPONSE")="AACK^AGMPIHLO"  ;Callback when 'application ACK' is received
 S APPARMS("ACCEPT ACK RESPONSE")="CACK^AGMPIHLO"  ;Callback when 'commit ACK' is received
 ;S APPARMS("APP ACK TYPE")="AL"  ;Application ACK type
 S APPARMS("APP ACK TYPE")="NE"  ;(FIELD 16) Application ACK type ;TPF - CHANGED TO THIS BECASUE OF "SE" ERROR
 S APPARMS("QUEUE")="MPI RPMS"   ;Incoming QUEUE
 S APPARMS("RECEIVING APPLICATION")="MPI RPMS"
 S WHO("RECEIVING APPLICATION")="MPI"  ;THIS DOES OVERRIDE LINE ABOVE
 S WHO("FACILITY LINK NAME")="MPI"
 S WHO("STATION NUMBER")=8990  ;IHS/SD/TPF MPI TEST
 ;S WHO("IE LINK NAME")="MPIVA"  ;FOR EARLIER TESTS
 S WHO("IE LINK NAME")="MPI"  ;FOR HLO TESTING
 ;S APPARMS("SENDING FACILITY")=14752  ;14752 IS SELLS
 S APPARMS("SENDING FACILITY")=$$GET1^DIQ(4,DUZ(2)_",",99,"E")
 Q
 ;SET(SEG,VALUE,FIELD,REP,COMP,SUBCOMP)
 ;THIS LOOKS MORE LIKE THE ARRAY WILL ACTUALLY TURN OUT
 ;AND ALSO MATCHES THE AGMPPARS V1.6 MESSAGE PARSER GENERIC OUTPUT
MYSET(ARY,V,F,R,C,S) ;EP
 D SET^HLOAPI(.ARY,.V,.F,.C,.S,.R)
 Q