Index: FOIAVistA/tag/r/CPT_HCPCS_CODES-ICPT-DGYA/ICPTMOD.m
===================================================================
--- FOIAVistA/trunk/r/CPT_HCPCS_CODES-ICPT-DGYA/ICPTMOD.m	(revision 631)
+++ FOIAVistA/tag/r/CPT_HCPCS_CODES-ICPT-DGYA/ICPTMOD.m	(revision 636)
@@ -1,13 +1,7 @@
-ICPTMOD ;ALB/DEK/KER - CPT MODIFIER APIS ;08/18/2007
- ;;6.0;CPT/HCPCS;**6,12,13,14,19,30,37**;May 19, 1997;Build 25
- ;             
- ; Global Variables
- ;    ^DIC(81.3
- ;    ^TMP("ICPTD"     SACC 2.3.2.5.1
- ;             
+ICPTMOD ; ALB/DEK/KER - CPT MODIFIER APIS ; 09/06/2006
+ ;;6.0;CPT/HCPCS;**6,12,13,14,19,30**;May 19, 1997;Build 1
+ ;
  ; External References
- ;    $$DT^XLFDT       DBIA  10103
- ;             
- ; External References
+ ;   DBIA  10103  $$DT^XLFDT
  ;
  Q
@@ -15,5 +9,5 @@
  ;
  ; Input:   MOD   Modifier, Internal or External (Required)
- ;          MFT   Format  "I"=IEN  "E"=.01 field (Default)
+ ;          MFT   Modifier Format  "I" = IEN  "E" = .01 field (Default)
  ;          MDT   Version Date, FileMan format (default = TODAY)
  ;          SRC   Source Screen
@@ -22,5 +16,5 @@
  ;          DFN   Not used
  ; 
- ; Output:  10 piece string delimited by the up-arrow (^)
+ ; Output:  Returns a 10 piece string delimited by the up-arrow (^)
  ; 
  ;            1  IEN
@@ -55,10 +49,9 @@
  S STR=STR_"^"_EFF_"^"_$$MSG^ICPTSUPT(MDT)
  S:$L(MODST) $P(STR,"^",3)=MODST
-MODQ ; Modifier Quit
- Q STR
+MODQ Q STR
  ;
 MODD(CODE,OUTARR,DFN,CDT)       ; returns CPT description in array
  ;
- ; Input:   CODE   CPT Modifier, internal or external (Required)
+ ; Input:   CODE   CPT Modifier code, internal or external (Required)
  ;          ARY    Output Array Name
  ;                   e.g. "ABC" or "ABC("TEST")" 
@@ -66,14 +59,14 @@
  ;          DFN    Not used
  ;          CDT    Versioning Date (default = TODAY)
- ;                   If prior to 1/1/1989, 1/1/1989 will be used
- ;                   If year only, use first of that year
- ;                   If month/year only, use first of the month
- ;                   If later than today, TODAY will be used
+ ;                   If CDT is prior to 1/1/1989, 1/1/1989 will be used
+ ;                   If CDT is year only, the first of that year will be used
+ ;                   If CDT is month/year only, the first of month will be used
+ ;                   If CDT is later than today, TODAY will be used
  ; 
  ; Output:  #      Number of lines in description
  ; 
- ;          @ARY(1:n) - Versioned Description (multiple 62)
+ ;          @ARY(1:n) - Versioned Description (from the 62 multiple)
  ;          @ARY(n+1) - blank
- ;          @ARY(n+1) - message: CODE TEXT MAY BE INACCURATE
+ ;          @ARY(n+1) - a message stating: CODE TEXT MAY BE INACCURATE
  ;      or
  ;          -1^Error
@@ -98,20 +91,83 @@
  . S N=N+1,ARR=OUTARR_N_")",@ARR=$$MSG^ICPTSUPT(CDT,1)
  I +N'>0 S N="-1^VERSIONED DESCRIPTION NOT FOUND FOR MODIFIER "_$P($G(^DIC(81.3,+CODE,0)),"^",1)
-MODDQ ; Modifier Description Quit
- Q N
+MODDQ Q N
  ;
 MODA(CODE,VDT,ARY) ; Return an array of Modifiers for a CPT Code
  D MODA^ICPTMOD2 Q
+ ;
 MODP(CODE,MOD,MFT,MDT,SRC,DFN) ;  Check if modifier can be used with code
- Q $$MODP^ICPTMOD2($G(CODE),$G(MOD),$G(MFT),$G(MDT),$G(SRC),$G(DFN))
+ ;
+ ; Input:
+ ; 
+ ;    CODE   CPT/HCPCS Code ?7N / ?1A4N / ?4N1A
+ ;    MOD    Modifier (External or Internal)
+ ;    MFT    Modifier Format "E" - or "I"
+ ;    VDT    Date service provided
+ ;    SRC    Source Screen
+ ;               If 0 or Null, Level I and II modifiers
+ ;               If >0, Level I, II, and III modifiers
+ ; Output:
+ ;
+ ;    If pair is acceptable - Positive 7 Piece "^" Delimited String
+ ;        
+ ;        1 - IEN of CPT Modifier
+ ;        2 - Versioned Short Text
+ ;        3 - Beginning Code for Code Range
+ ;        4 - Ending Code for Code Range
+ ;        5 - Code Range Activaiton Date
+ ;        6 - Code Range Inactivation Date
+ ;        7 - Modifier Identifier
+ ;        
+ ;    If pair is unacceptable
+ ;    
+ ;        0
+ ;  
+ N ACD,ADT,BEGA,BEGR,CDT,CODEA,CPTS,ENDA,ENDR,ICD,IDT,MIEN,MODEFF,MODI,MODNM,MODST,NEXT,NN,ND,PR,PRN,RIEN,SIEN,SRC,STA,STI,STX,TA,TEFF,TI,TIEN,VDT
+ S:$G(MFT)="" MFT="E" Q:"^E^I^"'[("^"_MFT_"^") "-1^Invalid Modifier Format"
+ S VDT=$P($G(MDT),".",1) Q:+VDT'>0!(VDT'?7N) "-1^Invalid Date"
+ I MFT="E" D  I +($G(MIEN))'>0 Q "-1^Multiple Modifiers with the same name, use IEN"
+ . S MIEN=0 S (TIEN,TI)=0 F  S TIEN=$O(^DIC(81.3,"B",MOD,TIEN)) Q:+TIEN'>0  D
+ . . S TEFF=$$EFF^ICPTSUPT(81.3,TIEN,VDT) Q:'$P(TEFF,"^",2)
+ . . S TI=TI+1,TA(TI)=TIEN,TA(0)=TI
+ . S:+($G(TA(0)))=1 MIEN=+($G(TA(1)))
+ S:MFT="I" MIEN=+MOD S CODE=$G(CODE)
+ S CODN=$S(CODE?1.N:+CODE,1:$$CODEN^ICPTCOD(CODE))
+ I CODN<1!'$D(^ICPT(CODN,0)) Q "-1^NO SUCH CPT CODE"
+ S CODE=$P($G(^ICPT(CODN,0)),"^") I '$L(CODE) Q:"-1^NO SUCH CPT CODE "
+ Q:$L(CODE)'=5 "-1^Invalid Code"
+ S CODEA=$S(CODE?1N.4N:+CODE,CODE?4N1A:$A($E(CODE,5))*10_$E(CODE,1,4),1:$A(CODE)_$E(CODE,2,5)) Q:+CODEA'>0 "-1^Invalid Code Source"
+ S MIEN=$G(MIEN) Q:+MIEN'>0 "-1^Invalid Modifier"
+ S SRC=+($G(SRC)) S SRC=$S(+SRC>0:1,1:0)
+ S SIEN=$O(^ICPT("BA",(CODE_" "),0)) Q:+SIEN'>0 "-3^Invalid Code"
+ S CPTS=$P($G(^ICPT(+SIEN,0)),"^",6)  Q:CPTS="L"&(SRC'>0) "-1^Invalid Code Source"
+ S MODEFF=$$EFF^ICPTSUPT(81.3,MIEN,VDT) Q:'$P(MODEFF,"^",2) "-1^Modifier Inactive"
+ S MODNM=$P($G(^DIC(81.3,MIEN,0)),"^",2) Q:'$L(MODNM) "-1^Invalid Modifier Name"
+ S MODI=$P($G(^DIC(81.3,MIEN,0)),"^",1) Q:'$L(MODI) "-1^Invalid Modifier ID"
+ S MODST=$$VSTCM^ICPTMOD(MIEN,VDT) K STX S (STA,STI)=0 S CDT=($$DTBR^ICPTSUPT(VDT))+.001
+ S RIEN=0 F  S RIEN=$O(^DIC(81.3,MIEN,10,RIEN)) Q:+RIEN'>0  D
+ . S ND=$G(^DIC(81.3,MIEN,10,RIEN,0))
+ . S BEGR=$P(ND,"^",1),BEGA=$S(BEGR?1N.4N:+BEGR,BEGR?4N1A:$A($E(BEGR,5))*10_$E(BEGR,1,4),1:$A(BEGR)_$E(BEGR,2,5)) Q:CODEA<BEGA
+ . S ENDR=$P(ND,"^",2),ENDA=$S(ENDR?1N.4N:+ENDR,ENDR?4N1A:$A($E(ENDR,5))*10_$E(ENDR,1,4),1:$A(ENDR)_$E(ENDR,2,5)) Q:CODEA>ENDA
+ . S (ACD,ADT)=$P(ND,"^",3),(ICD,IDT)=$P(ND,"^",4) S:ADT="" ADT=2890101 S:'$L(IDT) IDT=$$FMADD^XLFDT($$DT^XLFDT,365)
+ . S NN="^DIC(81.3,"_MIEN_",10,"_RIEN_",0)"
+ . S STA=+($G(STA))+1,STX(STA)=MIEN_"^"_MODST_"^"_BEGR_"^"_ENDR_"^"_ADT_"^"_ICD_"^"_MODI,STX("B",+ADT,+STA)=""
+ S ADT=$O(STX("B",+CDT),-1),STA=$O(STX("B",+ADT," "),-1),MOD=$G(STX(+STA)) Q:+MOD'>0 "0"
+ Q MOD
+ ;
 MODC(MOD) ; Checks modifier for range including code
  D MODC^ICPTMOD2($G(MOD))
  Q
+ ;
 MULT ; Finds Duplicate Modifiers
  D MULT^ICPTMOD2 Q
-CODEN(CODE)    ; Return the IEN of a CPT modifier CODE
+ ;
+CODEN(CODE)    ; Return the IEN of a CPT modifier
+ ;   Input:  CPT modifier code
+ ;  Output:  IEN
+ ;
  Q:$G(CODE)="" -1
  N COD S COD=+$O(^DIC(81.3,"BA",(CODE_" "),0))
  Q $S(COD>0:COD,1:-1)
+ ;
 VSTCM(IEN,VDATE) ; Versioned Short Text (CPT Modifier)
  N CPT0,CPTC,CPTI,CPTSTD,CPTSTI,CPTVDT,CPTTXT,CPTTD,CPTTI
