Home   Package List   Routine Alphabetical List   Global Alphabetical List   FileMan Files List   FileMan Sub-Files List   Package Component Lists   Package-Namespace Mapping  
Routine: AMHGD

AMHGD.m

Go to the documentation of this file.
AMHGD ; IHS/CMI/MAW - AMHG Get Data for GUI Front End 11/25/2008 9:38:11 AM ; 26 Jun 2017  3:55 PM
 ;;4.0;IHS BEHAVIORAL HEALTH;**1,4,8**;JUN 02, 2010;Build 7
 ;
 ;
 ;
DEBUG(RETVAL,AMHSTR) ;-- debug entry point
 D DEBUG^%Serenji("ADML^AMHGD(.RETVAL,.AMHSTR)")
 Q
 ;
VISITL(RETVAL,AMHSTR) ;-- get visit list for record selector screen
 S X="MERR^AMHGU",@^%ZOSF("TRAP") ; m error trap
 N AMHI,AMHP,AMHE,AMHB,P,AMHIVB,AMHIVE,AMHDA,AMHIEN
 S P="|"
 S RETVAL="^AMHTMP("_$J_")"
 S AMHI=0
 K ^AMHTMP($J)
 S @RETVAL@(AMHI)="T00010BMXIEN^T00030SortDate^T00030Date^T00050POV^T00020Axis V^T00020Clinic^T00020Activity^T00020Visit Type^T00020Contact Type^T00030Provider^T00001Signed^T00001EHR^T00001DeleteIntakes^T00030LocationofEncounter"
 S @RETVAL@(AMHI)=@RETVAL@(AMHI)_"^T00001Group"_U_"T00080Program"_$C(30)
 S AMHB=$P(AMHSTR,P)
 S AMHE=$P(AMHSTR,P,2)
 S AMHP=$P(AMHSTR,P,3)
 S AMHIVB=(9999999-AMHB)+.9999
 S AMHIVE=(9999999-AMHE)-.0001
 S AMHDA=AMHIVE F  S AMHDA=$O(^AMHREC("AE",AMHP,AMHDA)) Q:'AMHDA!(AMHDA>AMHIVB)  D
 . S AMHIEN=0 F  S AMHIEN=$O(^AMHREC("AE",AMHP,AMHDA,AMHIEN)) Q:'AMHIEN  D
 .. N AMHD0,AHMD11,AMHD14,AHMD15,AHMD16,AMHD17,AMHD21,AMHESIG,AMHPOVE,AMHIDEL,AMHLOC,AMHGRP
 .. N AMHDT,AMHPOV,AMHAXV,AMHCLN,AMHACT,AMHVT,AMHCT,AMHPRV,AMHPOVI,AMHPRVI,AMHACTI,AMHEHR
 .. N AMHPRVM,AMHPROG
 .. S AMHPRVM=0
 .. Q:'$$ALLOWVI^AMHUTIL(DUZ,AMHIEN)  ;screen on user and visit
 .. S AMHD0=$G(^AMHREC(AMHIEN,0))
 .. S AMHDT=$P($$GET1^DIQ(9002011,AMHIEN,.01,"I"),".")
 .. S AMHPOVI=$O(^AMHRPRO("AD",AMHIEN,0))
 .. S AMHPOV=$S($G(AMHPOVI):$$GET1^DIQ(9002011.01,AMHPOVI,.01,"I"),1:"")
 .. S AMHPOVE=$S($G(AMHPOVI):$$GET1^DIQ(9002011.01,AMHPOVI,.04),1:"")
 .. I $G(AMHPOVE)="" S AMHPOVE=$S($G(AMHPOV):$$GET1^DIQ(9002012.2,AMHPOV,.02),1:"")
 .. S AMHAXV=$$GET1^DIQ(9002011,AMHIEN,.14)
 .. S AMHCLN=$$GET1^DIQ(9002011,AMHIEN,.25)
 .. S AMHACTI=$$GET1^DIQ(9002011,AMHIEN,.06,"I")
 .. S AMHACT=$S($G(AMHACTI):$$GET1^DIQ(9002012,AMHACTI,.02),1:"")
 .. S AMHVT=$$GET1^DIQ(9002011,AMHIEN,.33)
 .. S AMHCT=$$GET1^DIQ(9002011,AMHIEN,.07)
 .. S AMHPRVI=$$GETPRV^AMHGU(AMHIEN,"P")
 .. S AMHPRV=$S($G(AMHPRVI):$$GET1^DIQ(200,AMHPRVI,.01),1:"")
 .. S AMHESIG=$S('$$GET1^DIQ(9002011,AMHIEN,1112,"I"):"*",1:"")
 .. S AMHEHR=$$GET1^DIQ(9002011,AMHIEN,1110,"I")
 .. I $G(AMHEHR) S AMHESIG=""  ;cmi/maw pr580/581
 .. S AMHIDEL=$$IINTAKE^AMHLEDEL(AMHIEN)
 .. S AMHLOC=$$GET1^DIQ(9002011,AMHIEN,.04)
 .. S AMHGRP=$$GET1^DIQ(9002011,AMHIEN,.34,"I")
 .. S AMHPROG=$$GET1^DIQ(9002011,AMHIEN,.02)
 .. S AMHI=AMHI+1
 .. S @RETVAL@(AMHI)=AMHIEN_U_AMHDT_U_$$LVDT^AMHGU(AMHDT)_U_AMHPOVE_U_AMHAXV_U_AMHCLN_U_AMHACT_U_AMHVT_U_AMHCT_U_AMHPRV_U_AMHESIG_U_AMHEHR_U_AMHIDEL_U_AMHLOC_U_AMHGRP_U_AMHPROG_$C(30)
 S @RETVAL@(AMHI+1)=$C(31)
 Q
 ;
VISITAP(RETVAL,AMHSTR) ;-- get visit list for record selector screen all patients
 S X="MERR^AMHGU",@^%ZOSF("TRAP") ; m error trap
 N AMHI,AMHP,AMHE,AMHB,P,AMHIVB,AMHIVE,AMHDA,R,AMHIEN
 S P="|",R="~"
 S RETVAL="^AMHTMP("_$J_")"
 S AMHI=0
 K ^AMHTMP($J)
 S @RETVAL@(AMHI)="T00010BMXIEN^T00030SortDate^T00030Date^T00040Patient^T00010Chart^T00001Sex^T00030DOB^T00050POV^T00020Axis V^T00020Clinic^T00020Activity^T00020Visit Type^T00020Contact Type^T00030Provider^T00001Signed^T00001EHR"
 S @RETVAL@(AMHI)=@RETVAL@(AMHI)_"^T00001DeleteIntakes^T00030LocationofEncounter^T00001Group^T00001Spt^T02500Message^T00080Program"_$C(30)
 S AMHB=$P(AMHSTR,P)
 S AMHE=$P(AMHSTR,P,2)
 S AMHP=$P(AMHSTR,P,3)
 S AMHIVB=(9999999-AMHB)+.0001
 S AMHIVE=(9999999-AMHE)-.9999
 S AMHDA=AMHIVE F  S AMHDA=$O(^AMHREC("AB",AMHDA)) Q:'AMHDA!(AMHDA>AMHIVB)  D
 . S AMHIEN=0 F  S AMHIEN=$O(^AMHREC("AB",AMHDA,AMHIEN)) Q:'AMHIEN  D
 .. N AMHD0,AHMD11,AMHD14,AHMD15,AHMD16,AMHD17,AMHD21,AMHPIEN,AMHPAT,AMHCHT,AMHDOB,AMHSEX,AMHPOVE,AMHLOC,AMHLOCI,AMHLOCA
 .. N AMHDT,AMHPOV,AMHAXV,AMHCLN,AMHACT,AMHVT,AMHCT,AMHPRV,AMHPOVI,AMHPRVI,AMHACTI,AMHESIG,AMHEHR,AMHIDEL,AMHNCHT,AMHGRP
 .. N AMHPRVM,AMHSPT,AMHMSG,AMHPROG
 .. S AMHPRVM=0
 .. Q:'$$ALLOWVI^AMHUTIL(DUZ,AMHIEN)  ;screen on user and visit
 .. S AMHD0=$G(^AMHREC(AMHIEN,0))
 .. S AMHPIEN=$P(AMHD0,U,8)
 .. Q:'AMHPIEN
 .. S AMHPAT=$$GET1^DIQ(2,AMHPIEN,.01)
 .. S AMHCHT=$$HRN^AUPNPAT(AMHPIEN,DUZ(2))
 .. S AMHDOB=$$GET1^DIQ(2,AMHPIEN,.03,"I")
 .. S AMHDOB=$$LVDT^AMHGU(AMHDOB)
 .. S AMHSEX=$$GET1^DIQ(2,AMHPIEN,.02,"I")
 .. S AMHDT=$P($$GET1^DIQ(9002011,AMHIEN,.01,"I"),".")
 .. S AMHPOVI=$O(^AMHRPRO("AD",AMHIEN,0))
 .. S AMHPOV=$S($G(AMHPOVI):$$GET1^DIQ(9002011.01,AMHPOVI,.01,"I"),1:"")
 .. S AMHPOVE=$S($G(AMHPOVI):$$GET1^DIQ(9002011.01,AMHPOVI,.04),1:"")
 .. I $G(AMHPOVE)="" S AMHPOVE=$S($G(AMHPOV):$$GET1^DIQ(9002012.2,AMHPOV,.02),1:"")
 .. S AMHAXV=$$GET1^DIQ(9002011,AMHIEN,.14)
 .. S AMHCLN=$$GET1^DIQ(9002011,AMHIEN,.25)
 .. S AMHACTI=$$GET1^DIQ(9002011,AMHIEN,.06,"I")
 .. S AMHACT=$S($G(AMHACTI):$$GET1^DIQ(9002012,AMHACTI,.02),1:"")
 .. S AMHVT=$$GET1^DIQ(9002011,AMHIEN,.33)
 .. S AMHCT=$$GET1^DIQ(9002011,AMHIEN,.07)
 .. S AMHPRVI=$$GETPRV^AMHGU(AMHIEN,"P")
 .. S AMHPRV=$S($G(AMHPRVI):$$GET1^DIQ(200,AMHPRVI,.01),1:"")
 .. S AMHESIG=$S('$$GET1^DIQ(9002011,AMHIEN,1112,"I"):"*",1:"")
 .. S AMHEHR=$$GET1^DIQ(9002011,AMHIEN,1110,"I")
 .. I $G(AMHEHR) S AMHESIG=""  ;cmi/maw pr580/581
 .. S AMHIDEL=$$IINTAKE^AMHLEDEL(AMHIEN)
 .. S AMHLOC=$$GET1^DIQ(9002011,AMHIEN,.04)
 .. S AMHLOCI=$$GET1^DIQ(9002011,AMHIEN,.04,"I")
 .. S AMHLOCA=$S(AMHLOCI:$$GET1^DIQ(9999999.06,AMHLOCI,.08),1:"")
 .. S AMHGRP=$$GET1^DIQ(9002011,AMHIEN,.34,"I")
 .. S AMHNCHT=AMHLOCA_$$HRN^AUPNPAT(AMHPIEN,AMHLOCI)
 .. S AMHSPT=$$SPT^AMHGDA(AMHPIEN)
 .. S AMHPROG=$$GET1^DIQ(9002011,AMHIEN,.02)
 .. I $G(AMHSPT) D
 ... S AMHDOB="**SENSITIVE**"
 ... S AMHMSG=$G(AMHDGMSG)
 .. S AMHI=AMHI+1
 .. S @RETVAL@(AMHI)=AMHIEN_U_AMHDT_U_$$LVDT^AMHGU(AMHDT)_U_AMHPIEN_R_AMHPAT_U_AMHNCHT_U_AMHSEX_U_AMHDOB_U_AMHPOVE_U_AMHAXV_U_AMHCLN_U_AMHACT_U_AMHVT_U_AMHCT_U_AMHPRV_U_AMHESIG_U_AMHEHR_U_AMHIDEL_U_AMHLOC_U_AMHGRP_U_$G(AMHSPT)
 .. S @RETVAL@(AMHI)=@RETVAL@(AMHI)_U_$G(AMHMSG)_U_AMHPROG_$C(30)
 S @RETVAL@(AMHI+1)=$C(31)
 Q
 ;
CML(RETVAL,AMHSTR) ;-- get case management list for record selector screen
 S X="MERR^AMHGU",@^%ZOSF("TRAP") ; m error trap
 N AMHI,AMHP,AMHE,AMHB,P,AMHIVB,AMHIVE,AMHDA,AMHIEN
 S P="|",R="~"
 S RETVAL="^AMHTMP("_$J_")"
 S AMHI=0
 K ^AMHTMP($J)
 S @RETVAL@(AMHI)="T00010BMXIEN^T00030SortDate^T00030OpenDate^T00030AdmitDate^T00030ClosedDate^T00050Disposition^T00030Program^T00030Provider"_$C(30)
 S AMHB=$P(AMHSTR,P)
 S AMHE=$P(AMHSTR,P,2)
 S AMHP=$P(AMHSTR,P,3)
 S AMHIVB=(9999999-AMHB)+.0001
 S AMHIVE=(9999999-AMHE)-.9999
 S AMHDA=AMHIVE F  S AMHDA=$O(^AMHPCASE("AA",AMHP,AMHDA)) Q:'AMHDA!(AMHDA>AMHIVB)  D
 . S AMHIEN=0 F  S AMHIEN=$O(^AMHPCASE("AA",AMHP,AMHDA,AMHIEN)) Q:'AMHIEN  D
 .. N AMHCO,AMHCA,AMHCC,AMHDSPI,AMHDSP,AMHDSPS,AMHPRGI,AMHPRG,AMHPRGS,AMHPRVI,AMHPRV,AMHPRVS
 .. Q:'$$ALLOWCD^AMHLCD(DUZ,AMHIEN)  ;screen on duz and case
 .. S AMHCO=$$GET1^DIQ(9002011.58,AMHIEN,.01,"I")
 .. S AMHCA=$$GET1^DIQ(9002011.58,AMHIEN,.04,"I")
 .. S AMHCC=$$GET1^DIQ(9002011.58,AMHIEN,.05,"I")
 .. S AMHDSPI=$$GET1^DIQ(9002011.58,AMHIEN,.06,"I")
 .. S AMHDSP=$$GET1^DIQ(9002011.58,AMHIEN,.06)
 .. I AMHDSPI S AMHDSPS=AMHDSPI_R_AMHDSP
 .. S AMHPRGI=$$GET1^DIQ(9002011.58,AMHIEN,.03,"I")
 .. S AMHPRG=$$GET1^DIQ(9002011.58,AMHIEN,.03)
 .. I AMHPRGI]"" S AMHPRGS=AMHPRGI_R_AMHPRG
 .. S AMHPRVI=$$GET1^DIQ(9002011.58,AMHIEN,.08,"I")
 .. S AMHPRV=$$GET1^DIQ(9002011.58,AMHIEN,.08)
 .. I AMHPRVI S AMHPRVS=AMHPRVI_R_AMHPRV
 .. S AMHI=AMHI+1
 .. S @RETVAL@(AMHI)=AMHIEN_U_AMHCO_U_$$LVDT^AMHGU(AMHCO)_U_$$LVDT^AMHGU(AMHCA)_U_$$LVDT^AMHGU(AMHCC)_U_$G(AMHDSPS)_U_$G(AMHPRGS)_U_$G(AMHPRVS)_$C(30)
 S @RETVAL@(AMHI+1)=$C(31)
 Q
 ;
TPL(RETVAL,AMHSTR) ;-- get treatment plans for record selector screen
 S X="MERR^AMHGU",@^%ZOSF("TRAP") ; m error trap
 N AMHI,AMHP,AMHE,AMHB,P,AMHIVB,AMHIVE,AMHDA,AMHIEN
 S P="|",R="~"
 S RETVAL="^AMHTMP("_$J_")"
 S AMHI=0
 K ^AMHTMP($J)
 S @RETVAL@(AMHI)="T00010BMXIEN^T00030SortDate^T00030DateEstablished^T00030Program^T00030Status^T00080Problem^T00030Provider^T00030ReviewDate^T00010Reviews"_$C(30)
 S AMHB=$P(AMHSTR,P)
 S AMHE=$P(AMHSTR,P,2)
 S AMHP=$P(AMHSTR,P,3)
 S AMHIVB=(9999999-AMHB)+.0001
 S AMHIVE=(9999999-AMHE)-.9999
 S AMHDA=AMHIVE F  S AMHDA=$O(^AMHPTXP("AA",AMHP,AMHDA)) Q:'AMHDA!(AMHDA>AMHIVB)  D
 . S AMHIEN=0 F  S AMHIEN=$O(^AMHPTXP("AA",AMHP,AMHDA,AMHIEN)) Q:'AMHIEN  D
 .. N AMHDE,AMHPRG,AMHST,AMHPRB,AMHPRV,AMHRD
 .. N AMHPRVM,AMHRCNT
 .. S AMHPRVM=0
 .. Q:'$$ALLOWTP^AMHLETP(DUZ,AMHIEN)  ;screen on user and treatment plan
 .. S AMHDE=$$GET1^DIQ(9002011.56,AMHIEN,.01,"I")
 .. S AMHPRG=$$GET1^DIQ(9002011.56,AMHIEN,.17)
 .. S AMHST=$$GET1^DIQ(9002011.56,AMHIEN,.15)
 .. S AMHPRB=$$GET1^DIQ(9002011.56,AMHIEN,1101)
 .. I AMHPRB="" S AMHPRB=$G(^AMHPTXP(AMHIEN,21,1,0))  ;v4.0p4 display the dx if no problem
 .. S AMHPRV=$$GET1^DIQ(9002011.56,AMHIEN,.04)
 .. S AMHRD=$$GET1^DIQ(9002011.56,AMHIEN,.09,"I")
 .. S AMHRCNT=+$P($G(^AMHPTXP(AMHIEN,41,0)),U,4)
 .. S AMHI=AMHI+1
 .. S @RETVAL@(AMHI)=AMHIEN_U_AMHDE_U_$$LVDT^AMHGU(AMHDE)_U_AMHPRG_U_AMHST_U_AMHPRB_U_AMHPRV_U_$$LVDT^AMHGU(AMHRD)_U_AMHRCNT_$C(30)
 S @RETVAL@(AMHI+1)=$C(31)
 Q
 ;
TPLAP(RETVAL,AMHSTR) ;-- get treatment plans for record selector screen all patients
 S X="MERR^AMHGU",@^%ZOSF("TRAP") ; m error trap
 N AMHI,AMHP,AMHE,AMHB,P,AMHIVB,AMHIVE,AMHDA,AMHIEN
 S P="|",R="~"
 S RETVAL="^AMHTMP("_$J_")"
 S AMHI=0
 K ^AMHTMP($J)
 S @RETVAL@(AMHI)="T00010BMXIEN^T00030SortDate^T00030DateEstablished^T00040Patient^T00010Chart^T00001Sex^T00030DOB^T00030Program^T00030Status^T00080Problem^T00030Provider^T00030ReviewDate^T00010Reviews^T00001Spt^T02500Message"_$C(30)
 S AMHB=$P(AMHSTR,P)
 S AMHE=$P(AMHSTR,P,2)
 S AMHP=$P(AMHSTR,P,3)
 S AMHIVB=(9999999-AMHB)+.0001
 S AMHIVE=(9999999-AMHE)-.9999
 S AMHDA=AMHIVE F  S AMHDA=$O(^AMHPTXP("AB",AMHDA)) Q:'AMHDA!(AMHDA>AMHIVB)  D
 . S AMHIEN=0 F  S AMHIEN=$O(^AMHPTXP("AB",AMHDA,AMHIEN)) Q:'AMHIEN  D
 .. N AMHDE,AMHPRG,AMHST,AMHPRB,AMHPRV,AMHRD,AMHPIEN,AMHPAT,AMHDOB,AMHSEX,AMHCHT
 .. N AMHPRVM,AMHSPT,AMHMSG
 .. S AMHPRVM=0
 .. Q:'$$ALLOWTP^AMHLETP(DUZ,AMHIEN)  ;screen on user and treatment plan
 .. S AMHPIEN=$$GET1^DIQ(9002011.56,AMHIEN,.02,"I")
 .. Q:'AMHPIEN
 .. S AMHPAT=$$GET1^DIQ(2,AMHPIEN,.01)
 .. S AMHCHT=$$HRN^AUPNPAT(AMHPIEN,DUZ(2))
 .. S AMHDOB=$$GET1^DIQ(2,AMHPIEN,.03,"I")
 .. S AMHDOB=$$LVDT^AMHGU(AMHDOB)
 .. S AMHSEX=$$GET1^DIQ(2,AMHPIEN,.02,"I")
 .. S AMHDE=$$GET1^DIQ(9002011.56,AMHIEN,.01,"I")
 .. S AMHPRG=$$GET1^DIQ(9002011.56,AMHIEN,.17)
 .. S AMHST=$$GET1^DIQ(9002011.56,AMHIEN,.15)
 .. S AMHPRB=$$GET1^DIQ(9002011.56,AMHIEN,1101)
 .. I AMHPRB="" S AMHPRB=$G(^AMHPTXP(AMHIEN,21,1,0))  ;v4.0p4 display the dx if no problem
 .. S AMHPRV=$$GET1^DIQ(9002011.56,AMHIEN,.04)
 .. S AMHRD=$$GET1^DIQ(9002011.56,AMHIEN,.09,"I")
 .. S AMHRCNT=+$P($G(^AMHPTXP(AMHIEN,41,0)),U,4)
 .. S AMHSPT=$$SPT^AMHGDA(AMHPIEN)
 .. I $G(AMHSPT) D
 ... S AMHDOB="**SENSITIVE**"
 ... S AMHMSG=$G(AMHDGMSG)
 .. S AMHI=AMHI+1
 .. S @RETVAL@(AMHI)=AMHIEN_U_AMHDE_U_$$LVDT^AMHGU(AMHDE)_U_AMHPIEN_R_AMHPAT_U_AMHCHT_U_AMHSEX_U_AMHDOB_U_AMHPRG_U_AMHST_U_AMHPRB_U_AMHPRV_U_$$LVDT^AMHGU(AMHRD)_U_AMHRCNT_U_+$G(AMHSPT)_U_$G(AMHMSG)_$C(30)
 S @RETVAL@(AMHI+1)=$C(31)
 Q
 ;
SFL(RETVAL,AMHSTR) ;-- get suicide forms for record selector screen
 S X="MERR^AMHGU",@^%ZOSF("TRAP") ; m error trap
 N AMHI,AMHP,AMHE,AMHB,P,AMHIVB,AMHIVE,AMHDA,AMHIEN
 S P="|",R="~"
 S RETVAL="^AMHTMP("_$J_")"
 S AMHI=0
 K ^AMHTMP($J)
 S @RETVAL@(AMHI)="T00010BMXIEN^T00030SortDate^T00030Date^T00030LocalCaseNumber^T00030Provider^T00080SuicidalBehavior^T00001Incomplete"_$C(30)
 S AMHB=$P(AMHSTR,P)
 S AMHE=$P(AMHSTR,P,2)
 S AMHP=$P(AMHSTR,P,3)
 S AMHIVB=(9999999-AMHB)+.0001
 S AMHIVE=(9999999-AMHE)-.9999
 S AMHDA=AMHIVE F  S AMHDA=$O(^AMHPSUIC("AA",AMHP,AMHDA)) Q:'AMHDA!(AMHDA>AMHIVB)  D
 . S AMHIEN=0 F  S AMHIEN=$O(^AMHPSUIC("AA",AMHP,AMHDA,AMHIEN)) Q:'AMHIEN  D
 .. N AMHPRVM
 .. S AMHPRVM=0
 .. Q:'$$ALLOW^AMHSFR(DUZ,AMHIEN)  ;screen on user and suicide form
 .. N AMHD,AMHLCN,AMHPRV,AMHSB,AMHINC
 .. S AMHINC=$S($$INCOMPSF^AMHLESF(AMHIEN):"I",1:"")  ;v4.0 p1
 .. S AMHD=$$GET1^DIQ(9002011.65,AMHIEN,.06,"I")
 .. S AMHLCN=$$GET1^DIQ(9002011.65,AMHIEN,.02)
 .. S AMHPRV=$$GET1^DIQ(9002011.65,AMHIEN,.03)
 .. S AMHSB=$$GET1^DIQ(9002011.65,AMHIEN,.13)
 .. S AMHI=AMHI+1
 .. S @RETVAL@(AMHI)=AMHIEN_U_AMHD_U_$$LVDT^AMHGU(AMHD)_U_AMHLCN_U_AMHPRV_U_AMHSB_U_AMHINC_$C(30)
 S @RETVAL@(AMHI+1)=$C(31)
 Q
 ;
SFLAP(RETVAL,AMHSTR) ;-- get suicide forms for record selector screen all patients
 S X="MERR^AMHGU",@^%ZOSF("TRAP") ; m error trap
 N AMHI,AMHP,AMHE,AMHB,P,AMHIVB,AMHIVE,AMHDA,AMHIEN
 S P="|",R="~"
 S RETVAL="^AMHTMP("_$J_")"
 S AMHI=0
 K ^AMHTMP($J)
 S @RETVAL@(AMHI)="T00010BMXIEN^T00030SortDate^T00030Date^T00040Patient^T00010Chart^T00001Sex^T00030DOB^T00030LocalCaseNumber^T00030Provider^T00080SuicidalBehavior^T00001Spt^T02500Message^T00001Incomplete"_$C(30)
 S AMHB=$P(AMHSTR,P)
 S AMHE=$P(AMHSTR,P,2)
 S AMHP=$P(AMHSTR,P,3)
 S AMHIVB=(9999999-AMHB)+.0001
 S AMHIVE=(9999999-AMHE)-.9999
 S AMHDA=AMHIVE F  S AMHDA=$O(^AMHPSUIC("AB",AMHDA)) Q:'AMHDA!(AMHDA>AMHIVB)  D
 . S AMHIEN=0 F  S AMHIEN=$O(^AMHPSUIC("AB",AMHDA,AMHIEN)) Q:'AMHIEN  D
 .. N AMHPRVM
 .. S AMHPRVM=0
 .. Q:'$$ALLOW^AMHSFR(DUZ,AMHIEN)  ;screen on user and suicide form
 .. N AMHD,AMHLCN,AMHPRV,AMHSB,AMHPIEN,AMHPAT,AMHSPT,AMHMSG,AMHCHT,AMHSEX,AMHINC
 .. S AMHPIEN=$$GET1^DIQ(9002011.65,AMHIEN,.04,"I")
 .. Q:'AMHPIEN
 .. S AMHINC=$S($$INCOMPSF^AMHLESF(AMHIEN):"I",1:"")  ;v4.0 p1
 .. S AMHPAT=$$GET1^DIQ(2,AMHPIEN,.01)
 .. S AMHCHT=$$HRN^AUPNPAT(AMHPIEN,DUZ(2))
 .. S AMHDOB=$$GET1^DIQ(2,AMHPIEN,.03,"I")
 .. S AMHDOB=$$LVDT^AMHGU(AMHDOB)
 .. S AMHSEX=$$GET1^DIQ(2,AMHPIEN,.02,"I")
 .. S AMHD=$$GET1^DIQ(9002011.65,AMHIEN,.06,"I")
 .. S AMHLCN=$$GET1^DIQ(9002011.65,AMHIEN,.02)
 .. S AMHPRV=$$GET1^DIQ(9002011.65,AMHIEN,.03)
 .. S AMHSB=$$GET1^DIQ(9002011.65,AMHIEN,.13)
 .. S AMHSPT=$$SPT^AMHGDA(AMHPIEN)
 .. I $G(AMHSPT) D
 ... S AMHDOB="**SENSITIVE**"
 ... S AMHMSG=$G(AMHDGMSG)
 .. S AMHI=AMHI+1
 .. S @RETVAL@(AMHI)=AMHIEN_U_AMHD_U_$$LVDT^AMHGU(AMHD)_U_AMHPIEN_R_AMHPAT_U_AMHCHT_U_AMHSEX_U_AMHDOB_U_AMHLCN_U_AMHPRV_U_AMHSB_U_+$G(AMHSPT)_U_$G(AMHMSG)_U_AMHINC_$C(30)
 S @RETVAL@(AMHI+1)=$C(31)
 Q
 ;