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

ORCSAVE1.m

Go to the documentation of this file.
  1. ORCSAVE1 ; SLC/MKB - Save Order Text ;02/22/07
  1. ;;3.0;ORDER ENTRY/RESULTS REPORTING;**92,132,141,163,187,223,243**;Dec 17, 1997;Build 242
  1. ;
  1. ; ^ORD(101.41,+ORDIALOG,10,ITM,2)=Seq#^Format^Omit^Lead Text^Trail Text
  1. ; ^ORD(101.41,+ORDIALOG,10,"ATXT",Seq#,ITM)=""
  1. ;
  1. ORDTEXT(ORDER) ; -- Build and save order text from ORDIALOG() into ORDER
  1. N ORTX,I,IFN,ACT,ORSET
  1. D ORTX(240) Q:'$G(ORTX)
  1. S IFN=+ORDER,ACT=+$P(ORDER,";",2) S:ACT'>0 ACT=1
  1. F I=1:1:ORTX S ^OR(100,IFN,8,ACT,.1,I,0)=ORTX(I)
  1. S ^OR(100,IFN,8,ACT,.1,0)=U_U_ORTX_U_ORTX_U_DT_U
  1. I $E($G(ORDEA))=2 D ;PKI Drug Schedule - in future may allow 2-5
  1. . S ORSET=0
  1. . D DIGTEXT(IFN,ORDEA)
  1. . F I=1:1:ORSET S ^OR(100,IFN,8,ACT,.2,I,0)=ORSET(I)
  1. . I ORSET>0 S ^OR(100,IFN,8,ACT,.2,0)=U_U_ORSET_U_ORSET_U_DT_U
  1. Q
  1. ;
  1. ORTX(WIDTH) ; -- May enter here to return order text in ORTX()
  1. N ORP,SEQ,ITEM,ORMAX,IVIEN,IVITEM,IVTYPE,RATE
  1. K ORTX S ORMAX=$S(+$G(WIDTH):WIDTH,1:240)
  1. D EXT ; get external form of values
  1. S SEQ=0 F S SEQ=$O(^ORD(101.41,+ORDIALOG,10,"ATXT",SEQ)) Q:SEQ'>0 D
  1. . S ITEM=0 F S ITEM=$O(^ORD(101.41,+ORDIALOG,10,"ATXT",SEQ,ITEM)) Q:ITEM'>0 D TEXT(ITEM)
  1. Q
  1. ;
  1. TEXT(DA) ; -- Includes text of item DA
  1. Q:$P(^ORD(101.41,ORDIALOG,10,DA,0),U,11) Q:'$O(ORP(DA,0))
  1. N NEWLN,INST,TYPE,PTR,CHSEQ,CHILD,ORI,X,Y
  1. S:'$G(ORTX) ORTX=1,ORTX(1)=""
  1. S NEWLN=+$P(ORP(DA),U,4),INST=$O(ORP(DA,0)),Y=""
  1. I NEWLN,$L(ORTX(ORTX)) S ORTX=ORTX+1,ORTX(ORTX)="",Y=" "
  1. S X=$$GETXT($P(ORP(DA),U,2)) I $L(X) S X=Y_X,Y="" D TXT^ORCHTAB ;lead tx
  1. S PTR=+ORP(DA),TYPE=$E(ORDIALOG(PTR,0))
  1. TXT1 I TYPE'="W" S X=Y_ORP(DA,INST),Y="" D TXT^ORCHTAB
  1. I TYPE="W" S ORI=0 F S ORI=$O(ORP(DA,INST,ORI)) Q:ORI'>0 D S Y=""
  1. . S Y=$S(Y=" ":" ",$P(ORP(DA),U,5):" ",1:"") ;new line, or as stored
  1. . S X=Y_ORP(DA,INST,ORI,0),Y=""
  1. . I $E(X)'=" " D TXT^ORCHTAB Q ; wrap
  1. . S:$L(ORTX(ORTX)) ORTX=ORTX+1,ORTX(ORTX)="" ; force new line
  1. . I X?1." " S ORTX(ORTX)=" ",ORTX=ORTX+1,ORTX(ORTX)="" ; blank line
  1. . E D TXT^ORCHTAB
  1. D:$D(^ORD(101.41,+ORDIALOG,10,"DAD",PTR)) CHILD(PTR)
  1. S INST=$O(ORP(DA,INST)) ; multiple?
  1. I INST S ORTX(ORTX)=ORTX(ORTX)_",",Y="" S:NEWLN ORTX=ORTX+1,ORTX(ORTX)="",Y=" " G TXT1
  1. S X=$$GETXT($P(ORP(DA),U,3)) D:$L(X) TXT^ORCHTAB ; trailing text
  1. Q
  1. ;
  1. CHILD(PARENT) ; -- add child values
  1. N CHSEQ,CHILD S CHSEQ=0
  1. F S CHSEQ=$O(^ORD(101.41,+ORDIALOG,10,"DAD",PARENT,CHSEQ)) Q:CHSEQ'>0 S CHILD=$O(^(CHSEQ,0)) D
  1. . Q:'$L($G(ORP(CHILD,INST)))
  1. . S X=$$GETXT($P(ORP(CHILD),U,2)) D:$L(X) TXT^ORCHTAB ; lead text
  1. . S X=ORP(CHILD,INST) D TXT^ORCHTAB
  1. . S X=$$GETXT($P(ORP(CHILD),U,3)) D:$L(X) TXT^ORCHTAB ; trail text
  1. Q
  1. ;
  1. GETXT(X) ; -- Returns text of X
  1. I $E(X)="@" N VAR S VAR=$E(X,2,99),X=$G(@VAR) K @VAR ; variable w/text
  1. Q X
  1. ;
  1. EXT ; -- Build ORP(DA) array of external forms
  1. N PROMPT,INST,DA,NODE,FORMAT,OMIT,X,Y,TYPE,PTR
  1. S PROMPT=0 F S PROMPT=$O(ORDIALOG(PROMPT)) Q:PROMPT'>0 D
  1. . S DA=+$G(ORDIALOG(PROMPT)),TYPE=$E($G(ORDIALOG(PROMPT,0))) Q:'$L(TYPE)
  1. . Q:'DA S NODE=$G(^ORD(101.41,ORDIALOG,10,DA,2)),FORMAT=$P(NODE,U,2),OMIT=$P(NODE,U,3)
  1. . S:$D(ORDIALOG(PROMPT,"FORMAT")) FORMAT=ORDIALOG(PROMPT,"FORMAT")
  1. . I $E(FORMAT)="@" S PTR=+$E(FORMAT,2,99) Q:'PTR ; Don't include
  1. . S INST=0 F S INST=$O(ORDIALOG(PROMPT,INST)) Q:INST'>0 D
  1. . . Q:ORDIALOG(PROMPT,INST)=""
  1. . . I $E(FORMAT)="@",$L($G(ORDIALOG(PTR,INST))) Q ; use PTR instead
  1. . . I $E(FORMAT)="*" S PTR=+$E(FORMAT,2,99) I '$L($G(ORDIALOG(PTR,INST))) Q ; must have PTR too
  1. . . I $E(FORMAT)="=" S PTR=+$E(FORMAT,2,99) I PTR,$L($G(ORDIALOG(PTR,INST))) S Y=$$EXT^ORCD(PTR,INST),X=$$EXT^ORCD(PROMPT,INST) I (X=Y)!(X[Y)!(Y[X) Q
  1. . . I TYPE="W" M ORP(DA,INST)=@ORDIALOG(PROMPT,INST)
  1. . . E S X=$$EXT^ORCD(PROMPT,INST,FORMAT) Q:X="" Q:OMIT[X S ORP(DA,INST)=X
  1. . . S ORP(DA)=PROMPT_U_$P(NODE,U,4,7) ; ptr^lead^trail^new line^wrap
  1. Q
  1. DIGTEXT(ORDER,ORDEA,ORSIGNER) ;Build text used to create Digital Signature
  1. ;ORDER = ifn of order # (file 100)
  1. ;ORDEA = Controlled substance schedule of drug (2-5)
  1. ;ORSIGNER = DUZ of sigining physician
  1. ;ORSET(1)=1)Date of Prescription (RX) -Date Ordered HL7 format 2)Full Patient Name 3)Patient SSN 4)DFN
  1. ;ORSET(2)=5)Patient Street1 6)Patient Street2 7)Patient Street3 8)Patient City 9)Patient State 10)Patient Zip 11)???
  1. ;ORSET(3)=12)Drug name (From Dispense Drug or Orderable Item) 13)Variable ptr for Drug (file 50 or 101.43) 14)Drug quantity prescribed 15)Schedule of medication 16)DEA Schedule
  1. ;ORSET(4)=17)Direction for use
  1. ;ORSET(5)=18)Practitioner's name 19)DUZ 20)Practitioner's (DEA) registration number
  1. ;ORSET(6)=22)SiteName 23)SiteStreet1 24)SiteStreet2 25)SiteCity 26)SiteState 27)SiteZip
  1. ;ORSET(7)=28)$H
  1. N I,DFN,OR80,ORPNM,ORSSN,ORXDT,VAERR,VAPA,X0,X1,X4,X5,X6,X8,X9,X10,X11,X12,X13,X14,SIG
  1. S OR80=$G(^OR(100,ORDER,8,1,0))
  1. Q:'$L(OR80)
  1. S:'$G(ORSIGNER) ORSIGNER=$P(OR80,"^",3)
  1. Q:'ORSIGNER
  1. S $P(^OR(100,ORDER,8,1,2),"^",4,5)=ORDEA_"^"_1 ;Flag to signing process to get digital signature
  1. S ORXDT=$P(OR80,"^"),X1=$$FMTHL7^XLFDT(ORXDT),X4="",X14="",X10=""
  1. I '$D(ORVP) S ORVP=$P(^OR(100,ORDER,0),"^",2)
  1. S DFN=+ORVP
  1. D ADD^VADPT
  1. S ORPNM=^DPT(+ORVP,0),ORSSN=$P(ORPNM,"^",9),ORPNM=$P(ORPNM,"^")
  1. F I=1:1:6 S X4=X4_$S($L($G(VAPA(I))):$S((I=5):$P(VAPA(I),"^",2),1:VAPA(I)),1:"")_"^"
  1. S X11=$$GET1^DIQ(200,ORSIGNER,.01,"E") Q:'$L(X11)
  1. S X12=$$DEA^XUSER(,ORSIGNER)
  1. S X0=$$GET1^DIQ(4,+$G(DUZ(2)),.01,"E")
  1. I $L(X0) S X14=X0_"^"_$$GET1^DIQ(4,DUZ(2),1.01,"E")_"^"_$$GET1^DIQ(4,DUZ(2),1.02,"E")_"^"_$$GET1^DIQ(4,DUZ(2),1.03,"E")_"^"_$$GET1^DIQ(4,DUZ(2),.02,"E")_"^"_$$GET1^DIQ(4,DUZ(2),1.04,"E")
  1. S X5=$$VALUE^ORX8(ORDER,"DRUG",,"E"),X6=$$VALUE^ORX8(ORDER,"DRUG")_";50"
  1. I '$L(X5) S X5=$$VALUE^ORX8(ORDER,"ORDERABLE",,"E"),X6=$$VALUE^ORX8(ORDER,"ORDERABLE")_";101.43"
  1. S X8=$$VALUE^ORX8(ORDER,"QTY",,"E"),X9=$$VALUE^ORX8(ORDER,"SCHEDULE",,"E")
  1. S SIG=+$O(^OR(100,ORDER,4.5,"ID","SIG",0)) I SIG,$L($G(^OR(100,ORDER,4.5,SIG,2,1,0))) S X10=^(0)
  1. S ORSET(1)=X1_"^"_ORPNM_"^"_ORSSN_"^"_+ORVP_"^"
  1. S ORSET(2)=X4_"^"
  1. S ORSET(3)=X5_"^"_X6_"^"_X8_"^"_X9_"^"_ORDEA_"^"
  1. S ORSET(4)=X10_"^"
  1. S ORSET(5)=X11_"^"_ORSIGNER_"^"_X12_"^"
  1. S ORSET(6)=X14
  1. S ORSET(7)=$H
  1. S ORSET=7
  1. Q