Changeset 1204 for ccr/trunk/p/C0CLABS.m


Ignore:
Timestamp:
Jun 23, 2011, 3:01:41 PM (13 years ago)
Author:
George Lilly
Message:

updates for MU Certification

File:
1 edited

Legend:

Unmodified
Added
Removed
  • ccr/trunk/p/C0CLABS.m

    r600 r1204  
    1 C0CALABS ; CCDCCR/GPL - CCR/CCD PROCESSING FOR LAB RESULTS ; 10/01/08
    2  ;;1.0;C0C;;May 19, 2009;
    3  ;Copyright 2008,2009 George Lilly, University of Minnesota.
    4  ;Licensed under the terms of the GNU General Public License.
    5  ;See attached copy of the License.
    6  ;
    7  ;This program is free software; you can redistribute it and/or modify
    8  ;it under the terms of the GNU General Public License as published by
    9  ;the Free Software Foundation; either version 2 of the License, or
    10  ;(at your option) any later version.
    11  ;
    12  ;This program is distributed in the hope that it will be useful,
    13  ;but WITHOUT ANY WARRANTY; without even the implied warranty of
    14  ;MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    15  ;GNU General Public License for more details.
    16  ;
    17  ;You should have received a copy of the GNU General Public License along
    18  ;with this program; if not, write to the Free Software Foundation, Inc.,
    19  ;51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
    20            ;
    21 MAP(MIXML,DFN,MOXML) ;TO MAKE THIS COMPATIBLE WITH OLD CALLING FOR EXTRACT
    22  ; ASSUMES THAT EXTRACT HAS BEEN RUN AND THE VARIABLES STORED IN MIVAR
    23  ; MIXML,MIVAR, AND MOXML ARE PASSED BY NAME
    24  ; MIXML IS THE TEMPLATE TO USE
    25  ; MOXML IS THE OUTPUT XML ARRAY
    26  ; DFN IS THE PATIENT RECORD NUMBER
    27  N C0COXML,C0CO,C0CV,C0CIXML
    28  I '$D(MIVAR) S C0CV="" ;DEFAULT
    29  E  S C0CV=MIVAR ;PASSED VARIABLE ARRAY
    30  I '$D(MIXML) S C0CIXML="" ;DEFAULT
    31  E  S C0CIXML=MIXML ;PASSED INPUT XML
    32  D RPCMAP(.C0COXML,DFN,C0CV,C0CIXML) ; CALL RPC TO DO THE WORK
    33  I '$D(MOXML) S C0CO=$NA(^TMP("C0CCCR",$J,DFN,"RESULTS")) ;DEFAULT FOR OUTPUT
    34  E  S C0CO=MOXML
    35  ; ZWR C0COXML
    36  M @C0CO=C0COXML ; COPY RESULTS TO OUTPUT
    37  Q
    38  ;
    39 RPCMAP(RTN,DFN,RMIVAR,RMIXML) ; RPC ENTRY POINT FOR MAPPING RESULTS
    40  ; RTN IS PASSED BY REFERENCE
    41  ;N C0CT0,C0CT,C0CV ; CCR TEMPLATE, RESULTS SUBTEMPLATE, VARIABLES
    42  ;N C0CRT,C0CTT ; TEST REQUEST TEMPLATE, TEST RESULT TEMPLATE
    43  I '$D(DEBUG) S DEBUG=0 ; DEFAULT NO DEBUGGING
    44  I RMIXML="" D  ; INPUT XML NOT PASSED
    45  . D LOAD^C0CCCR0("C0CT0") ; LOAD ENTIRE CCR TEMPLATE
    46  . D QUERY^C0CXPATH("C0CT0","//ContinuityOfCareRecord/Body/Results","C0CT0R")
    47  . S C0CT="C0CT0R" ; NAME OF EXTRACTED RESULTS TEMPLATE
    48  E  S C0CT=RMIXML ; WE ARE PASSED THE RESULTS PART OF THE TEMPLATE
    49  I RMIVAR="" D  ; LOCATION OF VARIABLES NOT PASSED
    50  . S C0CV=$NA(^TMP("C0CCCR",$J,"RESULTS")) ;DEFAULT VARIABLE LOCATION
    51  E  S C0CV=RMIVAR ; PASSED LOCATIONS OF VARS
    52  D CP^C0CXPATH(C0CT,"C0CRT") ; START MAKING TEST REQUEST TEMPLATE
    53  D REPLACE^C0CXPATH("C0CRT","","//Results/Result/Test") ; DELETE TEST FROM REQ
    54  D QUERY^C0CXPATH(C0CT,"//Results/Result/Test","C0CTT") ; MAKE TEST TEMPLATE
    55  I '$D(C0CQT) S C0CQT=0 ; DEFAULT NOT SILENT
    56  I 'C0CQT D  ; WE ARE DEBUGGING
    57  . W "I MAPPED",!
    58  . W "VARS:",C0CV,!
    59  . W "DFN:",DFN,!
    60  . ;D PARY^C0CXPATH("C0CT") ; SECTION TEMPLATE
    61  . ;D PARY^C0CXPATH("C0CRT") ;REQUEST TEMPLATE (OCR)
    62  . ;D PARY^C0CXPATH("C0CTT") ;TEST TEMPLATE (OCX)
    63  D EXTRACT("C0CT",DFN,) ; FIRST CALL EXTRACT
    64  I '$D(@C0CV@(0)) D  Q  ; NO VARS THERE
    65  . S RTN(0)=0 ; PASS BACK NO RESULTS INDICATOR
    66  I @C0CV@(0)=0 S RTN(0)=0 Q ; NO RESULTS
    67  S RIMVARS=$NA(^TMP("C0CRIM","VARS",DFN,"RESULTS"))
    68  K @RIMVARS
    69  M @RIMVARS=@C0CV ; UPDATE RIMVARS SO THEY STAY IN SYNCH
    70  N C0CI,C0CJ,C0CMAP,C0CTMAP,C0CTMP
    71  S C0CIN=@C0CV@(0) ; COUNT OF RESULTS (OBR)
    72  N C0CRTMP ; AREA TO BUILD ONE RESULT REQUEST AND ALL TESTS FOR IT
    73  N C0CRBASE S C0CRBASE=$NA(^TMP($J,"TESTTMP")) ;WORK AREA
    74  N C0CRBLD ; BUILD LIST FOR XML - THE BUILD IS DELAYED UNTIL THE END
    75  ; TO IMPROVE PERFORMANCE
    76  D QUEUE^C0CXPATH("C0CRBLD","C0CRT",1,1) ;<Results>
    77  F C0CI=1:1:C0CIN D  ; LOOP THROUGH VARIABLES
    78  . K C0CMAP,C0CTMP ;EMPTY OUT LAST BATCH OF VARIABLES
    79  . S C0CRTMP=$NA(@C0CRBASE@(C0CI)) ;PARTITION OF WORK AREA FOR EACH TEST
    80  . S C0CMAP=$NA(@C0CV@(C0CI)) ;
    81  . I 'C0CQT W "MAPOBR:",C0CMAP,!
    82  . ;MAPPING FOR TEST REQUEST GOES HERE
    83  . D MAP^C0CXPATH("C0CRT",C0CMAP,C0CRTMP) ; MAP OBR DATA
    84  . ;D QOPEN^C0CXPATH("C0CRBLD",C0CRTMP,C0CIS) ;1ST PART OF XML
    85  . D QUEUE^C0CXPATH("C0CRBLD",C0CRTMP,2,@C0CRTMP@(0)-4) ;UP TO <Test>
    86  . I $D(@C0CMAP@("M","TEST",0)) D  ; TESTS EXIST
    87  . . S C0CJN=@C0CMAP@("M","TEST",0) ; NUMBER OF TESTS
    88  . . K C0CTO ; CLEAR OUTPUT VARIABLE
    89  . . F C0CJ=1:1:C0CJN D   ;FOR EACH TEST RESULT
    90  . . . K C0CTMAP ; EMPTY MAPS FOR TEST RESULTS
    91  . . . S C0CTMP=$NA(@C0CRBASE@(C0CI,C0CJ)) ;WORK AREA FOR TEST RESULTS
    92  . . . S C0CTMAP=$NA(@C0CMAP@("M","TEST",C0CJ)) ;
    93  . . . I 'C0CQT W "MAPOBX:",C0CTMAP,!
    94  . . . D MAP^C0CXPATH("C0CTT",C0CTMAP,C0CTMP) ; MAP TO TMP
    95  . . . I C0CJ=1 S C0CJS=2 E  S C0CJS=1 ;FIRST TIME,SKIP THE <Test>
    96  . . . I C0CJ=C0CJN S C0CJE=@C0CTMP@(0)-1 E  S C0CJE=@C0CTMP@(0) ;</Test>
    97  . . . S C0CJS=1 S C0CJE=@C0CTMP@(0) ; INSERT ALL OF THE TEXT XML
    98  . . . D QUEUE^C0CXPATH("C0CRBLD",C0CTMP,C0CJS,C0CJE) ; ADD TO BUILD LIST
    99  . . . ;I C0CJ=1 D  ; FIRST TIME, JUST COPY
    100  . . . ;. D CP^C0CXPATH("C0CTMP","C0CTO") ; START BUILDING TEST XML
    101  . . . ;E  D INSINNER^C0CXPATH("C0CTO","C0CTMP")
    102  . . . ;
    103  . . . ;D PUSHA^C0CXPATH("C0CTO",C0CTMP) ;ADD THE TEST TO BUFFER
    104  . . ; I 'C0CQT D PARY^C0CXPATH("C0CTO")
    105  . . ;D INSINNER^C0CXPATH(C0CRTMP,"C0CTO","//Results/Result/Test") ;INSERT TST
    106  . ;D QCLOSE^C0CXPATH("C0CRBLD",C0CRTMP,"//Results/Result/Test") ;END OF XML
    107  . D QUEUE^C0CXPATH("C0CRBLD","C0CRT",C0CRT(0)-1,C0CRT(0)-1) ;</Result>
    108  . ;I C0CI=1 D  ; FIRST TIME, COPY INSTEAD OF INSERT
    109  . . ;D CP^C0CXPATH(C0CRTMP,"RTN") ;
    110  . ;E  D INSINNER^C0CXPATH("RTN",C0CRTMP) ; INSERT THIS TEST REQUEST
    111  D QUEUE^C0CXPATH("C0CRBLD","C0CRT",C0CRT(0),C0CRT(0)) ;</Results>
    112  D BUILD^C0CXPATH("C0CRBLD","RTN") ;RENDER THE XML
    113  K @C0CRBASE ; CLEAR OUT TEMPORARY STURCTURE
    114  Q
    115  ;
    116 EXTRACT(ILXML,DFN,OLXML) ; EXTRACT LABS INTO THE C0CLVAR GLOBAL
    117  ;
    118  ; LABXML AND LABOUTXML ARE PASSED BY NAME SO GLOBALS CAN BE USED
    119  ;
    120  ;
    121  ;
    122  N C0CNSSN ; IS THERE AN SSN FLAG
    123  S C0CNSSN=0
    124  S C0CLB=$NA(^TMP("C0CCCR",$J,"RESULTS")) ; BASE GLB FOR LABS VARS
    125  D GHL7 ; GET HL7 MESSAGE FOR THIS PATIENT
    126  I C0CNSSN=1 D  Q  ; NO SSN, CAN'T GET HL7 FOR THIS PATIENT
    127  . S @C0CLB@(0)=0
    128  K @C0CLB ; CLEAR OUT OLD VARS IF ANY
    129  N QTSAV S QTSAV=C0CQT ;SAVE QUIET FLAG
    130  S C0CQT=1 ; SURPRESS LISTING
    131  D LIST ; EXTRACT THE VARIABLES
    132  S C0CQT=QTSAV ; RESET SILENT FLAG
    133  K ^TMP("HLS",$J) ; KILL HL7 MESSAGE OUTPUT
    134  I $D(OLXML) S @OLXML@(0)=0 ; EXTRACT DOES NOT PRODUCE XML... SEE MAP^C0CLABS
    135  Q
    136      ;
    137 GHL7 ; GET HL7 MESSAGE FOR LABS FOR THIS PATIENT
    138  ; N C0CPTID,C0CSPC,C0CSDT,C0CEDT,C0CR
    139  ; SET UP FOR LAB API CALL
    140  S C0CPTID=$$SSN^C0CDPT(DFN) ; GET THE SSN FOR THIS PATIENT
    141  I C0CPTID="" D  Q  ; NO SSN, COMPLAIN AND QUIT
    142  . W "LAB LOOKUP FAILED, NO SSN",!
    143  . S C0CNSSN=1 ; SET NO SSN FLAG
    144  S C0CSPC="*" ; LOOKING FOR ALL LABS
    145  ;I $D(^TMP("C0CCCR","RPMS")) D  ; RUNNING RPMS
    146  ;. D DT^DILF(,"T-365",.C0CSDT) ; START DATE ONE YEAR AGO TO LIMIT VOLUME
    147  ;E  D DT^DILF(,"T-5000",.C0CSDT) ; START DATE LONG AGO TO GET EVERYTHING
    148  ;D DT^DILF(,"T",.C0CEDT) ; END DATE TODAY
    149  S C0CLLMT=$$GET^C0CPARMS("LABLIMIT") ; GET THE LIMIT PARM
    150  S C0CLSTRT=$$GET^C0CPARMS("LABSTART") ; GET START PARM
    151  D DT^DILF(,C0CLLMT,.C0CSDT) ;
    152  W "LAB LIMIT: ",C0CLLMT,!
    153  D DT^DILF(,C0CLSTRT,.C0CEDT) ; END DATE TODAY - IMPLEMENT END DATE PARM
    154  S C0CR=$$LAB^C0CLA7Q(C0CPTID,C0CSDT,C0CEDT,C0CSPC,C0CSPC) ; CALL LAB LOOKUP
    155  Q
    156  ;
    157 LIST ; LIST THE HL7 MESSAGE; ALSO, EXTRACT THE RESULT VARIABLES TO C0CLB
    158  ;
    159  ; N C0CI,C0CJ,C0COBT,C0CHB,C0CVAR
    160  I '$D(C0CLB) S C0CLB=$NA(^TMP("C0CCCR",$J,"RESULTS")) ; BASE GLB FOR LABS VARS
    161  I '$D(C0CQT) S C0CQT=0
    162  I '$D(DFN) S DFN=1 ; DEFAULT TEST PATIENT
    163  I '$D(^TMP("C0CCCR","LABTBL",0)) D SETTBL ;INITIALIZE LAB TABLE
    164  I ^TMP("C0CCCR","LABTBL",0)'="V3" D SETTBL ;NEED NEWEST VERSION
    165  I '$D(^TMP("HLS",$J,1)) D GHL7 ; GET HL7 MGS IF NOT ALREADY DONE
    166  S C0CTAB=$NA(^TMP("C0CCCR","LABTBL")) ; BASE OF OBX TABLE
    167  S C0CHB=$NA(^TMP("HLS",$J))
    168  S C0CI=""
    169  S @C0CLB@(0)=0 ; INITALIZE RESULTS VARS COUNT
    170  F  S C0CI=$O(@C0CHB@(C0CI)) Q:C0CI=""  D  ; FOR ALL RECORDS IN HL7 MSG
    171  . K C0CVAR,XV ; CLEAR OUT VARIABLE VALUES
    172  . S C0CTYP=$P(@C0CHB@(C0CI),"|",1)
    173  . D LTYP(@C0CHB@(C0CI),C0CTYP,.C0CVAR,C0CQT)
    174  . M XV=C0CVAR ;
    175  . I C0CTYP="OBR" D  ; BEGINNING OF NEW SECTION
    176  . . S @C0CLB@(0)=@C0CLB@(0)+1 ; INCREMENT COUNT
    177  . . S C0CLI=@C0CLB@(0) ; INDEX FOR THIS RESULT
    178  . . ;M @C0CLB@(C0CLI)=C0CVAR ; PERSIST THE OBR VARS
    179  . . S XV("RESULTOBJECTID")="RESULT_"_C0CLI
    180  . . S C0CX1=XV("RESULTSOURCEACTORID") ; SOURCE FROM OBR
    181  . . S XV("RESULTSOURCEACTORID")="ACTORPROVIDER_"_$P($P(C0CX1,"^",1),"-",1)
    182  . . S C0CX1=XV("RESULTASSESSMENTDATETIME") ;DATE TIME IN HL7 FORMAT
    183  . . S C0CX2=$$HL7TFM^XLFDT(C0CX1,"L") ;FM DT LOCAL
    184  . . S XV("RESULTASSESSMENTDATETIME")=$$FMDTOUTC^C0CUTIL(C0CX2,"DT") ;UTC TIME
    185  . . M @C0CLB@(C0CLI)=XV ; PERSIST THE OBR VARS
    186  . . S C0CLOBX=0 ; MARK THE BEGINNING OF A NEW SECTION
    187  . I C0CTYP="OBX" D  ; SPECIAL CASE FOR OBX3
    188  . . ; RESULTTESTCODEVALUE
    189  . . ; RESULTTESTDESCRIPTIONTEXT
    190  . . I C0CVAR("C3")="LN" D  ; PRIMARY CODE IS LOINC
    191  . . . S XV("RESULTTESTCODEVALUE")=C0CVAR("C1") ; THE LOINC CODE VALUE
    192  . . . S XV("RESULTTESTCODINGSYSTEM")="LOINC" ; DISPLAY NAME FOR LOINC
    193  . . . S XV("RESULTTESTDESCRIPTIONTEXT")=C0CVAR("C2") ; DESCRIPTION TEXT
    194  . . E  I C0CVAR("C6")="LN" D  ; SECONDARY CODE IS LOINC
    195  . . . S XV("RESULTTESTCODEVALUE")=C0CVAR("C4") ; THE LOINC CODE VALUE
    196  . . . S XV("RESULTTESTCODINGSYSTEM")="LOINC" ; DISPLAY NAME FOR LOINC
    197  . . . S XV("RESULTTESTDESCRIPTIONTEXT")=C0CVAR("C5") ; DESCRIPTION TEXT
    198  . . E  I C0CVAR("C6")'="" D  ; NO LOINC CODES, USE SECONDARY IF PRESENT
    199  . . . S XV("RESULTTESTCODEVALUE")=C0CVAR("C4") ; SECONDARY CODE VALUE
    200  . . . S XV("RESULTTESTCODINGSYSTEM")=C0CVAR("C6") ; SECONDARY CODE NAME
    201  . . . S XV("RESULTTESTDESCRIPTIONTEXT")=C0CVAR("C5") ; SECONDARY TEXT
    202  . . E  D  ; NO SECONDARY, USE PRIMARY
    203  . . . S XV("RESULTTESTCODEVALUE")=C0CVAR("C1") ; PRIMARY CODE VALUE
    204  . . . S XV("RESULTTESTCODINGSYSTEM")=C0CVAR("C3") ; PRIMARY DISPLAY NAME
    205  . . . S XV("RESULTTESTDESCRIPTIONTEXT")=C0CVAR("C2") ; USE PRIMARY TEXT
    206  . . N C0CZG S C0CZG=XV("RESULTTESTNORMALDESCTEXT") ;
    207  . . ; mod to remove local XML escaping rely upon MAP^C0CXPATH
    208  . . ;S XV("RESULTTESTNORMALDESCTEXT")=$$SYMENC^MXMLUTL(C0CZG) ;ESCAPE
    209  . . S XV("RESULTTESTNORMALDESCTEXT")=C0CZG
    210  . . S C0CZG=XV("RESULTTESTVALUE")
    211   . . ; mod to remove local XML escaping rely upon MAP^C0CXPATH
    212  . . ;S XV("RESULTTESTVALUE")=$$SYMENC^MXMLUTL(C0CZG) ;ESCAPE
    213  . . S XV("RESULTTESTVALUE")=C0CZG
    214  . I C0CTYP="OBX" D  ; PROCESS TEST RESULTS
    215  . . I C0CLOBX=0 D  ; FIRST TEST RESULT FOR THIS SECTION
    216  . . . S C0CLB2=$NA(@C0CLB@(C0CLI,"M","TEST")) ; INDENT FOR TEST RESULTS
    217  . . S C0CLOBX=C0CLOBX+1 ; INCREMENT TEST COUNT
    218  . . S @C0CLB2@(0)=C0CLOBX ; STORE THE TEST COUNT
    219  . . S XV("RESULTTESTOBJECTID")="RESULTTEST_"_C0CLI_"_"_C0CLOBX
    220  . . S C0CX1=XV("RESULTTESTSOURCEACTORID") ; TEST SOURCE
    221  . . S C0CX2=$P($P(C0CX1,"^",1),"-",1) ; PULL OUT STATION NUMBER
    222  . . S XV("RESULTTESTSOURCEACTORID")="ACTORORGANIZATION_"_C0CX2
    223  . . S XV("RESULTTESTNORMALSOURCEACTORID")=XV("RESULTTESTSOURCEACTORID")
    224  . . S C0CX1=XV("RESULTTESTDATETIME") ;DATE TIME IN HL7 FORMAT
    225  . . S C0CX2=$$HL7TFM^XLFDT(C0CX1,"L") ;FM DT LOCAL
    226  . . S XV("RESULTTESTDATETIME")=$$FMDTOUTC^C0CUTIL(C0CX2,"DT") ;UTC TIME
    227  . . ; I 'C0CQT ZWR XV
    228  . . M @C0CLB2@(C0CLOBX)=XV ; PERSIST THE TEST RESULT VARIABLES
    229  . I 'C0CQT D  ;
    230  . . W C0CI," ",C0CTYP,!
    231  . ; S C0CI=$O(@C0CHB@(C0CI))
    232  ;K ^TMP("C0CRIM","VARS",DFN,"RESULTS")
    233  ;M ^TMP("C0CRIM","VARS",DFN,"RESULTS")=@C0CLB
    234  Q
    235 LTYP(OSEG,OTYP,OVARA,OC0CQT) ;
    236  S OTAB=$NA(@C0CTAB@(OTYP)) ; TABLE FOR SEGMENT TYPE
    237  I '$D(OC0CQT) S C0CQT=0 ; NOT C0CQT IS DEFAULT
    238  E  S C0CQT=OC0CQT ; ACCEPT C0CQT FLAG
    239  I 1 D  ; FOR HL7 SEGMENT TYPE
    240  . S OI="" ; INDEX INTO FIELDS IN SEG
    241  . F  S OI=$O(@OTAB@(OI)) Q:OI=""  D  ; FOR EACH FIELD OF THE SEGMENT
    242  . . S OTI=$P(@OTAB@(OI),"^",1) ; TABLE INDEX
    243  . . S OVAR=$P(@OTAB@(OI),"^",4) ; CCR VARIABLE IF DEFINED
    244  . . S OV=$P(OSEG,"|",OTI+1) ; PULL OUT VALUE
    245  . . I $P(OI,";",2)'="" D  ; THIS IS DEFINING A SUB-VALUE
    246  . . . S OI2=$P(OTI,";",2) ; THE SUB-INDEX
    247  . . . S OV=$P(OV,"^",OI2) ; PULL OUT SUB-VALUE
    248  . . I OVAR'="" S OVARA(OVAR)=OV ; PASS BACK VARIABLE AND VALUE
    249  . . I 'C0CQT D  ; PRINT OUTPUT IF C0CQT IS FALSE
    250  . . . I OV'="" W OI_": "_$P(@OTAB@(OI),"^",3),": ",OVAR,": ",OV,!
    251  Q
    252 LOBX ;
    253  Q
    254  ;
    255 OUT(DFN) ; WRITE OUT A CCR THAT HAS JUST BEEN PROCESSED (FOR TESTING)
    256  N GA,GF,GD
    257  S GA=$NA(^TMP("C0CCCR",$J,DFN,"CCR",1))
    258  S GF="RPMS_CCR_"_DFN_"_"_DT_".xml"
    259  S GD=^TMP("C0CCCR","ODIR")
    260  W $$OUTPUT^C0CXPATH(GA,GF,GD)
    261  Q
    262  ;
    263 SETTBL ;
    264  K X ; CLEAR X
    265  S X("PID","PID1")="1^00104^Set ID - Patient ID"
    266  S X("PID","PID2")="2^00105^Patient ID (External ID)"
    267  S X("PID","PID3")="3^00106^Patient ID (Internal ID)"
    268  S X("PID","PID4")="4^00107^Alternate Patient ID"
    269  S X("PID","PID5")="5^00108^Patient's Name"
    270  S X("PID","PID6")="6^00109^Mother's Maiden Name"
    271  S X("PID","PID7")="7^00110^Date of Birth"
    272  S X("PID","PID8")="8^00111^Sex"
    273  S X("PID","PID9")="9^00112^Patient Alias"
    274  S X("PID","PID10")="10^00113^Race"
    275  S X("PID","PID11")="11^00114^Patient Address"
    276  S X("PID","PID12")="12^00115^County Code"
    277  S X("PID","PID13")="13^00116^Phone Number - Home"
    278  S X("PID","PID14")="14^00117^Phone Number - Business"
    279  S X("PID","PID15")="15^00118^Language - Patient"
    280  S X("PID","PID16")="16^00119^Marital Status"
    281  S X("PID","PID17")="17^00120^Religion"
    282  S X("PID","PID18")="18^00121^Patient Account Number"
    283  S X("PID","PID19")="19^00122^SSN Number - Patient"
    284  S X("PID","PID20")="20^00123^Drivers License - Patient"
    285  S X("PID","PID21")="21^00124^Mother's Identifier"
    286  S X("PID","PID22")="22^00125^Ethnic Group"
    287  S X("PID","PID23")="23^00126^Birth Place"
    288  S X("PID","PID24")="24^00127^Multiple Birth Indicator"
    289  S X("PID","PID25")="25^00128^Birth Order"
    290  S X("PID","PID26")="26^00129^Citizenship"
    291  S X("PID","PID27")="27^00130^Veteran.s Military Status"
    292  S X("PID","PID28")="28^00739^Nationality"
    293  S X("PID","PID29")="29^00740^Patient Death Date/Time"
    294  S X("PID","PID30")="30^00741^Patient Death Indicator"
    295  S X("NTE","NTE1")="1^00573^Set ID - NTE"
    296  S X("NTE","NTE2")="2^00574^Source of Comment"
    297  S X("NTE","NTE3")="3^00575^Comment"
    298  S X("ORC","ORC1")="1^00215^Order Control"
    299  S X("ORC","ORC2")="2^00216^Placer Order Number"
    300  S X("ORC","ORC3")="3^00217^Filler Order Number"
    301  S X("ORC","ORC4")="4^00218^Placer Order Number"
    302  S X("ORC","ORC5")="5^00219^Order Status"
    303  S X("ORC","ORC6")="6^00220^Response Flag"
    304  S X("ORC","ORC7")="7^00221^Quantity/Timing"
    305  S X("ORC","ORC8")="8^00222^Parent"
    306  S X("ORC","ORC9")="9^00223^Date/Time of Transaction"
    307  S X("ORC","ORC10")="10^00224^Entered By"
    308  S X("ORC","ORC11")="11^00225^Verified By"
    309  S X("ORC","ORC12")="12^00226^Ordering Provider"
    310  S X("ORC","ORC13")="13^00227^Enterer's Location"
    311  S X("ORC","ORC14")="14^00228^Call Back Phone Number"
    312  S X("ORC","ORC15")="15^00229^Order Effective Date/Time"
    313  S X("ORC","ORC16")="16^00230^Order Control Code Reason"
    314  S X("ORC","ORC17")="17^00231^Entering Organization"
    315  S X("ORC","ORC18")="18^00232^Entering Device"
    316  S X("ORC","ORC19")="19^00233^Action By"
    317  S X("OBR","OBR1")="1^00237^Set ID - Observation Request"
    318  S X("OBR","OBR2")="2^00216^Placer Order Number"
    319  S X("OBR","OBR3")="3^00217^Filler Order Number"
    320  S X("OBR","OBR4")="4^00238^Universal Service ID"
    321  S X("OBR","OBR4;LOINC")="4;1^00238^Universal Service ID - LOINC^RESULTCODE"
    322  S X("OBR","OBR4;DESC")="4;2^00238^Universal Service ID - DESC^RESULTDESCRIPTIONTEXT"
    323  S X("OBR","OBR4;VACODE")="4;3^00238^Universal Service ID - VACODE^RESULTCODINGSYSTEM"
    324  S X("OBR","OBR5")="5^00239^Priority"
    325  S X("OBR","OBR6")="6^00240^Requested Date/Time"
    326  S X("OBR","OBR7")="7^00241^Observation Date/Time^RESULTASSESSMENTDATETIME"
    327  S X("OBR","OBR8")="8^00242^Observation End Date/Time"
    328  S X("OBR","OBR9")="9^00243^Collection Volume"
    329  S X("OBR","OBR10")="10^00244^Collector Identifier"
    330  S X("OBR","OBR11")="11^00245^Specimen Action Code"
    331  S X("OBR","OBR12")="12^00246^Danger Code"
    332  S X("OBR","OBR13")="13^00247^Relevant Clinical Info."
    333  S X("OBR","OBR14")="14^00248^Specimen Rcv'd. Date/Time"
    334  S X("OBR","OBR15")="15^00249^Specimen Source"
    335  S X("OBR","OBR16")="16^00226^Ordering Provider XCN^RESULTSOURCEACTORID"
    336  S X("OBR","OBR17")="17^00250^Order Callback Phone Number"
    337  S X("OBR","OBR18")="18^00251^Placers Field 1"
    338  S X("OBR","OBR19")="19^00252^Placers Field 2"
    339  S X("OBR","OBR20")="20^00253^Filler Field 1"
    340  S X("OBR","OBR21")="21^00254^Filler Field 2"
    341  S X("OBR","OBR22")="22^00255^Results Rpt./Status Change"
    342  S X("OBR","OBR23")="23^00256^Charge to Practice"
    343  S X("OBR","OBR24")="24^00257^Diagnostic Service Sect"
    344  S X("OBR","OBR25")="25^00258^Result Status^RESULTSTATUS"
    345  S X("OBR","OBR26")="26^00259^Parent Result"
    346  S X("OBR","OBR27")="27^00221^Quantity/Timing"
    347  S X("OBR","OBR28")="28^00260^Result Copies to"
    348  S X("OBR","OBR29")="29^00261^Parent Number"
    349  S X("OBR","OBR30")="30^00262^Transportation Mode"
    350  S X("OBR","OBR31")="31^00263^Reason for Study"
    351  S X("OBR","OBR32")="32^00264^Principal Result Interpreter"
    352  S X("OBR","OBR33")="33^00265^Assistant Result Interpreter"
    353  S X("OBR","OBR34")="34^00266^Technician"
    354  S X("OBR","OBR35")="35^00267^Transcriptionist"
    355  S X("OBR","OBR36")="36^00268^Scheduled Date/Time"
    356  S X("OBR","OBR37")="37^01028^Number of Sample Containers"
    357  S X("OBR","OBR38")="38^38^01029 Transport Logistics of Collected Sample"
    358  S X("OBR","OBR39")="39^01030^Collector.s Comment"
    359  S X("OBR","OBR40")="40^01031^Transport Arrangement Responsibility"
    360  S X("OBR","OBR41")="41^01032^Transport Arranged"
    361  S X("OBR","OBR42")="42^01033^Escort Required"
    362  S X("OBR","OBR43")="43^01034^Planned Patient Transport Comment"
    363  S X("OBX","OBX1")="1^00559^Set ID - OBX"
    364  S X("OBX","OBX2")="2^00676^Value Type"
    365  S X("OBX","OBX3")="3^00560^Observation Identifier"
    366  S X("OBX","OBX3;C1")="3;1^00560^Observation Identifier^C1"
    367  S X("OBX","OBX3;C2")="3;2^00560^Observation Identifier^C2"
    368  S X("OBX","OBX3;C3")="3;3^00560^Observation Identifier^C3"
    369  S X("OBX","OBX3;C4")="3;4^00560^Observation Identifier^C4"
    370  S X("OBX","OBX3;C5")="3;5^00560^Observation Identifier^C5"
    371  S X("OBX","OBX3;C6")="3;6^00560^Observation Identifier^C6"
    372  S X("OBX","OBX4")="4^00769^Observation Sub-Id"
    373  S X("OBX","OBX5")="5^00561^Observation Results^RESULTTESTVALUE"
    374  S X("OBX","OBX6")="6^00562^Units^RESULTTESTUNITS"
    375  S X("OBX","OBX7")="7^00563^Reference Range^RESULTTESTNORMALDESCTEXT"
    376  S X("OBX","OBX8")="8^00564^Abnormal Flags^RESULTTESTFLAG"
    377  S X("OBX","OBX9")="9^00639^Probability"
    378  S X("OBX","OBX10")="10^00565^Nature of Abnormal Test"
    379  S X("OBX","OBX11")="11^00566^Observ. Result Status^RESULTTESTSTATUSTEXT"
    380  S X("OBX","OBX12")="12^00567^Date Last Normal Value"
    381  S X("OBX","OBX13")="13^00581^User Defined Access Checks"
    382  S X("OBX","OBX14")="14^00582^Date/Time of Observation^RESULTTESTDATETIME"
    383  S X("OBX","OBX15")="15^00583^Producer.s ID^RESULTTESTSOURCEACTORID"
    384  S X("OBX","OBX16")="16^00584^Responsible Observer"
    385  S X("OBX","OBX17")="17^00936^Observation Method"
    386  K ^TMP("C0CCCR","LABTBL")
    387  M ^TMP("C0CCCR","LABTBL")=X ; SET VALUES IN LAB TBL
    388  S ^TMP("C0CCCR","LABTBL",0)="V3"
    389  Q
    390  ;
     1C0CALABS        ; CCDCCR/GPL - CCR/CCD PROCESSING FOR LAB RESULTS ; 10/01/08
     2        ;;1.0;C0C;;May 19, 2009;Build 38
     3        ;Copyright 2008,2009 George Lilly, University of Minnesota.
     4        ;Licensed under the terms of the GNU General Public License.
     5        ;See attached copy of the License.
     6        ;
     7        ;This program is free software; you can redistribute it and/or modify
     8        ;it under the terms of the GNU General Public License as published by
     9        ;the Free Software Foundation; either version 2 of the License, or
     10        ;(at your option) any later version.
     11        ;
     12        ;This program is distributed in the hope that it will be useful,
     13        ;but WITHOUT ANY WARRANTY; without even the implied warranty of
     14        ;MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     15        ;GNU General Public License for more details.
     16        ;
     17        ;You should have received a copy of the GNU General Public License along
     18        ;with this program; if not, write to the Free Software Foundation, Inc.,
     19        ;51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
     20                  ;
     21MAP(MIXML,DFN,MOXML)    ;TO MAKE THIS COMPATIBLE WITH OLD CALLING FOR EXTRACT
     22        ; ASSUMES THAT EXTRACT HAS BEEN RUN AND THE VARIABLES STORED IN MIVAR
     23        ; MIXML,MIVAR, AND MOXML ARE PASSED BY NAME
     24        ; MIXML IS THE TEMPLATE TO USE
     25        ; MOXML IS THE OUTPUT XML ARRAY
     26        ; DFN IS THE PATIENT RECORD NUMBER
     27        N C0COXML,C0CO,C0CV,C0CIXML
     28        I '$D(MIVAR) S C0CV="" ;DEFAULT
     29        E  S C0CV=MIVAR ;PASSED VARIABLE ARRAY
     30        I '$D(MIXML) S C0CIXML="" ;DEFAULT
     31        E  S C0CIXML=MIXML ;PASSED INPUT XML
     32        D RPCMAP(.C0COXML,DFN,C0CV,C0CIXML) ; CALL RPC TO DO THE WORK
     33        I '$D(MOXML) S C0CO=$NA(^TMP("C0CCCR",$J,DFN,"RESULTS")) ;DEFAULT FOR OUTPUT
     34        E  S C0CO=MOXML
     35        ; ZWR C0COXML
     36        M @C0CO=C0COXML ; COPY RESULTS TO OUTPUT
     37        Q
     38        ;
     39RPCMAP(RTN,DFN,RMIVAR,RMIXML)   ; RPC ENTRY POINT FOR MAPPING RESULTS
     40        ; RTN IS PASSED BY REFERENCE
     41        ;N C0CT0,C0CT,C0CV ; CCR TEMPLATE, RESULTS SUBTEMPLATE, VARIABLES
     42        ;N C0CRT,C0CTT ; TEST REQUEST TEMPLATE, TEST RESULT TEMPLATE
     43        I '$D(DEBUG) S DEBUG=0 ; DEFAULT NO DEBUGGING
     44        I RMIXML="" D  ; INPUT XML NOT PASSED
     45        . D LOAD^C0CCCR0("C0CT0") ; LOAD ENTIRE CCR TEMPLATE
     46        . D QUERY^C0CXPATH("C0CT0","//ContinuityOfCareRecord/Body/Results","C0CT0R")
     47        . S C0CT="C0CT0R" ; NAME OF EXTRACTED RESULTS TEMPLATE
     48        E  S C0CT=RMIXML ; WE ARE PASSED THE RESULTS PART OF THE TEMPLATE
     49        I RMIVAR="" D  ; LOCATION OF VARIABLES NOT PASSED
     50        . S C0CV=$NA(^TMP("C0CCCR",$J,"RESULTS")) ;DEFAULT VARIABLE LOCATION
     51        E  S C0CV=RMIVAR ; PASSED LOCATIONS OF VARS
     52        D CP^C0CXPATH(C0CT,"C0CRT") ; START MAKING TEST REQUEST TEMPLATE
     53        D REPLACE^C0CXPATH("C0CRT","","//Results/Result/Test") ; DELETE TEST FROM REQ
     54        D QUERY^C0CXPATH(C0CT,"//Results/Result/Test","C0CTT") ; MAKE TEST TEMPLATE
     55        I '$D(C0CQT) S C0CQT=0 ; DEFAULT NOT SILENT
     56        I 'C0CQT D  ; WE ARE DEBUGGING
     57        . W "I MAPPED",!
     58        . W "VARS:",C0CV,!
     59        . W "DFN:",DFN,!
     60        . ;D PARY^C0CXPATH("C0CT") ; SECTION TEMPLATE
     61        . ;D PARY^C0CXPATH("C0CRT") ;REQUEST TEMPLATE (OCR)
     62        . ;D PARY^C0CXPATH("C0CTT") ;TEST TEMPLATE (OCX)
     63        D EXTRACT("C0CT",DFN,) ; FIRST CALL EXTRACT
     64        I '$D(@C0CV@(0)) D  Q  ; NO VARS THERE
     65        . S RTN(0)=0 ; PASS BACK NO RESULTS INDICATOR
     66        I @C0CV@(0)=0 S RTN(0)=0 Q ; NO RESULTS
     67        S RIMVARS=$NA(^TMP("C0CRIM","VARS",DFN,"RESULTS"))
     68        K @RIMVARS
     69        M @RIMVARS=@C0CV ; UPDATE RIMVARS SO THEY STAY IN SYNCH
     70        N C0CI,C0CJ,C0CMAP,C0CTMAP,C0CTMP
     71        S C0CIN=@C0CV@(0) ; COUNT OF RESULTS (OBR)
     72        N C0CRTMP ; AREA TO BUILD ONE RESULT REQUEST AND ALL TESTS FOR IT
     73        N C0CRBASE S C0CRBASE=$NA(^TMP($J,"TESTTMP")) ;WORK AREA
     74        N C0CRBLD ; BUILD LIST FOR XML - THE BUILD IS DELAYED UNTIL THE END
     75        ; TO IMPROVE PERFORMANCE
     76        D QUEUE^C0CXPATH("C0CRBLD","C0CRT",1,1) ;<Results>
     77        F C0CI=1:1:C0CIN D  ; LOOP THROUGH VARIABLES
     78        . K C0CMAP,C0CTMP ;EMPTY OUT LAST BATCH OF VARIABLES
     79        . S C0CRTMP=$NA(@C0CRBASE@(C0CI)) ;PARTITION OF WORK AREA FOR EACH TEST
     80        . S C0CMAP=$NA(@C0CV@(C0CI)) ;
     81        . I 'C0CQT W "MAPOBR:",C0CMAP,!
     82        . ;MAPPING FOR TEST REQUEST GOES HERE
     83        . D MAP^C0CXPATH("C0CRT",C0CMAP,C0CRTMP) ; MAP OBR DATA
     84        . ;D QOPEN^C0CXPATH("C0CRBLD",C0CRTMP,C0CIS) ;1ST PART OF XML
     85        . D QUEUE^C0CXPATH("C0CRBLD",C0CRTMP,2,@C0CRTMP@(0)-4) ;UP TO <Test>
     86        . I $D(@C0CMAP@("M","TEST",0)) D  ; TESTS EXIST
     87        . . S C0CJN=@C0CMAP@("M","TEST",0) ; NUMBER OF TESTS
     88        . . K C0CTO ; CLEAR OUTPUT VARIABLE
     89        . . F C0CJ=1:1:C0CJN D   ;FOR EACH TEST RESULT
     90        . . . K C0CTMAP ; EMPTY MAPS FOR TEST RESULTS
     91        . . . S C0CTMP=$NA(@C0CRBASE@(C0CI,C0CJ)) ;WORK AREA FOR TEST RESULTS
     92        . . . S C0CTMAP=$NA(@C0CMAP@("M","TEST",C0CJ)) ;
     93        . . . I 'C0CQT W "MAPOBX:",C0CTMAP,!
     94        . . . D MAP^C0CXPATH("C0CTT",C0CTMAP,C0CTMP) ; MAP TO TMP
     95        . . . I C0CJ=1 S C0CJS=2 E  S C0CJS=1 ;FIRST TIME,SKIP THE <Test>
     96        . . . I C0CJ=C0CJN S C0CJE=@C0CTMP@(0)-1 E  S C0CJE=@C0CTMP@(0) ;</Test>
     97        . . . S C0CJS=1 S C0CJE=@C0CTMP@(0) ; INSERT ALL OF THE TEXT XML
     98        . . . D QUEUE^C0CXPATH("C0CRBLD",C0CTMP,C0CJS,C0CJE) ; ADD TO BUILD LIST
     99        . . . ;I C0CJ=1 D  ; FIRST TIME, JUST COPY
     100        . . . ;. D CP^C0CXPATH("C0CTMP","C0CTO") ; START BUILDING TEST XML
     101        . . . ;E  D INSINNER^C0CXPATH("C0CTO","C0CTMP")
     102        . . . ;
     103        . . . ;D PUSHA^C0CXPATH("C0CTO",C0CTMP) ;ADD THE TEST TO BUFFER
     104        . . ; I 'C0CQT D PARY^C0CXPATH("C0CTO")
     105        . . ;D INSINNER^C0CXPATH(C0CRTMP,"C0CTO","//Results/Result/Test") ;INSERT TST
     106        . ;D QCLOSE^C0CXPATH("C0CRBLD",C0CRTMP,"//Results/Result/Test") ;END OF XML
     107        . D QUEUE^C0CXPATH("C0CRBLD","C0CRT",C0CRT(0)-1,C0CRT(0)-1) ;</Result>
     108        . ;I C0CI=1 D  ; FIRST TIME, COPY INSTEAD OF INSERT
     109        . . ;D CP^C0CXPATH(C0CRTMP,"RTN") ;
     110        . ;E  D INSINNER^C0CXPATH("RTN",C0CRTMP) ; INSERT THIS TEST REQUEST
     111        D QUEUE^C0CXPATH("C0CRBLD","C0CRT",C0CRT(0),C0CRT(0)) ;</Results>
     112        D BUILD^C0CXPATH("C0CRBLD","RTN") ;RENDER THE XML
     113        K @C0CRBASE ; CLEAR OUT TEMPORARY STURCTURE
     114        Q
     115        ;
     116EXTRACT(ILXML,DFN,OLXML)        ; EXTRACT LABS INTO THE C0CLVAR GLOBAL
     117        ;
     118        ; LABXML AND LABOUTXML ARE PASSED BY NAME SO GLOBALS CAN BE USED
     119        ;
     120        ;
     121        ;
     122        N C0CNSSN ; IS THERE AN SSN FLAG
     123        S C0CNSSN=0
     124        S C0CLB=$NA(^TMP("C0CCCR",$J,"RESULTS")) ; BASE GLB FOR LABS VARS
     125        D GHL7 ; GET HL7 MESSAGE FOR THIS PATIENT
     126        I C0CNSSN=1 D  Q  ; NO SSN, CAN'T GET HL7 FOR THIS PATIENT
     127        . S @C0CLB@(0)=0
     128        K @C0CLB ; CLEAR OUT OLD VARS IF ANY
     129        N QTSAV S QTSAV=C0CQT ;SAVE QUIET FLAG
     130        S C0CQT=1 ; SURPRESS LISTING
     131        D LIST ; EXTRACT THE VARIABLES
     132        S C0CQT=QTSAV ; RESET SILENT FLAG
     133        K ^TMP("HLS",$J) ; KILL HL7 MESSAGE OUTPUT
     134        I $D(OLXML) S @OLXML@(0)=0 ; EXTRACT DOES NOT PRODUCE XML... SEE MAP^C0CLABS
     135        Q
     136            ;
     137GHL7    ; GET HL7 MESSAGE FOR LABS FOR THIS PATIENT
     138        ; N C0CPTID,C0CSPC,C0CSDT,C0CEDT,C0CR
     139        ; SET UP FOR LAB API CALL
     140        S C0CPTID=$$SSN^C0CDPT(DFN) ; GET THE SSN FOR THIS PATIENT
     141        I C0CPTID="" D  Q  ; NO SSN, COMPLAIN AND QUIT
     142        . W "LAB LOOKUP FAILED, NO SSN",!
     143        . S C0CNSSN=1 ; SET NO SSN FLAG
     144        S C0CSPC="*" ; LOOKING FOR ALL LABS
     145        ;I $D(^TMP("C0CCCR","RPMS")) D  ; RUNNING RPMS
     146        ;. D DT^DILF(,"T-365",.C0CSDT) ; START DATE ONE YEAR AGO TO LIMIT VOLUME
     147        ;E  D DT^DILF(,"T-5000",.C0CSDT) ; START DATE LONG AGO TO GET EVERYTHING
     148        ;D DT^DILF(,"T",.C0CEDT) ; END DATE TODAY
     149        S C0CLLMT=$$GET^C0CPARMS("LABLIMIT") ; GET THE LIMIT PARM
     150        S C0CLSTRT=$$GET^C0CPARMS("LABSTART") ; GET START PARM
     151        D DT^DILF(,C0CLLMT,.C0CSDT) ;
     152        W "LAB LIMIT: ",C0CLLMT,!
     153        D DT^DILF(,C0CLSTRT,.C0CEDT) ; END DATE TODAY - IMPLEMENT END DATE PARM
     154        S C0CR=$$LAB^C0CLA7Q(C0CPTID,C0CSDT,C0CEDT,C0CSPC,C0CSPC) ; CALL LAB LOOKUP
     155        Q
     156        ;
     157LIST    ; LIST THE HL7 MESSAGE; ALSO, EXTRACT THE RESULT VARIABLES TO C0CLB
     158        ;
     159        ; N C0CI,C0CJ,C0COBT,C0CHB,C0CVAR
     160        I '$D(C0CLB) S C0CLB=$NA(^TMP("C0CCCR",$J,"RESULTS")) ; BASE GLB FOR LABS VARS
     161        I '$D(C0CQT) S C0CQT=0
     162        I '$D(DFN) S DFN=1 ; DEFAULT TEST PATIENT
     163        I '$D(^TMP("C0CCCR","LABTBL",0)) D SETTBL ;INITIALIZE LAB TABLE
     164        I ^TMP("C0CCCR","LABTBL",0)'="V3" D SETTBL ;NEED NEWEST VERSION
     165        I '$D(^TMP("HLS",$J,1)) D GHL7 ; GET HL7 MGS IF NOT ALREADY DONE
     166        S C0CTAB=$NA(^TMP("C0CCCR","LABTBL")) ; BASE OF OBX TABLE
     167        S C0CHB=$NA(^TMP("HLS",$J))
     168        S C0CI=""
     169        S @C0CLB@(0)=0 ; INITALIZE RESULTS VARS COUNT
     170        F  S C0CI=$O(@C0CHB@(C0CI)) Q:C0CI=""  D  ; FOR ALL RECORDS IN HL7 MSG
     171        . K C0CVAR,XV ; CLEAR OUT VARIABLE VALUES
     172        . S C0CTYP=$P(@C0CHB@(C0CI),"|",1)
     173        . D LTYP(@C0CHB@(C0CI),C0CTYP,.C0CVAR,C0CQT)
     174        . M XV=C0CVAR ;
     175        . I C0CTYP="OBR" D  ; BEGINNING OF NEW SECTION
     176        . . S @C0CLB@(0)=@C0CLB@(0)+1 ; INCREMENT COUNT
     177        . . S C0CLI=@C0CLB@(0) ; INDEX FOR THIS RESULT
     178        . . ;M @C0CLB@(C0CLI)=C0CVAR ; PERSIST THE OBR VARS
     179        . . S XV("RESULTOBJECTID")="RESULT_"_C0CLI
     180        . . S C0CX1=XV("RESULTSOURCEACTORID") ; SOURCE FROM OBR
     181        . . S XV("RESULTSOURCEACTORID")="ACTORPROVIDER_"_$P($P(C0CX1,"^",1),"-",1)
     182        . . S C0CX1=XV("RESULTASSESSMENTDATETIME") ;DATE TIME IN HL7 FORMAT
     183        . . S C0CX2=$$HL7TFM^XLFDT(C0CX1,"L") ;FM DT LOCAL
     184        . . S XV("RESULTASSESSMENTDATETIME")=$$FMDTOUTC^C0CUTIL(C0CX2,"DT") ;UTC TIME
     185        . . M @C0CLB@(C0CLI)=XV ; PERSIST THE OBR VARS
     186        . . S C0CLOBX=0 ; MARK THE BEGINNING OF A NEW SECTION
     187        . I C0CTYP="OBX" D  ; SPECIAL CASE FOR OBX3
     188        . . ; RESULTTESTCODEVALUE
     189        . . ; RESULTTESTDESCRIPTIONTEXT
     190        . . I C0CVAR("C3")="LN" D  ; PRIMARY CODE IS LOINC
     191        . . . S XV("RESULTTESTCODEVALUE")=C0CVAR("C1") ; THE LOINC CODE VALUE
     192        . . . S XV("RESULTTESTCODINGSYSTEM")="LOINC" ; DISPLAY NAME FOR LOINC
     193        . . . ;S XV("RESULTTESTDESCRIPTIONTEXT")=C0CVAR("C2") ; DESC TXT
     194        . . . S XV("RESULTTESTDESCRIPTIONTEXT")=C0CVAR("C2")_" LOINC: "_C0CVAR("C1")
     195        . . E  I C0CVAR("C6")="LN" D  ; SECONDARY CODE IS LOINC
     196        . . . S XV("RESULTTESTCODEVALUE")=C0CVAR("C4") ; THE LOINC CODE VALUE
     197        . . . S XV("RESULTTESTCODINGSYSTEM")="LOINC" ; DISPLAY NAME FOR LOINC
     198        . . . S XV("RESULTTESTDESCRIPTIONTEXT")=C0CVAR("C5") ; DESCRIPTION TEXT
     199        . . E  I C0CVAR("C6")'="" D  ; NO LOINC CODES, USE SECONDARY IF PRESENT
     200        . . . S XV("RESULTTESTCODEVALUE")=C0CVAR("C4") ; SECONDARY CODE VALUE
     201        . . . S XV("RESULTTESTCODINGSYSTEM")=C0CVAR("C6") ; SECONDARY CODE NAME
     202        . . . S XV("RESULTTESTDESCRIPTIONTEXT")=C0CVAR("C5") ; SECONDARY TEXT
     203        . . E  D  ; NO SECONDARY, USE PRIMARY
     204        . . . S XV("RESULTTESTCODEVALUE")=C0CVAR("C1") ; PRIMARY CODE VALUE
     205        . . . S XV("RESULTTESTCODINGSYSTEM")=C0CVAR("C3") ; PRIMARY DISPLAY NAME
     206        . . . S XV("RESULTTESTDESCRIPTIONTEXT")=C0CVAR("C2") ; USE PRIMARY TEXT
     207        . . N C0CZG S C0CZG=XV("RESULTTESTNORMALDESCTEXT") ;
     208        . . ; mod to remove local XML escaping rely upon MAP^C0CXPATH
     209        . . ;S XV("RESULTTESTNORMALDESCTEXT")=$$SYMENC^MXMLUTL(C0CZG) ;ESCAPE
     210        . . S XV("RESULTTESTNORMALDESCTEXT")=C0CZG
     211        . . S C0CZG=XV("RESULTTESTVALUE")
     212         . . ; mod to remove local XML escaping rely upon MAP^C0CXPATH
     213        . . ;S XV("RESULTTESTVALUE")=$$SYMENC^MXMLUTL(C0CZG) ;ESCAPE
     214        . . S XV("RESULTTESTVALUE")=C0CZG
     215        . I C0CTYP="OBX" D  ; PROCESS TEST RESULTS
     216        . . I C0CLOBX=0 D  ; FIRST TEST RESULT FOR THIS SECTION
     217        . . . S C0CLB2=$NA(@C0CLB@(C0CLI,"M","TEST")) ; INDENT FOR TEST RESULTS
     218        . . S C0CLOBX=C0CLOBX+1 ; INCREMENT TEST COUNT
     219        . . S @C0CLB2@(0)=C0CLOBX ; STORE THE TEST COUNT
     220        . . S XV("RESULTTESTOBJECTID")="RESULTTEST_"_C0CLI_"_"_C0CLOBX
     221        . . S C0CX1=XV("RESULTTESTSOURCEACTORID") ; TEST SOURCE
     222        . . S C0CX2=$P($P(C0CX1,"^",1),"-",1) ; PULL OUT STATION NUMBER
     223        . . S XV("RESULTTESTSOURCEACTORID")="ACTORORGANIZATION_"_C0CX2
     224        . . S XV("RESULTTESTNORMALSOURCEACTORID")=XV("RESULTTESTSOURCEACTORID")
     225        . . S C0CX1=XV("RESULTTESTDATETIME") ;DATE TIME IN HL7 FORMAT
     226        . . S C0CX2=$$HL7TFM^XLFDT(C0CX1,"L") ;FM DT LOCAL
     227        . . S XV("RESULTTESTDATETIME")=$$FMDTOUTC^C0CUTIL(C0CX2,"DT") ;UTC TIME
     228        . . ; I 'C0CQT ZWR XV
     229        . . M @C0CLB2@(C0CLOBX)=XV ; PERSIST THE TEST RESULT VARIABLES
     230        . I 'C0CQT D  ;
     231        . . W C0CI," ",C0CTYP,!
     232        . ; S C0CI=$O(@C0CHB@(C0CI))
     233        ;K ^TMP("C0CRIM","VARS",DFN,"RESULTS")
     234        ;M ^TMP("C0CRIM","VARS",DFN,"RESULTS")=@C0CLB
     235        Q
     236LTYP(OSEG,OTYP,OVARA,OC0CQT)    ;
     237        S OTAB=$NA(@C0CTAB@(OTYP)) ; TABLE FOR SEGMENT TYPE
     238        I '$D(OC0CQT) S C0CQT=0 ; NOT C0CQT IS DEFAULT
     239        E  S C0CQT=OC0CQT ; ACCEPT C0CQT FLAG
     240        I 1 D  ; FOR HL7 SEGMENT TYPE
     241        . S OI="" ; INDEX INTO FIELDS IN SEG
     242        . F  S OI=$O(@OTAB@(OI)) Q:OI=""  D  ; FOR EACH FIELD OF THE SEGMENT
     243        . . S OTI=$P(@OTAB@(OI),"^",1) ; TABLE INDEX
     244        . . S OVAR=$P(@OTAB@(OI),"^",4) ; CCR VARIABLE IF DEFINED
     245        . . S OV=$P(OSEG,"|",OTI+1) ; PULL OUT VALUE
     246        . . I $P(OI,";",2)'="" D  ; THIS IS DEFINING A SUB-VALUE
     247        . . . S OI2=$P(OTI,";",2) ; THE SUB-INDEX
     248        . . . S OV=$P(OV,"^",OI2) ; PULL OUT SUB-VALUE
     249        . . I OVAR'="" S OVARA(OVAR)=OV ; PASS BACK VARIABLE AND VALUE
     250        . . I 'C0CQT D  ; PRINT OUTPUT IF C0CQT IS FALSE
     251        . . . I OV'="" W OI_": "_$P(@OTAB@(OI),"^",3),": ",OVAR,": ",OV,!
     252        Q
     253LOBX    ;
     254        Q
     255        ;
     256OUT(DFN)        ; WRITE OUT A CCR THAT HAS JUST BEEN PROCESSED (FOR TESTING)
     257        N GA,GF,GD
     258        S GA=$NA(^TMP("C0CCCR",$J,DFN,"CCR",1))
     259        S GF="RPMS_CCR_"_DFN_"_"_DT_".xml"
     260        S GD=^TMP("C0CCCR","ODIR")
     261        W $$OUTPUT^C0CXPATH(GA,GF,GD)
     262        Q
     263        ;
     264SETTBL  ;
     265        K X ; CLEAR X
     266        S X("PID","PID1")="1^00104^Set ID - Patient ID"
     267        S X("PID","PID2")="2^00105^Patient ID (External ID)"
     268        S X("PID","PID3")="3^00106^Patient ID (Internal ID)"
     269        S X("PID","PID4")="4^00107^Alternate Patient ID"
     270        S X("PID","PID5")="5^00108^Patient's Name"
     271        S X("PID","PID6")="6^00109^Mother's Maiden Name"
     272        S X("PID","PID7")="7^00110^Date of Birth"
     273        S X("PID","PID8")="8^00111^Sex"
     274        S X("PID","PID9")="9^00112^Patient Alias"
     275        S X("PID","PID10")="10^00113^Race"
     276        S X("PID","PID11")="11^00114^Patient Address"
     277        S X("PID","PID12")="12^00115^County Code"
     278        S X("PID","PID13")="13^00116^Phone Number - Home"
     279        S X("PID","PID14")="14^00117^Phone Number - Business"
     280        S X("PID","PID15")="15^00118^Language - Patient"
     281        S X("PID","PID16")="16^00119^Marital Status"
     282        S X("PID","PID17")="17^00120^Religion"
     283        S X("PID","PID18")="18^00121^Patient Account Number"
     284        S X("PID","PID19")="19^00122^SSN Number - Patient"
     285        S X("PID","PID20")="20^00123^Drivers License - Patient"
     286        S X("PID","PID21")="21^00124^Mother's Identifier"
     287        S X("PID","PID22")="22^00125^Ethnic Group"
     288        S X("PID","PID23")="23^00126^Birth Place"
     289        S X("PID","PID24")="24^00127^Multiple Birth Indicator"
     290        S X("PID","PID25")="25^00128^Birth Order"
     291        S X("PID","PID26")="26^00129^Citizenship"
     292        S X("PID","PID27")="27^00130^Veteran.s Military Status"
     293        S X("PID","PID28")="28^00739^Nationality"
     294        S X("PID","PID29")="29^00740^Patient Death Date/Time"
     295        S X("PID","PID30")="30^00741^Patient Death Indicator"
     296        S X("NTE","NTE1")="1^00573^Set ID - NTE"
     297        S X("NTE","NTE2")="2^00574^Source of Comment"
     298        S X("NTE","NTE3")="3^00575^Comment"
     299        S X("ORC","ORC1")="1^00215^Order Control"
     300        S X("ORC","ORC2")="2^00216^Placer Order Number"
     301        S X("ORC","ORC3")="3^00217^Filler Order Number"
     302        S X("ORC","ORC4")="4^00218^Placer Order Number"
     303        S X("ORC","ORC5")="5^00219^Order Status"
     304        S X("ORC","ORC6")="6^00220^Response Flag"
     305        S X("ORC","ORC7")="7^00221^Quantity/Timing"
     306        S X("ORC","ORC8")="8^00222^Parent"
     307        S X("ORC","ORC9")="9^00223^Date/Time of Transaction"
     308        S X("ORC","ORC10")="10^00224^Entered By"
     309        S X("ORC","ORC11")="11^00225^Verified By"
     310        S X("ORC","ORC12")="12^00226^Ordering Provider"
     311        S X("ORC","ORC13")="13^00227^Enterer's Location"
     312        S X("ORC","ORC14")="14^00228^Call Back Phone Number"
     313        S X("ORC","ORC15")="15^00229^Order Effective Date/Time"
     314        S X("ORC","ORC16")="16^00230^Order Control Code Reason"
     315        S X("ORC","ORC17")="17^00231^Entering Organization"
     316        S X("ORC","ORC18")="18^00232^Entering Device"
     317        S X("ORC","ORC19")="19^00233^Action By"
     318        S X("OBR","OBR1")="1^00237^Set ID - Observation Request"
     319        S X("OBR","OBR2")="2^00216^Placer Order Number"
     320        S X("OBR","OBR3")="3^00217^Filler Order Number"
     321        S X("OBR","OBR4")="4^00238^Universal Service ID"
     322        S X("OBR","OBR4;LOINC")="4;1^00238^Universal Service ID - LOINC^RESULTCODE"
     323        S X("OBR","OBR4;DESC")="4;2^00238^Universal Service ID - DESC^RESULTDESCRIPTIONTEXT"
     324        S X("OBR","OBR4;VACODE")="4;3^00238^Universal Service ID - VACODE^RESULTCODINGSYSTEM"
     325        S X("OBR","OBR5")="5^00239^Priority"
     326        S X("OBR","OBR6")="6^00240^Requested Date/Time"
     327        S X("OBR","OBR7")="7^00241^Observation Date/Time^RESULTASSESSMENTDATETIME"
     328        S X("OBR","OBR8")="8^00242^Observation End Date/Time"
     329        S X("OBR","OBR9")="9^00243^Collection Volume"
     330        S X("OBR","OBR10")="10^00244^Collector Identifier"
     331        S X("OBR","OBR11")="11^00245^Specimen Action Code"
     332        S X("OBR","OBR12")="12^00246^Danger Code"
     333        S X("OBR","OBR13")="13^00247^Relevant Clinical Info."
     334        S X("OBR","OBR14")="14^00248^Specimen Rcv'd. Date/Time"
     335        S X("OBR","OBR15")="15^00249^Specimen Source"
     336        S X("OBR","OBR16")="16^00226^Ordering Provider XCN^RESULTSOURCEACTORID"
     337        S X("OBR","OBR17")="17^00250^Order Callback Phone Number"
     338        S X("OBR","OBR18")="18^00251^Placers Field 1"
     339        S X("OBR","OBR19")="19^00252^Placers Field 2"
     340        S X("OBR","OBR20")="20^00253^Filler Field 1"
     341        S X("OBR","OBR21")="21^00254^Filler Field 2"
     342        S X("OBR","OBR22")="22^00255^Results Rpt./Status Change"
     343        S X("OBR","OBR23")="23^00256^Charge to Practice"
     344        S X("OBR","OBR24")="24^00257^Diagnostic Service Sect"
     345        S X("OBR","OBR25")="25^00258^Result Status^RESULTSTATUS"
     346        S X("OBR","OBR26")="26^00259^Parent Result"
     347        S X("OBR","OBR27")="27^00221^Quantity/Timing"
     348        S X("OBR","OBR28")="28^00260^Result Copies to"
     349        S X("OBR","OBR29")="29^00261^Parent Number"
     350        S X("OBR","OBR30")="30^00262^Transportation Mode"
     351        S X("OBR","OBR31")="31^00263^Reason for Study"
     352        S X("OBR","OBR32")="32^00264^Principal Result Interpreter"
     353        S X("OBR","OBR33")="33^00265^Assistant Result Interpreter"
     354        S X("OBR","OBR34")="34^00266^Technician"
     355        S X("OBR","OBR35")="35^00267^Transcriptionist"
     356        S X("OBR","OBR36")="36^00268^Scheduled Date/Time"
     357        S X("OBR","OBR37")="37^01028^Number of Sample Containers"
     358        S X("OBR","OBR38")="38^38^01029 Transport Logistics of Collected Sample"
     359        S X("OBR","OBR39")="39^01030^Collector.s Comment"
     360        S X("OBR","OBR40")="40^01031^Transport Arrangement Responsibility"
     361        S X("OBR","OBR41")="41^01032^Transport Arranged"
     362        S X("OBR","OBR42")="42^01033^Escort Required"
     363        S X("OBR","OBR43")="43^01034^Planned Patient Transport Comment"
     364        S X("OBX","OBX1")="1^00559^Set ID - OBX"
     365        S X("OBX","OBX2")="2^00676^Value Type"
     366        S X("OBX","OBX3")="3^00560^Observation Identifier"
     367        S X("OBX","OBX3;C1")="3;1^00560^Observation Identifier^C1"
     368        S X("OBX","OBX3;C2")="3;2^00560^Observation Identifier^C2"
     369        S X("OBX","OBX3;C3")="3;3^00560^Observation Identifier^C3"
     370        S X("OBX","OBX3;C4")="3;4^00560^Observation Identifier^C4"
     371        S X("OBX","OBX3;C5")="3;5^00560^Observation Identifier^C5"
     372        S X("OBX","OBX3;C6")="3;6^00560^Observation Identifier^C6"
     373        S X("OBX","OBX4")="4^00769^Observation Sub-Id"
     374        S X("OBX","OBX5")="5^00561^Observation Results^RESULTTESTVALUE"
     375        S X("OBX","OBX6")="6^00562^Units^RESULTTESTUNITS"
     376        S X("OBX","OBX7")="7^00563^Reference Range^RESULTTESTNORMALDESCTEXT"
     377        S X("OBX","OBX8")="8^00564^Abnormal Flags^RESULTTESTFLAG"
     378        S X("OBX","OBX9")="9^00639^Probability"
     379        S X("OBX","OBX10")="10^00565^Nature of Abnormal Test"
     380        S X("OBX","OBX11")="11^00566^Observ. Result Status^RESULTTESTSTATUSTEXT"
     381        S X("OBX","OBX12")="12^00567^Date Last Normal Value"
     382        S X("OBX","OBX13")="13^00581^User Defined Access Checks"
     383        S X("OBX","OBX14")="14^00582^Date/Time of Observation^RESULTTESTDATETIME"
     384        S X("OBX","OBX15")="15^00583^Producer.s ID^RESULTTESTSOURCEACTORID"
     385        S X("OBX","OBX16")="16^00584^Responsible Observer"
     386        S X("OBX","OBX17")="17^00936^Observation Method"
     387        K ^TMP("C0CCCR","LABTBL")
     388        M ^TMP("C0CCCR","LABTBL")=X ; SET VALUES IN LAB TBL
     389        S ^TMP("C0CCCR","LABTBL",0)="V3"
     390        Q
     391        ;
Note: See TracChangeset for help on using the changeset viewer.