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

HLFNC.m

Go to the documentation of this file.
  1. HLFNC ;AISC/SAW/OAK-OIFO/RBN-Routine of Functions and Other Calls Used for HL7 Messages ;03/26/2008 11:34
  1. ;;1.6;HEALTH LEVEL SEVEN;**38,42,51,66,141**;Oct 13, 1995;Build 11
  1. ;Per VHA Directive 2004-038, this routine should not be modified.
  1. ;
  1. HLNAME(X,HLECDE) ;Convert a name in DHCP format to HL7 format
  1. ; INPUT: X - Name in DHCP format
  1. ; Optional - HLECDE - HL7 encoding chars
  1. ;**** NOTE: ****
  1. ;If this function is called without HLECDE as parameter than HLECH
  1. ;must be define.
  1. ;
  1. Q:'$D(X) "" Q:X="" ""
  1. I '$D(HLECH),'$D(HLECDE) Q ""
  1. I $D(HLECDE) N HLECH S HLECH=HLECDE
  1. I '$D(HLECH) Q ""
  1. N %,X1,X2,Y
  1. S X1=$P(X,",",2),X2=$L(X1," "),Y=$P(X,",")_$E(HLECH)_$P(X1," ") I X2 F %=2:1:X2 Q:$P(X1," ",%)']"" S Y=Y_$E(HLECH)_$P(X1," ",%)
  1. Q Y
  1. ;
  1. FMNAME(X,HLECDE) ;Convert a name in HL7 format to DHCP format
  1. ; INPUT: X - Name in HL7 format
  1. ; Optional - HLECDE - HL7 encoding chars
  1. ;**** NOTE: ****
  1. ;If this function is called without HLECDE as parameter than HLECH
  1. ;must be define.
  1. ;
  1. Q:'$D(X) "" Q:X="" ""
  1. I '$D(HLECH),'$D(HLECDE) Q ""
  1. I $D(HLECDE) N HLECH S HLECH=HLECDE
  1. I '$D(HLECH) Q ""
  1. N %,X1 S X1=$L(X,$E(HLECH)),Y="" F %=1:1:X1 D
  1. .I $P(X,$E(HLECH),%)]"",$P(X,$E(HLECH),%)'="""""" D
  1. ..;Only last name,first name.
  1. ..I %<3 S Y=Y_$P(X,$E(HLECH),%)_$S(%=1:",",1:"") Q
  1. ..S Y=Y_" "_$P(X,$E(HLECH),%)
  1. Q Y
  1. ;
  1. HLDATE(X,Y) ;Convert date, date/time or time only in FM format to HL7 format
  1. ;Optional Variables:
  1. ;Y = The type of format to be returned if you want to force return of a
  1. ; specific format. Y must be equal to one of the following:
  1. ; DT - Date only
  1. ; TM - Time only
  1. ; TS - Date and time
  1. I X="" Q ""
  1. S Y=$G(Y)
  1. N %,Z
  1. I $L(X)<7 D Q % ;Time input
  1. . S %=$S(X=2400:"0000",$L(X)<4:$E(X_"000",1,4),1:X) S:$L(%)=5 %=%_0
  1. . Q
  1. I Y="TM" D Q % ;Only time
  1. . S %=$P(X,".",2),%=$S(%="":"",$E(%,1,2)=24:"0000",$L(%)<4:$E(%_"000",1,4),1:%) S:$L(%)=5 %=%_0
  1. . Q
  1. S %=$$FMTHL7^XLFDT(X)
  1. Q $S(Y="DT":$E(%,1,8),1:%)
  1. ;
  1. FMDATE(X) ; Convert a date, date/time or time only in HL7 format to FM format
  1. I X="" Q ""
  1. N %
  1. S %=$P($TR(X,"+-","^"),"^")
  1. I $L(X)<7 Q %
  1. Q $$HL7TFM^XLFDT(X)
  1. ;
  1. M10(X,HLECDE) ; M10 check digit scheme
  1. ; INPUT : X - ID number
  1. ; Optional HLECDE - Encoding chars
  1. ;**** NOTE: ****
  1. ;If this function is called without HLECDE as parameter then HLECH
  1. ;must be defined.
  1. ;Return X if encoding character is not defined
  1. ;Return X with encoding characters concatenated if X is alphanumeric
  1. ;
  1. N HLCNT,HLODD,HLEVEN,HLX1,HLDIGIT
  1. Q:'$D(X) ""
  1. I $D(HLECDE) N HLECH S HLECH=HLECDE
  1. ;Return X if encoding character is not defined
  1. I '$D(HLECH) Q X
  1. ;Return X with encoding characters concatenated if X is alphanumeric
  1. I '(X?1.N) Q X_$E(HLECH)_$E(HLECH)
  1. ;
  1. S HLX1=+X
  1. S HLODD=""
  1. F HLCNT=$L(HLX1):-2:1 S HLODD=HLODD_$E(HLX1,HLCNT)
  1. S HLODD=HLODD*2
  1. S HLEVEN=""
  1. F HLCNT=($L(HLX1)-1):-2:1 S HLEVEN=HLEVEN_$E(HLX1,HLCNT)
  1. S HLX1=HLEVEN_HLODD
  1. S HLDIGIT=0
  1. F HLCNT=1:1:$L(HLX1) S HLDIGIT=HLDIGIT+$E(HLX1,HLCNT)
  1. S HLDIGIT=((HLDIGIT\10+1)*10-HLDIGIT)#10
  1. Q X_$E(HLECH)_HLDIGIT_$E(HLECH)_"M10"
  1. ;
  1. M11(X,HLECDE) ; M11 check digit scheme
  1. ; INPUT : X - ID number
  1. ; Optional HLECDE - Encoding chars
  1. ;**** NOTE: ****
  1. ;If this function is called without HLECDE as parameter then HLECH
  1. ;must be defined.
  1. ;Return X if encoding character is not defined
  1. ;Return X with encoding characters concatenated if X is alphanumeric
  1. ;
  1. N HLX1,HLCNT,HLWT,HLDIGIT
  1. Q:'$D(X) ""
  1. I $D(HLECDE) N HLECH S HLECH=HLECDE
  1. ;Return X if encoding character is not defined
  1. I '$D(HLECH) Q X
  1. ;Return X with encoding characters concatenated if X is alphanumeric
  1. I '(X?1N.N) Q X_$E(HLECH)_$E(HLECH)
  1. ;
  1. S HLX1=+X
  1. S HLDIGIT=0,HLWT=2
  1. F HLCNT=$L(HLX1):-1:1 D
  1. . I HLWT>7 S HLWT=2
  1. . S HLDIGIT=HLDIGIT+($E(HLX1,HLCNT)*HLWT)
  1. . S HLWT=HLWT+1
  1. S HLDIGIT=HLDIGIT#11
  1. I HLDIGIT=0 S HLDIGIT=1
  1. S HLDIGIT=(11-HLDIGIT)#10
  1. Q X_$E(HLECH)_HLDIGIT_$E(HLECH)_"M11"
  1. ;
  1. OLDM10(X,HLECDE) ;Calculate M10 checksum
  1. ; INPUT : X - String to calc checksum
  1. ; Optional HLECDE - Encoding chars
  1. ;**** NOTE: ****
  1. ;If this function is called without HLECDE as parameter than HLECH
  1. ;must be define.
  1. ;
  1. Q:'$D(X) ""
  1. I '$D(HLECH),'$D(HLECDE) Q ""
  1. I $D(HLECDE) N HLECH S HLECH=HLECDE
  1. I '$D(HLECH) Q ""
  1. N %,Y
  1. S Y=0 F %=1:1:$L(X) S Y=Y+$E(X,%)
  1. Q X_$E(HLECH)_(Y#10)_$E(HLECH)_"M10"
  1. ;
  1. OLDM11(X,HLECDE) ;Calculate M11 checksum
  1. ; INPUT : X - String to calc checksum
  1. ; Optional HLECDE - Encoding chars
  1. ;**** NOTE: ****
  1. ;If this function is called without HLECDE as parameter than HLECH
  1. ;must be define.
  1. ;
  1. Q:'$D(X) ""
  1. I '$D(HLECH),'$D(HLECDE) Q ""
  1. I $D(HLECDE) N HLECH S HLECH=HLECDE
  1. I '$D(HLECH) Q ""
  1. N %,Y S Y=0 F %=1:1:$L(X) S Y=Y+$E(X,%)
  1. Q X_$E(HLECH)_(Y#11)_$E(HLECH)_"M11"
  1. UPPER(X) ;Convert lowercase letters to uppercase
  1. Q:'$D(X) ""
  1. Q $TR(X,"abcdefghijklmnopqrstuvwxyz","ABCDEFGHIJKLMNOPQRSTUVWXYZ")
  1. HLPHONE(X,B,C) ;Convert DHCP Phone Number to HL7 Format
  1. ;Required parameters:
  1. ;X = Seven digit phone number at a minimum. Optionally, in addition,
  1. ; a three digit area code, two digit country code and other
  1. ; formatting characters (e.g., dashes)
  1. ;Optional Variables:
  1. ;B = Beeper number
  1. ;C = Comments
  1. Q:'$D(X) "" Q:$L(X)<7 ""
  1. N I,Y,Y1,Z S B=$S('$D(B):"",1:"B"_B),C=$S('$D(C):"",1:"C"_C)
  1. ;
  1. ; patch HL*1.6*141 start
  1. ; S Y="" F I=1:1:$L(X) S Y=Y_$S($E(X,I)?1N:$E(X,I),"X,x"[$E(X,I)&('$D(Z)):"X",1:"") I "X,x"[$E(X,I) S Z=""
  1. N CH
  1. S Y=""
  1. F I=1:1:$L(X) D
  1. . S CH=$E(X,I)
  1. . ; Next line modified by RBN
  1. . ;S Y=Y_$S(CH?1N:CH,"Xx"[CH&('$D(Z)):"X",1:"")
  1. . S Y=Y_$S(CH?1N:CH,"Xx,*"[CH&('$D(Z)):"X",1:"")
  1. . I "Xx"[CH S Z=""
  1. ;
  1. ; the number, following "X" character, should be greater than 0
  1. I Y["X",+$P(Y,"X",2)<1 S Y=$P(Y,"X")
  1. ; patch HL*1.6*141 end
  1. ;
  1. I $L(Y)<7 Q ""
  1. S Y1=$S(Y["X":"X"_$P(Y,"X",2),1:""),Y=$P(Y,"X") I $L(Y)<7 Q ""
  1. I $L(Y)=8,189[$E(Y) S Y=$E(Y,2,8)
  1. I $L(Y)=11,189[$E(Y) S Y=$E(Y,2,11)
  1. I $L(Y)=7 Q $E($E(Y,1,3)_"-"_$E(Y,4,7)_Y1_B_C,1,40)
  1. I $L(Y)=10 Q $E("("_$E(Y,1,3)_")"_$E(Y,4,6)_"-"_$E(Y,7,10)_Y1_B_C,1,40)
  1. I $L(Y)=12 Q $E($E(Y,1,2)_" ("_$E(Y,3,5)_")"_$E(Y,6,8)_"-"_$E(Y,9,12)_Y1_B_C,1,40)
  1. Q ""
  1. HLADDR(AD,GL,HLECDE) ;Convert DHCP address fields to HL7 address format
  1. ;Required parameters:
  1. ;AD = One to four street address lines separated by uparrows (^).
  1. ;GL = Three to four geographic location components separated by
  1. ; uparrows (^). City^State or Province^Zip Code^Country Code.
  1. ; If the fourth component is not defined, it will be set to 'USA'.
  1. ; The second component must be null or an IEN in the
  1. ; State file (#5). The third component must be null or pattern
  1. ; match 5N, 9N or 5N1"-"4N.
  1. ;
  1. ; Optional HLECDE - Encoding chars
  1. ;**** NOTE: ****
  1. ;If this function is called without HLECDE as parameter than HLECH
  1. ;must be define.
  1. ;
  1. ;
  1. ;A string will be returned with six components separated by the HL7
  1. ;component separator. The length of the string (including separators)
  1. ;may exceed 106 characters.
  1. ;
  1. Q:'$D(AD) "" Q:'$D(GL) ""
  1. I '$D(HLECH),'$D(HLECDE) Q ""
  1. I $D(HLECDE) N HLECH S HLECH=HLECDE
  1. I '$D(HLECH) Q ""
  1. I $D(XRTL) D T0^%ZOSV
  1. N I,X,Y
  1. I $P(GL,"^",4)="" S $P(GL,"^",4)="USA"
  1. I $P(GL,"^",4)="USA" S X=$P(GL,"^",3) S:X?9N X=$E(X,1,5)_"-"_$E(X,6,9) S $P(GL,"^",3)=$S(X?5N!(X?5N1"-"4N):X,1:"")
  1. S X=+$P(GL,"^",2) S $P(GL,"^",2)=$S('X:"",$P($G(^DIC(5,X,0)),"^",2)]"":$E($P(^(0),"^",2),1,2),1:"")
  1. S Y=$E(HLECH)_$P(GL,"^")_$E(HLECH)_$P(GL,"^",2)_$E(HLECH)_$P(GL,"^",3)_$E(HLECH)_$P(GL,"^",4)
  1. S X=$P(AD,"^",1,4) F I=1,2 I X["^^" S X=$P(X,"^^")_"^"_$P(X,"^^",2,3)
  1. I $E(X,$L(X))="^" S X=$E(X,1,($L(X)-1))
  1. I $D(XRT0) S XRTN="HLFNC" D T1^%ZOSV
  1. I $L(X,"^")=1 Q $P(X,"^")_$E(HLECH)_Y
  1. I $L(X,"^")=2 Q $P(X,"^")_$E(HLECH)_$P(X,"^",2)_Y
  1. I $L(X,"^")=3 Q $P(X,"^")_", "_$P(X,"^",2)_$E(HLECH)_$P(X,"^",3)_Y
  1. I $L(X,"^")=4 Q $P(X,"^")_", "_$P(X,"^",2)_$E(HLECH)_$P(X,"^",3)_", "_$P(X,"^",4)_Y