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

BPSJPHNM.m

Go to the documentation of this file.
  1. BPSJPHNM ;BHAM ISC/LJF - HL7 E-Pharm Phone Number Parser ;21-NOV-2003
  1. ;;1.0;E CLAIMS MGMT ENGINE;**1**;JUN 2004
  1. ;;Per VHA Directive 10-93-142, this routine should not be modified.
  1. ;
  1. Q
  1. ;
  1. EN(IX1,C,R) ;
  1. ; Called with Person Index from VA(200
  1. N N13,RETVAL,RETP,IX,IX2,UC,LC,PHT,SP,C3,PHD,PHDH,FLAG,PHI
  1. ;
  1. I '$G(IX1) Q ""
  1. I $G(IX1) S N13=$G(^VA(200,+IX1,.13))
  1. I $G(N13)="" Q ""
  1. I $G(C)="" S C="^"
  1. I $G(R)="" S R="~"
  1. ;
  1. ; Set up lowercase to UPPERCASE translation
  1. S LC="abcdefghijklmnopqrstuvwxyz"
  1. S UC="ABCDEFGHIJKLMNOPQRSTUVWXYZ"
  1. S SP=" ",C3=C_C_C
  1. ;
  1. S PHT(1)=C_"PRN"_C_"PH"_C3 ; home phone
  1. S PHT(2)=C_"WPN"_C_"PH"_C3 ; work phone
  1. S PHT(3)=C_"WPN"_C_"PH"_C3 ; 3rd phone
  1. S PHT(4)=C_"WPN"_C_"PH"_C3 ; 4th phone
  1. S PHT(5)=C_"WPN"_C_"PH"_C3 ; Commercial phone
  1. S PHT(6)=C_"WPN"_C_"FX"_C3 ; Fax Number
  1. S PHT(7)=C_"BPN"_C_"BP"_C3 ; Voice Pager Number
  1. S PHT(8)=C_"BPN"_C_"BP"_C3 ; Digital Pager Number
  1. S (PHI(9),PHI(9,1),PHI(9,2),PHI(9,3),PHI(9,4),PHI(9,5))=""
  1. ;
  1. K PHD M PHD=PHI S PHD=$G(^VA(200,IX1,.13)) I $TR(PHD,"^ ")="" Q ""
  1. S PHD(10)=PHD
  1. ; Trim leading and trailing spaces from each piece
  1. F IX2=1:1:8 D
  1. . I $TR($P(PHD,U,IX2),SP)="" S $P(PHD,U,IX2)="" Q
  1. . S PHDH=$P(PHD,U,IX2)
  1. . S $P(PHDH,$E($TR(PHDH,SP)))="" ; remove leading spaces
  1. . S PHDH=$RE(PHDH),$P(PHDH,$E($TR(PHDH,SP)))="",PHDH=$RE(PHDH) ; remove trailing spaces
  1. . ; remove duplicate work numbers
  1. . I IX2>1,IX2<6 D Q
  1. . . I $G(PHD(11,PHDH)) S $P(PHD,U,IX2)=""
  1. . . E S PHD(11,PHDH)=IX2 S $P(PHD,U,IX2)=PHDH
  1. . S $P(PHD,U,IX2)=PHDH
  1. S PHD(10)=PHD
  1. ;
  1. ; Massage pagers into pieces 7&8
  1. F IX2=1:1:6 S PHDH=$P(PHD,U,IX2),FLAG="" I PHDH]"" D
  1. . I PHDH["BEEPER" D
  1. . . S FLAG="1"_$P(PHDH,"BEEPER",2,99),PHDH=$P(PHDH,"BEEPER")
  1. . I PHDH["BEEP" D
  1. . . S FLAG="1"_$P(PHDH,"BEEP",2,99),PHDH=$P(PHDH,"BEEP")
  1. . I PHDH["BP#" D
  1. . . S FLAG="1"_$P(PHDH,"BP#",2,99),PHDH=$P(PHDH,"BP#")
  1. . I PHDH["BP #" D
  1. . . S FLAG="1"_$P(PHDH,"BP #",2,99),PHDH=$P(PHDH,"BP #")
  1. . I PHDH["BP " D
  1. . . S FLAG="1"_$P(PHDH,"BP ",2,99),PHDH=$P(PHDH,"BP ")
  1. . I PHDH["BP" D
  1. . . S FLAG="1"_$P(PHDH,"BP",2,99),PHDH=$P(PHDH,"BP")
  1. . I FLAG D
  1. . . S $P(PHD,U,IX2)=PHDH,$E(FLAG)=""
  1. . . I $P(PHD,U,8)="" S $P(PHD,U,8)=FLAG Q
  1. . . I $P(PHD,U,7)="" S $P(PHD,U,7)=FLAG Q
  1. . . S $P(PHD,U,8)=$P(PHD,U,8)_" BP#"_FLAG
  1. ;
  1. F IX2=1:1:8 S PHD(IX2)=$P(PHD,U,IX2),PHD(IX2,1)="" I PHD(IX2)]"" D
  1. . S PHD(IX2,1)=$$RESOLVEP(PHD(IX2))
  1. . ;Init flag fields then load flags
  1. . M PHD(IX2,9)=PHD(9)
  1. ;
  1. S RETVAL="",RETP=0
  1. F IX2=1:1:8 D
  1. . I '$L(PHD(IX2)) Q
  1. . I '$L(PHD(IX2,1)) S $P(PHD(IX2,1),U,4)=PHD(IX2)
  1. . S PHD(IX2,1)=PHT(IX2)_PHD(IX2,1)
  1. . S RETP=RETP+1,$P(RETVAL,R,RETP)=PHD(IX2,1)
  1. . Q
  1. Q RETVAL
  1. ;
  1. RESOLVEP(PH) ;
  1. ;
  1. N WPA,WPN,WPNH,STDN,WPT,IX,STDN,PREFIX
  1. ;
  1. S WPT=$TR(PH,LC,UC),PREFIX=0
  1. S $P(WPN,SP,$L(WPT))=SP,WPA=WPN
  1. ;
  1. ; Separate numerics from text
  1. F IX=1:1:$L(WPT) D
  1. . I '$E(WPT,IX),$E(WPT,IX)'=0 S $E(WPA,IX)=$E(WPT,IX)
  1. . E S $E(WPN,IX)=$E(PH,IX)
  1. ; Quit if no numerics
  1. I '$L($TR(WPN,SP)) Q ""
  1. ;
  1. S WPNH=WPN ; save a copy of the numeric data
  1. ;
  1. S $P(WPN,$E($TR(WPN,SP)))="" ; remove leading spaces
  1. S WPN=$RE(WPN),$P(WPN,$E($TR(WPN,SP)))="",WPN=$RE(WPN) ; remove trailing spaces
  1. ; Reduce multiple spaces to single spaces
  1. F IX=$L(WPN):-1:1 I ($E(WPN,IX,IX+1)=(SP_SP)) S $E(WPN,IX)=""
  1. ;
  1. ; WPN contains only NUMBERS and SPACES at this point
  1. ; check if it is preceded by a 1 as in "1 800 345 9933"
  1. I $E(WPN,1,2)="1 " S $E(WPN,1,2)="",PREFIX=2
  1. I 'PREFIX,$E(WPN)=1 S $E(WPN)="",PREFIX=1
  1. ; check if it's a standard 10 digit number
  1. S STDN=0
  1. I $L($TR(WPN,SP))=10 S STDN=1 D
  1. . I $L(WPN)=10 D I STDN=1 Q ; format: 1234567890
  1. . . S WPN(1)=$E(WPN,1,3),WPN(2)=$E(WPN,4,6),WPN(3)=$E(WPN,7,10)
  1. . . I PH[WPN(1),PH[WPN(2),PH[WPN(3)
  1. . . E S STDN=0
  1. . S STDN=1
  1. . I $L(WPN,SP)=3 D I STDN Q ; format: 123 456 7890
  1. . . S WPN(1)=$P(WPN,SP,1),WPN(2)=$P(WPN,SP,2),WPN(3)=$P(WPN,SP,3)
  1. . . I $L(WPN(1))=3,PH[WPN(1),$L(WPN(2))=3,PH[WPN(2),$L(WPN(3))=4,PH[WPN(3)
  1. . . E S STDN=0
  1. . S STDN=1
  1. . I $L(WPN,SP)=2 D I STDN=1 Q ; Still may be salvageable
  1. . . S WPN(1)=$P(WPN,SP,1),WPN(2)=$P(WPN,SP,2)
  1. . . ; is format "123 4567890"? area code & city/phone
  1. . . I $L(WPN(1))=3 S WPN(3)=$E(WPN(2),4,7),$E(WPN(2),4,7)="" Q
  1. . . ; is format "123456 7890"? area/city code & phone
  1. . . I $L(WPN(1))=6 S WPN(3)=WPN(2),WPN(2)=$E(WPN(1),4,6),$E(WPN(1),4,6)="" Q
  1. . . S STDN=0 ;unsalvageable as standard number
  1. . S STDN=0 ;unsalvageable as standard number
  1. ;
  1. ; Quit if standard format
  1. I STDN Q WPN(1)_WPN(2)_C_WPN(3)
  1. ;
  1. ;Not standard, need to do some work
  1. ;
  1. F IX=1:1:$L(WPN,SP) S WPN(IX)=$P(WPN,SP,IX)
  1. S IX=$L(WPN,SP),WPN(0)=""
  1. ;
  1. ; add prefix back in if applicable
  1. I PREFIX=1,$L(WPN(1))'=10 S WPN(1)="1"_WPN(1)
  1. ;
  1. ; 1 string of digits
  1. I IX=1 D Q:$L(WPN(0)) WPN(0)
  1. . I $L(WPN(1))<7 S WPN(0)=C_C_WPN(1) Q ;assume it's an extension
  1. . I $L(WPN(1))=7 S WPN(0)=$E(WPN(1),1,3)_C_$E(WPN(1),4,7) Q ;city code & local number
  1. ;
  1. ; 2 strings of digits
  1. I IX=2 D Q:$L(WPN(0)) WPN(0)
  1. . ; could be city code & local number
  1. . I $L(WPN(1))=3,$L(WPN(2))=4 S WPN(0)=WPN(1)_C_WPN(2) Q
  1. . ; could be full number plus extension
  1. . I $L(WPN(1))=10 S WPN(0)=$E(WPN(1),1,6)_C_$E(WPN(1),7,10)_C_WPN(2)
  1. ;
  1. ; 3 strings could include extension
  1. I IX=3 D Q:$L(WPN(0)) WPN(0)
  1. . ; "301 7933124 123"
  1. . I $L(WPN(1))=3,$L(WPN(2))=7 S WPN(0)=WPN(1)_$E(WPN(2),1,3)_C_$E(WPN(2),4,7)_C_WPN(3) Q
  1. . ; "793 3124 123"
  1. . I $L(WPN(1))=3,$L(WPN(2))=4 S WPN(0)=WPN(1)_C_WPN(2)_C_WPN(3)
  1. ;
  1. ; 4 strings could include extension "301 344 2111 3424
  1. I IX=4 D Q:$L(WPN(0)) WPN(0)
  1. . I $L(WPN(1))=3,$L(WPN(2))=3,$L(WPN(3))=4 S WPN(0)=WPN(1)_WPN(2)_C_WPN(3)_C_WPN(4)
  1. ;
  1. Q ""