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

BADEHL2.m

Go to the documentation of this file.
  1. BADEHL2 ;IHS/MSC/MGH/PLS/VAC - Dentrix HL7 interface ;16-Jul-2009 10:54;PLS
  1. ;;1.0;DENTAL/EDR INTERFACE;**1**;AUG 22, 2011
  1. ;; Modified - IHS/MSC/AMF - 11/23/10 - More descriptive alert messages
  1. Q
  1. ; Build Outbound Master File Updates for the provider file
  1. NEWMSG(IEN,MFNTYP) ;EP
  1. N HLPM,HLST,ARY,HLQ,TODAY,NODE,NODE1,NODE11,NODE13,WHO,ERR
  1. N LN,HL1,APPARMS,HLPM,HLFS,HLECH,NPI
  1. S LN=0
  1. S HLPM("MESSAGE TYPE")="MFN"
  1. S HLPM("EVENT")="M02"
  1. S HLPM("VERSION")=2.4
  1. I '$$NEWMSG^HLOAPI(.HLPM,.HLST,.ERR) D Q
  1. .D NOTIF(IEN,"Unable to build HL7 message. "_$G(ERR)) ;IHS/MSC/AMF 11/23/10 More descriptive alert
  1. S HLFS=HLPM("FIELD SEPARATOR")
  1. S HLECH=HLPM("ENCODING CHARACTERS")
  1. S HL1("ECH")=HLECH
  1. S HL1("FS")=HLFS
  1. S HL1("Q")=""
  1. S HL1("VER")=HLPM("VERSION")
  1. ;Create segments
  1. ;
  1. D MFI
  1. I '$D(ERR) D MFE(IEN)
  1. I '$D(ERR) D STF(IEN)
  1. I '$D(ERR) D PRA(IEN)
  1. Q:$D(ERR)>0
  1. ; Define sending and receiving parameters
  1. I '$D(ERR) D
  1. .S APPARMS("SENDING APPLICATION")="RPMS-DEN"
  1. .S APPARMS("ACCEPT ACK TYPE")="AL" ;Commit ACK type
  1. .S APPARMS("APP ACK RESPONSE")="AACK^BADEHL1" ;Callback when 'application ACK' is received
  1. .S APPARMS("ACCEPT ACK RESPONSE")="CACK^BADEHL1" ;Callback when 'commit ACK' is received
  1. .S APPARMS("APP ACK TYPE")="AL" ;Application ACK type
  1. .S APPARMS("QUEUE")="DENT MFE" ;Incoming QUEUE
  1. .S WHO("RECEIVING APPLICATION")="DENTRIX"
  1. .S WHO("FACILITY LINK NAME")="DENTRIX"
  1. .I '$$SENDONE^HLOAPI1(.HLST,.APPARMS,.WHO,.ERR) D
  1. ..D NOTIF(IEN,"Unable to send HL7 message. "_$G(ERR)) ;IHS/MSC/AMF 11/23/10 More descriptive alert
  1. Q
  1. ;
  1. ERR ;
  1. Q
  1. ;
  1. MFI ;Create the MFI segment
  1. N NOW,FLD
  1. S NOW=$$NOW^XLFDT()
  1. S NOW=$$HLDATE^HLFNC(NOW,"TS")
  1. D SET(.ARY,"MFI",0)
  1. D SET(.ARY,"PRA",1)
  1. D SET(.ARY,"RPMS",2)
  1. D SET(.ARY,"UPD",3)
  1. D SET(.ARY,NOW,4)
  1. D SET(.ARY,NOW,5)
  1. D SET(.ARY,"NE",6)
  1. S X=$$ADDSEG^HLOAPI(.HLST,.ARY,.ERR)
  1. I $D(ERR) D NOTIF(IEN,"Can't create MFI. "_ERR) ;IHS/MSC/AMF 11/23/10 More descriptive alert
  1. Q
  1. ; Create MFE segment
  1. MFE(IEN) ;EP
  1. Q:'$G(IEN)
  1. N PID,SGM,X,LP,VAL,HLQ
  1. S HLQ=HL1("Q")
  1. D SET(.ARY,"MFE",0)
  1. D SET(.ARY,MFNTYP,1)
  1. D SET(.ARY,1,2)
  1. D SET(.ARY,$$HLDATE^HLFNC($$DT^XLFDT()),3)
  1. D SET(.ARY,IEN,4)
  1. D SET(.ARY,"CE",5)
  1. S X=$$ADDSEG^HLOAPI(.HLST,.ARY,.ERR)
  1. I $D(ERR) D NOTIF(IEN,"Can't create MFE. "_ERR) ;IHS/MSC/AMF 11/23/10 More descriptive alert
  1. Q
  1. ; Create segment
  1. STF(IEN) ;Create the STF segment
  1. Q:'$G(IEN)
  1. N ADDR,PHONE,DGNAME,FLD,K,CNT,SHIP,REL,FLD,VAL,LP,X
  1. N AC,PN,EX
  1. S HLQ=HL1("Q")
  1. S NODE=$G(^VA(200,IEN,0)),NODE13=$G(^VA(200,IEN,.13))
  1. S NODE1=$G(^VA(200,IEN,1))
  1. S NODE11=$G(^VA(200,IEN,.11))
  1. Q:NODE=""
  1. D SET(.ARY,"STF",0)
  1. S NPI=""
  1. S NPI=$$NPI^XUSNPI("Individual_ID",IEN)
  1. I NPI<1 S ERR="No NPI. Can't create STF." D NOTIF(IEN,ERR) Q ;IHS/MSC/AMF 11/23/10 More descriptive alert
  1. D SET(.ARY,+IEN,1) ;Primary Key
  1. D SET(.ARY,+NPI,2) ;NPI
  1. S DGNAME("FILE")=200,DGNAME("IENS")=IEN
  1. S DGNAME("FIELD")=.01
  1. ;Name of provider
  1. S FLD=$$HLNAME^XLFNAME(.DGNAME,"","^")
  1. I FLD="" S ERR="No provider name. Can't create STF." D NOTIF(IEN,ERR) Q ;IHS/MSC/AMF 11/23/10 More descriptive alert
  1. ; More descriptive alert message
  1. F LP=1:1:$L(FLD,$E(HLECH)) S VAL=$P(FLD,$E(HLECH),LP) D
  1. .D SET(.ARY,VAL,3,LP)
  1. D SET(.ARY,"N",4) ; Staff type
  1. ;D SET(.ARY,$P(NODE1,U,2),5) ;Gender
  1. ;D SET(.ARY,$$HLDATE^HLFNC($P(NODE1,U,3)),6) ;DOB
  1. D SET(.ARY,$S(MFNTYP="MDC":"I",1:"A"),7) ;Active/Inactive flag
  1. S PHONE=$$HLPHONE^HLFNC($P(NODE13,U,2))
  1. I $L(PHONE) D
  1. .D SET(.ARY,PHONE,10,1) ;Work phone
  1. .D SET(.ARY,"WPH",10,2)
  1. .I $L($P(PHONE,")")) D
  1. ..S AC=+$P($P(PHONE,")"),"(",2)
  1. ..D:AC SET(.ARY,AC,10,3)
  1. .I $P(PHONE,")",2) D
  1. ..S PN=$E($P($P(PHONE,")",2),"X"),1,8) ;extract the phone number
  1. ..D:PN SET(.ARY,PN,10,4)
  1. .S EX=$P(PHONE,"X",2)
  1. .D:$L(EX) SET(.ARY,EX,10,5)
  1. S ADDR=$$ADDR^VAFHLFNC($P(NODE11,U,1,6))
  1. F LP=1:1:$L(ADDR,$E(HLECH)) S VAL=$P(ADDR,$E(HLECH),LP) D
  1. .D SET(.ARY,VAL,11,LP) ;Address
  1. ;D SET(.ARY,TODAY,12) ;Activation Date
  1. S X=$$ADDSEG^HLOAPI(.HLST,.ARY,.ERR)
  1. I $D(ERR) D NOTIF(IEN,"Can't create STF. "_ERR) ;IHS/MSC/AMF 11/23/10 More descriptive alert
  1. Q
  1. PRA(IEN) ;Create the PRA segment
  1. Q:'$G(IEN)
  1. N I,SSN,MEDICAID,DATA,RP,X,LP,FLD,VAL,VAL1,DEA,VA
  1. D SET(.ARY,"PRA",0)
  1. D SET(.ARY,IEN,1)
  1. D SET(.ARY,"Dental General Practice",5)
  1. S SSN=$P(NODE1,U,9)
  1. S MEDICAID=$P($G(^VA(200,IEN,9999999)),U,7)
  1. S DEA=$P($G(^VA(200,IEN,"PS")),U,2)
  1. S VA=$P($G(^VA(200,IEN,"PS")),U,3)
  1. ;Only include items which have values
  1. S FLD=1
  1. ;S FLD=""
  1. I $L(NPI) D
  1. .D SET(.ARY,+NPI,6,1,1,FLD)
  1. .D SET(.ARY,"NPI",6,2,1,FLD)
  1. .S FLD=FLD+1
  1. I $L(SSN) D
  1. .D SET(.ARY,SSN,6,1,1,FLD)
  1. .D SET(.ARY,"SSN",6,2,1,FLD)
  1. .S FLD=FLD+1
  1. I $L(DEA) D
  1. .D SET(.ARY,DEA,6,1,1,FLD)
  1. .D SET(.ARY,"DEA",6,2,1,FLD)
  1. .S FLD=FLD+1
  1. I $L(VA) D
  1. .D SET(.ARY,VA,6,1,1,FLD)
  1. .D SET(.ARY,"VA",6,2,1,FLD)
  1. .S FLD=FLD+1
  1. I $L(MEDICAID) D
  1. .D SET(.ARY,MEDICAID,6,1,1,FLD)
  1. .D SET(.ARY,"MEDICAIDID",6,2,1,FLD)
  1. .S FLD=FLD+1
  1. ;S:NPI'="" FLD=NPI_"^NPI"
  1. ;S:SSN'="" FLD=FLD_$S($L(FLD):"~",1:"")_SSN_"^SSN"
  1. ;S:DEA'="" FLD=FLD_$S($L(FLD):"~",1:"")_DEA_"^DEA"
  1. ;S:VA'="" FLD=FLD_$S($L(FLD):"~",1:"")_VA_"^VA"
  1. ;S:MEDICAID'="" FLD=FLD_$S($L(FLD):"~",1:"")_MEDICAID_"^MEDICAID"
  1. ;F RP=1:1:$L(FLD,$E(HLECH,2,2)) S VAL1=$P(FLD,$E(HLECH,2,2),RP) D
  1. ;.F LP=1:1:$L(VAL1,$E(HLECH)) S VAL=$P(VAL1,$E(HLECH),LP) D
  1. ;..D SET(.ARY,VAL,6,LP,,RP)
  1. S X=$$ADDSEG^HLOAPI(.HLST,.ARY,.ERR)
  1. I $D(ERR) D NOTIF(IEN,"Can't create PRA. "_ERR) ;IHS/MSC/AMF 11/23/10 More descriptive alert
  1. Q
  1. SET(ARY,V,F,C,S,R) ;EP
  1. D SET^HLOAPI(.ARY,.V,.F,.C,.S,.R)
  1. Q
  1. NOTIF(IEN,MSG) ;EP ------- IHS/MSC/AMF 11/23/10 More descriptive alert
  1. N PVDIEN,RET,X,SAVE,STR,LEN
  1. N XQA,XQAID,XQDATA,XQAMSG
  1. S LEN=$L("Provider: ["_IEN_"]. "_$G(MSG))
  1. S STR=""
  1. I $L(IEN) S STR=$P($G(^VA(200,IEN,0)),U,1) I ($L(STR)+LEN)>70 S STR=$E(STR,1,(67-LEN))_"..."
  1. S XQAMSG="Provider: "_STR_" ["_IEN_"]. "_$G(MSG)
  1. ; -------- end IHS/MSC/AMF 11/23/10
  1. S XQAID="ADEN,"_IEN_","_50
  1. S XQDATA="IEN="_IEN
  1. S XQA("G.RPMS DENTAL")=""
  1. D SETUP^XQALERT
  1. ;Save the IEN in a parameter for correction
  1. S X=$$GET^XPAR("ALL","BADE EDR TOTAL PROVIDER ERRORS",1,"E")
  1. S X=X+1
  1. S SAVE=IEN_" "_MSG
  1. D EN^XPAR("SYS","BADE EDR TOTAL PROVIDER ERRORS",1,X)
  1. D EN^XPAR("SYS","BADE EDR PROVIDER ERRORS",X,SAVE)
  1. Q
  1. FINDTYP(IEN) ;Find out if a new or update message should be sent
  1. ;If MFNTYP exists, no need to do the lookup
  1. N TD,ENTER,ACTIVE,RES
  1. Q:$D(MFNTYP) MFNTYP
  1. S TD=$$DT^XLFDT()
  1. S ENTER=$P($G(^VA(200,IEN,1)),U,7) ; Date Entered
  1. I TD>ENTER S RES="MUP1"
  1. I ENTER=TD D
  1. .I $P($G(^VA(200,IEN,1.1)),U,1)'="" S RES="MUP1"
  1. .I $P($G(^VA(200,IEN,1.1)),U,1)="" S RES="MAD"
  1. I $P($G(^VA(200,IEN,0)),U,11)!($P($G(^VA(200,IEN,"PS")),U,4)) S RES="MDC"
  1. Q RES