LA7QRY2 ;DALOI/JMC - Lab HL7 Query Utility ; 04/13/09 ; 10/30/12 10:16am
;;1.2;CCD/CCR GENERATION UTILITIES;;Oct 30, 2012;Build 50
; JMC - mods to check for IHS V LAB file
;
; (C) John McCormack 2009
;
; This program is free software: you can redistribute it and/or modify
; it under the terms of the GNU Affero General Public License as
; published by the Free Software Foundation, either version 3 of the
; License, or (at your option) any later version.
;
; This program is distributed in the hope that it will be useful,
; but WITHOUT ANY WARRANTY; without even the implied warranty of
; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
; GNU Affero General Public License for more details.
;
; You should have received a copy of the GNU Affero General Public License
; along with this program. If not, see .
;
;
Q
;
PATID ; Resolve patient id and establish patient environment
;
N LA7X
;
S (DFN,LRDFN)="",LA7PTYP=0
;
; SSN passed as patient identifier
I LA7PTID?9N.1A D
. S LA7PTYP=1
. S LA7X=$O(^DPT("SSN",LA7PTID,0))
. I LA7X>0 D SETDFN(LA7X)
;
; MPI/ICN (integration control number) passed as patient identifier
I LA7PTID?10N1"V"6N D
. S LA7PTYP=2
. S LA7X=$$GETDFN^MPIF001($P(LA7PTID,"V"))
. I LA7X>0 D SETDFN(LA7X)
;
; If no patient identified/no laboratory record - return exception message
I 'LA7PTYP S LA7ERR(1)="Invalid patient identifier passed"
I 'DFN S LA7ERR(2)="No patient found with requested identifier"
I DFN,'LRDFN S LA7ERR(3)="No laboratory record for requested patient"
I LRDFN,'$D(^LR(LRDFN)) S LA7ERR(4)="Database error - missing laboratory record for requested patient"
Q
;
;
BCD ; Search by specimen collection date.
;
N LA763,LA7QUIT
;
S (LA7SDT(0),LA7EDT(0))=0
I LA7SDT S LA7SDT(0)=9999999-LA7SDT
I LA7EDT S LA7EDT(0)=9999999-LA7EDT
;
F LRSS="CH","MI","SP" D
. S (LA7QUIT,LRIDT)=0
. I LA7EDT(0) S LRIDT=$O(^LR(LRDFN,LRSS,LA7EDT(0)),-1)
. F S LRIDT=$O(^LR(LRDFN,LRSS,LRIDT)) Q:LA7QUIT D
. . ; Quit if reached end of data or outside date criteria
. . I 'LRIDT!(LRIDT>LA7SDT(0)) S LA7QUIT=1 Q
. . D SEARCH
;
Q
;
;
BRAD ; Search by results available date (completion date).
; Assumes cross-references still exist for dates in LRO(69) global.
; Collects specimen date/time values for a given LRDFN and completion date.
; Cross-reference is by date only, time stripped from start date.
; Uses cross-reference ^LRO(69,DT,1,"AN",'LOCATION',LRDFN,LRIDT)=""
;
N LA763,LA7DT,LA7ROOT,LA7SRC,X
;
; Check if orders still exist Iin file #69 for search range
S LA7SDT(1)=(LA7SDT\1)-.0000000001,LA7EDT(1)=(LA7EDT\1)+.24,LA7SRC=0
S X=$O(^LRO(69,LA7SDT(1)))
I X,XLA7EDT(1)) D
. . S LA7ROOT="^LRO(69,LA7DT,1,""AN"")"
. . F S LA7ROOT=$Q(@LA7ROOT) Q:LA7ROOT=""!($QS(LA7ROOT,2)'=LA7DT)!($QS(LA7ROOT,4)'="AN") D
. . . I $QS(LA7ROOT,6)'=LRDFN Q
. . . S LRIDT=$QS(LA7ROOT,7)
. . . F LRSS="CH","MI","SP" D SEARCH
;
; If no orders in #69 then do long search through file #63.
I 'LA7SRC D
. F LRSS="CH","MI","SP" D
. . S LRIDT=0
. . F S LRIDT=$O(^LR(LRDFN,LRSS,LRIDT)) Q:'LRIDT D
. . . S LA763(0)=$G(^LR(LRDFN,LRSS,LRIDT,0))
. . . I $P(LA763(0),"^",3)>LA7SDT(1),$P(LA763(0),"^",3)