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

BEHOOGP.m

Go to the documentation of this file.
  1. BEHOOGP ;IHS/MSC/MGH - Group Order API ;01-May-2012 15:58;PLS
  1. ;;1.1;BEH COMPONENTS;**011003,011005**;Sep 23,2004
  1. Q
  1. ;===================================================================
  1. ;Input
  1. ; LST=array containing LST(n,"DFN")=PATIENT IEN
  1. ; LST(n,"PRV")=PROVIDER IEN
  1. ; LST(n,"CLN")=ICD9 code for clinical indication
  1. ; ORDITM=IEN of the orderable item(ie. screening mammogram)
  1. ; STDT=Start date/time in fileman format
  1. ; LOC=IEN of ordering location from hosital location file (File 44)
  1. ; DGRPRV = IEN of group provider (optional) (File 200)
  1. ; ORDTXT = Array of text
  1. ; Entered as ORDTXT(n,0)=TEXT
  1. ;Return array of entries in the format
  1. ;
  1. ; OUTLST(1)="12^623^ORDER CREATED"
  1. ; DFN^ORDER IEN^Additional Order TEXT
  1. ; OUTLST(2)="24^0^Duplicate order: MAMMOGRAM BILAT 9/21/10 [PENDING]"
  1. ; DFN^NOT CREATED^ERROR MESSAGE
  1. ;=====================================================================
  1. GRPORD(OUTLST,LST,ORDITM,STDT,LOC,DGRPRV,ORDTXT) ;API Entry point to make group order
  1. N ENTRY,DFN,PRV,PROV,DIALOG,CNT,INACT,OIOK,PKG,CI,IMGLO
  1. S OIOK=$$OICHK(ORDITM)
  1. I 'OIOK D ERR("Non-existent or inactive orderable item sent") Q
  1. I $G(STDT)="" D ERR("No date/time for order sent") Q
  1. ;Find order dialog
  1. S DIALOG=$$ODIALOG(ORDITM)
  1. I 'DIALOG D ERR("Order dialog could not be found.") Q
  1. S PKG=$$OPKG(DIALOG)
  1. I PKG="" D ERR("Package data for order dialog not available") Q
  1. I PKG="RA"&($D(ORDTXT)<10) D ERR("Missing reason for exam") Q
  1. I PKG="RA" D I 'IMGLO D ERR("Imaging location not properly defined for this division") Q
  1. .S IMGLO=$$IMGLOC(ORDITM)
  1. S CNT=0
  1. S ENTRY="" F S ENTRY=$O(LST(ENTRY)) Q:ENTRY="" D
  1. .S DFN=$G(LST(ENTRY,"DFN"))
  1. .S PROV=+$G(LST(ENTRY,"PRV"))
  1. .S:'PROV PROV=$$FINDPRV()
  1. .I 'PROV D RETERR("Unable to find provider for order") Q
  1. .I PKG="LR" D I 'CI D RETERR("Unable to find clinical indication for order") Q
  1. ..S CI=$G(LST(ENTRY,"CLN"))
  1. .D CREATE
  1. Q
  1. CREATE ; Create new OE/RR order
  1. N ITEM,IEN,IENS,ID,IDIEN,DAT,LST,LST2,ORDCHK,NORIEN,Y
  1. N DUR,SIGNOD,SIG,INSTNOD,DUPD,X,Z,ORDIALOG,NORIFN,ORVP,ORNP,STATUS
  1. N DIEN,IDIEN,DUOUT,LIST,FID,OIL,DIR,OPSIEN,WP,MISLIST,ACT
  1. ; Get the orderable item
  1. D DLGDEF^ORWDX(.LIST,"RA OERR EXAM")
  1. S ORDIALOG=DIALOG
  1. S ORDIALOG($$PTR^ORCD("OR GTX ORDERABLE ITEM"),1)=ORDITM
  1. S ORDIALOG($$PTR^ORCD("OR GTX START DATE/TIME"),1)=STDT
  1. S ORDIALOG($$PTR^ORCD("OR GTX URGENCY"),1)=$O(^ORD(101.42,"B","ROUTINE",0))
  1. S ORDIALOG($$PTR^ORCD("OR GTX LOCATION"),1)=LOC
  1. S ORDIALOG($$PTR^ORCD("OR GTX PROVIDER"),1)=PROV
  1. S ACT="C"_PKG
  1. I $L($T(@ACT)) D @ACT
  1. ;Do order checks first
  1. S FID=PKG
  1. S OIL(1)=ORDITM
  1. D ACCEPT^ORWDXC(.LST2,DFN,FID,STDT,1,.OIL)
  1. I $G(LST2(1))'="" D RETERR($P(LST2(1),U,4)) Q
  1. ;Put dialog together
  1. S ORDCHK=$$CHKORD(.ORDIALOG,.MISLIST)
  1. I 'ORDCHK D DISPMIS(.MISLIST) Q
  1. S ORVP=DFN_";DPT(",ORNP=PROV
  1. D SAVE^ORWD(.Y,DFN,PROV,$G(LOC),DIALOG,"N",.ORDIALOG)
  1. I $G(Y) S NORIEN=$P($P($P(Y(1),U),";"),"~",2)
  1. I '$G(NORIEN) D RETERR("Order not filed.") Q
  1. S CNT=CNT+1
  1. S OUTLST(CNT)=DFN_U_NORIEN_U_"ORDER CREATED"
  1. ;Check for signature action
  1. S SIG=$$GET^XPAR("ALL","BEHOOGP SIGN ORDERS",1,"I")
  1. I SIG=1 D SIGN(.ERRLST,DFN,PROV,LOC,NORIEN)
  1. Q
  1. ;
  1. DISPMIS(MLIST) ;EP -
  1. N ITEM,LINE
  1. D RETERR("Items were missing from the order dialog.This order can not be created")
  1. Q
  1. ; Return patient primary provider if defined, otherwise the group provider passed in.
  1. FINDPRV() ;EP-
  1. N PCP
  1. S PCP=$$GET1^DIQ(9000001,DFN,.14,"I") ;pcp ien
  1. S:'PCP PCP=$G(DGRPRV)
  1. Q +PCP
  1. ; Add signature for either electronic or policy order
  1. SIGN(ERRLST,DFN,ORNP,LOC,ORDER) ;EP -
  1. N ORVP,ORL,ERRCNT,RELSTS,ACTION,SIGSTS,ORIFN,ANERROR,NATR,ORWSIGN
  1. S RELSTS=1,ACTION=1,SIGSTS=1
  1. S ORVP=DFN_";DPT(",ORL(2)=LOC_";SC(",ORL=ORL(2),ERRCNT=0
  1. I '$D(^XUSEC("ORES",DUZ))&('$D(^XUSEC("ORELSE",DUZ))) Q
  1. I $D(^XUSEC("ORES",DUZ)) S NATR="E"
  1. I $D(^XUSEC("ORELSE",DUZ)) S NATR="I"
  1. S ORIFN=ORDER_";1"
  1. D EN^ORCSEND(ORIFN,"",SIGSTS,RELSTS,NATR,"",.ANERROR)
  1. I $L(ANERROR) D Q ; don't print if an error occurred
  1. . S OUTLST(CNT)=OUTLST(CNT)_" "_ANERROR
  1. . K ORWSIGN(1)
  1. I RELSTS=0 K ORWSIGN(1) Q ; don't print if unreleased
  1. S ORWSIGN(1)=ORDER
  1. D PRINTS^ORWD1(.ORWSIGN,LOC)
  1. Q
  1. ; Add error text to output array if error in input validation of parameters
  1. ERR(ERRTXT) ;EP-
  1. S OUTLST(0)=ERRTXT
  1. Q
  1. ; Add error text to output array if error occurs during processing or validation of patient specific information
  1. RETERR(ERRTXT) ;EP-
  1. S CNT=CNT+1
  1. S OUTLST(CNT)=DFN_U_0_U_ERRTXT
  1. Q
  1. ; Build Radiology order dialog responses
  1. CRA ;EP-
  1. S ORDIALOG($$PTR^ORCD("OR GTX MODE OF TRANSPORT"),1)="A"
  1. S ORDIALOG($$PTR^ORCD("OR GTX IMAGING LOCATION"),1)=IMGLO
  1. S ORDIALOG($$PTR^ORCD("OR GTX PREGNANT"),1)="u"
  1. S ORDIALOG($$PTR^ORCD("OR GTX CATEGORY"),1)="O"
  1. S WP=$$PTR^ORCD("OR GTX WORD PROCESSING 1")
  1. M ORDIALOG("WP",WP,1)=ORDTXT
  1. S ORDIALOG(WP,1)="ORDIALOG(""WP"",WP,1)"
  1. Q
  1. ; Return imaging location associated with orderable item
  1. IMGLOC(ORDITM) ;EP-
  1. N RAD,RADIEN,RADTYP,ABB,X,ILOC,STOP,ORY
  1. S STOP=0,ILOC=""
  1. S RAD=$$GET1^DIQ(101.43,ORDITM,2,"I")
  1. I 'RAD Q ""
  1. S RADIEN=$P(RAD,";",1)
  1. I 'RADIEN Q ""
  1. S RADTYP=$$GET1^DIQ(71,RADIEN,12,"I")
  1. I 'RADTYP Q ""
  1. S ABB=$P($G(^RA(79.2,RADTYP,0)),U,3)
  1. I ABB="" Q ""
  1. D EN4^RAO7PC1(ABB,"ORY")
  1. S X="" F S X=$O(ORY(X)) Q:X=""!(STOP=1) D
  1. .I $P($G(ORY(X)),U,3)=DUZ(2) S ILOC=$P($G(ORY(X)),U,1),STOP=1
  1. Q ILOC
  1. ;
  1. ; Input: OARY - ORDIALOG passed in by reference
  1. ; MLIST - List of data elements that are missing from the order (pass by ref.), returned to calling module
  1. OICHK(ORDITM) ;EP-
  1. ;Check and get data on the orderable item
  1. N DATE
  1. I 'ORDITM Q ""
  1. S DATE=$$GET1^DIQ(101.43,ORDITM,.1,"I")
  1. I 'DATE Q 1
  1. I STDT<DATE Q ""
  1. Q DATE
  1. ; Return Order Dialog associated with the Orderable Item
  1. ODIALOG(ORDITM) ;EP-
  1. N DSPGP,DIALOG
  1. S DSPGP=$$GET1^DIQ(101.43,ORDITM,5,"I")
  1. I 'DSPGP Q ""
  1. S DIALOG=$$GET1^DIQ(100.98,DSPGP,4,"I")
  1. I 'DIALOG S DIALOG=$O(^ORD(100.98,"AD",DSPGP,""))
  1. Q DIALOG
  1. ; Return package associated with an Order Dialog
  1. OPKG(DIALOG) ;EP-
  1. N PACK,AB
  1. S PACK=$$GET1^DIQ(101.41,DIALOG,7,"I")
  1. I 'PACK Q ""
  1. S AB=$$GET1^DIQ(9.4,PACK,1,"E")
  1. Q AB
  1. ; Validate input array
  1. CHKORD(OARY,MLIST) ;EP-
  1. N STAT,I,DONE,CHKITEM,CHKIEN
  1. S STAT=1,DONE=0
  1. F I=1:1 D Q:DONE
  1. .S CHKITEM=$P($T(REQFLDS+I),";;",2)
  1. .I '$L(CHKITEM) S DONE=1 Q
  1. .S CHKIEN=$O(^ORD(101.41,"B",CHKITEM,0))
  1. .I 'CHKIEN Q
  1. . ; if the array item doesn't exist, place it in the 'missing' array and set stat to zero
  1. .I '$D(OARY(CHKIEN)) S MLIST(CHKITEM)=CHKIEN,STAT=0 Q
  1. . ; if the array item exists, but there is no data populated, set the 'missing' array item and stat to zero
  1. .I $D(OARY(CHKIEN)),'$L($G(OARY(CHKIEN,1))) S MLIST(CHKITEM)=CHKIEN,STAT=0 Q
  1. Q STAT
  1. ; Require elements for Radiology dialog
  1. REQFLDS ;
  1. ;;OR GTX ORDERABLE ITEM
  1. ;;OR GTX WORD PROCESSING 1
  1. ;;OR GTX CATEGORY
  1. ;;OR GTX LOCATION
  1. ;;OR GTX URGENCY
  1. ;;OR GTX PREGNANT
  1. ;;OR GTX START DATE/TIME
  1. ;;OR GTX MODE OF TRANSPORT
  1. ;;OR GTX IMAGING LOCATION
  1. ;;OR GTX PROVIDER
  1. ;;
  1. Q