Index: ccr/trunk/p/CCRMEDS.m
===================================================================
--- ccr/trunk/p/CCRMEDS.m	(revision 158)
+++ ccr/trunk/p/CCRMEDS.m	(revision 161)
@@ -45,7 +45,9 @@
 	  I DEBUG ZWR MEDS
 	  N RXIEN S RXIEN=0
+	  N MEDCOUNT S MEDCOUNT=0
 	  F  S RXIEN=$O(MEDS(RXIEN)) Q:RXIEN=""  D  ; FOR EACH MEDICATION IN THE LIST
+	  . S MEDCOUNT=MEDCOUNT+1
 	  . I DEBUG W "RXIEN IS ",RXIEN,!
-	  . S MAP=$NA(^TMP("GPLCCR",$J,"MEDMAP",J))
+	  . S MAP=$NA(^TMP("GPLCCR",$J,"MEDMAP"))
 	  . K @MAP
 	  . I DEBUG W "MAP= ",MAP,!
@@ -78,7 +80,6 @@
 	  . ; These can be obtained using NDF^PSS50 (IEN,,,,,"SUBSCRIPT")
 	  . ; Documented in the same manual.
-	  . N IEN S IEN=^PSDRUG($P(MED(6),U))
-	  . D NDF^PSS50(IEN,,,,,"CONC")
-	  . N NDFDATA M NDFDATA=^TMP($J,"CONC",IEN)
+	  . D NDF^PSS50(MEDIEN,,,,,"CONC")
+	  . N NDFDATA M NDFDATA=^TMP($J,"CONC",MEDIEN)
 	  . N NDFIEN S NDFIEN=$P(NDFDATA(20),U)
 	  . N VAPROD S VAPROD=$P(NDFDATA(22),U)
@@ -93,6 +94,6 @@
 	  . ; That would be DATA^PSS50(IEN,,,,,"SUBSCRIPT")
 	  . ; Node 14.5 is the Dispense Unit
-	  . D DATA^PSS50(IEN,,,,,"QTY")
-	  . N QTYDATA M QTYDATA=^TMP($J,"QTY",IEN)
+	  . D DATA^PSS50(MEDIEN,,,,,"QTY")
+	  . N QTYDATA M QTYDATA=^TMP($J,"QTY",MEDIEN)
 	  . S @MAP@("MEDQUANTITYUNIT")=QTYDATA(14.5)
 	  . ;
@@ -106,8 +107,8 @@
 	  . ; So, here we go again
 	  . ; ^PSRX(D0,6,D1,0)= (#.01) DOSAGE ORDERED [1F] ^ (#1) DISPENSE UNITS PER DOSE
-	    ; ==>[2N] ^ (#2) UNITS [3P:50.607] ^ (#3) NOUN [4F] ^ (#4)
-	    ; ==>DURATION [5F] ^ (#5) CONJUNCTION [6S] ^ (#6) ROUTE
-	    ; ==>[7P:51.2] ^ (#7) SCHEDULE [8F] ^ (#8) VERB [9F] ^
-	    N SIGDATA S SIGDATA=^PSRX(IEN,6,1,0)
+	  . ; ==>[2N] ^ (#2) UNITS [3P:50.607] ^ (#3) NOUN [4F] ^ (#4)
+	  . ; ==>DURATION [5F] ^ (#5) CONJUNCTION [6S] ^ (#6) ROUTE
+	  . ; ==>[7P:51.2] ^ (#7) SCHEDULE [8F] ^ (#8) VERB [9F] ^
+	  . N SIGDATA S SIGDATA=^PSRX(RXIEN,6,1,0)
 	  . S @MAP@("MEDDELIVERYMETHOD")=$P(SIGDATA,U,9)
 	  . S @MAP@("MEDDOSEVALUE")=$P(SIGDATA,U,1)
@@ -117,5 +118,5 @@
 	  . S @MAP@("MEDVEHICLETEXT")=""  ; For inpatient
 	  . S @MAP@("MEDDIRECTIONROUTETEXT")=$$GET1^DIQ(51.2,$P(SIGDATA,U,7),.01)
-	  . S @MAP@("MEDFREQUENCYVALUE")=$P(SIGDATA,U,7)
+	  . S @MAP@("MEDFREQUENCYVALUE")=$P(SIGDATA,U,8)
 	  . ; Invervals... again another call.
 	  . ; In the wisdom of the original programmers, the schedule is a free text field
@@ -127,8 +128,8 @@
 	  . ; I looked), PSSFT is the name, and list is the ^TMP name to store the data in.
 	  . ; So...
-	  . D AP^PSS51P1("PSJ",$P(SIGDATA,U,7),,,"SCHEDULE")
+	  . D AP^PSS51P1("PSJ",$P(SIGDATA,U,8),,,"SCHEDULE")
 	  . N SCHEDATA M SCHEDATA=^TMP($J,"SCHEDULE")
 	  . N INTERVAL
-	  . I SCHEDATA(0)=-1 S INTERVAL=""
+	  . I $P(SCHEDATA(0),U)=-1 S INTERVAL=""
 	  . E  D
 	  . . N SUB S SUB=$O(SCHEDATA(0))
@@ -138,5 +139,5 @@
 	  . S @MAP@("MEDDURATIONVALUE")=$P(SIGDATA,U,5)
 	  . S @MAP@("MEDDURATIONUNIT")=""
-	  . S @MAP@("MEDPRNFLAG")=$P(SIGDATA,U,7)["PRN"
+	  . S @MAP@("MEDPRNFLAG")=$P(SIGDATA,U,8)["PRN"
 	  . S @MAP@("MEDPROBLEMOBJECTID")=""
 	  . S @MAP@("MEDPROBLEMDESCRIPTION")=""
@@ -152,13 +153,13 @@
 	  . ;
 	  . ; ^PSRX(22,"INS1",1,0)="FOR BLOOD PRESSURE"
-	  . S @MAP@("MEDPTINSTRUCTIONS")=^PSRX(RXIEN,"INS1",1,0)
+	  . S @MAP@("MEDPTINSTRUCTIONS")=$G(^PSRX(RXIEN,"INS1",1,0))
 	  . ; ^PSRX(22,"PRC",1,0)="Pharmacist: you must obey my command"
-	  . S @MAP@("MEDFULLFILLMENTINSTRUCTIONS")=^PSRX(RXIEN,"PRC",1,0)
+	  . S @MAP@("MEDFULLFILLMENTINSTRUCTIONS")=$G(^PSRX(RXIEN,"PRC",1,0))
 	  . S @MAP@("MEDRFNO")=MED(9)
-	  . N RESULT S RESULT=$NA(^TMP("GPLCCR",$J,"RESULT",J))
+	  . N RESULT S RESULT=$NA(^TMP("GPLCCR",$J,"RESULT"))
 	  . K @RESULT
 	  . D MAP^GPLXPATH(INXML,MAP,RESULT)
-	  . D:J=1 CP^GPLXPATH(RESULT,OUTXML) ; First one is a copy
-	  . D:J>1 INSINNER^GPLXPATH(OUTXML,RESULT) ; AFTER THE FIRST, INSERT INNER XML
+	  . D:MEDCOUNT=1 CP^GPLXPATH(RESULT,OUTXML) ; First one is a copy
+	  . D:MEDCOUNT>1 INSINNER^GPLXPATH(OUTXML,RESULT) ; AFTER THE FIRST, INSERT INNER XML
 	  N MEDTMP,MEDI
 	  D MISSING^GPLXPATH(OUTXML,"MEDTMP") ; SEARCH XML FOR MISSING VARS
