Changeset 421 for ccr/trunk


Ignore:
Timestamp:
Mar 29, 2009, 4:19:05 PM (16 years ago)
Author:
Sam Habiel
Message:

Refactor of Med Routines, part 1

Location:
ccr/trunk/p
Files:
5 edited

Legend:

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

    r418 r421  
    4141        ;
    4242        ; --Prep variables     
    43         D:$$RPMS^C0CUTIL() RPMS QUIT
    44         D:($$VISTA^C0CUTIL())!($$WV^C0CUTIL()) VISTA QUIT
    45         D EXTRACT^C0CMED1(MEDXML,DFN,MEDOUTXML) ; FIRST EXTRACT OUTPATIENT MEDS
    46         I @MEDOUTXML@(0)>0 D  ; C0CMED FOUND ACTIVE OP MEDS
    47         . W "HAS ACTIVE OP MEDS",!
    48         N PENDINGXML
    49         S PENDINGXML="MEDPENDING" ;NAME FOR ARRAY
    50         D EXTRACT^C0CMED2(MEDXML,DFN,PENDINGXML) ; FIRST EXTRACT OUTPATIENT MEDS
    51         I @PENDINGXML@(0)>0 D  ; C0CMED FOUND PENDING OP MEDS
    52         . I @MEDOUTXML@(0)>0 D  ; IF WE NEED TO COMBINE MEDS
    53         . . D INSINNER^C0CXPATH(MEDOUTXML,PENDINGXML) ;ADD PENDING TO ACTIVE
    54         . E  D CP^C0CXPATH(PENDINGXML,MEDOUTXML) ; NO ACTIVE MEDS, JUST COPY
    55         . W "HAS OP PENDING MEDS",!
    56         N PENDINGXML
    57         S PENDINGXML="MEDPENDING" ;NAME FOR ARRAY
    58         D EXTRACT^C0CMED3(MEDXML,DFN,PENDINGXML) ; FIRST EXTRACT OUTPATIENT MEDS
    59         I @PENDINGXML@(0)>0 D  ; C0CMED FOUND PENDING OP MEDS
    60         . I @MEDOUTXML@(0)>0 D  ; IF WE NEED TO COMBINE MEDS
    61         . . D INSINNER^C0CXPATH(MEDOUTXML,PENDINGXML) ;ADD NON-VA TO MEDS
    62         . E  D CP^C0CXPATH(PENDINGXML,MEDOUTXML) ; NO PREVIOUS MEDS, JUST COPY
     43        I $$RPMS^C0CUTIL() D RPMS QUIT
     44        I ($$VISTA^C0CUTIL())!($$WV^C0CUTIL())!($$OV^C0CUTIL()) D VISTA QUIT
     45        ; Extraction Sections
     46RPMS   
     47        D EXTRACT^C0CMED6(MEDXML,DFN,MEDOUTXML) QUIT
     48VISTA   
     49        N MEDCOUNT S MEDCOUNT=0
     50        N HIST S HIST=$NA(^TMP($J,"MED","HIST")) ; Meds already dispensed
     51        N PEND S PEND=$NA(^TMP($J,"MED","PEND")) ; Pending Meds
     52        N NVA S NVA=$NA(^TMP($J,"MED","NVA")) ; non-VA Meds
     53        ; N IPIV ; Inpatient IV Meds
     54        ; N IPUD ; Inpatient UD Meds
     55        K ^TMP($J,"MED")
     56        D EXTRACT^C0CMED1(MEDXML,DFN,HIST,.MEDCOUNT) ; Historical OP Meds
     57        D EXTRACT^C0CMED2(MEDXML,DFN,PEND,.MEDCOUNT) ; Pending Meds
     58        D EXTRACT^C0CMED3(MEDXML,DFN,NVA,.MEDCOUNT) ; non-VA Meds
     59        I @HIST@(0)>0 D 
     60        . D CP^C0CXPATH(HIST,MEDOUTXML)
     61        . W:$G(DEBUG) "HAS ACTIVE OP MEDS",!
     62        I @PEND@(0)>0 D 
     63        . I @HIST@(0)>0 D INSINNER^C0CXPATH(MEDOUTXML,PEND) ;Add Pending to Historical
     64        . E  D CP^C0CXPATH(PEND,MEDOUTXML) ; No historical, just copy
     65        . W:$G(DEBUG) "HAS OP PENDING MEDS",!
     66        I @NVA@(0)>0 D
     67        . I @HIST@(0)>0!(@PEND@(0)>0) D INSINNER^C0CXPATH(MEDOUTXML,NVA)
     68        . E  D CP^C0CXPATH(NVA,MEDOUTXML)
    6369        . W:$G(DEBUG) "HAS NON-VA MEDS",!
    6470        Q
    65         ; Extraction Sections
    66 RPMS
    67         D EXTRACT^C0CMED6(MEDXML,DFN,MEDOUTXML) QUIT
    68 VISTA
    6971       
  • ccr/trunk/p/C0CMED1.m

    r416 r421  
    1 C0CMED1 ; WV/CCDCCR/SMH - CCR/CCD PROCESSING FOR MEDICATIONS ;01/10/09
    2  ;;0.1;CCDCCR;;JUL 16,2008;
    3  ;;Last modified Sat Jan 10 21:42:27 PST 2009
    4  ; Copyright 2009 WorldVistA.  Licensed under the terms of the GNU
    5  ; General Public License 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  W "NO ENTRY FROM TOP",!
    22  Q
    23  ;
    24 EXTRACT(MINXML,DFN,OUTXML)  ; EXTRACT MEDICATIONS INTO PROVIDED XML TEMPLATE
    25  ;
    26  ; INXML AND OUTXML ARE PASSED BY NAME SO GLOBALS CAN BE USED
    27  ; INXML WILL CONTAIN ONLY THE MEDICATIONS SECTION OF THE OVERALL TEMPLATE
    28  ;
    29  ; MEDS is return array from RPC.
    30  ; MAP is a mapping variable map (store result) for each med
    31  ; MED is holds each array element from MEDS(J), one medicine
    32  ; J is a counter.
    33  ;
    34  ; RX^PSO52API is a Pharmacy Re-Enginnering (PRE) API to get all
    35  ; med data available.
    36  ; http://www.va.gov/vdl/documents/Clinical/Pharm-Outpatient_Pharmacy/phar_1_api_r0807.pdf
    37  ; Output of API is ^TMP($J,"SUBSCRIPT",DFN,RXIENS).
    38  ; D PARY^C0CXPATH(MINXML)
    39  N MEDS,MAP
    40  K ^TMP($J,"CCDCCR") ; PLEASE DON'T KILL ALL OF ^TMP($J) HERE!!!!
    41  D RX^PSO52API(DFN,"CCDCCR")
    42  M MEDS=^TMP($J,"CCDCCR",DFN)
    43  ; @(0) contains the number of meds or -1^NO DATA FOUND
    44  ; If it is -1, we quit.
    45  I $P(MEDS(0),U)=-1 S @OUTXML@(0)=0 QUIT
    46  I DEBUG ZWR MEDS
    47  N RXIEN S RXIEN=0
    48  N MEDCOUNT S MEDCOUNT=0
    49  S MEDMAP=$NA(^TMP("C0CCCR",$J,"MEDMAP")) ; THIS IS THE VARIABLE MAP
    50  S MEDCOUNT=@MEDMAP@(0) ; ACCOUNT FOR MEDS ALREADY IN ARRAY
    51  F  S RXIEN=$O(MEDS(RXIEN)) Q:RXIEN=""  D  ; FOR EACH MEDICATION IN THE LIST
    52  . S MEDCOUNT=MEDCOUNT+1
    53  . I DEBUG W "RXIEN IS ",RXIEN,!
    54  . S MAP=$NA(^TMP("C0CCCR",$J,"MEDMAP",MEDCOUNT))
    55  . ; K @MAP DO NOT KILL HERE, WAS CLEARED IN C0CMED
    56  . S @MEDMAP@(0)=@MEDMAP@(0)+1 ; INCREMENT TOTAL MEDS IN VAR ARRAY
    57  . I DEBUG W "MAP= ",MAP,!
    58  . N MED M MED=MEDS(RXIEN) ; PULL OUT MEDICATION FROM
    59  . S @MAP@("MEDOBJECTID")="MED"_MEDCOUNT ; MEDCOUNT FOR ID
    60  . ; S @MAP@("MEDOBJECTID")="MED"_MED(.01) ;Rx Number
    61  . S @MAP@("MEDISSUEDATETXT")="Issue Date"
    62  . S @MAP@("MEDISSUEDATE")=$$FMDTOUTC^C0CUTIL($P(MED(1),U))
    63  . S @MAP@("MEDLASTFILLDATETXT")="Last Fill Date"
    64  . S @MAP@("MEDLASTFILLDATE")=$$FMDTOUTC^C0CUTIL($P(MED(101),U))
    65  . S @MAP@("MEDRXNOTXT")="Prescription Number"
    66  . S @MAP@("MEDRXNO")=MED(.01)
    67  . S @MAP@("MEDTYPETEXT")="Medication"
    68  . S @MAP@("MEDDETAILUNADORNED")=""  ; Leave blank, field has its uses
    69  . S @MAP@("MEDSTATUSTEXT")=$P(MED(100),U,2)
    70  . S @MAP@("MEDSOURCEACTORID")="ACTORPROVIDER_"_$P(MED(4),U)
    71  . S @MAP@("MEDPRODUCTNAMETEXT")=$P(MED(6),U,2)
    72  . ; 12/30/08: I will be using RxNorm for coding...
    73  . ; 176.001 is the file for Concepts; 176.003 is the file for
    74  . ; sources (i.e. for RxNorm Version)
    75  . ;
    76  . ; We need the VUID first for the National Drug File entry first
    77  . ; We get the VUID of the drug, by looking up the VA Product entry
    78  . ; (file 50.68) using the call NDF^PSS50, returned in node 22.
    79  . ; Field 99.99 is the VUID.
    80  . ;
    81  . ; We use the VUID to look up the RxNorm in file 176.001; same idea.
    82  . ; Get IEN first using $$FIND1^DIC, then get the RxNorm number by
    83  . ; $$GET1^DIQ.
    84  . ;
    85  . ; I get the RxNorm name and version from the RxNorm Sources (file
    86  . ; 176.003), by searching for "RXNORM", then get the data.
    87  . N MEDIEN S MEDIEN=$P(MED(6),U)
    88  . D NDF^PSS50(MEDIEN,,,,,"NDF")
    89  . N NDFDATA M NDFDATA=^TMP($J,"NDF",MEDIEN)
    90  . N NDFIEN S NDFIEN=$P(NDFDATA(20),U)
    91  . N VAPROD S VAPROD=$P(NDFDATA(22),U)
    92  . ;
    93  . ; NDFIEN is not necessarily defined; it won't be if the drug
    94  . ; is not matched to the national drug file (e.g. if the drug is
    95  . ; new on the market, compounded, or is a fake drug [blue pill].
    96  . ; To protect against failure, I will put an if/else block
    97  . ;
    98  . N VUID,RXNIEN,RXNORM,SRCIEN,RXNNAME,RXNVER
    99  . I NDFIEN,$D(^C0CRXN) D  ; $Data is for Systems that don't have our RxNorm file yet.
    100  . . S VUID=$$GET1^DIQ(50.68,VAPROD,99.99)
    101  . . S RXNIEN=$$FIND1^DIC(176.001,,,VUID,"VUID")
    102  . . S RXNORM=$$GET1^DIQ(176.001,RXNIEN,.01)
    103  . . S SRCIEN=$$FIND1^DIC(176.003,,"B","RXNORM")
    104  . . S RXNNAME=$$GET1^DIQ(176.003,SRCIEN,6)
    105  . . S RXNVER=$$GET1^DIQ(176.003,SRCIEN,7)
    106  . ;
    107  . E  S (RXNORM,RXNNAME,RXNVER)=""
    108  . ; End if/else block
    109  . S @MAP@("MEDPRODUCTNAMECODEVALUE")=RXNORM
    110  . S @MAP@("MEDPRODUCTNAMECODINGINGSYSTEM")=RXNNAME
    111  . S @MAP@("MEDPRODUCTNAMECODEVERSION")=RXNVER
    112  . ;
    113  . S @MAP@("MEDBRANDNAMETEXT")=MED(6.5)
    114  . D DOSE^PSS50(MEDIEN,,,,,"DOSE")
    115  . N DOSEDATA M DOSEDATA=^TMP($J,"DOSE",MEDIEN)
    116  . S @MAP@("MEDSTRENGTHVALUE")=DOSEDATA(901)
    117  . S @MAP@("MEDSTRENGTHUNIT")=$P(DOSEDATA(902),U,2)
    118  . ; Units, concentration, etc, come from another call
    119  . ; $$CPRS^PSNAPIS which returns dosage-form^va class^strengh^unit
    120  . ; This call takes nodes 1 and 3 of ^PSDRUG(D0,"ND") as parameters
    121  . ; NDF Entry IEN, and VA Product IEN
    122  . ; These can be obtained using NDF^PSS50 (IEN,,,,,"SUBSCRIPT")
    123  . ; These have been collected above.
    124  . N CONCDATA
    125  . ; If a drug was not matched to NDF, then the NDFIEN is gonna be ""
    126  . ; and this will crash the call. So...
    127  . I NDFIEN="" S CONCDATA=""
    128  . E  S CONCDATA=$$CPRS^PSNAPIS(NDFIEN,VAPROD)
    129  . S @MAP@("MEDFORMTEXT")=$P(CONCDATA,U,1)
    130  . S @MAP@("MEDCONCVALUE")=$P(CONCDATA,U,3)
    131  . S @MAP@("MEDCONCUNIT")=$P(CONCDATA,U,4)
    132  . S @MAP@("MEDQUANTITYVALUE")=MED(7)
    133  . ; Oddly, there is no easy place to find the dispense unit.
    134  . ; It's not included in the original call, so we have to go to the drug file.
    135  . ; That would be DATA^PSS50(IEN,,,,,"SUBSCRIPT")
    136  . ; Node 14.5 is the Dispense Unit
    137  . D DATA^PSS50(MEDIEN,,,,,"QTY")
    138  . N QTYDATA M QTYDATA=^TMP($J,"QTY",MEDIEN)
    139  . S @MAP@("MEDQUANTITYUNIT")=QTYDATA(14.5)
    140  . ;
    141  . ; --- START OF DIRECTIONS ---
    142  . ; Sig data not in any API :-(  Oh yes, you can get the whole thing, but...
    143  . ; we want the compoenents.
    144  . ; It's in node 6 of ^PSRX(IEN)
    145  . ; So, here we go again
    146  . ; ^PSRX(D0,6,D1,0)= (#.01) DOSAGE ORDERED [1F] ^ (#1) DISPENSE UNITS PER DOSE
    147  . ; ==>[2N] ^ (#2) UNITS [3P:50.607] ^ (#3) NOUN [4F] ^ (#4)
    148  . ; ==>DURATION [5F] ^ (#5) CONJUNCTION [6S] ^ (#6) ROUTE
    149  . ; ==>[7P:51.2] ^ (#7) SCHEDULE [8F] ^ (#8) VERB [9F] ^
    150  . ;
    151  . N DIRNUM S DIRNUM=0 ; Sigline number
    152  . S DIRCNT=0 ; COUNT OF MULTIPLE DIRECTIONS
    153  . F  S DIRNUM=$O(^PSRX(RXIEN,6,DIRNUM)) Q:DIRNUM=""  D
    154  . . S DIRCNT=DIRCNT+1 ; INCREMENT DIRECTIONS COUNT
    155  . . S @MAP@("M","DIRECTIONS",DIRCNT,"MEDDIRECTIONDESCRIPTIONTEXT")=""  ; This is reserved for systems not able to generate the sig in components.
    156  . . S @MAP@("M","DIRECTIONS",DIRCNT,"MEDDOSEINDICATOR")="1"  ; means that we are specifying it. See E2369-05.
    157  . . N SIGDATA S SIGDATA=^PSRX(RXIEN,6,DIRNUM,0)
    158  . . S @MAP@("M","DIRECTIONS",DIRCNT,"MEDDELIVERYMETHOD")=$P(SIGDATA,U,9)
    159  . . S @MAP@("M","DIRECTIONS",DIRCNT,"MEDDOSEVALUE")=$P(SIGDATA,U,1)
    160  . . S @MAP@("M","DIRECTIONS",DIRCNT,"MEDDOSEUNIT")=@MAP@("MEDCONCUNIT")
    161  . . S @MAP@("M","DIRECTIONS",DIRCNT,"MEDRATEVALUE")=""  ; For inpatient
    162  . . S @MAP@("M","DIRECTIONS",DIRCNT,"MEDRATEUNIT")=""  ; For inpatient
    163  . . S @MAP@("M","DIRECTIONS",DIRCNT,"MEDVEHICLETEXT")=""  ; For inpatient
    164  . . S @MAP@("M","DIRECTIONS",DIRCNT,"MEDDIRECTIONROUTETEXT")=$$GET1^DIQ(51.2,$P(SIGDATA,U,7),.01)
    165  . . S @MAP@("M","DIRECTIONS",DIRCNT,"MEDFREQUENCYVALUE")=$P(SIGDATA,U,8)
    166  . . ; Invervals... again another call.
    167  . . ; In the wisdom of the original programmers, the schedule is a free text field
    168  . . ; However, it gets translated by a call to the administration schedule file
    169  . . ; to see if that schedule exists.
    170  . . ; That's the same thing I am going to do.
    171  . . ; The call is AP^PSS51P1(PSSPP,PSSFT,PSSWDIEN,PSSSTPY,LIST,PSSFREQ).
    172  . . ; PSSPP is "PSJ" (for some reason, schedules are stored as PSJ, not PSO--
    173  . . ; I looked), PSSFT is the name, and list is the ^TMP name to store the data in.
    174  . . ; So...
    175  . . D AP^PSS51P1("PSJ",$P(SIGDATA,U,8),,,"SCHEDULE")
    176  . . N SCHEDATA M SCHEDATA=^TMP($J,"SCHEDULE")
    177  . . N INTERVAL
    178  . . I $P(SCHEDATA(0),U)=-1 S INTERVAL=""
    179  . . E  D
    180  . . . N SUB S SUB=$O(SCHEDATA(0))
    181  . . . S INTERVAL=SCHEDATA(SUB,2)
    182  . . S @MAP@("M","DIRECTIONS",DIRCNT,"MEDINTERVALVALUE")=INTERVAL
    183  . . S @MAP@("M","DIRECTIONS",DIRCNT,"MEDINTERVALUNIT")="Minute"
    184  . . S @MAP@("M","DIRECTIONS",DIRCNT,"MEDDURATIONVALUE")=$P(SIGDATA,U,5)
    185  . . S @MAP@("M","DIRECTIONS",DIRCNT,"MEDDURATIONUNIT")=""
    186  . . S @MAP@("M","DIRECTIONS",DIRCNT,"MEDPRNFLAG")=$P(SIGDATA,U,8)["PRN"
    187  . . S @MAP@("M","DIRECTIONS",DIRCNT,"MEDPROBLEMOBJECTID")=""
    188  . . S @MAP@("M","DIRECTIONS",DIRCNT,"MEDPROBLEMTYPETXT")=""
    189  . . S @MAP@("M","DIRECTIONS",DIRCNT,"MEDPROBLEMDESCRIPTION")=""
    190  . . S @MAP@("M","DIRECTIONS",DIRCNT,"MEDPROBLEMCODEVALUE")=""
    191  . . S @MAP@("M","DIRECTIONS",DIRCNT,"MEDPROBLEMCODINGSYSTEM")=""
    192  . . S @MAP@("M","DIRECTIONS",DIRCNT,"MEDPROBLEMCODINGVERSION")=""
    193  . . S @MAP@("M","DIRECTIONS",DIRCNT,"MEDPROBLEMSOURCEACTORID")=""
    194  . . S @MAP@("M","DIRECTIONS",DIRCNT,"MEDSTOPINDICATOR")=""
    195  . . S @MAP@("M","DIRECTIONS",DIRCNT,"MEDDIRSEQ")=DIRNUM
    196  . . N DIRMOD S DIRMOD=$P(SIGDATA,U,6)
    197  . . S @MAP@("M","DIRECTIONS",DIRCNT,"MEDMULDIRMOD")=$S(DIRMOD="T":"THEN",DIRMOD="A":"AND",DIRMOD="X":"EXCEPT",1:"")
    198  . ;
    199  . ; --- END OF DIRECTIONS ---
    200  . ;
    201  . ; ^PSRX(22,"INS1",1,0)="FOR BLOOD PRESSURE"
    202  . S @MAP@("MEDPTINSTRUCTIONS")=$G(^PSRX(RXIEN,"INS1",1,0))
    203  . ; ^PSRX(22,"PRC",1,0)="Pharmacist: you must obey my command"
    204  . S @MAP@("MEDFULLFILLMENTINSTRUCTIONS")=$G(^PSRX(RXIEN,"PRC",1,0))
    205  . S @MAP@("MEDRFNO")=MED(9)
    206  . N RESULT S RESULT=$NA(^TMP("C0CCCR",$J,"MAPPED"))
    207  . K @RESULT
    208  . D MAP^C0CXPATH(MINXML,MAP,RESULT)
    209  . ; D PARY^C0CXPATH(RESULT)
    210  . ; MAPPING DIRECTIONS
    211  . N MEDDIR1,DIRXML1 S DIRXML1="MEDDIR1" ; VARIABLE AND NAME VARIABLE TEMPLATE
    212  . N MEDDIR2,DIRXML2 S DIRXML2="MEDDIR2" ; VARIABLE AND NAME VARIABLE RESULT
    213  . D QUERY^C0CXPATH(MINXML,"//Medications/Medication/Directions",DIRXML1)
    214  . D REPLACE^C0CXPATH(RESULT,"","//Medications/Medication/Directions")
    215  . ; N MDZ1,MDZNA
    216  . I DIRCNT>0 D  ; IF THERE ARE DIRCTIONS
    217  . . F MDZ1=1:1:DIRCNT  D  ; FOR EACH DIRECTION
    218  . . . S MDZNA=$NA(@MAP@("M","DIRECTIONS",MDZ1))
    219  . . . D MAP^C0CXPATH(DIRXML1,MDZNA,DIRXML2)
    220  . . . D INSERT^C0CXPATH(RESULT,DIRXML2,"//Medications/Medication")
    221  . D:MEDCOUNT=1 CP^C0CXPATH(RESULT,OUTXML) ; First one is a copy
    222  . D:MEDCOUNT>1 INSINNER^C0CXPATH(OUTXML,RESULT) ; AFTER THE FIRST, INSERT INNER XML
    223  N MEDTMP,MEDI
    224  D MISSING^C0CXPATH(OUTXML,"MEDTMP") ; SEARCH XML FOR MISSING VARS
    225  I MEDTMP(0)>0 D  ; IF THERE ARE MISSING VARS - MARKED AS @@X@@
    226  . W "MEDICATION MISSING ",!
    227  . F MEDI=1:1:MEDTMP(0) W MEDTMP(MEDI),!
    228  Q
    229  ;
     1C0CMED1 ; WV/CCDCCR/SMH - CCR/CCD PROCESSING FOR MEDICATIONS ;01/10/09
     2        ;;0.1;CCDCCR;;JUL 16,2008;
     3        ;;Last modified Sat Jan 10 21:42:27 PST 2009
     4        ; Copyright 2009 WorldVistA.  Licensed under the terms of the GNU
     5        ; General Public License 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        W "NO ENTRY FROM TOP",!
     22        Q
     23        ;
     24EXTRACT(MINXML,DFN,OUTXML,MEDCOUNT)      ; EXTRACT MEDICATIONS INTO PROVIDED XML TEMPLATE
     25        ;
     26        ; INXML AND OUTXML ARE PASSED BY NAME SO GLOBALS CAN BE USED
     27        ; INXML WILL CONTAIN ONLY THE MEDICATIONS SECTION OF THE OVERALL TEMPLATE
     28        ;
     29        ; MEDS is return array from RPC.
     30        ; MAP is a mapping variable map (store result) for each med
     31        ; MED is holds each array element from MEDS(J), one medicine
     32        ; MEDCOUNT is a counter passed by Reference.
     33        ;
     34        ; RX^PSO52API is a Pharmacy Re-Enginnering (PRE) API to get all
     35        ; med data available.
     36        ; http://www.va.gov/vdl/documents/Clinical/Pharm-Outpatient_Pharmacy/phar_1_api_r0807.pdf
     37        ; Output of API is ^TMP($J,"SUBSCRIPT",DFN,RXIENS).
     38        ; D PARY^C0CXPATH(MINXML)
     39        N MEDS,MAP
     40        K ^TMP($J,"CCDCCR") ; PLEASE DON'T KILL ALL OF ^TMP($J) HERE!!!!
     41        D RX^PSO52API(DFN,"CCDCCR")
     42        M MEDS=^TMP($J,"CCDCCR",DFN)
     43        ; @(0) contains the number of meds or -1^NO DATA FOUND
     44        ; If it is -1, we quit.
     45        I $P(MEDS(0),U)=-1 S @OUTXML@(0)=0 QUIT
     46        ZWRITE:$G(DEBUG) MEDS
     47        N RXIEN S RXIEN=0
     48        F  S RXIEN=$O(MEDS(RXIEN)) Q:RXIEN=""  D  ; FOR EACH MEDICATION IN THE LIST
     49        . S MEDCOUNT=MEDCOUNT+1
     50        . W:$G(DEBUG) "RXIEN IS ",RXIEN,!
     51        . S MAP=$NA(^TMP("C0CCCR",$J,"MEDMAP",MEDCOUNT))
     52        . ; K @MAP DO NOT KILL HERE, WAS CLEARED IN C0CMED
     53        . W:$G(DEBUG) "MAP= ",MAP,!
     54        . N MED M MED=MEDS(RXIEN) ; PULL OUT MEDICATION FROM
     55        . S @MAP@("MEDOBJECTID")="MED"_MEDCOUNT ; MEDCOUNT FOR ID
     56        . ; S @MAP@("MEDOBJECTID")="MED"_MED(.01) ;Rx Number
     57        . S @MAP@("MEDISSUEDATETXT")="Issue Date"
     58        . S @MAP@("MEDISSUEDATE")=$$FMDTOUTC^C0CUTIL($P(MED(1),U))
     59        . S @MAP@("MEDLASTFILLDATETXT")="Last Fill Date"
     60        . S @MAP@("MEDLASTFILLDATE")=$$FMDTOUTC^C0CUTIL($P(MED(101),U))
     61        . S @MAP@("MEDRXNOTXT")="Prescription Number"
     62        . S @MAP@("MEDRXNO")=MED(.01)
     63        . S @MAP@("MEDTYPETEXT")="Medication"
     64        . S @MAP@("MEDDETAILUNADORNED")=""  ; Leave blank, field has its uses
     65        . S @MAP@("MEDSTATUSTEXT")=$P(MED(100),U,2)
     66        . S @MAP@("MEDSOURCEACTORID")="ACTORPROVIDER_"_$P(MED(4),U)
     67        . S @MAP@("MEDPRODUCTNAMETEXT")=$P(MED(6),U,2)
     68        . ; 12/30/08: I will be using RxNorm for coding...
     69        . ; 176.001 is the file for Concepts; 176.003 is the file for
     70        . ; sources (i.e. for RxNorm Version)
     71        . ;
     72        . ; We need the VUID first for the National Drug File entry first
     73        . ; We get the VUID of the drug, by looking up the VA Product entry
     74        . ; (file 50.68) using the call NDF^PSS50, returned in node 22.
     75        . ; Field 99.99 is the VUID.
     76        . ;
     77        . ; We use the VUID to look up the RxNorm in file 176.001; same idea.
     78        . ; Get IEN first using $$FIND1^DIC, then get the RxNorm number by
     79        . ; $$GET1^DIQ.
     80        . ;
     81        . ; I get the RxNorm name and version from the RxNorm Sources (file
     82        . ; 176.003), by searching for "RXNORM", then get the data.
     83        . N MEDIEN S MEDIEN=$P(MED(6),U)
     84        . D NDF^PSS50(MEDIEN,,,,,"NDF")
     85        . N NDFDATA M NDFDATA=^TMP($J,"NDF",MEDIEN)
     86        . N NDFIEN S NDFIEN=$P(NDFDATA(20),U)
     87        . N VAPROD S VAPROD=$P(NDFDATA(22),U)
     88        . ;
     89        . ; NDFIEN is not necessarily defined; it won't be if the drug
     90        . ; is not matched to the national drug file (e.g. if the drug is
     91        . ; new on the market, compounded, or is a fake drug [blue pill].
     92        . ; To protect against failure, I will put an if/else block
     93        . ;
     94        . N VUID,RXNIEN,RXNORM,SRCIEN,RXNNAME,RXNVER
     95        . I NDFIEN,$D(^C0CRXN) D  ; $Data is for Systems that don't have our RxNorm file yet.
     96        . . S VUID=$$GET1^DIQ(50.68,VAPROD,99.99)
     97        . . S RXNIEN=$$FIND1^DIC(176.001,,,VUID,"VUID")
     98        . . S RXNORM=$$GET1^DIQ(176.001,RXNIEN,.01)
     99        . . S SRCIEN=$$FIND1^DIC(176.003,,"B","RXNORM")
     100        . . S RXNNAME=$$GET1^DIQ(176.003,SRCIEN,6)
     101        . . S RXNVER=$$GET1^DIQ(176.003,SRCIEN,7)
     102        . ;
     103        . E  S (RXNORM,RXNNAME,RXNVER)=""
     104        . ; End if/else block
     105        . S @MAP@("MEDPRODUCTNAMECODEVALUE")=RXNORM
     106        . S @MAP@("MEDPRODUCTNAMECODINGINGSYSTEM")=RXNNAME
     107        . S @MAP@("MEDPRODUCTNAMECODEVERSION")=RXNVER
     108        . ;
     109        . S @MAP@("MEDBRANDNAMETEXT")=MED(6.5)
     110        . D DOSE^PSS50(MEDIEN,,,,,"DOSE")
     111        . N DOSEDATA M DOSEDATA=^TMP($J,"DOSE",MEDIEN)
     112        . S @MAP@("MEDSTRENGTHVALUE")=DOSEDATA(901)
     113        . S @MAP@("MEDSTRENGTHUNIT")=$P(DOSEDATA(902),U,2)
     114        . ; Units, concentration, etc, come from another call
     115        . ; $$CPRS^PSNAPIS which returns dosage-form^va class^strengh^unit
     116        . ; This call takes nodes 1 and 3 of ^PSDRUG(D0,"ND") as parameters
     117        . ; NDF Entry IEN, and VA Product IEN
     118        . ; These can be obtained using NDF^PSS50 (IEN,,,,,"SUBSCRIPT")
     119        . ; These have been collected above.
     120        . N CONCDATA
     121        . ; If a drug was not matched to NDF, then the NDFIEN is gonna be ""
     122        . ; and this will crash the call. So...
     123        . I NDFIEN="" S CONCDATA=""
     124        . E  S CONCDATA=$$CPRS^PSNAPIS(NDFIEN,VAPROD)
     125        . S @MAP@("MEDFORMTEXT")=$P(CONCDATA,U,1)
     126        . S @MAP@("MEDCONCVALUE")=$P(CONCDATA,U,3)
     127        . S @MAP@("MEDCONCUNIT")=$P(CONCDATA,U,4)
     128        . S @MAP@("MEDQUANTITYVALUE")=MED(7)
     129        . ; Oddly, there is no easy place to find the dispense unit.
     130        . ; It's not included in the original call, so we have to go to the drug file.
     131        . ; That would be DATA^PSS50(IEN,,,,,"SUBSCRIPT")
     132        . ; Node 14.5 is the Dispense Unit
     133        . D DATA^PSS50(MEDIEN,,,,,"QTY")
     134        . N QTYDATA M QTYDATA=^TMP($J,"QTY",MEDIEN)
     135        . S @MAP@("MEDQUANTITYUNIT")=QTYDATA(14.5)
     136        . ;
     137        . ; --- START OF DIRECTIONS ---
     138        . ; Sig data not in any API :-(  Oh yes, you can get the whole thing, but...
     139        . ; we want the compoenents.
     140        . ; It's in node 6 of ^PSRX(IEN)
     141        . ; So, here we go again
     142        . ; ^PSRX(D0,6,D1,0)= (#.01) DOSAGE ORDERED [1F] ^ (#1) DISPENSE UNITS PER DOSE
     143        . ; ==>[2N] ^ (#2) UNITS [3P:50.607] ^ (#3) NOUN [4F] ^ (#4)
     144        . ; ==>DURATION [5F] ^ (#5) CONJUNCTION [6S] ^ (#6) ROUTE
     145        . ; ==>[7P:51.2] ^ (#7) SCHEDULE [8F] ^ (#8) VERB [9F] ^
     146        . ;
     147        . N DIRNUM S DIRNUM=0 ; Sigline number
     148        . S DIRCNT=0 ; COUNT OF MULTIPLE DIRECTIONS
     149        . F  S DIRNUM=$O(^PSRX(RXIEN,6,DIRNUM)) Q:DIRNUM=""  D
     150        . . S DIRCNT=DIRCNT+1 ; INCREMENT DIRECTIONS COUNT
     151        . . S @MAP@("M","DIRECTIONS",DIRCNT,"MEDDIRECTIONDESCRIPTIONTEXT")=""  ; This is reserved for systems not able to generate the sig in components.
     152        . . S @MAP@("M","DIRECTIONS",DIRCNT,"MEDDOSEINDICATOR")="1"  ; means that we are specifying it. See E2369-05.
     153        . . N SIGDATA S SIGDATA=^PSRX(RXIEN,6,DIRNUM,0)
     154        . . S @MAP@("M","DIRECTIONS",DIRCNT,"MEDDELIVERYMETHOD")=$P(SIGDATA,U,9)
     155        . . S @MAP@("M","DIRECTIONS",DIRCNT,"MEDDOSEVALUE")=$P(SIGDATA,U,1)
     156        . . S @MAP@("M","DIRECTIONS",DIRCNT,"MEDDOSEUNIT")=@MAP@("MEDCONCUNIT")
     157        . . S @MAP@("M","DIRECTIONS",DIRCNT,"MEDRATEVALUE")=""  ; For inpatient
     158        . . S @MAP@("M","DIRECTIONS",DIRCNT,"MEDRATEUNIT")=""  ; For inpatient
     159        . . S @MAP@("M","DIRECTIONS",DIRCNT,"MEDVEHICLETEXT")=""  ; For inpatient
     160        . . S @MAP@("M","DIRECTIONS",DIRCNT,"MEDDIRECTIONROUTETEXT")=$$GET1^DIQ(51.2,$P(SIGDATA,U,7),.01)
     161        . . S @MAP@("M","DIRECTIONS",DIRCNT,"MEDFREQUENCYVALUE")=$P(SIGDATA,U,8)
     162        . . ; Invervals... again another call.
     163        . . ; In the wisdom of the original programmers, the schedule is a free text field
     164        . . ; However, it gets translated by a call to the administration schedule file
     165        . . ; to see if that schedule exists.
     166        . . ; That's the same thing I am going to do.
     167        . . ; The call is AP^PSS51P1(PSSPP,PSSFT,PSSWDIEN,PSSSTPY,LIST,PSSFREQ).
     168        . . ; PSSPP is "PSJ" (for some reason, schedules are stored as PSJ, not PSO--
     169        . . ; I looked), PSSFT is the name, and list is the ^TMP name to store the data in.
     170        . . ; So...
     171        . . D AP^PSS51P1("PSJ",$P(SIGDATA,U,8),,,"SCHEDULE")
     172        . . N SCHEDATA M SCHEDATA=^TMP($J,"SCHEDULE")
     173        . . N INTERVAL
     174        . . I $P(SCHEDATA(0),U)=-1 S INTERVAL=""
     175        . . E  D
     176        . . . N SUB S SUB=$O(SCHEDATA(0))
     177        . . . S INTERVAL=SCHEDATA(SUB,2)
     178        . . S @MAP@("M","DIRECTIONS",DIRCNT,"MEDINTERVALVALUE")=INTERVAL
     179        . . S @MAP@("M","DIRECTIONS",DIRCNT,"MEDINTERVALUNIT")="Minute"
     180        . . S @MAP@("M","DIRECTIONS",DIRCNT,"MEDDURATIONVALUE")=$P(SIGDATA,U,5)
     181        . . S @MAP@("M","DIRECTIONS",DIRCNT,"MEDDURATIONUNIT")=""
     182        . . S @MAP@("M","DIRECTIONS",DIRCNT,"MEDPRNFLAG")=$P(SIGDATA,U,8)["PRN"
     183        . . S @MAP@("M","DIRECTIONS",DIRCNT,"MEDPROBLEMOBJECTID")=""
     184        . . S @MAP@("M","DIRECTIONS",DIRCNT,"MEDPROBLEMTYPETXT")=""
     185        . . S @MAP@("M","DIRECTIONS",DIRCNT,"MEDPROBLEMDESCRIPTION")=""
     186        . . S @MAP@("M","DIRECTIONS",DIRCNT,"MEDPROBLEMCODEVALUE")=""
     187        . . S @MAP@("M","DIRECTIONS",DIRCNT,"MEDPROBLEMCODINGSYSTEM")=""
     188        . . S @MAP@("M","DIRECTIONS",DIRCNT,"MEDPROBLEMCODINGVERSION")=""
     189        . . S @MAP@("M","DIRECTIONS",DIRCNT,"MEDPROBLEMSOURCEACTORID")=""
     190        . . S @MAP@("M","DIRECTIONS",DIRCNT,"MEDSTOPINDICATOR")=""
     191        . . S @MAP@("M","DIRECTIONS",DIRCNT,"MEDDIRSEQ")=DIRNUM
     192        . . N DIRMOD S DIRMOD=$P(SIGDATA,U,6)
     193        . . S @MAP@("M","DIRECTIONS",DIRCNT,"MEDMULDIRMOD")=$S(DIRMOD="T":"THEN",DIRMOD="A":"AND",DIRMOD="X":"EXCEPT",1:"")
     194        . ;
     195        . ; --- END OF DIRECTIONS ---
     196        . ;
     197        . ; ^PSRX(22,"INS1",1,0)="FOR BLOOD PRESSURE"
     198        . S @MAP@("MEDPTINSTRUCTIONS")=$G(^PSRX(RXIEN,"INS1",1,0))
     199        . ; ^PSRX(22,"PRC",1,0)="Pharmacist: you must obey my command"
     200        . S @MAP@("MEDFULLFILLMENTINSTRUCTIONS")=$G(^PSRX(RXIEN,"PRC",1,0))
     201        . S @MAP@("MEDRFNO")=MED(9)
     202        . N RESULT S RESULT=$NA(^TMP("C0CCCR",$J,"MAPPED"))
     203        . K @RESULT
     204        . D MAP^C0CXPATH(MINXML,MAP,RESULT)
     205        . ; MAPPING DIRECTIONS
     206        . N DIRXML1 S DIRXML1="MEDDIR1" ; VARIABLE AND NAME VARIABLE TEMPLATE
     207        . N DIRXML2 S DIRXML2="MEDDIR2" ; VARIABLE AND NAME VARIABLE RESULT
     208        . D QUERY^C0CXPATH(MINXML,"//Medications/Medication/Directions",DIRXML1)
     209        . D REPLACE^C0CXPATH(RESULT,"","//Medications/Medication/Directions")
     210        . ; N MDZ1,MDZNA
     211        . I DIRCNT>0 D  ; IF THERE ARE DIRCTIONS
     212        . . F MDZ1=1:1:DIRCNT  D  ; FOR EACH DIRECTION
     213        . . . S MDZNA=$NA(@MAP@("M","DIRECTIONS",MDZ1))
     214        . . . D MAP^C0CXPATH(DIRXML1,MDZNA,DIRXML2)
     215        . . . D INSERT^C0CXPATH(RESULT,DIRXML2,"//Medications/Medication")
     216        . I MEDCOUNT=1 D CP^C0CXPATH(RESULT,OUTXML) ; First one is a copy
     217        . E  D INSINNER^C0CXPATH(OUTXML,RESULT) ; AFTER FIRST, INSERT INNER XML
     218        N MEDTMP,MEDI
     219        D MISSING^C0CXPATH(OUTXML,"MEDTMP") ; SEARCH XML FOR MISSING VARS
     220        I MEDTMP(0)>0 D  ; IF THERE ARE MISSING VARS - MARKED AS @@X@@
     221        . W "MEDICATION MISSING ",!
     222        . F MEDI=1:1:MEDTMP(0) W MEDTMP(MEDI),!
     223        Q
     224        ;
  • ccr/trunk/p/C0CMED2.m

    r416 r421  
    1 C0CMED2 ; WV/CCDCCR/SMH - CCR/CCD Meds - Pending for Vista
    2  ;;0.1;CCDCCR;;JUL 16,2008;
    3  ;;Last Modified Sat Jan 10 21:41:14 PST 2009
    4  ; Copyright 2008 WorldVistA.  Licensed under the terms of the GNU
    5  ; General Public License 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  W "NO ENTRY FROM TOP",!
    22  Q
    23  ;
    24 EXTRACT(MINXML,DFN,OUTXML)           ; EXTRACT MEDICATIONS INTO PROVIDED XML TEMPLATE
    25  ;
    26  ; MINXML is the Input XML Template, passed by name
    27  ; DFN is Patient IEN
    28  ; OUTXML is the resultant XML.
    29  ;
    30  ; MEDS is return array from RPC.
    31  ; MAP is a mapping variable map (store result) for each med
    32  ; MED is holds each array element from MEDS, one medicine
    33  ;
    34  ; PEN^PSO5241 is a Pharmacy Re-Enginnering (PRE) API to get Pending
    35  ; meds data available.
    36  ; http://www.va.gov/vdl/documents/Clinical/Pharm-Outpatient_Pharmacy/phar_1_api_r0807.pdf
    37  ; Output of API is ^TMP($J,"SUBSCRIPT",DFN,RXIENS).
    38  ; File for pending meds is 52.41
    39  ; Unfortuantely, API does not supply us with any useful info beyond
    40  ; the IEN in 52.41, and the Med Name, and route.
    41  ; So, most of the info is going to get pulled from 52.41.
    42  N MEDS,MAP
    43  K ^TMP($J,"CCDCCR") ; PLEASE DON'T KILL ALL OF ^TMP($J) HERE!!!!
    44  D PEN^PSO5241(DFN,"CCDCCR")
    45  M MEDS=^TMP($J,"CCDCCR",DFN)
    46  ; @(0) contains the number of meds or -1^NO DATA FOUND
    47  ; If it is -1, we quit.
    48  I $P(MEDS(0),U)=-1 S @OUTXML@(0)=0 QUIT
    49  I DEBUG ZWR MEDS
    50  N RXIEN S RXIEN=0
    51  N MEDCOUNT S MEDCOUNT=0
    52  N MEDFIRST S MEDFIRST=1 ; FLAG FOR FIRST MED IN THIS SECTION FOR MERGING
    53  S MEDMAP=$NA(^TMP("C0CCCR",$J,"MEDMAP")) ; THIS IS THE VARIABLE MAP
    54  S MEDCOUNT=@MEDMAP@(0) ; ACCOUNT FOR MEDS ALREADY IN ARRAY
    55  F  S RXIEN=$O(MEDS(RXIEN)) Q:RXIEN="B"  D  ; FOR EACH MEDICATION IN THE LIST
    56  . I $$GET1^DIQ(52.41,RXIEN,2,"I")="RF" QUIT  ; Dont' want refill request as a "pending" order
    57  . S MEDCOUNT=MEDCOUNT+1
    58  . I DEBUG W "RXIEN IS ",RXIEN,!
    59  . S MAP=$NA(^TMP("C0CCCR",$J,"MEDMAP",MEDCOUNT))
    60  . ; K @MAP DON'T KILL MAP HERE, IT IS DONE IN C0CMED
    61  . S @MEDMAP@(0)=@MEDMAP@(0)+1 ; INCREMENT TOTAL MEDS IN VAR ARRAY
    62  . I DEBUG W "MAP= ",MAP,!
    63  . N MED M MED=MEDS(RXIEN) ; PULL OUT MEDICATION FROM
    64  . S @MAP@("MEDOBJECTID")="MED_PENDING"_MEDCOUNT ; MEDCOUNT FOR ID
    65  . ; S @MAP@("MEDOBJECTID")="MED_PENDING"_MED(.01) ;Pending IEN
    66  . S @MAP@("MEDISSUEDATETXT")="Issue Date"
    67  . ; Field 6 is "Effective date", and we pull it in timson format w/ I
    68  . S @MAP@("MEDISSUEDATE")=$$FMDTOUTC^C0CUTIL($$GET1^DIQ(52.41,RXIEN,6,"I"),"DT")
    69  . ; Med never filled; next 4 fields are not applicable.
    70  . S @MAP@("MEDLASTFILLDATETXT")=""
    71  . S @MAP@("MEDLASTFILLDATE")=""
    72  . S @MAP@("MEDRXNOTXT")=""
    73  . S @MAP@("MEDRXNO")=""
    74  . S @MAP@("MEDTYPETEXT")="Medication"
    75  . S @MAP@("MEDDETAILUNADORNED")=""  ; Leave blank, field has its uses
    76  . S @MAP@("MEDSTATUSTEXT")="On Hold" ; nearest status for pending meds
    77  . S @MAP@("MEDSOURCEACTORID")="ACTORPROVIDER_"_$$GET1^DIQ(52.41,RXIEN,5,"I")
    78  . S @MAP@("MEDPRODUCTNAMETEXT")=$P(MED(11),U,2)
    79  . ; NDC not supplied in API, but is rather trivial to obtain
    80  . ; MED(11) piece 1 has the IEN of the drug (file 50)
    81  . ; IEN is field 31 in the drug file.
    82  . ;
    83  . ; MEDIEN (node 11 in the returned output) might not necessarily be defined
    84  . ; It is not defined when a dose in not chosen in CPRS. There is a long
    85  . ; series of fields that depend on it. We will use If and Else to deal
    86  . ; with that
    87  . N MEDIEN S MEDIEN=$P(MED(11),U)
    88  . I +MEDIEN>0 D  ; start of if/else block
    89  . . ; 12/30/08: I will be using RxNorm for coding...
    90  . . ; 176.001 is the file for Concepts; 176.003 is the file for
    91  . . ; sources (i.e. for RxNorm Version)
    92  . . ;
    93  . . ; We need the VUID first for the National Drug File entry first
    94  . . ; We get the VUID of the drug, by looking up the VA Product entry
    95  . . ; (file 50.68) using the call NDF^PSS50, returned in node 22.
    96  . . ; Field 99.99 is the VUID.
    97  . . ;
    98  . . ; We use the VUID to look up the RxNorm in file 176.001; same idea.
    99  . . ; Get IEN first using $$FIND1^DIC, then get the RxNorm number by
    100  . . ; $$GET1^DIQ.
    101  . . ;
    102  . . ; I get the RxNorm name and version from the RxNorm Sources (file
    103  . . ; 176.003), by searching for "RXNORM", then get the data.
    104  . . D NDF^PSS50(MEDIEN,,,,,"NDF")
    105  . . N NDFDATA M NDFDATA=^TMP($J,"NDF",MEDIEN)
    106  . . N NDFIEN S NDFIEN=$P(NDFDATA(20),U)
    107  . . N VAPROD S VAPROD=$P(NDFDATA(22),U)
    108  . . ;
    109  . . ; NDFIEN is not necessarily defined; it won't be if the drug
    110  . . ; is not matched to the national drug file (e.g. if the drug is
    111  . . ; new on the market, compounded, or is a fake drug [blue pill].
    112  . . ; To protect against failure, I will put an if/else block
    113  . . N VUID,RXNIEN,RXNORM,SRCIEN,RXNNAME,RXNVER
    114  . . I NDFIEN,$D(^C0CRXN) D  ; $Data is for Systems that don't have our RxNorm file yet.
    115  . . . S VUID=$$GET1^DIQ(50.68,VAPROD,99.99)
    116  . . . S RXNIEN=$$FIND1^DIC(176.001,,,VUID,"VUID")
    117  . . . S RXNORM=$$GET1^DIQ(176.001,RXNIEN,.01)
    118  . . . S SRCIEN=$$FIND1^DIC(176.003,,"B","RXNORM")
    119  . . . S RXNNAME=$$GET1^DIQ(176.003,SRCIEN,6)
    120  . . . S RXNVER=$$GET1^DIQ(176.003,SRCIEN,7)
    121  . . ;
    122  . . E  S (RXNORM,RXNNAME,RXNVER)=""
    123  . . ; End if/else block
    124  . . S @MAP@("MEDPRODUCTNAMECODEVALUE")=RXNORM
    125  . . S @MAP@("MEDPRODUCTNAMECODINGINGSYSTEM")=RXNNAME
    126  . . S @MAP@("MEDPRODUCTNAMECODEVERSION")=RXNVER
    127  . . ;
    128  . . S @MAP@("MEDBRANDNAMETEXT")=""
    129  . . D DOSE^PSS50(MEDIEN,,,,,"DOSE")
    130  . . N DOSEDATA M DOSEDATA=^TMP($J,"DOSE",MEDIEN)
    131  . . S @MAP@("MEDSTRENGTHVALUE")=DOSEDATA(901)
    132  . . S @MAP@("MEDSTRENGTHUNIT")=$P(DOSEDATA(902),U,2)
    133  . . ; Units, concentration, etc, come from another call
    134  . . ; $$CPRS^PSNAPIS which returns dosage-form^va class^strengh^unit
    135  . . ; This call takes nodes 1 and 3 of ^PSDRUG(D0,"ND") as parameters
    136  . . ; NDF Entry IEN, and VA Product Name
    137  . . ; These can be obtained using NDF^PSS50 (IEN,,,,,"SUBSCRIPT")
    138  . . ; Documented in the same manual; executed above.
    139  . . N CONCDATA
    140  . . ; If a drug was not matched to NDF, then the NDFIEN is gonna be ""
    141  . . ; and this will crash the call. So...
    142  . . I NDFIEN="" S CONCDATA=""
    143  . . E  S CONCDATA=$$CPRS^PSNAPIS(NDFIEN,VAPROD)
    144  . . S @MAP@("MEDFORMTEXT")=$P(CONCDATA,U,1)
    145  . . S @MAP@("MEDCONCVALUE")=$P(CONCDATA,U,3)
    146  . . S @MAP@("MEDCONCUNIT")=$P(CONCDATA,U,4)
    147  . . S @MAP@("MEDQUANTITYVALUE")=$$GET1^DIQ(52.41,RXIEN,12)
    148  . . ; Oddly, there is no easy place to find the dispense unit.
    149  . . ; It's not included in the original call, so we have to go to the drug file.
    150  . . ; That would be DATA^PSS50(IEN,,,,,"SUBSCRIPT")
    151  . . ; Node 14.5 is the Dispense Unit
    152  . . D DATA^PSS50(MEDIEN,,,,,"QTY")
    153  . . N QTYDATA M QTYDATA=^TMP($J,"QTY",MEDIEN)
    154  . . S @MAP@("MEDQUANTITYUNIT")=QTYDATA(14.5)
    155  . E  D
    156  . . S @MAP@("MEDPRODUCTNAMECODEVALUE")=""
    157  . . S @MAP@("MEDPRODUCTNAMECODINGINGSYSTEM")=""
    158  . . S @MAP@("MEDPRODUCTNAMECODEVERSION")=""
    159  . . S @MAP@("MEDBRANDNAMETEXT")=""
    160  . . S @MAP@("MEDSTRENGTHVALUE")=""
    161  . . S @MAP@("MEDSTRENGTHUNIT")=""
    162  . . S @MAP@("MEDFORMTEXT")=""
    163  . . S @MAP@("MEDCONCVALUE")=""
    164  . . S @MAP@("MEDCONCUNIT")=""
    165  . . S @MAP@("MEDSIZETEXT")=""
    166  . . S @MAP@("MEDQUANTITYVALUE")=""
    167  . . S @MAP@("MEDQUANTITYUNIT")=""
    168  . ; end of if/else block
    169  . ;
    170  . ; --- START OF DIRECTIONS ---
    171  . ; Sig data is not in any API. We obtain it using the IEN from
    172  . ; the PEN API to file 52.41. It's in field 3, which is a multiple.
    173  . ; I will be using FM call GETS^DIQ(FILE,IENS,FIELD,FLAGS,TARGET_ROOT)
    174  . K FMSIG ; it's passed via the symbol table, so remove any leftovers from last call
    175  . D GETS^DIQ(52.41,RXIEN,"3*",,"FMSIG")
    176  . N FMSIGNUM S FMSIGNUM=0 ; Sigline number in fileman.
    177  . ; FMSIGNUM gets outputted as "IEN,RXIEN,".
    178  . ; DIRNUM will be first piece for IEN.
    179  . ; DIRNUM is the proper Sigline numer.
    180  . ; SIGDATA is the simplfied array. Subscripts are really field numbers
    181  . ; in subfile 52.413.
    182  . N DIRCNT S DIRCNT=0 ; COUNT OF DIRECTIONS
    183  . F  S FMSIGNUM=$O(FMSIG(52.413,FMSIGNUM)) Q:FMSIGNUM=""  D
    184  . . N DIRNUM S DIRNUM=$P(FMSIGNUM,",")
    185  . . S DIRCNT=DIRCNT+1 ; INCREMENT DIRECTIONS COUNT
    186  . . N SIGDATA M SIGDATA=FMSIG(52.413,FMSIGNUM)
    187  . . ; If this is an order for a refill; it's not really a new order; move on to next
    188  . . S @MAP@("M","DIRECTIONS",DIRCNT,"MEDDIRECTIONDESCRIPTIONTEXT")=""  ; This is reserved for systems not able to generate the sig in components.
    189  . . S @MAP@("M","DIRECTIONS",DIRCNT,"MEDDOSEINDICATOR")="1"  ; means that we are specifying it. See E2369-05.
    190  . . S @MAP@("M","DIRECTIONS",DIRCNT,"MEDDELIVERYMETHOD")=SIGDATA(13)
    191  . . S @MAP@("M","DIRECTIONS",DIRCNT,"MEDDOSEVALUE")=SIGDATA(8)
    192  . . S @MAP@("M","DIRECTIONS",DIRCNT,"MEDDOSEUNIT")=@MAP@("MEDCONCUNIT")
    193  . . S @MAP@("M","DIRECTIONS",DIRCNT,"MEDRATEVALUE")=""  ; For inpatient
    194  . . S @MAP@("M","DIRECTIONS",DIRCNT,"MEDRATEUNIT")=""  ; For inpatient
    195  . . S @MAP@("M","DIRECTIONS",DIRCNT,"MEDVEHICLETEXT")=""  ; For inpatient
    196  . . S @MAP@("M","DIRECTIONS",DIRCNT,"MEDDIRECTIONROUTETEXT")=SIGDATA(10)
    197  . . S @MAP@("M","DIRECTIONS",DIRCNT,"MEDFREQUENCYVALUE")=SIGDATA(1)
    198  . . ; Invervals... again another call.
    199  . . ; The schedule is a free text field
    200  . . ; However, it gets translated by a call to the administration
    201  . . ; schedule file to see if that schedule exists.
    202  . . ; That's the same thing I am going to do.
    203  . . ; The call is AP^PSS51P1(PSSPP,PSSFT,PSSWDIEN,PSSSTPY,LIST,PSSFREQ).
    204  . . ; PSSPP is "PSJ" (for some reason, schedules are stored as PSJ, not PSO--
    205  . . ; I looked), PSSFT is the name,
    206  . . ; and list is the ^TMP name to store the data in.
    207  . . ; Also, freqency may have "PRN" in it, so strip that out
    208  . . N FREQ S FREQ=SIGDATA(1)
    209  . . I FREQ["PRN" S FREQ=$E(FREQ,1,$F(FREQ,"PRN")-5) ; 5 for $L("PRN") + 1 + sp
    210  . . D AP^PSS51P1("PSJ",FREQ,,,"SCHEDULE")
    211  . . N SCHEDATA M SCHEDATA=^TMP($J,"SCHEDULE")
    212  . . N INTERVAL
    213  . . I $P(SCHEDATA(0),U)=-1 S INTERVAL=""
    214  . . E  D
    215  . . . N SUB S SUB=$O(SCHEDATA(0))
    216  . . . S INTERVAL=SCHEDATA(SUB,2)
    217  . . S @MAP@("M","DIRECTIONS",DIRCNT,"MEDINTERVALVALUE")=INTERVAL
    218  . . S @MAP@("M","DIRECTIONS",DIRCNT,"MEDINTERVALUNIT")="Minute"
    219  . . ; Duration comes as M2,H2,D2,W2,L2 for 2 minutes,hours,days,weeks,months
    220  . . N DUR S DUR=SIGDATA(2)
    221  . . S @MAP@("M","DIRECTIONS",DIRCNT,"MEDDURATIONVALUE")=$E(DUR,2,$L(DUR))
    222  . . N DURUNIT S DURUNIT=$E(DUR)
    223  . . S @MAP@("M","DIRECTIONS",DIRCNT,"MEDDURATIONUNIT")=$S(DURUNIT="M":"Minutes",DURUNIT="H":"Hours",DURUNIT="D":"Days",DURUNIT="W":"Weeks",DURUNIT="L":"Months",1:"")
    224  . . S @MAP@("M","DIRECTIONS",DIRCNT,"MEDPRNFLAG")=SIGDATA(1)["PRN"
    225  . . S @MAP@("M","DIRECTIONS",DIRCNT,"MEDPROBLEMOBJECTID")=""
    226  . . S @MAP@("M","DIRECTIONS",DIRCNT,"MEDPROBLEMTYPETXT")=""
    227  . . S @MAP@("M","DIRECTIONS",DIRCNT,"MEDPROBLEMDESCRIPTION")=""
    228  . . S @MAP@("M","DIRECTIONS",DIRCNT,"MEDPROBLEMCODEVALUE")=""
    229  . . S @MAP@("M","DIRECTIONS",DIRCNT,"MEDPROBLEMCODINGSYSTEM")=""
    230  . . S @MAP@("M","DIRECTIONS",DIRCNT,"MEDPROBLEMCODINGVERSION")=""
    231  . . S @MAP@("M","DIRECTIONS",DIRCNT,"MEDPROBLEMSOURCEACTORID")=""
    232  . . S @MAP@("M","DIRECTIONS",DIRCNT,"MEDSTOPINDICATOR")="" ; Vista doesn't have that field
    233  . . S @MAP@("M","DIRECTIONS",DIRCNT,"MEDDIRSEQ")=DIRNUM
    234  . . S @MAP@("M","DIRECTIONS",DIRCNT,"MEDMULDIRMOD")=SIGDATA(6)
    235  . ;
    236  . ; --- END OF DIRECTIONS ---
    237  . ;
    238  . ; S @MAP@("MEDPTINSTRUCTIONS","F")="52.41^105"
    239  . S @MAP@("MEDPTINSTRUCTIONS")=$G(^PSRX(RXIEN,"PI",1,0)) ;GPL
    240  . ; W @MAP@("MEDPTINSTRUCTIONS"),!
    241  . ; S @MAP@("MEDFULLFILLMENTINSTRUCTIONS","F")="52.41^9"
    242  . S @MAP@("MEDFULLFILLMENTINSTRUCTIONS")=$G(^PSRX(RXIEN,"SIG1",1,0)) ;GPL
    243  . ; W @MAP@("MEDFULLFILLMENTINSTRUCTIONS"),!
    244  . S @MAP@("MEDRFNO")=$$GET1^DIQ(52.41,RXIEN,13)
    245  . N RESULT S RESULT=$NA(^TMP("C0CCCR",$J,"MAPPED"))
    246  . K @RESULT
    247  . D MAP^C0CXPATH(MINXML,MAP,RESULT)
    248  . ; D PARY^C0CXPATH(RESULT)
    249  . ; MAPPING DIRECTIONS
    250  . N MEDDIR1,DIRXML1 S DIRXML1="MEDDIR1" ; VARIABLE AND NAME VARIABLE TEMPLATE
    251  . N MEDDIR2,DIRXML2 S DIRXML2="MEDDIR2" ; VARIABLE AND NAME VARIABLE RESULT
    252  . D QUERY^C0CXPATH(MINXML,"//Medications/Medication/Directions",DIRXML1)
    253  . D REPLACE^C0CXPATH(RESULT,"","//Medications/Medication/Directions")
    254  . ; N MDZ1,MDZNA
    255  . I DIRCNT>0 D  ; IF THERE ARE DIRCTIONS
    256  . . F MDZ1=1:1:DIRCNT  D  ; FOR EACH DIRECTION
    257  . . . S MDZNA=$NA(@MAP@("M","DIRECTIONS",MDZ1))
    258  . . . D MAP^C0CXPATH(DIRXML1,MDZNA,DIRXML2)
    259  . . . D INSERT^C0CXPATH(RESULT,DIRXML2,"//Medications/Medication")
    260  . I MEDFIRST D  ;
    261  . . S MEDFIRST=0 ; RESET FIRST FLAG
    262  . . D CP^C0CXPATH(RESULT,OUTXML) ; First one is a copy
    263  . D:'MEDFIRST INSINNER^C0CXPATH(OUTXML,RESULT) ; AFTER FIRST, INSERT INNER XML
    264  N MEDTMP,MEDI
    265  D MISSING^C0CXPATH(OUTXML,"MEDTMP") ; SEARCH XML FOR MISSING VARS
    266  I MEDTMP(0)>0 D  ; IF THERE ARE MISSING VARS - MARKED AS @@X@@
    267  . W "MEDICATION MISSING ",!
    268  . F MEDI=1:1:MEDTMP(0) W MEDTMP(MEDI),!
    269  Q
    270  ;
     1C0CMED2 ; WV/CCDCCR/SMH - CCR/CCD Meds - Pending for Vista
     2        ;;0.1;CCDCCR;;JUL 16,2008;
     3        ;;Last Modified Sat Jan 10 21:41:14 PST 2009
     4        ; Copyright 2008 WorldVistA.  Licensed under the terms of the GNU
     5        ; General Public License 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        W "NO ENTRY FROM TOP",!
     22        Q
     23        ;
     24EXTRACT(MINXML,DFN,OUTXML,MEDCOUNT)               ; EXTRACT MEDICATIONS INTO PROVIDED XML TEMPLATE
     25        ;
     26        ; MINXML is the Input XML Template, passed by name
     27        ; DFN is Patient IEN (by Value)
     28        ; OUTXML is the resultant XML (by Name)
     29        ; MEDCOUNT is the current count of extracted meds, passed by Reference
     30        ;
     31        ; MEDS is return array from RPC.
     32        ; MAP is a mapping variable map (store result) for each med
     33        ; MED is holds each array element from MEDS, one medicine
     34        ;
     35        ; PEN^PSO5241 is a Pharmacy Re-Enginnering (PRE) API to get Pending
     36        ; meds data available.
     37        ; http://www.va.gov/vdl/documents/Clinical/Pharm-Outpatient_Pharmacy/phar_1_api_r0807.pdf
     38        ; Output of API is ^TMP($J,"SUBSCRIPT",DFN,RXIENS).
     39        ; File for pending meds is 52.41
     40        ; Unfortuantely, API does not supply us with any useful info beyond
     41        ; the IEN in 52.41, and the Med Name, and route.
     42        ; So, most of the info is going to get pulled from 52.41.
     43        N MEDS,MAP
     44        K ^TMP($J,"CCDCCR") ; PLEASE DON'T KILL ALL OF ^TMP($J) HERE!!!!
     45        D PEN^PSO5241(DFN,"CCDCCR")
     46        M MEDS=^TMP($J,"CCDCCR",DFN)
     47        ; @(0) contains the number of meds or -1^NO DATA FOUND
     48        ; If it is -1, we quit.
     49        I $P(MEDS(0),U)=-1 S @OUTXML@(0)=0 QUIT
     50        ZWRITE:$G(DEBUG) MEDS
     51        N RXIEN S RXIEN=0
     52        N MEDFIRST S MEDFIRST=1 ; FLAG FOR FIRST MED IN THIS SECTION FOR MERGING
     53        F  S RXIEN=$O(MEDS(RXIEN)) Q:RXIEN="B"  D  ; FOR EACH MEDICATION IN THE LIST
     54        . I $$GET1^DIQ(52.41,RXIEN,2,"I")="RF" QUIT  ; Dont' want refill request as a "pending" order
     55        . S MEDCOUNT=MEDCOUNT+1
     56        . I DEBUG W "RXIEN IS ",RXIEN,!
     57        . S MAP=$NA(^TMP("C0CCCR",$J,"MEDMAP",MEDCOUNT))
     58        . ; K @MAP DON'T KILL MAP HERE, IT IS DONE IN C0CMED
     59        . I DEBUG W "MAP= ",MAP,!
     60        . N MED M MED=MEDS(RXIEN) ; PULL OUT MEDICATION FROM
     61        . S @MAP@("MEDOBJECTID")="MED_PENDING"_MEDCOUNT ; MEDCOUNT FOR ID
     62        . ; S @MAP@("MEDOBJECTID")="MED_PENDING"_MED(.01) ;Pending IEN
     63        . S @MAP@("MEDISSUEDATETXT")="Issue Date"
     64        . ; Field 6 is "Effective date", and we pull it in timson format w/ I
     65        . S @MAP@("MEDISSUEDATE")=$$FMDTOUTC^C0CUTIL($$GET1^DIQ(52.41,RXIEN,6,"I"),"DT")
     66        . ; Med never filled; next 4 fields are not applicable.
     67        . S @MAP@("MEDLASTFILLDATETXT")=""
     68        . S @MAP@("MEDLASTFILLDATE")=""
     69        . S @MAP@("MEDRXNOTXT")=""
     70        . S @MAP@("MEDRXNO")=""
     71        . S @MAP@("MEDTYPETEXT")="Medication"
     72        . S @MAP@("MEDDETAILUNADORNED")=""  ; Leave blank, field has its uses
     73        . S @MAP@("MEDSTATUSTEXT")="On Hold" ; nearest status for pending meds
     74        . S @MAP@("MEDSOURCEACTORID")="ACTORPROVIDER_"_$$GET1^DIQ(52.41,RXIEN,5,"I")
     75        . S @MAP@("MEDPRODUCTNAMETEXT")=$P(MED(11),U,2)
     76        . ; NDC not supplied in API, but is rather trivial to obtain
     77        . ; MED(11) piece 1 has the IEN of the drug (file 50)
     78        . ; IEN is field 31 in the drug file.
     79        . ;
     80        . ; MEDIEN (node 11 in the returned output) might not necessarily be defined
     81        . ; It is not defined when a dose in not chosen in CPRS. There is a long
     82        . ; series of fields that depend on it. We will use If and Else to deal
     83        . ; with that
     84        . N MEDIEN S MEDIEN=$P(MED(11),U)
     85        . I +MEDIEN>0 D  ; start of if/else block
     86        . . ; 12/30/08: I will be using RxNorm for coding...
     87        . . ; 176.001 is the file for Concepts; 176.003 is the file for
     88        . . ; sources (i.e. for RxNorm Version)
     89        . . ;
     90        . . ; We need the VUID first for the National Drug File entry first
     91        . . ; We get the VUID of the drug, by looking up the VA Product entry
     92        . . ; (file 50.68) using the call NDF^PSS50, returned in node 22.
     93        . . ; Field 99.99 is the VUID.
     94        . . ;
     95        . . ; We use the VUID to look up the RxNorm in file 176.001; same idea.
     96        . . ; Get IEN first using $$FIND1^DIC, then get the RxNorm number by
     97        . . ; $$GET1^DIQ.
     98        . . ;
     99        . . ; I get the RxNorm name and version from the RxNorm Sources (file
     100        . . ; 176.003), by searching for "RXNORM", then get the data.
     101        . . D NDF^PSS50(MEDIEN,,,,,"NDF")
     102        . . N NDFDATA M NDFDATA=^TMP($J,"NDF",MEDIEN)
     103        . . N NDFIEN S NDFIEN=$P(NDFDATA(20),U)
     104        . . N VAPROD S VAPROD=$P(NDFDATA(22),U)
     105        . . ;
     106        . . ; NDFIEN is not necessarily defined; it won't be if the drug
     107        . . ; is not matched to the national drug file (e.g. if the drug is
     108        . . ; new on the market, compounded, or is a fake drug [blue pill].
     109        . . ; To protect against failure, I will put an if/else block
     110        . . N VUID,RXNIEN,RXNORM,SRCIEN,RXNNAME,RXNVER
     111        . . I NDFIEN,$D(^C0CRXN) D  ; $Data is for Systems that don't have our RxNorm file yet.
     112        . . . S VUID=$$GET1^DIQ(50.68,VAPROD,99.99)
     113        . . . S RXNIEN=$$FIND1^DIC(176.001,,,VUID,"VUID")
     114        . . . S RXNORM=$$GET1^DIQ(176.001,RXNIEN,.01)
     115        . . . S SRCIEN=$$FIND1^DIC(176.003,,"B","RXNORM")
     116        . . . S RXNNAME=$$GET1^DIQ(176.003,SRCIEN,6)
     117        . . . S RXNVER=$$GET1^DIQ(176.003,SRCIEN,7)
     118        . . ;
     119        . . E  S (RXNORM,RXNNAME,RXNVER)=""
     120        . . ; End if/else block
     121        . . S @MAP@("MEDPRODUCTNAMECODEVALUE")=RXNORM
     122        . . S @MAP@("MEDPRODUCTNAMECODINGINGSYSTEM")=RXNNAME
     123        . . S @MAP@("MEDPRODUCTNAMECODEVERSION")=RXNVER
     124        . . ;
     125        . . S @MAP@("MEDBRANDNAMETEXT")=""
     126        . . D DOSE^PSS50(MEDIEN,,,,,"DOSE")
     127        . . N DOSEDATA M DOSEDATA=^TMP($J,"DOSE",MEDIEN)
     128        . . S @MAP@("MEDSTRENGTHVALUE")=DOSEDATA(901)
     129        . . S @MAP@("MEDSTRENGTHUNIT")=$P(DOSEDATA(902),U,2)
     130        . . ; Units, concentration, etc, come from another call
     131        . . ; $$CPRS^PSNAPIS which returns dosage-form^va class^strengh^unit
     132        . . ; This call takes nodes 1 and 3 of ^PSDRUG(D0,"ND") as parameters
     133        . . ; NDF Entry IEN, and VA Product Name
     134        . . ; These can be obtained using NDF^PSS50 (IEN,,,,,"SUBSCRIPT")
     135        . . ; Documented in the same manual; executed above.
     136        . . N CONCDATA
     137        . . ; If a drug was not matched to NDF, then the NDFIEN is gonna be ""
     138        . . ; and this will crash the call. So...
     139        . . I NDFIEN="" S CONCDATA=""
     140        . . E  S CONCDATA=$$CPRS^PSNAPIS(NDFIEN,VAPROD)
     141        . . S @MAP@("MEDFORMTEXT")=$P(CONCDATA,U,1)
     142        . . S @MAP@("MEDCONCVALUE")=$P(CONCDATA,U,3)
     143        . . S @MAP@("MEDCONCUNIT")=$P(CONCDATA,U,4)
     144        . . S @MAP@("MEDQUANTITYVALUE")=$$GET1^DIQ(52.41,RXIEN,12)
     145        . . ; Oddly, there is no easy place to find the dispense unit.
     146        . . ; It's not included in the original call, so we have to go to the drug file.
     147        . . ; That would be DATA^PSS50(IEN,,,,,"SUBSCRIPT")
     148        . . ; Node 14.5 is the Dispense Unit
     149        . . D DATA^PSS50(MEDIEN,,,,,"QTY")
     150        . . N QTYDATA M QTYDATA=^TMP($J,"QTY",MEDIEN)
     151        . . S @MAP@("MEDQUANTITYUNIT")=QTYDATA(14.5)
     152        . E  D
     153        . . S @MAP@("MEDPRODUCTNAMECODEVALUE")=""
     154        . . S @MAP@("MEDPRODUCTNAMECODINGINGSYSTEM")=""
     155        . . S @MAP@("MEDPRODUCTNAMECODEVERSION")=""
     156        . . S @MAP@("MEDBRANDNAMETEXT")=""
     157        . . S @MAP@("MEDSTRENGTHVALUE")=""
     158        . . S @MAP@("MEDSTRENGTHUNIT")=""
     159        . . S @MAP@("MEDFORMTEXT")=""
     160        . . S @MAP@("MEDCONCVALUE")=""
     161        . . S @MAP@("MEDCONCUNIT")=""
     162        . . S @MAP@("MEDSIZETEXT")=""
     163        . . S @MAP@("MEDQUANTITYVALUE")=""
     164        . . S @MAP@("MEDQUANTITYUNIT")=""
     165        . ; end of if/else block
     166        . ;
     167        . ; --- START OF DIRECTIONS ---
     168        . ; Sig data is not in any API. We obtain it using the IEN from
     169        . ; the PEN API to file 52.41. It's in field 3, which is a multiple.
     170        . ; I will be using FM call GETS^DIQ(FILE,IENS,FIELD,FLAGS,TARGET_ROOT)
     171        . K FMSIG ; it's passed via the symbol table, so remove any leftovers from last call
     172        . D GETS^DIQ(52.41,RXIEN,"3*",,"FMSIG")
     173        . N FMSIGNUM S FMSIGNUM=0 ; Sigline number in fileman.
     174        . ; FMSIGNUM gets outputted as "IEN,RXIEN,".
     175        . ; DIRNUM will be first piece for IEN.
     176        . ; DIRNUM is the proper Sigline numer.
     177        . ; SIGDATA is the simplfied array. Subscripts are really field numbers
     178        . ; in subfile 52.413.
     179        . N DIRCNT S DIRCNT=0 ; COUNT OF DIRECTIONS
     180        . F  S FMSIGNUM=$O(FMSIG(52.413,FMSIGNUM)) Q:FMSIGNUM=""  D
     181        . . N DIRNUM S DIRNUM=$P(FMSIGNUM,",")
     182        . . S DIRCNT=DIRCNT+1 ; INCREMENT DIRECTIONS COUNT
     183        . . N SIGDATA M SIGDATA=FMSIG(52.413,FMSIGNUM)
     184        . . ; If this is an order for a refill; it's not really a new order; move on to next
     185        . . S @MAP@("M","DIRECTIONS",DIRCNT,"MEDDIRECTIONDESCRIPTIONTEXT")=""  ; This is reserved for systems not able to generate the sig in components.
     186        . . S @MAP@("M","DIRECTIONS",DIRCNT,"MEDDOSEINDICATOR")="1"  ; means that we are specifying it. See E2369-05.
     187        . . S @MAP@("M","DIRECTIONS",DIRCNT,"MEDDELIVERYMETHOD")=SIGDATA(13)
     188        . . S @MAP@("M","DIRECTIONS",DIRCNT,"MEDDOSEVALUE")=SIGDATA(8)
     189        . . S @MAP@("M","DIRECTIONS",DIRCNT,"MEDDOSEUNIT")=@MAP@("MEDCONCUNIT")
     190        . . S @MAP@("M","DIRECTIONS",DIRCNT,"MEDRATEVALUE")=""  ; For inpatient
     191        . . S @MAP@("M","DIRECTIONS",DIRCNT,"MEDRATEUNIT")=""  ; For inpatient
     192        . . S @MAP@("M","DIRECTIONS",DIRCNT,"MEDVEHICLETEXT")=""  ; For inpatient
     193        . . S @MAP@("M","DIRECTIONS",DIRCNT,"MEDDIRECTIONROUTETEXT")=SIGDATA(10)
     194        . . S @MAP@("M","DIRECTIONS",DIRCNT,"MEDFREQUENCYVALUE")=SIGDATA(1)
     195        . . ; Invervals... again another call.
     196        . . ; The schedule is a free text field
     197        . . ; However, it gets translated by a call to the administration
     198        . . ; schedule file to see if that schedule exists.
     199        . . ; That's the same thing I am going to do.
     200        . . ; The call is AP^PSS51P1(PSSPP,PSSFT,PSSWDIEN,PSSSTPY,LIST,PSSFREQ).
     201        . . ; PSSPP is "PSJ" (for some reason, schedules are stored as PSJ, not PSO--
     202        . . ; I looked), PSSFT is the name,
     203        . . ; and list is the ^TMP name to store the data in.
     204        . . ; Also, freqency may have "PRN" in it, so strip that out
     205        . . N FREQ S FREQ=SIGDATA(1)
     206        . . I FREQ["PRN" S FREQ=$E(FREQ,1,$F(FREQ,"PRN")-5) ; 5 for $L("PRN") + 1 + sp
     207        . . D AP^PSS51P1("PSJ",FREQ,,,"SCHEDULE")
     208        . . N SCHEDATA M SCHEDATA=^TMP($J,"SCHEDULE")
     209        . . N INTERVAL
     210        . . I $P(SCHEDATA(0),U)=-1 S INTERVAL=""
     211        . . E  D
     212        . . . N SUB S SUB=$O(SCHEDATA(0))
     213        . . . S INTERVAL=SCHEDATA(SUB,2)
     214        . . S @MAP@("M","DIRECTIONS",DIRCNT,"MEDINTERVALVALUE")=INTERVAL
     215        . . S @MAP@("M","DIRECTIONS",DIRCNT,"MEDINTERVALUNIT")="Minute"
     216        . . ; Duration comes as M2,H2,D2,W2,L2 for 2 minutes,hours,days,weeks,months
     217        . . N DUR S DUR=SIGDATA(2)
     218        . . S @MAP@("M","DIRECTIONS",DIRCNT,"MEDDURATIONVALUE")=$E(DUR,2,$L(DUR))
     219        . . N DURUNIT S DURUNIT=$E(DUR)
     220        . . S @MAP@("M","DIRECTIONS",DIRCNT,"MEDDURATIONUNIT")=$S(DURUNIT="M":"Minutes",DURUNIT="H":"Hours",DURUNIT="D":"Days",DURUNIT="W":"Weeks",DURUNIT="L":"Months",1:"")
     221        . . S @MAP@("M","DIRECTIONS",DIRCNT,"MEDPRNFLAG")=SIGDATA(1)["PRN"
     222        . . S @MAP@("M","DIRECTIONS",DIRCNT,"MEDPROBLEMOBJECTID")=""
     223        . . S @MAP@("M","DIRECTIONS",DIRCNT,"MEDPROBLEMTYPETXT")=""
     224        . . S @MAP@("M","DIRECTIONS",DIRCNT,"MEDPROBLEMDESCRIPTION")=""
     225        . . S @MAP@("M","DIRECTIONS",DIRCNT,"MEDPROBLEMCODEVALUE")=""
     226        . . S @MAP@("M","DIRECTIONS",DIRCNT,"MEDPROBLEMCODINGSYSTEM")=""
     227        . . S @MAP@("M","DIRECTIONS",DIRCNT,"MEDPROBLEMCODINGVERSION")=""
     228        . . S @MAP@("M","DIRECTIONS",DIRCNT,"MEDPROBLEMSOURCEACTORID")=""
     229        . . S @MAP@("M","DIRECTIONS",DIRCNT,"MEDSTOPINDICATOR")="" ; Vista doesn't have that field
     230        . . S @MAP@("M","DIRECTIONS",DIRCNT,"MEDDIRSEQ")=DIRNUM
     231        . . S @MAP@("M","DIRECTIONS",DIRCNT,"MEDMULDIRMOD")=SIGDATA(6)
     232        . ;
     233        . ; --- END OF DIRECTIONS ---
     234        . ;
     235        . ; S @MAP@("MEDPTINSTRUCTIONS","F")="52.41^105"
     236        . S @MAP@("MEDPTINSTRUCTIONS")=$G(^PSRX(RXIEN,"PI",1,0)) ;GPL
     237        . ; W @MAP@("MEDPTINSTRUCTIONS"),!
     238        . ; S @MAP@("MEDFULLFILLMENTINSTRUCTIONS","F")="52.41^9"
     239        . S @MAP@("MEDFULLFILLMENTINSTRUCTIONS")=$G(^PSRX(RXIEN,"SIG1",1,0)) ;GPL
     240        . ; W @MAP@("MEDFULLFILLMENTINSTRUCTIONS"),!
     241        . S @MAP@("MEDRFNO")=$$GET1^DIQ(52.41,RXIEN,13)
     242        . N RESULT S RESULT=$NA(^TMP("C0CCCR",$J,"MAPPED"))
     243        . K @RESULT
     244        . D MAP^C0CXPATH(MINXML,MAP,RESULT)
     245        . ; D PARY^C0CXPATH(RESULT)
     246        . ; MAPPING DIRECTIONS
     247        . N MEDDIR1,DIRXML1 S DIRXML1="MEDDIR1" ; VARIABLE AND NAME VARIABLE TEMPLATE
     248        . N MEDDIR2,DIRXML2 S DIRXML2="MEDDIR2" ; VARIABLE AND NAME VARIABLE RESULT
     249        . D QUERY^C0CXPATH(MINXML,"//Medications/Medication/Directions",DIRXML1)
     250        . D REPLACE^C0CXPATH(RESULT,"","//Medications/Medication/Directions")
     251        . ; N MDZ1,MDZNA
     252        . I DIRCNT>0 D  ; IF THERE ARE DIRCTIONS
     253        . . F MDZ1=1:1:DIRCNT  D  ; FOR EACH DIRECTION
     254        . . . S MDZNA=$NA(@MAP@("M","DIRECTIONS",MDZ1))
     255        . . . D MAP^C0CXPATH(DIRXML1,MDZNA,DIRXML2)
     256        . . . D INSERT^C0CXPATH(RESULT,DIRXML2,"//Medications/Medication")
     257        . I MEDFIRST D  ;
     258        . . S MEDFIRST=0 ; RESET FIRST FLAG
     259        . . D CP^C0CXPATH(RESULT,OUTXML) ; First one is a copy
     260        . D:'MEDFIRST INSINNER^C0CXPATH(OUTXML,RESULT) ; AFTER FIRST, INSERT INNER XML
     261        N MEDTMP,MEDI
     262        D MISSING^C0CXPATH(OUTXML,"MEDTMP") ; SEARCH XML FOR MISSING VARS
     263        I MEDTMP(0)>0 D  ; IF THERE ARE MISSING VARS - MARKED AS @@X@@
     264        . W "Pending Medication MISSING ",!
     265        . F MEDI=1:1:MEDTMP(0) W MEDTMP(MEDI),!
     266        Q
     267        ;
  • ccr/trunk/p/C0CMED3.m

    r416 r421  
    2222 Q
    2323 ;
    24 EXTRACT(MINXML,DFN,OUTXML) ; Extract medications into provided xml template
    25  ;
    26  ; MINXML is the Input XML Template, passed by name
    27  ; DFN is Patient IEN
    28  ; OUTXML is the resultant XML.
     24EXTRACT(MINXML,DFN,OUTXML,MEDCOUNT) ; Extract medications into provided xml template
     25 ;
     26 ; MINXML is the Input XML Template, (passed by name)
     27 ; DFN is Patient IEN (passed by value)
     28 ; OUTXML is the resultant XML (passed by name)
     29 ; MEDCOUNT is the number of Meds extracted so far (passed by reference)
    2930 ;
    3031 ; MEDS is return array from RPC.
     
    3940 N MEDS,MAP
    4041 K ^TMP($J,"CCDCCR") ; PLEASE DON'T KILL ALL OF ^TMP($J) HERE!!!!
    41  K NVA
     42 N NVA
    4243 D GETS^DIQ(55,DFN,"52.2*","IE","NVA") ; Output in NVA in FDA array format.
    4344 ; If NVA does not exist, then patient has no non-VA meds
     
    5051 I DEBUG ZWR MEDS
    5152 N FDAIEN S FDAIEN=0 ; For use in $Order in the MEDS array.
    52  S MEDMAP=$NA(^TMP("C0CCCR",$J,"MEDMAP"))
    53  N MEDCOUNT S MEDCOUNT=@MEDMAP@(0) ; We already have meds in the array
    5453 N MEDFIRST S MEDFIRST=1 ; FLAG FOR FIRST MED PROCESSED HERE
    5554 F  S FDAIEN=$O(MEDS(FDAIEN)) Q:FDAIEN=""  D  ; FOR EACH MEDICATION IN THE LIST
     
    5857 . S MEDCOUNT=MEDCOUNT+1
    5958 . S MAP=$NA(^TMP("C0CCCR",$J,"MEDMAP",MEDCOUNT))
    60  . S @MEDMAP@(0)=@MEDMAP@(0)+1 ; INCREMENT TOTAL MEDS IN VAR ARRAY
    6159 . N RXIEN S RXIEN=$P(FDAIEN,",") ; First piece of FDAIEN is the number of the med for this patient
    6260 . I DEBUG W "RXIEN IS ",RXIEN,!
  • ccr/trunk/p/C0CUTIL.m

    r418 r421  
    1 C0CUTIL ;WV/C0C/SMH - Various Utilites for generating the CCR/CCD;06/15/08
    2  ;;0.1;C0C;;Jun 15, 2008;
    3  ;Copyright 2008-2009 Sam Habiel & George Lilly. 
    4  ;Licensed under the terms of the GNU
    5  ;General Public License 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  W "No Entry at Top!"
    22  Q
    23  ;
    24 FMDTOUTC(DATE,FORMAT) ; Convert Fileman Date to UTC Date Format; PUBLIC; Extrinsic
    25  ; FORMAT is Format of Date. Can be either D (Day) or DT (Date and Time)
    26  ; If not passed, or passed incorrectly, it's assumed that it is D.
    27  ; FM Date format is "YYYMMDD.HHMMSS" HHMMSS may not be supplied.
    28  ; UTC date is formatted as follows: YYYY-MM-DDThh:mm:ss_offsetfromUTC
    29  ; UTC, Year, Month, Day, Hours, Minutes, Seconds, Time offset (obtained from Mailman Site Parameters)
    30  N UTC,Y,M,D,H,MM,S,OFF
    31  S Y=1700+$E(DATE,1,3)
    32  S M=$E(DATE,4,5)
    33  S D=$E(DATE,6,7)
    34  S H=$E(DATE,9,10)
    35  I $L(H)=1 S H="0"_H
    36  S MM=$E(DATE,11,12)
    37  I $L(MM)=1 S MM="0"_MM
    38  S S=$E(DATE,13,14)
    39  I $L(S)=1 S S="0"_S
    40  S OFF=$$TZ^XLFDT ; See Kernel Manual for documentation.
    41  S OFFS=$E(OFF,1,1)
    42  S OFF0=$TR(OFF,"+-")
    43  S OFF1=$E(OFF0+10000,2,3)
    44  S OFF2=$E(OFF0+10000,4,5)
    45  S OFF=OFFS_OFF1_":"_OFF2
    46  ;S OFF2=$E(OFF,1,2) ;
    47  ;S OFF2=$E(100+OFF2,2,3) ; GPL 11/08 CHANGED TO -05:00 FORMAT
    48  ;S OFF3=$E(OFF,3,4) ;MINUTES
    49  ;S OFF=$S(OFF2="":"00",0:"00",1:OFF2)_"."_$S(OFF3="":"00",1:OFF3)
    50  ; If H, MM and S are empty, it means that the FM date didn't supply the time.
    51  ; In this case, set H, MM and S to "00"
    52  ; S:('$L(H)&'$L(MM)&'$L(S)) (H,MM,S)="00" ; IF ONLY SOME ARE MISSING?
    53  S:'$L(H) H="00"
    54  S:'$L(MM) MM="00"
    55  S:'$L(S) S="00"
    56  S UTC=Y_"-"_M_"-"_D_"T"_H_":"_MM_$S(S="":":00",1:":"_S)_OFF ; Skip's code to fix hanging colon if no seconds
    57  I $L($G(FORMAT)),FORMAT="DT" Q UTC ; Date with time.
    58  E  Q $P(UTC,"T")
    59  ;
    60 SORTDT(V1,V2,ORDR) ; DATE SORT ARRAY AND RETURN INDEX IN V1 AND COUNT
    61  ; AS EXTRINSIC ORDR IS 1 OR -1 FOR FORWARD OR REVERSE
    62  ; DATE AND TIME ORDER. DEFAULT IS FORWARD
    63  ; V2 IS AN ARRAY OF DATES IN FILEMAN FORMAT
    64  ; V1 IS RETURNS INDIRECT INDEXES OF V2 IN REVERSE DATE ORDER
    65  ; SO V2(V1(X)) WILL RETURN THE DATES IN DATE/TIME ORDER
    66  ; THE COUNT OF THE DATES IS RETURNED AS AN EXTRINSIC
    67  ; BOTH V1 AND V2 ARE PASSED BY REFERENCE
    68  N VSRT ; TEMP FOR HASHING DATES
    69  N ZI,ZJ,ZTMP,ZCNT,ZP1,ZP2
    70  S ZCNT=V2(0) ; COUNTING NUMBER OF DATES
    71  F ZI=1:1:ZCNT D  ; FOR EACH DATE IN THE ARRAY
    72  . I $D(V2(ZI)) D  ; IF THE DATE EXISTS
    73  . . S ZP1=$P(V2(ZI),".",1) ; THE DATE PIECE
    74  . . S ZP2=$P(V2(ZI),".",2) ; THE TIME PIECE
    75  . . ; W "DATE: ",ZP1," TIME: ",ZP2,!
    76  . . S VSRT(ZP1,ZP2,ZI)=ZI ; INDEX OF DATE, TIME AND COUNT
    77  N ZG
    78  S ZG=$Q(VSRT(""))
    79  F  D  Q:ZG=""  ;
    80  . ; W ZG,!
    81  . D PUSH^GPLXPATH("V1",@ZG)
    82  . S ZG=$Q(@ZG)
    83  I ORDR=-1 D  ; HAVE TO REVERSE ORDER
    84  . N ZG2
    85  . F ZI=1:1:V1(0) D  ; FOR EACH ELELMENT
    86  . . S ZG2(V1(0)-ZI+1)=V1(ZI) ; SET IN REVERSE ORDER
    87  . S ZG2(0)=V1(0)
    88  . D CP^GPLXPATH("ZG2","V1") ; COPY OVER THE NEW ARRAY
    89  Q ZCNT
    90  ;
    91 DA2SNO(RTN,DNAME) ; LOOK UP DRUG ALLERGY CODE IN ^LEX
    92  ; RETURNS AN ARRAY RTN PASSED BY REFERENCE
    93  ; THIS ROUTINE CAN BE USED AS AN RPC
    94  ; RTN(0) IS THE NUMBER OF ELEMENTS IN THE ARRAY
    95  ; RTN(1) IS THE SNOMED CODE FOR THE DRUG ALLERGY
    96  ;
    97  N LEXIEN
    98  I $O(^LEX(757.21,"ADIS",DNAME,""))'="" D  ; IEN FOUND FOR THIS DRUG
    99  . S LEXIEN=$O(^LEX(757.21,"ADIS",DNAME,"")) ; GET THE IEN IN THE LEXICON
    100  . W LEXIEN,!
    101  . S RTN(1)=$P(^LEX(757.02,LEXIEN,0),"^",2) ; SNOMED CODE IN P2
    102  . S RTN(0)=1 ; ONE THING RETURNED
    103  E  S RTN(0)=0 ; NOT FOUND
    104  Q
    105  ;
    106 DASNO(DANAME) ; PRINTS THE SNOMED CODE FOR ALLERGY TO DRUG DANAME
    107  ;
    108  N DARTN
    109  D DA2SNO(.DARTN,DANAME) ; CALL THE LOOKUP ROUTINE
    110  I DARTN(0)>0 D  ; GOT RESULTS
    111  . W !,DARTN(1) ;PRINT THE SNOMED CODE
    112  E  W !,"NOT FOUND",!
    113  Q
    114  ;
    115 DASNALL(WHICH) ; ROUTINE TO EXAMINE THE ADIS INDEX IN LEX AND RETRIEVE ALL
    116  ; ASSOCIATED SNOMED CODES
    117  N DASTMP,DASIEN,DASNO
    118  S DASTMP=""
    119  F  S DASTMP=$O(^LEX(757.21,WHICH,DASTMP)) Q:DASTMP=""  D  ; NAME OF MED
    120  . S DASIEN=$O(^LEX(757.21,WHICH,DASTMP,"")) ; IEN OF MED
    121  . S DASNO=$P(^LEX(757.02,DASIEN,0),"^",2) ; SNOMED CODE FOR ENTRY
    122  . W DASTMP,"=",DASNO,! ; PRINT IT OUT
    123  Q
    124  ;
    125 RPMS() ; Are we running on an RPMS system rather than Vista?
    126  Q $G(DUZ("AG"))="I" ; If User Agency is Indian Health Service
    127 VISTA() ; Are we running on Vanilla Vista?
    128  Q $G(DUZ("AG"))="V" ; If User Agency is VA
    129 WV() ; Are we running on Customized Vista (WV or OpenVista)?
    130  Q $G(DUZ("AG"))="E"!($G(DUZ("AG"))="O") ; Codes for WV and Other.
     1C0CUTIL ;WV/C0C/SMH - Various Utilites for generating the CCR/CCD;06/15/08
     2        ;;0.1;C0C;;Jun 15, 2008;
     3        ;Copyright 2008-2009 Sam Habiel & George Lilly. 
     4        ;Licensed under the terms of the GNU
     5        ;General Public License 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        W "No Entry at Top!"
     22        Q
     23        ;
     24FMDTOUTC(DATE,FORMAT)   ; Convert Fileman Date to UTC Date Format; PUBLIC; Extrinsic
     25        ; FORMAT is Format of Date. Can be either D (Day) or DT (Date and Time)
     26        ; If not passed, or passed incorrectly, it's assumed that it is D.
     27        ; FM Date format is "YYYMMDD.HHMMSS" HHMMSS may not be supplied.
     28        ; UTC date is formatted as follows: YYYY-MM-DDThh:mm:ss_offsetfromUTC
     29        ; UTC, Year, Month, Day, Hours, Minutes, Seconds, Time offset (obtained from Mailman Site Parameters)
     30        N UTC,Y,M,D,H,MM,S,OFF
     31        S Y=1700+$E(DATE,1,3)
     32        S M=$E(DATE,4,5)
     33        S D=$E(DATE,6,7)
     34        S H=$E(DATE,9,10)
     35        I $L(H)=1 S H="0"_H
     36        S MM=$E(DATE,11,12)
     37        I $L(MM)=1 S MM="0"_MM
     38        S S=$E(DATE,13,14)
     39        I $L(S)=1 S S="0"_S
     40        S OFF=$$TZ^XLFDT ; See Kernel Manual for documentation.
     41        S OFFS=$E(OFF,1,1)
     42        S OFF0=$TR(OFF,"+-")
     43        S OFF1=$E(OFF0+10000,2,3)
     44        S OFF2=$E(OFF0+10000,4,5)
     45        S OFF=OFFS_OFF1_":"_OFF2
     46        ;S OFF2=$E(OFF,1,2) ;
     47        ;S OFF2=$E(100+OFF2,2,3) ; GPL 11/08 CHANGED TO -05:00 FORMAT
     48        ;S OFF3=$E(OFF,3,4) ;MINUTES
     49        ;S OFF=$S(OFF2="":"00",0:"00",1:OFF2)_"."_$S(OFF3="":"00",1:OFF3)
     50        ; If H, MM and S are empty, it means that the FM date didn't supply the time.
     51        ; In this case, set H, MM and S to "00"
     52        ; S:('$L(H)&'$L(MM)&'$L(S)) (H,MM,S)="00" ; IF ONLY SOME ARE MISSING?
     53        S:'$L(H) H="00"
     54        S:'$L(MM) MM="00"
     55        S:'$L(S) S="00"
     56        S UTC=Y_"-"_M_"-"_D_"T"_H_":"_MM_$S(S="":":00",1:":"_S)_OFF ; Skip's code to fix hanging colon if no seconds
     57        I $L($G(FORMAT)),FORMAT="DT" Q UTC ; Date with time.
     58        E  Q $P(UTC,"T")
     59        ;
     60SORTDT(V1,V2,ORDR)      ; DATE SORT ARRAY AND RETURN INDEX IN V1 AND COUNT
     61        ; AS EXTRINSIC ORDR IS 1 OR -1 FOR FORWARD OR REVERSE
     62        ; DATE AND TIME ORDER. DEFAULT IS FORWARD
     63        ; V2 IS AN ARRAY OF DATES IN FILEMAN FORMAT
     64        ; V1 IS RETURNS INDIRECT INDEXES OF V2 IN REVERSE DATE ORDER
     65        ; SO V2(V1(X)) WILL RETURN THE DATES IN DATE/TIME ORDER
     66        ; THE COUNT OF THE DATES IS RETURNED AS AN EXTRINSIC
     67        ; BOTH V1 AND V2 ARE PASSED BY REFERENCE
     68        N VSRT ; TEMP FOR HASHING DATES
     69        N ZI,ZJ,ZTMP,ZCNT,ZP1,ZP2
     70        S ZCNT=V2(0) ; COUNTING NUMBER OF DATES
     71        F ZI=1:1:ZCNT D  ; FOR EACH DATE IN THE ARRAY
     72        . I $D(V2(ZI)) D  ; IF THE DATE EXISTS
     73        . . S ZP1=$P(V2(ZI),".",1) ; THE DATE PIECE
     74        . . S ZP2=$P(V2(ZI),".",2) ; THE TIME PIECE
     75        . . ; W "DATE: ",ZP1," TIME: ",ZP2,!
     76        . . S VSRT(ZP1,ZP2,ZI)=ZI ; INDEX OF DATE, TIME AND COUNT
     77        N ZG
     78        S ZG=$Q(VSRT(""))
     79        F  D  Q:ZG=""  ;
     80        . ; W ZG,!
     81        . D PUSH^GPLXPATH("V1",@ZG)
     82        . S ZG=$Q(@ZG)
     83        I ORDR=-1 D  ; HAVE TO REVERSE ORDER
     84        . N ZG2
     85        . F ZI=1:1:V1(0) D  ; FOR EACH ELELMENT
     86        . . S ZG2(V1(0)-ZI+1)=V1(ZI) ; SET IN REVERSE ORDER
     87        . S ZG2(0)=V1(0)
     88        . D CP^GPLXPATH("ZG2","V1") ; COPY OVER THE NEW ARRAY
     89        Q ZCNT
     90        ;
     91DA2SNO(RTN,DNAME)       ; LOOK UP DRUG ALLERGY CODE IN ^LEX
     92        ; RETURNS AN ARRAY RTN PASSED BY REFERENCE
     93        ; THIS ROUTINE CAN BE USED AS AN RPC
     94        ; RTN(0) IS THE NUMBER OF ELEMENTS IN THE ARRAY
     95        ; RTN(1) IS THE SNOMED CODE FOR THE DRUG ALLERGY
     96        ;
     97        N LEXIEN
     98        I $O(^LEX(757.21,"ADIS",DNAME,""))'="" D  ; IEN FOUND FOR THIS DRUG
     99        . S LEXIEN=$O(^LEX(757.21,"ADIS",DNAME,"")) ; GET THE IEN IN THE LEXICON
     100        . W LEXIEN,!
     101        . S RTN(1)=$P(^LEX(757.02,LEXIEN,0),"^",2) ; SNOMED CODE IN P2
     102        . S RTN(0)=1 ; ONE THING RETURNED
     103        E  S RTN(0)=0 ; NOT FOUND
     104        Q
     105        ;
     106DASNO(DANAME)   ; PRINTS THE SNOMED CODE FOR ALLERGY TO DRUG DANAME
     107        ;
     108        N DARTN
     109        D DA2SNO(.DARTN,DANAME) ; CALL THE LOOKUP ROUTINE
     110        I DARTN(0)>0 D  ; GOT RESULTS
     111        . W !,DARTN(1) ;PRINT THE SNOMED CODE
     112        E  W !,"NOT FOUND",!
     113        Q
     114        ;
     115DASNALL(WHICH)  ; ROUTINE TO EXAMINE THE ADIS INDEX IN LEX AND RETRIEVE ALL
     116        ; ASSOCIATED SNOMED CODES
     117        N DASTMP,DASIEN,DASNO
     118        S DASTMP=""
     119        F  S DASTMP=$O(^LEX(757.21,WHICH,DASTMP)) Q:DASTMP=""  D  ; NAME OF MED
     120        . S DASIEN=$O(^LEX(757.21,WHICH,DASTMP,"")) ; IEN OF MED
     121        . S DASNO=$P(^LEX(757.02,DASIEN,0),"^",2) ; SNOMED CODE FOR ENTRY
     122        . W DASTMP,"=",DASNO,! ; PRINT IT OUT
     123        Q
     124        ;
     125RPMS()  ; Are we running on an RPMS system rather than Vista?
     126        Q $G(DUZ("AG"))="I" ; If User Agency is Indian Health Service
     127VISTA() ; Are we running on Vanilla Vista?
     128        Q $G(DUZ("AG"))="V" ; If User Agency is VA
     129WV()    ; Are we running on WorldVista?
     130        Q $G(DUZ("AG"))="E" ; Code for WV.
     131OV()    ; Are we running on OpenVista?
     132        Q $G(DUZ("AG"))="O" ; Code for OpenVista
Note: See TracChangeset for help on using the changeset viewer.