source: WorldVistAEHR/trunk/r/HEALTH_LEVEL_SEVEN-HL/HLOPRS1.m@ 1438

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

initial load of WorldVistAEHR

File size: 4.2 KB
Line 
1HLOPRS1 ;IRMFO-ALB/CJM -RTNs for parsing messages (continued);03/24/2004 14:43 ;01/19/2007
2 ;;1.6;HEALTH LEVEL SEVEN;**118,131,133,134**;Oct 13, 1995;Build 30
3 ;Per VHA Directive 2004-038, this routine should not be modified.
4 ;
5PARSE(FIELD,REP,COMP,SUBCOMP,ESCAPE,SEG,TO) ;
6 ;Parses the segment stored in SEG(1),SEG(2),... into TO()
7 ;Input:
8 ; FIELD - field separator
9 ; REP - field repetition separator
10 ; COMP - component separator
11 ; SUBCOMP - subcomponent separator
12 ; ESCAPE - escape character
13 ; SEG - (pass by reference) the array holding the unparsed segment.
14 ;Output:
15 ; Function returns 1 on success, 0 on failure
16 ; TO - (pass by reference) - the parsed values
17 ; SEG- This input variable is deleted during the processing. If it is needs to be retained, pass in a copy!
18 ;
19 N VALUE,CHAR,COUNTS
20 K TO
21 Q:$L($G(FIELD))'=1 0
22 Q:$L($G(REP))'=1 0
23 Q:$L($G(COMP))'=1 0
24 Q:'$D(SUBCOMP) 0
25 Q:'$D(SEG) 0
26 S COUNTS("FIELD")=0
27 S COUNTS("REP")=1
28 S COUNTS("COMP")=1
29 S COUNTS("SUBCOMP")=1
30 S VALUE=""
31 S SEG("LINE")=$O(SEG(0)),SEG("CHAR")=0
32 F S CHAR=$$NEXTCHAR(.SEG) D Q:'$L(CHAR)
33 .I '$L(CHAR) D Q
34 ..I $L(VALUE) S TO(COUNTS("FIELD"),COUNTS("REP"),COUNTS("COMP"),COUNTS("SUBCOMP"))=VALUE
35 .E I CHAR=FIELD D Q
36 ..I $L(VALUE) S TO(COUNTS("FIELD"),COUNTS("REP"),COUNTS("COMP"),COUNTS("SUBCOMP"))=$$DESCAPE(VALUE,.FIELD,.COMP,.SUBCOMP,.REP,.ESCAPE),VALUE=""
37 ..S COUNTS("FIELD")=COUNTS("FIELD")+1,COUNTS("REP")=1,COUNTS("COMP")=1,COUNTS("SUBCOMP")=1
38 .E I CHAR=REP D Q
39 ..I $L(VALUE) S TO(COUNTS("FIELD"),COUNTS("REP"),COUNTS("COMP"),COUNTS("SUBCOMP"))=$$DESCAPE(VALUE,.FIELD,.COMP,.SUBCOMP,.REP,.ESCAPE),VALUE=""
40 ..S COUNTS("REP")=COUNTS("REP")+1,COUNTS("COMP")=1,COUNTS("SUBCOMP")=1
41 .E I CHAR=COMP D Q
42 ..I $L(VALUE) S TO(COUNTS("FIELD"),COUNTS("REP"),COUNTS("COMP"),COUNTS("SUBCOMP"))=$$DESCAPE(VALUE,.FIELD,.COMP,.SUBCOMP,.REP,.ESCAPE),VALUE=""
43 ..S COUNTS("COMP")=COUNTS("COMP")+1,COUNTS("SUBCOMP")=1
44 .E I CHAR=SUBCOMP D Q
45 ..I $L(VALUE) S TO(COUNTS("FIELD"),COUNTS("REP"),COUNTS("COMP"),COUNTS("SUBCOMP"))=$$DESCAPE(VALUE,.FIELD,.COMP,.SUBCOMP,.REP,.ESCAPE),VALUE=""
46 ..S COUNTS("SUBCOMP")=COUNTS("SUBCOMP")+1
47 .E S VALUE=VALUE_CHAR
48 S TO("SEGMENT TYPE")=$G(TO(0,1,1,1)),TO(0)=TO("SEGMENT TYPE")
49 I (TO("SEGMENT TYPE")="BHS")!(TO("SEGMENT TYPE")="MSH") S TO("FIELD SEPARATOR")=FIELD
50 Q 1
51 ;
52NEXTCHAR(SEG) ;
53 ;returns the next character in the segment array
54 ;
55 Q:'SEG("LINE") ""
56 N RET
57 S SEG("CHAR")=SEG("CHAR")+1
58 S RET=$E(SEG(SEG("LINE")),SEG("CHAR"))
59 Q:RET]"" RET
60 S SEG("LINE")=$O(SEG(SEG("LINE")))
61 I SEG("LINE") S SEG("CHAR")=1 Q $E(SEG(SEG("LINE")))
62 Q ""
63 ;
64DESCAPE(VALUE,FIELD,COMP,SUBCOMP,REP,ESCAPE) ;
65 ;Replaces the escape sequences with the corresponding encoding character and returns the result as the function value
66 ;
67 Q:ESCAPE="" VALUE
68 N NEWSTRNG,SUBSTRNG,SET,LEN,I,SUBLEN,CHAR
69 S (NEWSTRNG,SUBSTRNG,SUBLEN)=""
70 S SET="FSTRE"
71 S LEN=$L(VALUE)
72 F I=1:1:LEN S SUBSTRNG=SUBSTRNG_$E(VALUE,I),SUBLEN=SUBLEN+1 D:SUBLEN=3
73 .S CHAR=$E(SUBSTRNG,2)
74 .I $E(SUBSTRNG,1)=ESCAPE,$E(SUBSTRNG,3)=ESCAPE,SET[CHAR D
75 ..I CHAR="F" S NEWSTRNG=NEWSTRNG_FIELD,SUBSTRNG="",SUBLEN=0 Q
76 ..I CHAR="S" S NEWSTRNG=NEWSTRNG_COMP,SUBSTRNG="",SUBLEN=0 Q
77 ..I CHAR="T" S NEWSTRNG=NEWSTRNG_SUBCOMP,SUBSTRNG="",SUBLEN=0 Q
78 ..I CHAR="R" S NEWSTRNG=NEWSTRNG_REP,SUBSTRNG="",SUBLEN=0 Q
79 ..I CHAR="E" S NEWSTRNG=NEWSTRNG_ESCAPE,SUBSTRNG="",SUBLEN=0 Q
80 .E S NEWSTRNG=NEWSTRNG_$E(SUBSTRNG),SUBSTRNG=$E(SUBSTRNG,2,3),SUBLEN=2
81 Q NEWSTRNG_SUBSTRNG
82 ;
83GETCODE(SEG,VALUE,FIELD,COMP,REP) ;
84 ;Implements GETCNE and GETCWE
85 ;
86 N SUB,VAR
87 Q:'$G(FIELD)
88 I '$G(COMP) D
89 .S VAR="COMP",SUB=1
90 E D
91 .S VAR="SUB"
92 S:'$G(REP) REP=1
93 S @VAR=1,VALUE("ID")=$$GET^HLOPRS(.SEG,FIELD,COMP,SUB,REP)
94 S @VAR=2,VALUE("TEXT")=$$GET^HLOPRS(.SEG,FIELD,COMP,SUB,REP)
95 S @VAR=3,VALUE("SYSTEM")=$$GET^HLOPRS(.SEG,FIELD,COMP,SUB,REP)
96 S @VAR=4,VALUE("ALTERNATE ID")=$$GET^HLOPRS(.SEG,FIELD,COMP,SUB,REP)
97 S @VAR=5,VALUE("ALTERNATE TEXT")=$$GET^HLOPRS(.SEG,FIELD,COMP,SUB,REP)
98 S @VAR=6,VALUE("ALTERNATE SYSTEM")=$$GET^HLOPRS(.SEG,FIELD,COMP,SUB,RE)
99 S @VAR=7,VALUE("SYSTEM VERSION")=$$GET^HLOPRS(.SEG,FIELD,COMP,SUB,REP)
100 S @VAR=8,VALUE("ALTERNATE SYSTEM VERSION")=$$GET^HLOPRS(.SEG,FIELD,COM)
101 S @VAR=9,VALUE("ORIGINAL TEXT")=$$GET^HLOPRS(.SEG,FIELD,COMP,SUB,REP)
102 Q
Note: See TracBrowser for help on using the repository browser.