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

BADEMRG.m

Go to the documentation of this file.
  1. BADEMRG ;IHS/MSC/MGH - Dentrix HL7 interface ;31-Aug-2010 13:46;EDR
  1. ;;1.0;DENTAL/EDR INTERFACE;**1**;AUG 22, 2011
  1. Q
  1. TLOADPT ;EP Taskman call to start patient load
  1. N STOP,ZTDTH,ZTIO,ZTDESC,ZTRTN,ZTSAVE,ZTPRI,ZTSK
  1. ;Make sure its not already running
  1. S STOP=$$GET^XPAR("ALL","BADE EDR PAUSE MRG LOAD",1,"E")
  1. ;Its already running and shouldn't be restarted
  1. I STOP="NO" D H 3 Q
  1. .W !,"Merge Upload is already running",!
  1. I $$GET^XPAR("ALL","BADE EDR MRG DFN") D H 3 Q
  1. .W !,"Upload process has already begun. Please use Restart option.",!
  1. S ZTIO=""
  1. S ZTPRI=1
  1. S ZTDESC="Load Patient Merge Data to EDR"
  1. S ZTRTN="LOADPT^BADEMRG"
  1. S ZTSAVE("DUZ")=""
  1. D ^%ZTLOAD
  1. I $G(ZTSK) D
  1. .D EN^XPAR("SYS","BADE EDR MRG LOAD TSK",1,ZTSK)
  1. .W !,"Task number "_ZTSK H 2
  1. Q
  1. LOADPT ;EP Load all patient's data
  1. N FDFN,CNT,CNTCHK,DATA,TOTAL,STOP,THROTTLE,RESULT
  1. ;Make sure the stop parameter is NO
  1. D EN^XPAR("SYS","BADE EDR PAUSE MRG LOAD",1,"NO")
  1. ;Set the dfn to null
  1. S FDFN=$$GET^XPAR("ALL","BADE EDR MRG DFN")
  1. ;Loop through the patients and send data
  1. LOOP S FDFN=$S(FDFN>0:FDFN,1:0),CNT=0,STOP="NO",TOTAL=0
  1. F S FDFN=$O(^DPT(FDFN)) Q:+FDFN'>0!(STOP="YES") D
  1. .Q:'$D(^DPT(FDFN,-9)) ;Patient has not been merged
  1. .;If patient was merged, find the merged to patient and send A40 message
  1. .;and an A31 message on the merged to patient
  1. .S RESULT=""
  1. .S RESULT=$$MRGTODFN^BADEUTIL(FDFN)
  1. .D A40(FDFN,RESULT)
  1. .D A31(RESULT)
  1. .;Set IEN into the DFN parameter
  1. .D EN^XPAR("SYS","BADE EDR MRG DFN",1,FDFN)
  1. .;Add to total count
  1. .S TOTAL=TOTAL+1
  1. .D EN^XPAR("SYS","BADE EDR MRG TOTAL",1,TOTAL)
  1. .;Check to see if we should stop
  1. .S STOP=$$GET^XPAR("ALL","BADE EDR PAUSE MRG LOAD",1,"E")
  1. .Q:STOP="YES"
  1. ;Finish up by resetting the pt parameter to null and the stop paramater to YES
  1. I STOP="NO" D
  1. .D EN^XPAR("SYS","BADE EDR PAUSE MRG LOAD",1,"YES")
  1. .D EN^XPAR("SYS","BADE EDR MRG LOAD TSK",1,"Upload complete")
  1. .D COMPLETE("DONE")
  1. Q
  1. TRESTRT ;EP Taskman call to restart patient load
  1. N STOP,ZTDTH,ZTIO,ZTDESC,ZTRTN,ZTSAVE,ZTPRI,ZTSK
  1. ;Make sure its not already running
  1. S STOP=$$GET^XPAR("ALL","BADE EDR PAUSE MRG LOAD",1,"E")
  1. ;Its already running and shouldn't be restarted
  1. I STOP="NO" W !,"Process is already running",!!! H 3 Q
  1. S ZTIO=""
  1. S ZTPRI=1
  1. S ZTDESC="Load Merge Data to EDR"
  1. S ZTRTN="RESTPT^BADEMRG"
  1. S ZTSAVE("DUZ")=""
  1. D ^%ZTLOAD
  1. I $G(ZTSK) D
  1. .D EN^XPAR("SYS","BADE EDR MRG LOAD TSK",,ZTSK)
  1. .W !,"Task number "_ZTSK H 2
  1. Q
  1. RESTPT ;EP Restart the patient load
  1. N FDFN,CNT,CNTCHK,TOTAL,DATA,STOP,RESULT
  1. ;Get the last used DFN from the parameter
  1. S FDFN=$$GET^XPAR("ALL","BADE EDR MRG DFN")
  1. ;Set the stop parameter to NO
  1. D EN^XPAR("SYS","BADE EDR PAUSE MRG LOAD",,0)
  1. ;Get the total count
  1. S TOTAL=$$GET^XPAR("ALL","BADE EDR MRG TOTAL")
  1. ;Task off the job of restarting
  1. LOOP2 S CNT=0,STOP="NO"
  1. S FDFN=$S(FDFN>0:FDFN,1:0)
  1. F S FDFN=$O(^DPT(FDFN)) Q:+FDFN'>0!(STOP="YES") D
  1. .Q:'$D(^DPT(FDFN,-9)) ;Patient has not been merged
  1. .;If patient was merged, find the merged to patient and send A40 messag
  1. .;and an A31 message on the merged to patient
  1. .S RESULT=""
  1. .S RESULT=$$MRGTODFN^BADEUTIL(FDFN)
  1. .D A40(FDFN,RESULT)
  1. .D A31(RESULT)
  1. .;Send message if patient was merged
  1. .;Set IEN into the DFN parameter
  1. .D EN^XPAR("SYS","BADE EDR MRG DFN",1,FDFN)
  1. .;Add to total count
  1. .S TOTAL=TOTAL+1
  1. .D EN^XPAR("SYS","BADE EDR MRG TOTAL",1,TOTAL)
  1. .;See if we should stop
  1. .S STOP=$$GET^XPAR("ALL","BADE EDR PAUSE MRG LOAD",1,"E")
  1. .Q:STOP="YES"
  1. ;Finish up by resetting the pt parameter to null and the stop parameter to YES
  1. I STOP="NO" D
  1. .D EN^XPAR("SYS","BADE EDR PAUSE MRG LOAD",1,1)
  1. .D EN^XPAR("SYS","BADE EDR MRG LOAD TSK",1,"Upload complete")
  1. .D COMPLETE("DONE")
  1. Q
  1. COMPLETE(WHICH) ;Mark options out of order
  1. N MSG,MENU,I
  1. S MENU(1)="BADE EDR UPLOAD ALL MERGED PTS"
  1. S MENU(2)="BADE EDR RESTART MRG UPLOAD"
  1. S MENU(3)="BADE EDR PAUSE MRG LOAD"
  1. S MENU(4)="BADE EDR SEND A40"
  1. F I=1:1:4 D
  1. .N DA,DIE,DR
  1. .I (WHICH="DONE"),(I=4) Q
  1. .S MSG=$S(WHICH="DONE":"Upload completed",1:"Patient merge not installed")
  1. .S DA=$O(^DIC(19,"B",MENU(I),""))
  1. .I DA'="" D
  1. ..S DIE="^DIC(19,",DR="2///^S X=MSG"
  1. ..D ^DIE
  1. ; Enable event protocols
  1. D EDPROT^BADEUTIL("BADE PATIENT A40")
  1. Q
  1. SENDA40 ;Send one A40 message
  1. N ERR,DIC,DIR,DT,DFN,DFN2,BADERR,X,Y,RESULT,ARRAY,CNT,NAME,QUIT
  1. S CNT=0
  1. S DIC=2,DIC("A")=" Select Patient: ",DIC(0)="AEQMZ",DT=$$DT^XLFDT
  1. D ^DIC I Y=-1 G SENDX
  1. I +Y>0 D
  1. .S DFN=+Y
  1. .Q:'DFN
  1. .S NAME=$P($G(^DPT(DFN,0)),U,1)
  1. .S DFN2=0 F S DFN2=$O(^DPT(DFN2)) Q:'+DFN2 D
  1. ..Q:'$D(^DPT(DFN2,-9))
  1. ..S RESULT=$$MRGTODFN^BADEUTIL(DFN2)
  1. ..I RESULT=DFN D
  1. ...S CNT=CNT+1
  1. ...S ARRAY(CNT)=DFN2_U_$P($G(^DPT(DFN2,0)),U,1)
  1. I CNT=0 W !,"There were no patients merged to "_NAME G SENDA40
  1. S QUIT=0
  1. I CNT>0 D
  1. .N I
  1. .S I=0 F S I=$O(ARRAY(I)) Q:I="" D
  1. ..W !,CNT,?10,$P(ARRAY(I),U,2)
  1. ..S DIR(0)="N",DIR("A")="Select the MERGED FROM PT" D ^DIR
  1. ..I '$D(ARRAY(X)) W !,"Invalid Selection, Try again" S QUIT=1
  1. ..E S FROM=$P(ARRAY(X),U,1),TO=DFN D MSG(FROM,TO)
  1. I QUIT G SENDA40
  1. Q
  1. SENDX Q
  1. MSG(FROM,TO) ;EP to send A40 and A31 messages
  1. D A40(FROM,TO)
  1. I $D(ERR) W !,"Unable to send HL7 message" H 2 Q
  1. D A31(TO)
  1. I '$D(ERR) W !,"Message was sent" H 2
  1. I $D(ERR) W !,"Unable to send HL7 message" H 2
  1. Q
  1. A40(FROM,TO) ;EP Create and send one A40 message
  1. N EVNTTYPE
  1. S EVNTTYPE="A40"
  1. D NEWMSG^BADEMRG1(FROM,TO,EVNTTYPE)
  1. Q
  1. A31(DFN) ;EP Create and send one A31 message
  1. N EVNTTYPE,DOD
  1. S EVNTTYPE="A31"
  1. I '$D(^DPT(DFN,0)) D NOTIF^BADEHL1(DFN,"Missing zero node. Cannot create A31.") Q
  1. D NEWMSG^BADEHL1(DFN,EVNTTYPE)
  1. Q
  1. MSA ;EP
  1. N MSA,HLST
  1. D SET(.ARY,"MSA",0)
  1. D SET(.ARY,"AA",1)
  1. D SET(.ARY,"TODO-MSGID",2)
  1. D SET(.ARY,"Transaction Successful",3)
  1. D SET(.ARY,"todo-010",4)
  1. S MSA=$$ADDSEG^HLOAPI(.HLST,.ARY)
  1. Q
  1. SET(ARY,V,F,C,S,R) ;EP
  1. D SET^HLOAPI(.ARY,.V,.F,.C,.S,.R)
  1. Q