source: WorldVistAEHR/trunk/r/ORDER_ENTRY_RESULTS_REPORTING-OR-OCX--ORRC--ORRJ/ORHLESC.m@ 1605

Last change on this file since 1605 was 613, checked in by George Lilly, 15 years ago

initial load of WorldVistAEHR

File size: 2.3 KB
RevLine 
[613]1ORHLESC ;SLC/JMH - HL7 UTILITY ;11:26 AM 2 Apr 2001
2 ;;3.0;ORDER ENTRY/RESULTS REPORTING;**243**;Dec 17, 1997;Build 242
3 ;
4 ; VAL = COMPONENT_REPETITION_ESCAPE_SUBCOMPONENT_FIELD
5 ;
6ESC(ORSTR,VAL) ; REPLACE HL7 DELIMITER CHAR
7 N SEPC,SEPR,SEPS,SEPF,SEPE,REPSEPC,REPSEPR,REPSEPS,REPSEPF,REPSEPE,I,HL7DEL
8 I '$L($G(VAL)) S VAL="~|\&^"
9 I $G(ORSTR)="" Q ""
10 I $TR(ORSTR,$G(VAL))=ORSTR Q ORSTR
11 N X,Y,Z,RES
12 S SEPE=$E(VAL,3),REPSEPE=SEPE_"E"_SEPE
13 S SEPC=$E(VAL,1),REPSEPC=SEPE_"S"_SEPE
14 S SEPR=$E(VAL,2),REPSEPR=SEPE_"R"_SEPE
15 S SEPS=$E(VAL,4),REPSEPS=SEPE_"T"_SEPE
16 S SEPF=$E(VAL,5),REPSEPF=SEPE_"F"_SEPE
17 S RES=ORSTR
18 I $F(ORSTR,SEPE) S X=RES D
19 . S Z=$P(X,SEPE,2,9999),Y=$P(X,SEPE)_REPSEPE_Z,RES=Y,X=Z I '$F(Z,SEPE) Q
20 . F I=2:1 S Z=$P(X,SEPE,2,9999),Y=$P(RES,REPSEPE,1,I-1)_REPSEPE_$P(X,SEPE)_REPSEPE_Z,RES=Y,X=Z I '$F(Z,SEPE) Q
21 ;
22 I $F(RES,SEPC) F I=1:1 S Y=$P(RES,SEPC)_REPSEPC_$P(RES,SEPC,2,9999),RES=Y I '$F(RES,SEPC) Q
23 I $F(RES,SEPR) F I=1:1 S Y=$P(RES,SEPR)_REPSEPR_$P(RES,SEPR,2,9999),RES=Y I '$F(RES,SEPR) Q
24 I $F(RES,SEPS) F I=1:1 S Y=$P(RES,SEPS)_REPSEPS_$P(RES,SEPS,2,9999),RES=Y I '$F(RES,SEPS) Q
25 I $F(RES,SEPF) F I=1:1 S Y=$P(RES,SEPF)_REPSEPF_$P(RES,SEPF,2,9999),RES=Y I '$F(RES,SEPF) Q
26 Q RES
27UNESC(ORSTR,VAL) ;
28 ; Remove Escape Characters from HL7 Message Text
29 ; Escape Sequence codes:
30 ; F = field separator (ORFS)
31 ; S = component separator (ORCS)
32 ; R = repetition separator (ORRS)
33 ; E = escape character (ORES)
34 ; T = subcomponent separator (ORSS)
35 N ORFS,ORCS,ORRS,ORES,ORSS
36 I '$L($G(VAL)) S VAL="~|\&^"
37 S ORFS=$E(VAL,5)
38 S ORCS=$E(VAL,1)
39 S ORRS=$E(VAL,2)
40 S ORES=$E(VAL,3)
41 S ORSS=$E(VAL,4)
42 N ORCHR,ORREP,I1,I2,J1,J2,K,VALUE
43 F ORCHR="F","S","R","E","T" S ORREP(ORES_ORCHR_ORES)=$S(ORCHR="F":ORFS,ORCHR="S":ORCS,ORCHR="R":ORRS,ORCHR="E":ORES,ORCHR="T":ORSS)
44 S ORSTR=$$REPLACE^XLFSTR(ORSTR,.ORREP)
45 F S I1=$P(ORSTR,ORES_"X") Q:$L(I1)=$L(ORSTR) D
46 .S I2=$P(ORSTR,ORES_"X",2,99)
47 .S J1=$P(I2,ORES) Q:'$L(J1)
48 .S J2=$P(I2,ORES,2,99)
49 .S VALUE=$$BASE^XLFUTL($$UP^XLFSTR(J1),16,10)
50 .S K=$S(VALUE>255:"?",VALUE<32!(VALUE>127&(VALUE<160)):"",1:$C(VALUE))
51 .S ORSTR=I1_K_J2
52 Q ORSTR
53REPLACE(X,Y,Z) ;
54 ; X is initial string
55 ; Y is string to be replaced
56 ; Z is string to replace
57 N RET
58 I X'[Y Q X
59 S I=1,RET=$P(X,Y) F S I=I+1,RET=RET_Z_$P(X,Y,I) Q:I=$L(X,Y)
60 Q RET
Note: See TracBrowser for help on using the repository browser.