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

PXRRWLSE.m

Go to the documentation of this file.
  1. PXRRWLSE ;ISL/PKR,ISA/Zoltan - Sort encounters for encounter summary report. ;12/1/1998
  1. ;;1.0;PCE PATIENT CARE ENCOUNTER;**20,58,61**;Aug 12, 1996
  1. ;
  1. ;Sort the encounters according to the selection criteria.
  1. SORT ;
  1. N BYCLOC,BD,BUSY,CLINIC,CLINIEN,CPT,CSSCR
  1. N DATE,DAY,DFN,ED,EM,EMLIST,FAC,FACILITY,FOUND
  1. N HLOCIEN,HLOCNAM,HSSCR,IC,INOUT,LOCATION,NEWPIEN
  1. N PCLASS,PPNAME
  1. N PROVIDER,PRVCNT,PRVIEN,PRVSCR
  1. N STOIND,TEMP,TOTUNIQ,TOTVIS,UPAT,VIEN,VISIT,VISIT150,VISITS
  1. N MULTPR
  1. ;
  1. D SORT2^PXRRWLS2
  1. ;
  1. S BD=PXRRBDT-.0001
  1. S ED=PXRREDT+.2359
  1. NDATE S BD=$O(^AUPNVSIT("B",BD))
  1. ;If we have passed the ending date we are done.
  1. I (BD>ED)!(BD="") G DONE
  1. ;
  1. ;If this is an interactive session let the user know that something
  1. ;is happening.
  1. I '(PXRRQUE!$D(IO("S"))) D SPIN^PXRRBUSY("Sorting encounters",.BUSY)
  1. ;
  1. ;Check for a user request to stop the task.
  1. I $$S^%ZTLOAD S ZTSTOP=1 D EXIT^PXRRGUT
  1. ;
  1. ;Get the VISIT IEN
  1. S VIEN=0
  1. VISIT S VIEN=$O(^AUPNVSIT("B",BD,VIEN))
  1. I VIEN="" G NDATE
  1. S VISIT=^AUPNVSIT(VIEN,0)
  1. ;
  1. ;Screen out inappropriate vists.
  1. ;Service categories.
  1. I PXRRSCAT'[$P(VISIT,U,7) G VISIT
  1. ;Encounter types.
  1. S VISIT150=$G(^AUPNVSIT(VIEN,150))
  1. I PXRRENTY'[$P(VISIT150,U,3) G VISIT
  1. ;
  1. ;Make sure that the facility is on the list.
  1. S FOUND=0
  1. S FAC=$P(VISIT,U,6)
  1. F IC=1:1:NFAC I $P(PXRRFAC(IC),U,1)=FAC D Q
  1. . S FACILITY=FAC
  1. . S FOUND=1
  1. I 'FOUND G VISIT
  1. ;
  1. S HLOCNAM=""
  1. ;
  1. D VISIT2^PXRRWLS2
  1. ;
  1. I 'FOUND G VISIT
  1. ;
  1. ;Get the Provider
  1. S PRVCNT=0
  1. S PRVIEN=0
  1. S MULTPR=""
  1. PRV ;
  1. S PRVIEN=$O(^AUPNVPRV("AD",VIEN,PRVIEN))
  1. I (PRVIEN="")&(PRVCNT>0) G VISIT
  1. I (PRVIEN="") S NEWPIEN=0
  1. E S NEWPIEN=+$P(^AUPNVPRV(PRVIEN,0),U,1)
  1. S PRVCNT=PRVCNT+1
  1. I NEWPIEN>0 S PPNAME=$P(^VA(200,NEWPIEN,0),U,1)_U_NEWPIEN
  1. E S PPNAME="Unknown"_U_NEWPIEN
  1. ;
  1. ;Apply any Provider screens.
  1. ;List of providers.
  1. I $D(PXRRPRPL) D G:'FOUND PRV
  1. . S FOUND=0
  1. . F IC=1:1:NPL I $P(PXRRPRPL(IC),U,2)=NEWPIEN D Q
  1. ..;Mark this provider as being matched.
  1. .. S $P(PXRRPRPL(IC),U,4)="M"
  1. .. S FOUND=1
  1. ;
  1. ;Person class screen.
  1. I $D(PXRRPECL) D G:'FOUND PRV
  1. . S PCLASS=$$OCCUP^PXBGPRV(NEWPIEN,BD,"",1,"")
  1. . S FOUND=$$MATCH^PXRRPECU(PCLASS)
  1. . S PPNAME=PPNAME_U_$P(PCLASS,U,7)
  1. ;
  1. D PRV2^PXRRWLS2
  1. ;
  1. CLOC ;
  1. D CLOC2^PXRRWLS2
  1. ;
  1. ;Find the CPT code(s) and associated E&M codes for this encounter.
  1. S IC=$O(^AUPNVCPT("AD",VIEN,""))
  1. I +IC=0 D G BYCLOC
  1. . S ^XTMP(PXRRXTMP,FACILITY,STOIND,"NOCPT")=$G(^XTMP(PXRRXTMP,FACILITY,STOIND,"NOCPT"))+1
  1. .;Total for multiple provider encounters.
  1. . I MULTPR S ^XTMP(PXRRXTMP,FACILITY,"&&","NOCPT")=$G(^XTMP(PXRRXTMP,FACILITY,"&&","NOCPT"))+1
  1. ;
  1. S IC=""
  1. GETCPT S IC=$O(^AUPNVCPT("AD",VIEN,IC))
  1. I +IC>0 D GC2^PXRRWLS2 G GETCPT
  1. ;
  1. BYCLOC ;If necessary accumulate the information about each clinic stop
  1. ;location.
  1. I BYCLOC,$L(STOIND,U)=3 D G CLOC
  1. . S HLOCIEN=$P(VISIT,U,22)
  1. . ;Null Subscript: Visit is missing hospital location.
  1. . ;Undefined: Hospital Location may have been deleted.
  1. . S STOIND=STOIND_U_$P(^SC(HLOCIEN,0),U,1)
  1. ;Pass flag to report for header message.
  1. I MULTPR=1 S ^XTMP(PXRRXTMP,"PXRRMPR")=1
  1. ; Get the next provider for the encounter...
  1. S PXRRPRSC=$G(PXRRPRSC) ; Ensure it exists.
  1. I $E(PXRRPRSC)="S",$G(NPL)>1 S MULTPR=1 G PRV
  1. I $E(PXRRPRSC)="C"!($E(PXRRPRSC)="A") S MULTPR=1 G PRV
  1. ; ...or get the next encounter.
  1. G VISIT
  1. ;
  1. DONE ;
  1. ;Process the patient list, get the number of unique patients, and the
  1. ;number of visits. A visit is defined to be any activity for a patient
  1. ;within a 24 hour period.
  1. ;
  1. S FACILITY=0
  1. NFAC S FACILITY=$O(^TMP(PXRRXTMP,$J,FACILITY))
  1. I +FACILITY=0 G SDONE
  1. ;
  1. D NF2^PXRRWLS2
  1. ;
  1. S STOIND="&"
  1. NSTO S STOIND=$O(^TMP(PXRRXTMP,$J,FACILITY,STOIND))
  1. I STOIND="" G NFAC
  1. ;
  1. S TOTVIS=0
  1. S UPAT=0
  1. S VISITS(0)=0
  1. S VISITS(1)=0
  1. ;
  1. ;If this is an interactive session let the user know that something
  1. ;is happening.
  1. I '(PXRRQUE!$D(IO("S"))) D SPIN^PXRRBUSY("Sorting encounters",.BUSY)
  1. ;
  1. S DFN=0
  1. NDFN S DFN=$O(^TMP(PXRRXTMP,$J,FACILITY,STOIND,"PATIENT",DFN))
  1. I +DFN=0 D G NSTO
  1. . S ^XTMP(PXRRXTMP,FACILITY,STOIND,"TOTVIS")=TOTVIS
  1. . S ^XTMP(PXRRXTMP,FACILITY,STOIND,"UPAT")=UPAT
  1. . S ^XTMP(PXRRXTMP,FACILITY,STOIND,"VISITS",0)=VISITS(0)
  1. . S ^XTMP(PXRRXTMP,FACILITY,STOIND,"VISITS",1)=VISITS(1)
  1. S UPAT=UPAT+1
  1. ;
  1. S DAY=""
  1. NDAY S DAY=$O(^TMP(PXRRXTMP,$J,FACILITY,STOIND,"PATIENT",DFN,DAY))
  1. I DAY="" G NDFN
  1. S TOTVIS=TOTVIS+1
  1. ;
  1. S INOUT=-1
  1. NINOUT S INOUT=$O(^TMP(PXRRXTMP,$J,FACILITY,STOIND,"PATIENT",DFN,DAY,INOUT))
  1. I INOUT="" G NDAY
  1. S VISITS(INOUT)=VISITS(INOUT)+1
  1. G NINOUT
  1. ;
  1. SDONE ;Sorting is done.
  1. I '(PXRRQUE!$D(IO("S"))) D DONE^PXRRBUSY("done")
  1. K ^TMP(PXRRXTMP)
  1. ;
  1. ;If there were selected clinic stops build dummy entries for all
  1. ;those without entries.
  1. I $D(PXRRCS) D
  1. . F FAC=1:1:NFAC D
  1. .. S FACILITY=$P(PXRRFAC(FAC),U,1)
  1. .. F IC=1:1:NCS D
  1. ... I $P(PXRRCS(IC),U,4)'="M" D
  1. .... S HLOCNAM=PXRRCS(IC)
  1. .... S ^XTMP(PXRRXTMP,FACILITY,HLOCNAM,0,0)=""
  1. ;
  1. ;If there were selected hospital locations build dummy entries for all
  1. ;those without entries.
  1. I $D(PXRRLCHL) D
  1. . F FAC=1:1:NFAC D
  1. .. S FACILITY=$P(PXRRFAC(FAC),U,1)
  1. .. F IC=1:1:NHL D
  1. ... I $P(PXRRLCHL(IC),U,4)'="M" D
  1. .... S HLOCNAM=PXRRLCHL(IC)
  1. .... S ^XTMP(PXRRXTMP,FACILITY,HLOCNAM,0,0)=""
  1. ;
  1. EXIT ;
  1. ;Sort the appointment information.
  1. I PXRRQUE D
  1. .;Start the appointment sorting that was queued but not scheduled.
  1. . N DESC,ROUTINE,TASK
  1. . S ROUTINE="PXRRWLSA"
  1. . S DESC="Encounter Summary Report - sort appointments"
  1. . S ZTDTH=$$NOW^XLFDT
  1. . S TASK=^XTMP(PXRRXTMP,"SAZTSK")
  1. . D REQUE^PXRRQUE(DESC,ROUTINE,TASK)
  1. E D SORT^PXRRWLSA
  1. Q