LA7QRY ;DALOI/JMC - Lab HL7 Query Utility ;Apr 26, 2007
;;5.2;AUTOMATED LAB INSTRUMENTS;**46,69,68**;Sep 27, 1994;Build 56
;
; Reference to variable DIQUIET supported by DBIA #2098
; Reference to ^DPT("SSN") global supported by DBIA #10035
;
Q
;
GCPR(LA7PTID,LA7SDT,LA7EDT,LA7SC,LA7SPEC,LA7QERR,LA7DEST,LA7HL7) ; Entry point for Government Computerized Patient Record query
;
; Call with LA7PTID = patient identifier, either SSN or MPI/ICN or medical record number.
; if MPI/ICN then should be full ICN (10 digit number followed by "V" and six digit checksum)
; Pass in the 2nd piece of this variable the type of identifier:
; SS = Social Security number
; PI = VA MPI Integration Control Number
; MR = medical record number of patient in file PATIENT/IHS (#9000001)
; Example: 1000720100V271387^PI
; 123456789^SS
; 123456789^MR
;
; LA7SDT = start date of query (FileMan D/T,time optional)
; LA7EDT = end date of query (FileMan D/T, time optional)
; (FileMan D/T^type of date ("CD" or "RAD")
; Both start and end date values can pass a parameter in the second piece to indicate that the date values are for specimen collection date/time (CD) or results available date (RAD)
; Example: LA7SDT="2991001.1239^CD"
; LA7EDT="2991002.0331^CD"
; LA7SDT="3010201^RAD"
; LA7EDT="3010201^RAD"
;
; LA7SC = Array of search codes, either NLT or LOINC (code^coding system ("NLT" or "LN");
; Example: LA7SC(1)="89628.0000^NLT"
; LA7SC(2)="84330.0000^NLT"
; LA7SC(3)="84295.0000^NLT"
; LA7SC(4)="14749-6^LN"
;
; = The "*" (wildcard) for any code;
; Example: LA7SC="*"
;
; = A list of subscripts (separated by commas) from where the results will be extracted ("CH", "MI", "SP", "EM", "CY").
; Example: LA7SC="CH,MI" (CH and MI results only)
;
; Pass in the 2nd piece of LA7SC the indicator (1) to return VUID when available.
; Example: LA7SC="*^1) or LA7SC="CH,MI^1"
;
; LA7SPEC = array of specimen types using HL7 source table 0070 or "*" (wildcard) for any code
; Currently specimen type only supported for CH and MI subscripted tests.
; Example: LA7SPEC="*"
; or
; LA7SPEC(1)="UR"
; LA7SPEC(2)="SER"
; LA7SPEC(3)="PLAS"
;
; LA7QERR = array (by reference) to return any errors
;
; LA7DEST = closed root global reference to return search results (optional). If this parameter is omitted or equals an empty string, then node ^TMP("HLS",$J) is used.
; Example: LA7DEST=$NA(^TMP("ZZTMP",$J))
;
; LA7HL7 = HL7 field separator and encoding characters (4) to use to encode results (optional).
; If undefined or incomplete (length<5) then uses field separator = "|" and encoding characters ="^\~&"
;
; Returns LA7DEST = contains global reference of search results in HL7 message structure, usually ^TMP("HLS",$J)
;
; LA7QERR = array (by reference) containing any errors
;
N DFN,DIQUIET,LA761,LA76248,LA7CODE,LA7INTYP,LA7NLT,LA7NOMSG,LA7PTYP,LA7QUIT,LA7SCDE,LA7X,LRDFN,LRIDT,LRSS,LRSSLST
;
D CLEANUP
S U="^",DT=$$DT^XLFDT,DTIME=$$DTIME^XUP($G(DUZ))
S GBL=$S($G(LA7DEST)'="":LA7DEST,1:"^TMP(""HLS"","_$J_")")
K LA7QERR
; Prevent FileMan from issuing any unwanted WRITE(s).
S DIQUIET=1
; Currently not using file #62.48 for configuration information.
S (LA76248,LA7INTYP)=0
;
; Setup DUZ array to 'non-human' user LRLAB,HL if DUZ not valid
; Handle calls from non-VistA packages.
I $G(DUZ)<1 D
. S LA7X=$$FIND1^DIC(200,"","OX","LRLAB,HL","B","")
. I LA7X<1 D Q
. D DUZ^XUP(LA7X)
;
; Identify patient, quit if error
D PATID^LA7QRY2
I $D(LA7QERR) Q ""
;
; Move LA7SC into local variable to check and modify if necessary.
M LA7SCDE=LA7SC
;
; Resolve search codes to lab datanames
S LA7SCDE=$G(LA7SCDE)
;
; Set flag to return VUID when available
I $P(LA7SCDE,"^",2)=1 S LA7INTYP=30
;
; Parse list of subscripts if any.
D SCLIST^LA7QRY2($P(LA7SCDE,"^"),.LRSSLST)
Q:$D(LA7QERR) ""
;
; If passing specific subscripts but no specific search codes then use wildcard ("*") for search codes.
I LA7SCDE'="",$P(LA7SCDE,"^")'="*",'$O(LA7SCDE(0)) S $P(LA7SCDE,"^")="*"
I $P(LA7SCDE,"^")'="*",$O(LA7SCDE(0)) D CHKSC^LA7QRY1
;
; Convert specimen codes to file #61 Topography entries
S LA7SPEC=$G(LA7SPEC)
I LA7SPEC'="*" D SPEC^LA7QRY1
;
; Search by collection or results available date
I $P(LA7SDT,"^",2)="" S $P(LA7SDT,"^",2)="CD"
I $P(LA7SDT,"^",2)="RAD" D BRAD^LA7QRY2
I $P(LA7SDT,"^",2)="CD" D BCD^LA7QRY2
;
I '$D(^TMP("LA7-QRY",$J)) D
. S LA7QERR(99)="No results found for requested parameters"
. S GBL=""
E S LA7NOMSG=1 D BUILDMSG^LA7QRY1
;
D CLEANUP
;
Q GBL
;
;
CLEANUP ; Cleanup TMP nodes that are used.
;
N I
F I="LA7-61","LA7-DN","LA7-INST-DNS","LA7-LN","LA7-NLT","LA7-QRY" K ^TMP(I,$J)
D KVAR^LRX
;
Q
--- Routine Detail --- with STRUCTURED ROUTINE LISTING ---[H[J[2J[HLA7QRY 5692 printed Dec 13, 2024@01:39:16 Page 2
LA7QRY ;DALOI/JMC - Lab HL7 Query Utility ;Apr 26, 2007
+1 ;;5.2;AUTOMATED LAB INSTRUMENTS;**46,69,68**;Sep 27, 1994;Build 56
+2 ;
+3 ; Reference to variable DIQUIET supported by DBIA #2098
+4 ; Reference to ^DPT("SSN") global supported by DBIA #10035
+5 ;
+6 QUIT
+7 ;
GCPR(LA7PTID,LA7SDT,LA7EDT,LA7SC,LA7SPEC,LA7QERR,LA7DEST,LA7HL7) ; Entry point for Government Computerized Patient Record query
+1 ;
+2 ; Call with LA7PTID = patient identifier, either SSN or MPI/ICN or medical record number.
+3 ; if MPI/ICN then should be full ICN (10 digit number followed by "V" and six digit checksum)
+4 ; Pass in the 2nd piece of this variable the type of identifier:
+5 ; SS = Social Security number
+6 ; PI = VA MPI Integration Control Number
+7 ; MR = medical record number of patient in file PATIENT/IHS (#9000001)
+8 ; Example: 1000720100V271387^PI
+9 ; 123456789^SS
+10 ; 123456789^MR
+11 ;
+12 ; LA7SDT = start date of query (FileMan D/T,time optional)
+13 ; LA7EDT = end date of query (FileMan D/T, time optional)
+14 ; (FileMan D/T^type of date ("CD" or "RAD")
+15 ; Both start and end date values can pass a parameter in the second piece to indicate that the date values are for specimen collection date/time (CD) or results available date (RAD)
+16 ; Example: LA7SDT="2991001.1239^CD"
+17 ; LA7EDT="2991002.0331^CD"
+18 ; LA7SDT="3010201^RAD"
+19 ; LA7EDT="3010201^RAD"
+20 ;
+21 ; LA7SC = Array of search codes, either NLT or LOINC (code^coding system ("NLT" or "LN");
+22 ; Example: LA7SC(1)="89628.0000^NLT"
+23 ; LA7SC(2)="84330.0000^NLT"
+24 ; LA7SC(3)="84295.0000^NLT"
+25 ; LA7SC(4)="14749-6^LN"
+26 ;
+27 ; = The "*" (wildcard) for any code;
+28 ; Example: LA7SC="*"
+29 ;
+30 ; = A list of subscripts (separated by commas) from where the results will be extracted ("CH", "MI", "SP", "EM", "CY").
+31 ; Example: LA7SC="CH,MI" (CH and MI results only)
+32 ;
+33 ; Pass in the 2nd piece of LA7SC the indicator (1) to return VUID when available.
+34 ; Example: LA7SC="*^1) or LA7SC="CH,MI^1"
+35 ;
+36 ; LA7SPEC = array of specimen types using HL7 source table 0070 or "*" (wildcard) for any code
+37 ; Currently specimen type only supported for CH and MI subscripted tests.
+38 ; Example: LA7SPEC="*"
+39 ; or
+40 ; LA7SPEC(1)="UR"
+41 ; LA7SPEC(2)="SER"
+42 ; LA7SPEC(3)="PLAS"
+43 ;
+44 ; LA7QERR = array (by reference) to return any errors
+45 ;
+46 ; LA7DEST = closed root global reference to return search results (optional). If this parameter is omitted or equals an empty string, then node ^TMP("HLS",$J) is used.
+47 ; Example: LA7DEST=$NA(^TMP("ZZTMP",$J))
+48 ;
+49 ; LA7HL7 = HL7 field separator and encoding characters (4) to use to encode results (optional).
+50 ; If undefined or incomplete (length<5) then uses field separator = "|" and encoding characters ="^\~&"
+51 ;
+52 ; Returns LA7DEST = contains global reference of search results in HL7 message structure, usually ^TMP("HLS",$J)
+53 ;
+54 ; LA7QERR = array (by reference) containing any errors
+55 ;
+56 NEW DFN,DIQUIET,LA761,LA76248,LA7CODE,LA7INTYP,LA7NLT,LA7NOMSG,LA7PTYP,LA7QUIT,LA7SCDE,LA7X,LRDFN,LRIDT,LRSS,LRSSLST
+57 ;
+58 DO CLEANUP
+59 SET U="^"
SET DT=$$DT^XLFDT
SET DTIME=$$DTIME^XUP($GET(DUZ))
+60 SET GBL=$SELECT($GET(LA7DEST)'="":LA7DEST,1:"^TMP(""HLS"","_$JOB_")")
+61 KILL LA7QERR
+62 ; Prevent FileMan from issuing any unwanted WRITE(s).
+63 SET DIQUIET=1
+64 ; Currently not using file #62.48 for configuration information.
+65 SET (LA76248,LA7INTYP)=0
+66 ;
+67 ; Setup DUZ array to 'non-human' user LRLAB,HL if DUZ not valid
+68 ; Handle calls from non-VistA packages.
+69 IF $GET(DUZ)<1
Begin DoDot:1
+70 SET LA7X=$$FIND1^DIC(200,"","OX","LRLAB,HL","B","")
+71 IF LA7X<1
Begin DoDot:2
End DoDot:2
QUIT
+72 DO DUZ^XUP(LA7X)
End DoDot:1
+73 ;
+74 ; Identify patient, quit if error
+75 DO PATID^LA7QRY2
+76 IF $DATA(LA7QERR)
QUIT ""
+77 ;
+78 ; Move LA7SC into local variable to check and modify if necessary.
+79 MERGE LA7SCDE=LA7SC
+80 ;
+81 ; Resolve search codes to lab datanames
+82 SET LA7SCDE=$GET(LA7SCDE)
+83 ;
+84 ; Set flag to return VUID when available
+85 IF $PIECE(LA7SCDE,"^",2)=1
SET LA7INTYP=30
+86 ;
+87 ; Parse list of subscripts if any.
+88 DO SCLIST^LA7QRY2($PIECE(LA7SCDE,"^"),.LRSSLST)
+89 if $DATA(LA7QERR)
QUIT ""
+90 ;
+91 ; If passing specific subscripts but no specific search codes then use wildcard ("*") for search codes.
+92 IF LA7SCDE'=""
IF $PIECE(LA7SCDE,"^")'="*"
IF '$ORDER(LA7SCDE(0))
SET $PIECE(LA7SCDE,"^")="*"
+93 IF $PIECE(LA7SCDE,"^")'="*"
IF $ORDER(LA7SCDE(0))
DO CHKSC^LA7QRY1
+94 ;
+95 ; Convert specimen codes to file #61 Topography entries
+96 SET LA7SPEC=$GET(LA7SPEC)
+97 IF LA7SPEC'="*"
DO SPEC^LA7QRY1
+98 ;
+99 ; Search by collection or results available date
+100 IF $PIECE(LA7SDT,"^",2)=""
SET $PIECE(LA7SDT,"^",2)="CD"
+101 IF $PIECE(LA7SDT,"^",2)="RAD"
DO BRAD^LA7QRY2
+102 IF $PIECE(LA7SDT,"^",2)="CD"
DO BCD^LA7QRY2
+103 ;
+104 IF '$DATA(^TMP("LA7-QRY",$JOB))
Begin DoDot:1
+105 SET LA7QERR(99)="No results found for requested parameters"
+106 SET GBL=""
End DoDot:1
+107 IF '$TEST
SET LA7NOMSG=1
DO BUILDMSG^LA7QRY1
+108 ;
+109 DO CLEANUP
+110 ;
+111 QUIT GBL
+112 ;
+113 ;
CLEANUP ; Cleanup TMP nodes that are used.
+1 ;
+2 NEW I
+3 FOR I="LA7-61","LA7-DN","LA7-INST-DNS","LA7-LN","LA7-NLT","LA7-QRY"
KILL ^TMP(I,$JOB)
+4 DO KVAR^LRX
+5 ;
+6 QUIT