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

HLOPBLD.m

Go to the documentation of this file.
  1. HLOPBLD ;ALB/CJM-HL7 - Building segments ;10/24/2006
  1. ;;1.6;HEALTH LEVEL SEVEN;**126,132**;Oct 13, 1995;Build 6
  1. ;Per VHA Directive 2004-038, this routine should not be modified.
  1. ;
  1. ;
  1. BUILDSEG(HLMSTATE,SEG,TOARY,ERROR) ;Builds the segment from the individual values
  1. ;Input:
  1. ; HLMSTATE() - (pass by reference, required) Used to track the progress of the message. Uses these subscripts:
  1. ; ("HDR","FIELD SEPARATOR")
  1. ; ("HDR","ENCODING CHARACTERS")
  1. ; SEG() - (pass by reference, required) Contains the data. It must be built by calls to SET^HLOAPI prior to calling $$BUILDSEG.
  1. ;
  1. ;Note#1: The '0' field must be a 3 character segment type
  1. ;Note#2: ***SEG is killed upon successfully adding the segment***
  1. ;
  1. ;Output:
  1. ; Function - returns 1 on success, 0 on failure
  1. ; TOARY (pass by reference) This will return the segment in an array format TOARY(1),TOARY(2),... For segments that are shorter than the MUMPS maximum string length, there will be only TOARY(1)
  1. ; ERROR (optional, pass by reference) - returns an error message on failure
  1. ;
  1. ;
  1. K ERROR,TOARY
  1. N TEMP1,TEMP2,LINE,LAST,SEQ,MAX,COUNT,SEGTYPE
  1. S COUNT=0
  1. S MAX=HLMSTATE("SYSTEM","MAXSTRING")-1 ;save some room for the <CR>
  1. S SEGTYPE=$G(SEG(0,1,1,1))
  1. S LAST=0,(TEMP1,TEMP2)="",LINE=SEGTYPE_HLMSTATE("HDR","FIELD SEPARATOR")
  1. F S SEQ=$O(SEG(LAST)) Q:'SEQ D
  1. .S TEMP2="",$P(TEMP2,HLMSTATE("HDR","FIELD SEPARATOR"),$S(LAST=0:SEQ,1:SEQ-LAST+1))=""
  1. .S TEMP1=TEMP2
  1. .S LAST=SEQ
  1. .N REP,LAST
  1. .S LAST=0
  1. .F S REP=$O(SEG(SEQ,LAST)) Q:'REP D
  1. ..S TEMP2="",$P(TEMP2,$E(HLMSTATE("HDR","ENCODING CHARACTERS"),2),$S(LAST=0:REP,1:REP-LAST+1))=""
  1. ..S TEMP1=TEMP1_TEMP2
  1. ..S LAST=REP
  1. ..;
  1. ..N COMP,LAST
  1. ..S LAST=0
  1. ..F S COMP=$O(SEG(SEQ,REP,LAST)) Q:'COMP D
  1. ...S TEMP2="",$P(TEMP2,$E(HLMSTATE("HDR","ENCODING CHARACTERS"),1),$S(LAST=0:COMP,1:COMP-LAST+1))=""
  1. ...S TEMP1=TEMP1_TEMP2
  1. ...S LAST=COMP
  1. ...;
  1. ...N SUBCOMP,LAST
  1. ...S LAST=0
  1. ...F S SUBCOMP=$O(SEG(SEQ,REP,COMP,LAST)) Q:'SUBCOMP D
  1. ....N VALUE
  1. ....S TEMP2="",$P(TEMP2,$E(HLMSTATE("HDR","ENCODING CHARACTERS"),4),$S(LAST=0:SUBCOMP,1:SUBCOMP-LAST+1))=""
  1. ....S VALUE=$G(SEG(SEQ,REP,COMP,SUBCOMP))
  1. ....K SEG(SEQ,REP,COMP,SUBCOMP)
  1. ....S:((SEGTYPE'="MSH")&(SEGTYPE'="BHS"))!(SEQ'=2) VALUE=$$ESCAPE(.HLMSTATE,VALUE)
  1. ....S TEMP2=TEMP2_VALUE
  1. ....S TEMP1=TEMP1_TEMP2
  1. ....I $L(LINE)+$L(TEMP1)<MAX D
  1. .....S LINE=LINE_TEMP1
  1. ....E D
  1. .....D ADDLINE(.TOARY,LINE_$E(TEMP1,1,MAX-$L(LINE)),.COUNT)
  1. .....S LINE=$E(TEMP1,MAX-$L(LINE)+1,MAX+100)
  1. ....S TEMP1=""
  1. ....S LAST=SUBCOMP
  1. I $L(LINE) D ADDLINE(.TOARY,LINE,.COUNT)
  1. K SEG
  1. Q 1
  1. ;
  1. ADDLINE(TOARY,LINE,COUNT) ;
  1. S COUNT=COUNT+1
  1. S TOARY(COUNT)=LINE
  1. Q
  1. ;
  1. ESCAPE(HLMSTATE,VALUE) ;
  1. ;Replaces the HL7 encoding characters with the corresponding escape sequences and returns the result as the function value
  1. ;
  1. N ESC,CHARS,I,NEWVALUE,LEN,CUR
  1. S CHARS=HLMSTATE("HDR","ENCODING CHARACTERS")
  1. S ESC=$E(CHARS,3)
  1. S NEWVALUE="",LEN=$L(VALUE)
  1. F I=1:1:LEN D
  1. .S CUR=$E(VALUE,I)
  1. .S NEWVALUE=NEWVALUE_$S(CUR=HLMSTATE("HDR","FIELD SEPARATOR"):ESC_"F"_ESC,CUR=ESC:ESC_"E"_ESC,CUR=$E(CHARS,1):ESC_"S"_ESC,CUR=$E(CHARS,4):ESC_"T"_ESC,CUR=$E(CHARS,2):ESC_"R"_ESC,1:CUR)
  1. Q NEWVALUE
  1. ;
  1. REPLACE(VALUE,CHAR,STRING) ;
  1. ;Takes the input string=VALUE and replaces each instance of the character
  1. ;=CHAR with the string=STRING and returns the resultant string
  1. ;as the function value
  1. ;
  1. N I,NEWVALUE,CURCHAR
  1. S NEWVALUE=""
  1. F I=1:1:$L(VALUE) D
  1. .S CURCHAR=$E(VALUE,I)
  1. .S NEWVALUE=NEWVALUE_$S(CURCHAR=CHAR:STRING,1:CURCHAR)
  1. Q NEWVALUE