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

ORWOR1.m

Go to the documentation of this file.
  1. ORWOR1 ; slc/dcm - PKI RPC functions
  1. ;;3.0;ORDER ENTRY/RESULTS REPORTING;**132,141,163**;Dec 17, 1997
  1. SIG(RET,ID,X1,X2,X3,X4,ORX5,X6) ;Store the signature.
  1. ;ID = orifn;action
  1. ;X1 = Hash
  1. ;X2 = Length of the array
  1. ;X3 = Datafile (100)
  1. ;X4 = Provider DUZ
  1. ;ORX5 = Array for the sig
  1. ;X6 = CRLURL
  1. N Y1,ORIFN,ACT
  1. S Y1=$$STORESIG^XUSSPKI(X1,X2,.ORX5,X4,X3)
  1. I +Y1>0,$L($G(X6)) S Y1=$$CRLURL^XUSSPKI(X6)
  1. I +Y1>0 D
  1. . S ORIFN=+ID,ACT=$P(ID,";",2)
  1. . S $P(^OR(100,ORIFN,8,+ACT,2),"^",3)=X1
  1. S RET=Y1
  1. Q
  1. CRLURL(RET,X1) ;Store the URL's
  1. S RET=$$CRLURL^XUSSPKI(X1)
  1. Q
  1. VERIFY(RET,ORDER,DFN) ;Verify PKI Data
  1. ;DBIA #3750
  1. ;ORDER = ORIFN;ACTION - NOTE: if no ACTION then 1 (new order) is assumed
  1. ;Returned values: "1" if digital signature verifies
  1. ; "-1^error message" if DS fails during initial parameter checking
  1. ; "898020xx^message" if DS fails during verification
  1. N ORIFN,ORACTION,HASH,DATE
  1. K ^TMP("ORPKIDATA",$J)
  1. I '$G(ORDER) S RET="-1^No order number passed" Q
  1. I '$G(DFN) S RET="-1^No DFN passed" Q
  1. S ORIFN=$P(ORDER,";"),ORACTION=$P(ORDER,";",2)
  1. I 'ORACTION S ORACTION=1
  1. I '$D(^OR(100,ORIFN,0)) S RET="-1^Invalid order number" Q
  1. I DFN'=+$P(^OR(100,ORIFN,0),"^",2) S RET="-1^DFN does not match patient on order" Q
  1. I '$D(^OR(100,ORIFN,8,ORACTION)) S RET="-1^Invalid order action passed" Q
  1. S HASH=$P($G(^OR(100,ORIFN,8,ORACTION,2)),"^",3)
  1. I '$L(HASH) S RET="-1^Order has no PKI Hash" Q
  1. I '$O(^OR(100,ORIFN,8,ORACTION,.2,0)) S RET="-1^Order has no PKI Data" Q
  1. S DATE=$P($G(^OR(100,ORIFN,8,ORACTION,.2,1,0)),"^")
  1. I '$L(DATE) S RET="-1^No date associated with PKI Data" Q
  1. S DATE=$$HL7TFM^XLFDT(DATE),I=0
  1. F S I=$O(^OR(100,ORIFN,8,ORACTION,.2,I)) Q:'I S ^TMP("ORPKIDATA",$J,I)=^(I,0)
  1. S RET=$$VERIFY^XUSSPKI(HASH,$NA(^TMP("ORPKIDATA",$J)),DATE)
  1. I RET="OK" S RET=1 Q
  1. I $E(RET,1,7)="-898020" S RET=$E(RET,2,99)
  1. Q
  1. CHKDIG(REQ,ORDER) ;Check if Digital Signature is required
  1. N IFN,ACTION
  1. S REQ=0,IFN=+ORDER,ACTION=$P(ORDER,";",2)
  1. I +$P($G(^OR(100,+IFN,8,+ACTION,2)),U,5) S REQ=1
  1. Q
  1. GETDTEXT(TEXT,ORDER) ;Get External Text
  1. N IFN,ACTION
  1. S IFN=+ORDER,ACTION=$P(ORDER,";",2),I=0
  1. F S I=$O(^OR(100,+IFN,8,+ACTION,.2,I)) Q:'I S TEXT(I)=^(I,0)
  1. Q
  1. GETDSIG(SIG,ORDER) ;Get Digital Signature
  1. N IFN,ACTION
  1. S SIG=0,IFN=+ORDER,ACTION=$P(ORDER,";",2)
  1. I +$P($G(^OR(100,+IFN,8,+ACTION,2)),U,3) S SIG=$P(^(2),"^",3)
  1. Q
  1. GETDEA(Y,ORUSER) ;Get user DEA
  1. S Y=$$DEA^XUSER(,$G(ORUSER))
  1. Q
  1. GETDSCH(Y,ORDER) ;Check if Drug Schedule
  1. N IFN,ACTION
  1. S IFN=+ORDER,ACTION=$P(ORDER,";",2)
  1. S Y=$P($G(^OR(100,+IFN,8,+ACTION,2)),U,4)
  1. Q
  1. SETDTEXT(Y,ORDER,ORDEA,ORSIGNER) ;Set Digital Text data into file 100 & return the array
  1. ;ORDER = ORIFN;ACTION
  1. ;ORDEA = Schedule of Drug (2-5)
  1. ;ORSIGNER = DUZ of signer
  1. N ORSET,IFN,ACT,I
  1. S Y="-1^Digital Text failed to build",IFN=+ORDER,ACT=$P(ORDER,";",2)
  1. I '$G(ORDEA) Q
  1. I '$G(ORSIGNER) S ORSIGNER=DUZ
  1. D DIGTEXT^ORCSAVE1(IFN,ORDEA,ORSIGNER)
  1. S Y=0
  1. I '$G(ORSET) Q
  1. K ^OR(100,IFN,8,ACT,.2)
  1. F I=1:1:ORSET S (Y(I),^OR(100,IFN,8,ACT,.2,I,0))=ORSET(I)
  1. S ^OR(100,IFN,8,ACT,.2,0)="^^"_ORSET_"^"_ORSET_"^"_DT_"^",Y=ORSET
  1. Q
  1. GETDATA(Y,ORDER,DFN) ;Get PKI Data
  1. ;DBIA #3750
  1. ;On error: Y = -1^Error message
  1. ;Else: Y = 1^ Order # ^ Nature of order ^ Order Status ^ Date Signed
  1. ;Y(1) = Patient name ^ Street1 ^ Street2 ^ Street3 ^ City ^ State ^ Zip
  1. ;Y(2) = Drug name_strength_dosage form (Dispense drug) ^ Drug IEN (file 50) ^ Drug quantity prescribed ^ Schedule of medication ^ DEA Schedule
  1. ;Y(3) = Directions for use (SIG)
  1. ;Y(4) = Practitioner's name ^ DUZ ^ Practitioner's (DEA) registration number
  1. ;Y(5) = SiteName ^ SiteStreet1 ^ SiteStreet2 ^ SiteCity ^ SiteState ^ SiteZip
  1. ;Y(6) = Orderable Item ^ Orderable Item IEN (file 101.43)
  1. N X0,X1,X2,X3,X4,X5,X6,ORNAT,ORSTAT
  1. I '$D(^OR(100,+$G(ORDER),0)) S Y="-1^INVALID ORDER #" Q
  1. I $G(DFN)'=+$P(^OR(100,ORDER,0),"^",2) S Y="-1^INVALID PATIENT ID" Q
  1. I '$D(^OR(100,ORDER,8,1,.2,0)) S Y="-1^MISSING DIGITAL SIGNATURE TEXT" Q
  1. S X0=$G(^OR(100,ORDER,8,1,0))
  1. I $P($G(^OR(100,ORDER,8,1,0)),"^",4)'=7 S Y="-1^ORDER HAS NOT BEEN DIGITALLY SIGNED" Q
  1. S X1=$G(^OR(100,ORDER,8,1,.2,1,0))
  1. I DFN'=$P(X1,"^",4) S Y="-1^PKI PATIENT ID DOES NOT MATCH DFN" Q
  1. S ORNAT=$P(X0,"^",12),ORSTAT=$P($G(^OR(100,ORDER,3)),"^",3)
  1. I ORNAT S ORNAT=$P($G(^ORD(100.02,ORNAT,0)),"^")
  1. I ORSTAT S ORSTAT=ORSTAT_";"_$P(^ORD(100.01,ORSTAT,0),"^")
  1. S Y="1^"_ORDER_"^"_ORNAT_"^"_ORSTAT_"^"_$P(X0,"^",6)
  1. S X2=$G(^OR(100,ORDER,8,1,.2,2,0)),X3=$G(^OR(100,ORDER,8,1,.2,3,0)),X4=$G(^OR(100,ORDER,8,1,.2,4,0)),X5=$G(^OR(100,ORDER,8,1,.2,5,0)),X6=$G(^OR(100,ORDER,8,1,.2,6,0))
  1. S X3=$$VALUE^ORX8(ORDER,"DRUG",,"E")_"^"_$$VALUE^ORX8(ORDER,"DRUG",,"I")_"^"_$P(X3,"^",3,99)
  1. S Y(1)=$P(X1,"^",2)_"^"_X2
  1. S Y(2)=X3,Y(3)=X4,Y(4)=X5,Y(5)=X6
  1. S Y(6)=$$VALUE^ORX8(ORDER,"ORDERABLE",,"E")_"^"_$$VALUE^ORX8(ORDER,"ORDERABLE",,"I")
  1. Q