LA7VHLU4 ;VA/DALOI/JMC - HL7 segment builder utility ; 13-Aug-2013 09:09 ; MKK
;;5.2;AUTOMATED LAB INSTRUMENTS;**46,1018,64,1027,68,1033**;NOV 01, 1997
;
;
INST(LA74,LA7FS,LA7ECH) ; Build institution field
; Call with LA74 = ien of institution in file #4
; if null/undefined then use Kernel Site file.
; LA7FS = HL field separator
; LA7ECH = HL encoding characters
;
; Returns facility that performed the testing (ID^text^99VA4)
;
N LA7NVAF,LA7X,LA7Y,LA7Z
;
S LA74=$G(LA74),LA7ECH=$G(LA7ECH),LA7Y=""
;
; If no institution, use Kernel Site default
I LA74="" S LA74=+$$KSP^XUPARAM("INST")
;
; Check if this field has been built previously for this institution
I LA74'="",$D(^TMP($J,"LA7VHLU","99VA4",LA74,LA7FS_LA7ECH)) S LA7Y=^TMP($J,"LA7VHLU","99VA4",LA74,LA7FS_LA7ECH)
;
; Value passed not a pointer - only build 2nd component
I LA7Y="",LA74'="",LA74'=+LA74 D
. S $P(LA7Y,$E(LA7ECH,1),2)=$$CHKDATA^LA7VHLU3(LA74,LA7FS_LA7ECH)
;
I LA7Y="",LA74>0,LA74=+LA74 D
. S LA7NVAF=$$NVAF^LA7VHLU2(LA74)
. ; Build id - VA station #/DMIS code
. I LA7NVAF<2 S LA7Y=$$ID^XUAF4($S(LA7NVAF=1:"DMIS",1:"VASTANUM"),LA74)
. ; Build name using field #100, otherwise #.01
. S LA7Z=$$NAME^XUAF4(LA74)
. S $P(LA7Y,$E(LA7ECH,1),2)=$$CHKDATA^LA7VHLU3(LA7Z,LA7FS_LA7ECH)
. ;
. S $P(LA7Y,$E(LA7ECH,1),3)="99VA4"
;
; Save this field to TMP global to use for subsequent calls.
S ^TMP($J,"LA7VHLU","99VA4",LA74,LA7FS_LA7ECH)=LA7Y
;
Q LA7Y
;
;
XAD(LA7FN,LA7DA,LA7DT,LA7FS,LA7ECH) ; Build extended address
; Call with LA7FN = Source File number
; Presently file #2 (PATIENT), #4 (INSTITUTION) or #200 (NEW PERSON)
; LA7DA = Entry in source file
; LA7DT = As of date in FileMan format
; LA7FS = HL field separator
; LA7ECH = HL encoding characters
;
; Returns extended address
;
N LA7X,LA7Y,LA7Z
;
S LA7Y=""
;
; Check if this field has been built previously for this institution
;I LA7FN,LA7DA,$D(^TMP($J,"LA7VHLU","99VA4A",LA7FN,LA7DA,LA7FS_LA7ECH)) S LA7Y=^TMP($J,"LA7VHLU","99VA4A",LA7FN,LA7DA,LA7FS_LA7ECH)
;
; Build from file #2
I LA7Y="",LA7FN=2,LA7DA D
. N DFN,VAHOW,VAPA,VAERR,VAROOT,VATEST
. S DFN=LA7DA
. I LA7DT S (VATEST("ADD",9),VATEST("ADD",10))=LA7DT
. D ADD^VADPT
. I VAERR Q
. S $P(LA7Y,$E(LA7ECH),1)=$$CHKDATA^LA7VHLU3(VAPA(1),LA7FS_LA7ECH)
. S $P(LA7Y,$E(LA7ECH),2)=$$CHKDATA^LA7VHLU3(VAPA(2),LA7FS_LA7ECH)
. S $P(LA7Y,$E(LA7ECH),3)=$$CHKDATA^LA7VHLU3(VAPA(4),LA7FS_LA7ECH)
. S $P(LA7Y,$E(LA7ECH),4)=$$CHKDATA^LA7VHLU3($P(VAPA(5),"^",2),LA7FS_LA7ECH)
. S $P(LA7Y,$E(LA7ECH),5)=$$CHKDATA^LA7VHLU3(VAPA(11),LA7FS_LA7ECH)
. I VAPA(9) S $P(LA7Y,$E(LA7ECH),7)="C"
. E S $P(LA7Y,$E(LA7ECH),7)="P"
. S $P(LA7Y,$E(LA7ECH),9)=$$CHKDATA^LA7VHLU3($P(VAPA(7),"^",2),LA7FS_LA7ECH)
;
; Get address info from file #4, add 2nd address line
; change state to pointer to file #5
I LA7Y="",LA7FN=4,LA7DA D
. S LA7Z=$$PADD^XUAF4(LA7DA)
. S LA7X=$P(LA7Z,"^"),$P(LA7X,"^",2)=$$WHAT^XUAF4(LA7DA,1.02)
. F I=1,2 I $P(LA7X,"^",I)'="" S $P(LA7X,"^",I)=$$CHKDATA^LA7VHLU3($P(LA7X,"^",I),LA7FS_LA7ECH)
. S LA7Z=$P(LA7Z,"^",2,4),$P(LA7Z,"^",2)=$$GET1^DIQ(4,LA7DA_",",.02,"I")
. S $P(LA7Z,"^")=$$CHKDATA^LA7VHLU3($P(LA7Z,"^"),LA7FS_LA7ECH)
. S LA7Y=$$HLADDR^HLFNC(LA7X,LA7Z,LA7ECH)
;
I LA7Y="",LA7FN=200,LA7DA D
. Q
;
; Save this field to TMP global to use for subsequent calls.
I LA7Y'="" S ^TMP($J,"LA7VHLU","99VA4A",LA7FN,LA7DA,LA7FS_LA7ECH)=LA7Y
;
Q LA7Y
;
;
XON(LA7FN,LA7DA,LA7TYP,LA7FS,LA7ECH) ; Build extended composite name/id for organization
; Call with LA7FN = Source File number
; Presently #4 (INSTITUTION)
; LA7DA = Entry in source file
; LA7TYP = type of identifer (0/null=station #, 1=CLIA)
; LA7FS = HL field separator
; LA7ECH = HL encoding characters
;
;
N LA7X,LA7Y,LA7Z
;
S LA7Y="",LA7TYP=+$G(LA7TYP)
;
; Check if this field has been built previously for this institution
I LA7FN,LA7DA,$D(^TMP($J,"LA7VHLU","99VA4N",LA7FN,LA7DA,LA7TYP,LA7FS_LA7ECH)) S LA7Y=^TMP($J,"LA7VHLU","99VA4N",LA7FN,LA7DA,LA7TYP,LA7FS_LA7ECH)
;
; Build name using field #100, otherwise #.01
; Send facility id in 3rd component if numeric - conform to standard.
I LA7Y="",LA7FN=4,LA7DA D
. S LA7Z(1)=$P($$NS^XUAF4(LA7DA),"^"),LA7Z(2)=$$WHAT^XUAF4(LA7DA,100)
. S $P(LA7Y,$E(LA7ECH,1),1)=$$CHKDATA^LA7VHLU3(LA7Z(1),LA7FS_LA7ECH)
. S $P(LA7Y,$E(LA7ECH,1),2)="D"
. S LA7X=$$RETFACID^LA7VHLU2(LA7DA,2,1)
. I LA7X'="" D
. . I LA7X?1.N S $P(LA7Y,$E(LA7ECH,1),3)=LA7X
. . S $P(LA7Y,$E(LA7ECH,1),10)=LA7X
. S $P(LA7Y,$E(LA7ECH,1),6)="USVHA"
. S $P(LA7Y,$E(LA7ECH,1),7)="FI"
. S $P(LA7Y,$E(LA7ECH,1),9)="A"
. I LA7Z(2)'="" D
. . S $P(LA7Y,$E(LA7ECH,1),1)=$$CHKDATA^LA7VHLU3(LA7Z(2),LA7FS_LA7ECH)
. . S $P(LA7Y,$E(LA7ECH,1),2)="L"
. I LA7TYP=1 D
. . S LA7X=$$ID^XUAF4("CLIA",LA7DA) Q:LA7X=""
. . S $P(LA7Y,$E(LA7ECH,1),3)=""
. . S $P(LA7Y,$E(LA7ECH,1),6)="CLIA"
. . S $P(LA7Y,$E(LA7ECH,1),7)="LN"
. . S $P(LA7Y,$E(LA7ECH,1),10)=LA7X
;
; Save this field to TMP global to use for subsequent calls.
I LA7Y'="" S ^TMP($J,"LA7VHLU","99VA4N",LA7FN,LA7DA,LA7TYP,LA7FS_LA7ECH)=LA7Y
;
Q LA7Y
;
;
XCNTFM(LA7X,LA7ECH) ; Resolve XCN data type to FileMan (last name, first name, mi [id])
; Call with LA7X = HL7 field containing name
; LA7ECH = HL7 encoding characters
;
; Returns LA7Y = ID code^DUZ^FileMan name (DUZ=0 if name not found on local system).
; Stub until all calls can be converted to call XCNTFM^LA7VHLU9
;
Q $$XCNTFM^LA7VHLU9(LA7X,LA7ECH)
;
;
PLTFM(LA7PL,LA7ECH) ; Resolve location from PL (person location) data type.
; Call with LA7PL = HL7 field containing person location
; LA7ECH = HL7 encoding characters
;
; Returns LA7Y = file #44 ien^name field (#.01)^division(institution)
;
N LA7X,LA7Y,X,Y
S LA7X=$P(LA7PL,$E(LA7ECH)),(LA7Y,Y)=""
I LA7X?1.N S Y=$$GET1^DIQ(44,LA7X_",",.01)
; If not ien try as name
I Y="" D
. S X=$$FIND1^DIC(44,"","X",LA7X,"B")
. I X S Y=LA7X,LA7X=X
I Y'="" S LA7Y=LA7X_"^"_Y
E I $P(LA7PL,$E(LA7ECH),2)'="" S LA7Y="^"_$P(LA7PL,$E(LA7ECH),2)
;
; Process division (institution) - pass 1st sub-component of 4th component
S LA7X=$P(LA7PL,$E(LA7ECH),4)
S LA7X=$P(LA7X,$E(LA7ECH,4))
S Y=""
I LA7X'="" S Y=$$FINDSITE^LA7VHLU2(LA7X,1,1)
S $P(LA7Y,"^",3)=Y
;
Q LA7Y
LA7VHLU4 ;VA/DALOI/JMC - HL7 segment builder utility ; 13-Aug-2013 09:09 ; MKK
+1 ;;5.2;AUTOMATED LAB INSTRUMENTS;**46,1018,64,1027,68,1033**;NOV 01, 1997
+2 ;
+3 ;
INST(LA74,LA7FS,LA7ECH) ; Build institution field
+1 ; Call with LA74 = ien of institution in file #4
+2 ; if null/undefined then use Kernel Site file.
+3 ; LA7FS = HL field separator
+4 ; LA7ECH = HL encoding characters
+5 ;
+6 ; Returns facility that performed the testing (ID^text^99VA4)
+7 ;
+8 NEW LA7NVAF,LA7X,LA7Y,LA7Z
+9 ;
+10 SET LA74=$GET(LA74)
SET LA7ECH=$GET(LA7ECH)
SET LA7Y=""
+11 ;
+12 ; If no institution, use Kernel Site default
+13 IF LA74=""
SET LA74=+$$KSP^XUPARAM("INST")
+14 ;
+15 ; Check if this field has been built previously for this institution
+16 IF LA74'=""
IF $DATA(^TMP($JOB,"LA7VHLU","99VA4",LA74,LA7FS_LA7ECH))
SET LA7Y=^TMP($JOB,"LA7VHLU","99VA4",LA74,LA7FS_LA7ECH)
+17 ;
+18 ; Value passed not a pointer - only build 2nd component
+19 IF LA7Y=""
IF LA74'=""
IF LA74'=+LA74
Begin DoDot:1
+20 SET $PIECE(LA7Y,$EXTRACT(LA7ECH,1),2)=$$CHKDATA^LA7VHLU3(LA74,LA7FS_LA7ECH)
End DoDot:1
+21 ;
+22 IF LA7Y=""
IF LA74>0
IF LA74=+LA74
Begin DoDot:1
+23 SET LA7NVAF=$$NVAF^LA7VHLU2(LA74)
+24 ; Build id - VA station #/DMIS code
+25 IF LA7NVAF<2
SET LA7Y=$$ID^XUAF4($SELECT(LA7NVAF=1:"DMIS",1:"VASTANUM"),LA74)
+26 ; Build name using field #100, otherwise #.01
+27 SET LA7Z=$$NAME^XUAF4(LA74)
+28 SET $PIECE(LA7Y,$EXTRACT(LA7ECH,1),2)=$$CHKDATA^LA7VHLU3(LA7Z,LA7FS_LA7ECH)
+29 ;
+30 SET $PIECE(LA7Y,$EXTRACT(LA7ECH,1),3)="99VA4"
End DoDot:1
+31 ;
+32 ; Save this field to TMP global to use for subsequent calls.
+33 SET ^TMP($JOB,"LA7VHLU","99VA4",LA74,LA7FS_LA7ECH)=LA7Y
+34 ;
+35 QUIT LA7Y
+36 ;
+37 ;
XAD(LA7FN,LA7DA,LA7DT,LA7FS,LA7ECH) ; Build extended address
+1 ; Call with LA7FN = Source File number
+2 ; Presently file #2 (PATIENT), #4 (INSTITUTION) or #200 (NEW PERSON)
+3 ; LA7DA = Entry in source file
+4 ; LA7DT = As of date in FileMan format
+5 ; LA7FS = HL field separator
+6 ; LA7ECH = HL encoding characters
+7 ;
+8 ; Returns extended address
+9 ;
+10 NEW LA7X,LA7Y,LA7Z
+11 ;
+12 SET LA7Y=""
+13 ;
+14 ; Check if this field has been built previously for this institution
+15 ;I LA7FN,LA7DA,$D(^TMP($J,"LA7VHLU","99VA4A",LA7FN,LA7DA,LA7FS_LA7ECH)) S LA7Y=^TMP($J,"LA7VHLU","99VA4A",LA7FN,LA7DA,LA7FS_LA7ECH)
+16 ;
+17 ; Build from file #2
+18 IF LA7Y=""
IF LA7FN=2
IF LA7DA
Begin DoDot:1
+19 NEW DFN,VAHOW,VAPA,VAERR,VAROOT,VATEST
+20 SET DFN=LA7DA
+21 IF LA7DT
SET (VATEST("ADD",9),VATEST("ADD",10))=LA7DT
+22 DO ADD^VADPT
+23 IF VAERR
QUIT
+24 SET $PIECE(LA7Y,$EXTRACT(LA7ECH),1)=$$CHKDATA^LA7VHLU3(VAPA(1),LA7FS_LA7ECH)
+25 SET $PIECE(LA7Y,$EXTRACT(LA7ECH),2)=$$CHKDATA^LA7VHLU3(VAPA(2),LA7FS_LA7ECH)
+26 SET $PIECE(LA7Y,$EXTRACT(LA7ECH),3)=$$CHKDATA^LA7VHLU3(VAPA(4),LA7FS_LA7ECH)
+27 SET $PIECE(LA7Y,$EXTRACT(LA7ECH),4)=$$CHKDATA^LA7VHLU3($PIECE(VAPA(5),"^",2),LA7FS_LA7ECH)
+28 SET $PIECE(LA7Y,$EXTRACT(LA7ECH),5)=$$CHKDATA^LA7VHLU3(VAPA(11),LA7FS_LA7ECH)
+29 IF VAPA(9)
SET $PIECE(LA7Y,$EXTRACT(LA7ECH),7)="C"
+30 IF '$TEST
SET $PIECE(LA7Y,$EXTRACT(LA7ECH),7)="P"
+31 SET $PIECE(LA7Y,$EXTRACT(LA7ECH),9)=$$CHKDATA^LA7VHLU3($PIECE(VAPA(7),"^",2),LA7FS_LA7ECH)
End DoDot:1
+32 ;
+33 ; Get address info from file #4, add 2nd address line
+34 ; change state to pointer to file #5
+35 IF LA7Y=""
IF LA7FN=4
IF LA7DA
Begin DoDot:1
+36 SET LA7Z=$$PADD^XUAF4(LA7DA)
+37 SET LA7X=$PIECE(LA7Z,"^")
SET $PIECE(LA7X,"^",2)=$$WHAT^XUAF4(LA7DA,1.02)
+38 FOR I=1,2
IF $PIECE(LA7X,"^",I)'=""
SET $PIECE(LA7X,"^",I)=$$CHKDATA^LA7VHLU3($PIECE(LA7X,"^",I),LA7FS_LA7ECH)
+39 SET LA7Z=$PIECE(LA7Z,"^",2,4)
SET $PIECE(LA7Z,"^",2)=$$GET1^DIQ(4,LA7DA_",",.02,"I")
+40 SET $PIECE(LA7Z,"^")=$$CHKDATA^LA7VHLU3($PIECE(LA7Z,"^"),LA7FS_LA7ECH)
+41 SET LA7Y=$$HLADDR^HLFNC(LA7X,LA7Z,LA7ECH)
End DoDot:1
+42 ;
+43 IF LA7Y=""
IF LA7FN=200
IF LA7DA
Begin DoDot:1
+44 QUIT
End DoDot:1
+45 ;
+46 ; Save this field to TMP global to use for subsequent calls.
+47 IF LA7Y'=""
SET ^TMP($JOB,"LA7VHLU","99VA4A",LA7FN,LA7DA,LA7FS_LA7ECH)=LA7Y
+48 ;
+49 QUIT LA7Y
+50 ;
+51 ;
XON(LA7FN,LA7DA,LA7TYP,LA7FS,LA7ECH) ; Build extended composite name/id for organization
+1 ; Call with LA7FN = Source File number
+2 ; Presently #4 (INSTITUTION)
+3 ; LA7DA = Entry in source file
+4 ; LA7TYP = type of identifer (0/null=station #, 1=CLIA)
+5 ; LA7FS = HL field separator
+6 ; LA7ECH = HL encoding characters
+7 ;
+8 ;
+9 NEW LA7X,LA7Y,LA7Z
+10 ;
+11 SET LA7Y=""
SET LA7TYP=+$GET(LA7TYP)
+12 ;
+13 ; Check if this field has been built previously for this institution
+14 IF LA7FN
IF LA7DA
IF $DATA(^TMP($JOB,"LA7VHLU","99VA4N",LA7FN,LA7DA,LA7TYP,LA7FS_LA7ECH))
SET LA7Y=^TMP($JOB,"LA7VHLU","99VA4N",LA7FN,LA7DA,LA7TYP,LA7FS_LA7ECH)
+15 ;
+16 ; Build name using field #100, otherwise #.01
+17 ; Send facility id in 3rd component if numeric - conform to standard.
+18 IF LA7Y=""
IF LA7FN=4
IF LA7DA
Begin DoDot:1
+19 SET LA7Z(1)=$PIECE($$NS^XUAF4(LA7DA),"^")
SET LA7Z(2)=$$WHAT^XUAF4(LA7DA,100)
+20 SET $PIECE(LA7Y,$EXTRACT(LA7ECH,1),1)=$$CHKDATA^LA7VHLU3(LA7Z(1),LA7FS_LA7ECH)
+21 SET $PIECE(LA7Y,$EXTRACT(LA7ECH,1),2)="D"
+22 SET LA7X=$$RETFACID^LA7VHLU2(LA7DA,2,1)
+23 IF LA7X'=""
Begin DoDot:2
+24 IF LA7X?1.N
SET $PIECE(LA7Y,$EXTRACT(LA7ECH,1),3)=LA7X
+25 SET $PIECE(LA7Y,$EXTRACT(LA7ECH,1),10)=LA7X
End DoDot:2
+26 SET $PIECE(LA7Y,$EXTRACT(LA7ECH,1),6)="USVHA"
+27 SET $PIECE(LA7Y,$EXTRACT(LA7ECH,1),7)="FI"
+28 SET $PIECE(LA7Y,$EXTRACT(LA7ECH,1),9)="A"
+29 IF LA7Z(2)'=""
Begin DoDot:2
+30 SET $PIECE(LA7Y,$EXTRACT(LA7ECH,1),1)=$$CHKDATA^LA7VHLU3(LA7Z(2),LA7FS_LA7ECH)
+31 SET $PIECE(LA7Y,$EXTRACT(LA7ECH,1),2)="L"
End DoDot:2
+32 IF LA7TYP=1
Begin DoDot:2
+33 SET LA7X=$$ID^XUAF4("CLIA",LA7DA)
IF LA7X=""
QUIT
+34 SET $PIECE(LA7Y,$EXTRACT(LA7ECH,1),3)=""
+35 SET $PIECE(LA7Y,$EXTRACT(LA7ECH,1),6)="CLIA"
+36 SET $PIECE(LA7Y,$EXTRACT(LA7ECH,1),7)="LN"
+37 SET $PIECE(LA7Y,$EXTRACT(LA7ECH,1),10)=LA7X
End DoDot:2
End DoDot:1
+38 ;
+39 ; Save this field to TMP global to use for subsequent calls.
+40 IF LA7Y'=""
SET ^TMP($JOB,"LA7VHLU","99VA4N",LA7FN,LA7DA,LA7TYP,LA7FS_LA7ECH)=LA7Y
+41 ;
+42 QUIT LA7Y
+43 ;
+44 ;
XCNTFM(LA7X,LA7ECH) ; Resolve XCN data type to FileMan (last name, first name, mi [id])
+1 ; Call with LA7X = HL7 field containing name
+2 ; LA7ECH = HL7 encoding characters
+3 ;
+4 ; Returns LA7Y = ID code^DUZ^FileMan name (DUZ=0 if name not found on local system).
+5 ; Stub until all calls can be converted to call XCNTFM^LA7VHLU9
+6 ;
+7 QUIT $$XCNTFM^LA7VHLU9(LA7X,LA7ECH)
+8 ;
+9 ;
PLTFM(LA7PL,LA7ECH) ; Resolve location from PL (person location) data type.
+1 ; Call with LA7PL = HL7 field containing person location
+2 ; LA7ECH = HL7 encoding characters
+3 ;
+4 ; Returns LA7Y = file #44 ien^name field (#.01)^division(institution)
+5 ;
+6 NEW LA7X,LA7Y,X,Y
+7 SET LA7X=$PIECE(LA7PL,$EXTRACT(LA7ECH))
SET (LA7Y,Y)=""
+8 IF LA7X?1.N
SET Y=$$GET1^DIQ(44,LA7X_",",.01)
+9 ; If not ien try as name
+10 IF Y=""
Begin DoDot:1
+11 SET X=$$FIND1^DIC(44,"","X",LA7X,"B")
+12 IF X
SET Y=LA7X
SET LA7X=X
End DoDot:1
+13 IF Y'=""
SET LA7Y=LA7X_"^"_Y
+14 IF '$TEST
IF $PIECE(LA7PL,$EXTRACT(LA7ECH),2)'=""
SET LA7Y="^"_$PIECE(LA7PL,$EXTRACT(LA7ECH),2)
+15 ;
+16 ; Process division (institution) - pass 1st sub-component of 4th component
+17 SET LA7X=$PIECE(LA7PL,$EXTRACT(LA7ECH),4)
+18 SET LA7X=$PIECE(LA7X,$EXTRACT(LA7ECH,4))
+19 SET Y=""
+20 IF LA7X'=""
SET Y=$$FINDSITE^LA7VHLU2(LA7X,1,1)
+21 SET $PIECE(LA7Y,"^",3)=Y
+22 ;
+23 QUIT LA7Y