GPLALABS ; CCDCCR/GPL - CCR/CCD PROCESSING FOR LAB RESULTS ; 10/01/08
 ;;0.3;CCDCCR;nopatch;noreleasedate
 ;Copyright 2008 WorldVistA.  Licensed under the terms of the GNU
 ;General Public License See attached copy of the License.
 ;
 ;This program is free software; you can redistribute it and/or modify
 ;it under the terms of the GNU General Public License as published by
 ;the Free Software Foundation; either version 2 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 General Public License for more details.
 ;
 ;You should have received a copy of the GNU General Public License along
 ;with this program; if not, write to the Free Software Foundation, Inc.,
 ;51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
           ;
EXTRACT(LABXML,DFN,LABOUTXML) ; EXTRACT LABS INTO PROVIDED XML TEMPLATE
 ;
 ; LABXML AND LABOUTXML ARE PASSED BY NAME SO GLOBALS CAN BE USED
 ;
 ;
 ;
 ; N C0CPTID,C0CSPC,C0CSDT,C0CEDT,C0CR
 ; SET UP FOR LAB API CALL
 S C0CPTID=$$SSN^CCRDPT(DFN) ; GET THE SSN FOR THIS PATIENT
 I C0CPTID="" D  Q  ; NO SSN, COMPLAIN AND QUIT
 . W "LAB LOOKUP FAILED, NO SSN",!
 S C0CSPC="*" ; LOOKING FOR ALL LABS
 D DT^DILF(,"T-5000",.C0CSDT) ; START DATE LONG AGO TO GET EVERYTHING
 D DT^DILF(,"T",.C0CEDT) ; END DATE TODAY TO GET EVERYTHING
 S C0CR=$$GCPR^LA7QRY(C0CPTID,C0CSDT,C0CEDT,C0CSPC,C0CSPC) ; CALL LAB LOOKUP
 W "i'm back",!
 Q
     ;
LIST ; LIST THE HL7 MESSAGE
 ;
 ; N C0CI,C0CJ,C0COBT,C0CHB
 ; D EXTRACT^GPLLABS(,1,)
 S C0CTAB=$NA(^KBAI) ; BASE OF OBX TABLE
 S C0CHB=$NA(^TMP("HLS",$J))
 S C0CI=""
 F  S C0CI=$O(@C0CHB@(C0CI)) Q:C0CI=""  D  ; FOR ALL RECORDS IN HL7 MSG
 . S C0CTYP=$P(@C0CHB@(C0CI),"|",1)
 . D LTYP(@C0CHB@(C0CI),C0CTYP)
 . W C0CI," ",C0CTYP,!
 . ; S C0CI=$O(@C0CHB@(C0CI))
 Q
LTYP(OSEG,OTYP) ;
 S OTAB=$NA(@C0CTAB@(OTYP)) ; TABLE FOR SEGMENT TYPE
 I 1 D  ; RIGHT NOW JUST OBX
 . S OI="" ; INDEX INTO SEGS
 . F  S OI=$O(@OTAB@(OI)) Q:OI=""  D  ; FOR EACH ELEMENT OF THE SEGMENT
 . . S OV=$P(OSEG,"|",$P(@OTAB@(OI),"^",1)+1) ; PULL OUT VALUE
 . . I OV'="" W OI_": "_$P(@OTAB@(OI),"^",3),": ",OV,!
 Q
LOBX ;
 Q
 ;
SETTBL ;
 K X ; CLEAR X
 S X("PID","PID1")="1^00104^Set ID - Patient ID"
 S X("PID","PID2")="2^00105^Patient ID (External ID) CX (20)"
 S X("PID","PID3")="3^00106^Patient ID (Internal ID) R CX (20) ( )"
 S X("PID","PID4")="4^00107^Alternate Patient ID CX (20) ( )"
 S X("PID","PID5")="5^00108^Patient's Name R XPN (48) ( )"
 S X("PID","PID6")="6^00109^Mother's Maiden Name XPN (48)"
 S X("PID","PID7")="7^00110^Date of Birth TS (26)"
 S X("PID","PID8")="8^00111^Sex IS (1) (0001)"
 S X("PID","PID9")="9^00112^Patient Alias XPN (48) ( )"
 S X("PID","PID10")="10^00113^Race IS (1) (0005)"
 S X("PID","PID11")="11^00114^Patient Address XAD (106) ( )"
 S X("PID","PID12")="12^00115^County Code B IS (4)"
 S X("PID","PID13")="13^00116^Phone Number - Home XTN (40) ( )"
 S X("PID","PID14")="14^00117^Phone Number - Business XTN (40) ( )"
 S X("PID","PID15")="15^00118^Language - Patient CE (60) (0296)"
 S X("PID","PID16")="16^00119^Marital Status IS (1) (0002)"
 S X("PID","PID17")="17^00120^Religion IS (3) (0006)"
 S X("PID","PID18")="18^00121^Patient Account Number CX (20)"
 S X("PID","PID19")="19^00122^SSN Number - Patient ST (16)"
 S X("PID","PID20")="20^00123^Drivers License - Patient DLN (25)"
 S X("PID","PID21")="21^00124^Mother's Identifier CX (20) ( )"
 S X("PID","PID22")="22^00125^Ethnic Group IS (3) (0189)"
 S X("PID","PID23")="23^00126^Birth Place ST (60)"
 S X("PID","PID24")="24^00127^Multiple Birth Indicator ID (2) (0136)"
 S X("PID","PID25")="25^00128^Birth Order NM (2)"
 S X("PID","PID26")="26^00129^Citizenship IS (4) ( ) (0171)"
 S X("PID","PID27")="27^00130^Veteran.s Military Status CE (60) (0172)"
 S X("PID","PID28")="28^00739^Nationality CE (80)"
 S X("PID","PID29")="29^00740^Patient Death Date/Time TS (26)"
 S X("PID","PID30")="30^00741^Patient Death Indicator"
 S X("NTE","NTE1")="1^00573^Set ID - NTE SI (4)"
 S X("NTE","NTE2")="2^00574^Source of Comment ID (8) (0105)"
 S X("NTE","NTE3")="3^00575^Comment"
 S X("ORC","ORC1")="1^00215^Order Control R ID (2)"
 S X("ORC","ORC2")="2^00216^Placer Order Number EI (22)"
 S X("ORC","ORC3")="3^00217^Filler Order Number EI (22)"
 S X("ORC","ORC4")="4^00218^Placer Order Number EI (22)"
 S X("ORC","ORC5")="5^00219^Order Status ID (2) (0038)"
 S X("ORC","ORC6")="6^00220^Response Flag ID (1) (0121)"
 S X("ORC","ORC7")="7^00221^Quantity/Timing TQ (200)"
 S X("ORC","ORC8")="8^00222^Parent CM (200)"
 S X("ORC","ORC9")="9^00223^Date/Time of Transaction TS (26)"
 S X("ORC","ORC10")="10^00224^Entered By XCN (120)"
 S X("ORC","ORC11")="11^00225^Verified By XCN (120)"
 S X("ORC","ORC12")="12^00226^Ordering Provider XCN (120)"
 S X("ORC","ORC13")="13^00227^Enterer's Location PL (80)"
 S X("ORC","ORC14")="14^00228^Call Back Phone Number XTN (40) ( )"
 S X("ORC","ORC15")="15^00229^Order Effective Date/Time TS (26)"
 S X("ORC","ORC16")="16^00230^Order Control Code Reason CE (200)"
 S X("ORC","ORC17")="17^00231^Entering Organization CE (60)"
 S X("ORC","ORC18")="18^00232^Entering Device CE (60)"
 S X("ORC","ORC19")="19^00233^Action By"
 S X("OBR","OBR1")="1^00237^Set ID - Observation Request C SI (4)"
 S X("OBR","OBR2")="2^00216^Placer Order Number C EI (75)"
 S X("OBR","OBR3")="3^00217^Filler Order Number C EI (75)"
 S X("OBR","OBR4")="4^00238^Universal Service ID R CE (200)"
 S X("OBR","OBR5")="5^00239^Priority B ID (2)"
 S X("OBR","OBR6")="6^00240^Requested Date/Time B TS (26)"
 S X("OBR","OBR7")="7^00241^Observation Date/Time C TS (26)"
 S X("OBR","OBR8")="8^00242^Observation End Date/Time TS (26)"
 S X("OBR","OBR9")="9^00243^Collection Volume CQ (20)"
 S X("OBR","OBR10")="10^00244^Collector Identifier XCN (60) ( )"
 S X("OBR","OBR11")="11^00245^Specimen Action Code ID (1) (0065)"
 S X("OBR","OBR12")="12^00246^Danger Code CE (60)"
 S X("OBR","OBR13")="13^00247^Relevant Clinical Info. ST (300)"
 S X("OBR","OBR14")="14^00248^Specimen Rcv'd. Date/Time C TS (26)"
 S X("OBR","OBR15")="15^00249^Specimen Source CM (300) (0070)"
 S X("OBR","OBR16")="16^00226^Ordering Provider XCN (80) ( )"
 S X("OBR","OBR17")="17^00250^Order Callback Phone Number XTN (40) ( )"
 S X("OBR","OBR18")="18^00251^Placers Field 1 ST (60)"
 S X("OBR","OBR19")="19^00252^Placers Field 2"
 S X("OBR","OBR20")="20^00253^Filler Field 1 ST (60)"
 S X("OBR","OBR21")="21^00254^Filler Field 2 ST (60)"
 S X("OBR","OBR22")="22^00255^Results Rpt./Status Change C TS (26)"
 S X("OBR","OBR23")="23^00256^Charge to Practice CM (40)"
 S X("OBR","OBR24")="24^00257^Diagnostic Service Sect ID ID (10) (0074)"
 S X("OBR","OBR25")="25^00258^Result Status C ID (1) (0123)"
 S X("OBR","OBR26")="26^00259^Parent Result CM (400)"
 S X("OBR","OBR27")="27^00221^Quantity/Timing TQ (200) ( )"
 S X("OBR","OBR28")="28^00260^Result Copies to CN (150) ( )"
 S X("OBR","OBR29")="29^00261^Parent Number CM (150)"
 S X("OBR","OBR30")="30^00262^Transportation Mode ID (20) (0124)"
 S X("OBR","OBR31")="31^00263^Reason for Study CE (300) ( )"
 S X("OBR","OBR32")="32^00264^Principal Result Interpreter CM (200)"
 S X("OBR","OBR33")="33^00265^Assistant Result Interpreter CM (200) ( )"
 S X("OBR","OBR34")="34^00266^Technician CM (200) ( )"
 S X("OBR","OBR35")="35^00267^Transcriptionist CM (200) ( )"
 S X("OBR","OBR36")="36^00268^Scheduled Date/Time TS (26)"
 S X("OBR","OBR37")="37^01028^Number of Sample Containers NM (4)"
 S X("OBR","OBR38")="38^38^01029 Transport Logistics of Collected Sample CE (60) ( )"
 S X("OBR","OBR39")="39^01030^Collector.s Comment CE (200) ( )"
 S X("OBR","OBR40")="40^01031^Transport Arrangement Responsibility CE (60)"
 S X("OBR","OBR41")="41^01032^Transport Arranged ID (30) (0224)"
 S X("OBR","OBR42")="42^01033^Escort Required ID (1) (0225)"
 S X("OBR","OBR43")="43^01034^Planned Patient Transport Comment"
 S X("OBX","OBX1")="1^00559^Set ID - OBX"
 S X("OBX","OBX2")="2^00676^Value Type"
 S X("OBX","OBX3")="3^00560^Observation Identifier"
 S X("OBX","OBX4")="4^00769^Observation Sub-Id"
 S X("OBX","OBX5")="5^00561^Observation Results"
 S X("OBX","OBX6")="6^00562^Units"
 S X("OBX","OBX7")="7^00563^Reference Range"
 S X("OBX","OBX8")="8^00564^Abnormal Flags"
 S X("OBX","OBX9")="9^00639^Probability"
 S X("OBX","OBX10")="10^00565^Nature of Abnormal Test"
 S X("OBX","OBX11")="11^00566^Observ. Result Status"
 S X("OBX","OBX12")="12^00567^Date Last Normal Value"
 S X("OBX","OBX13")="13^00581^User Defined Access Checks"
 S X("OBX","OBX14")="14^00582^Date/Time of Observation"
 S X("OBX","OBX15")="15^00583^Producer.s ID"
 S X("OBX","OBX16")="16^00584^Responsible Observer"
 S X("OBX","OBX17")="17^00936^Observation Method"
 M ^KBAI=X ; SET VALUES IN ^KBAI
 Q
 ;
