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

AGRPTEMP.m

Go to the documentation of this file.
AGRPTEMP ;IHS/SD/TPF - LIST EMPLOYEES BY EMPLOYER
 ;;7.1;PATIENT REGISTRATION;;AUG 25,2005
 ;
 ;ABILITY TO LIST EMPLOYEES BY EMPLOYER.
 ;
EN ;EP
 K EXCLSION
 S $P(AGLINE("EQ"),"=",81)=""
 S $P(AGLINE("-"),"-",81)=""
 W !,"This program generates a listing of the Employees for each Employer, sorted in alphabetical order."
 W !!
 K DIR
 S DIR("A")="Do you wish the Run the Program"
 S DIR("B")="Y"
 S DIR(0)="YO"
 D ^DIR
 Q:$D(DTOUT)!($D(DUOUT))!($D(DIRUT))!($D(DIROUT))
 Q:'Y
 K DIR
 D MAIN    ;MAIN SLECTION DRIVER
 D EXIT    ;CLEANUP VARS
 Q
MAIN ;MAIN SELECTION DRIVER
 K ^XTMP("AGRPTEMP",$J),PRINTOUT
 D EXCHDR  ;PRINT EXCLUSION PARAMETERS CHOSEN BY USER
 N TAG
 K DIR
 S DIR("A")="Select ONE or MORE of the above EXCLUSION PARAMETERS"
 S DIR(0)="SO^1:EMP;2:STAT"
 S DIR("L",1)="Select one of the following:"
 S DIR("L",2)=""
 S DIR("L",3)="     1  EMPLOYER"
 S DIR("L",4)="             ALL EMPLOYERS"
 S DIR("L",5)="             SPECIFIC EMPLOYERS (enter specific names or from to)"
 S DIR("L",6)="     2  EMPLOYMENT STATUS"
 S DIR("L")="              Select Employment Status"
 D ^DIR
 I X="" D DOSORT(.EXCLSION),DOPRINT("") G MAIN
 Q:$D(DTOUT)!($D(DUOUT))!($D(DIRUT))!($D(DIROUT))
 S TAG="ASK"_Y(0)
 D @TAG
 K TAG
 G MAIN
 Q
ASKEMP ;ASK FOR EMPLOYERS
 N TAG
 K EXCLSION("Employers")
 K DIR
 S DIR("A")="Choose one"
 S DIR("B")="A"
 S DIR(0)="SO^A:ALL;S:SPECIFIC NAMES;F:FROM/TO"
 D ^DIR
 Q:$D(DTOUT)!($D(DUOUT))!($D(DIRUT))!($D(DIROUT))
 S TAG="EMP"_Y
 D @TAG
 K TAG,DIR
 Q
ASKDATES ;ASK FOR DATE RANGES
 K DIR,DTOUT,DUOUT,DIRUT,DIROUT
 S DIR("A")="Effective Date"
 S:$D(EXCLSION("Effective Date")) DIR("B")=EXCLSION("Effective Date")
 S DIR(0)="DO"
 D ^DIR
 I X="@" K EXCLSION("Effective Date") W "Deleted"
 Q:$D(DTOUT)!($D(DUOUT))!($D(DIROUT))
 S EFFDATE=$G(Y)
 S EXCLSION("Effective Date")=EFFDATE
 K DIR
 S DIR("A")="Termination Date"
 S:$D(EXCLSION("Termination Date")) DIR("B")=EXCLSION("Termination Date")
 S DIR(0)="DO"
 D ^DIR
 I X="@" K EXCLSION("Effective Date") W "Deleted"
 Q:$D(DTOUT)!($D(DUOUT))!($D(DIROUT))
 S TERMDATE=$G(Y)
 S EXCLSION("Termination Date")=TERMDATE
 K:EXCLSION("Termination Date")="" EXCLSION("Termination Date")
 Q
ASKSTAT ;ASK FOR STATUS FULL,PART ETC
 N CODES
 K DIR
 S CODES=$P($G(^DD(9000001,.21,0)),U,3)
 S DIR("A")="Employment Status"
 S DIR(0)="SO"_U_CODES_"A:ALL"
 D ^DIR
 Q:$D(DTOUT)!($D(DUOUT))!($D(DIRUT))!($D(DIROUT))
 S EMPSTAT=Y(0)
 S EXCLSION("Employment Status")=Y_U_Y(0)
 K:EXCLSION("Employment Status")="" EXCLSION("Employment Status")
 Q
EMPA ;DO ALL EMPLOYERS
 W !,"YOU CHOSE DO ALL EMPLOYERS"
 S EXCLSION("Employers")="ALL"
 Q
EMPS ;ALLOW SELECTION OF SPECIFIC EMPLOYERS
 W !,"YOU CHOSE TO DO SPECIFIC EMPLOYERS"
 S EXCLSION("Employers")="SPECIFIC EMPLOYERS"
EMPS1 K DIR,DTOUT,DUOUT,DIRUT,DIROUT
 S DIR(0)="PO^9999999.75:AEM"
 D ^DIR
 Q:$D(DTOUT)!($D(DUOUT))!($D(DIROUT))
 I X="@" K EXCLSION("Employers") Q
 Q:X=""
 S EXCLSION("Employers",+Y)=Y
 G:+Y EMPS1
 Q
EMPF ;ALLOW SELECTION OF FROM/TO EMPLOYERS
 W !,"YOU CHOSE TO ENTER A RANGE OF EMPLOYERS"
 S EXCLSION("Employers")="RANGE OF EMPLOYERS"
 S COUNT=0
FROM K DIR,DTOUT,DUOUT,DIRUT,DIROUT
 S COUNT=COUNT+1
 W !
 S DIR("A")="From Employer"
 S DIR(0)="PO^9999999.75:AEM"
 D ^DIR
 Q:$D(DTOUT)!($D(DUOUT))!($D(DIROUT))
 I X="@" K EXCLSION("Employers") Q
 Q:X=""
 S EXCLSION("Employers",COUNT)=Y
TO K DIR,DTOUT,DUOUT,DIRUT,DIROUT
 W !
 S DIR("A")="To Employer"
 S DIR(0)="PO^9999999.75:AEM"
 D ^DIR
 Q:$D(DTOUT)!($D(DUOUT))!($D(DIROUT))
 I X'="",($P(Y,U,2)']$P(EXCLSION("Employers",COUNT),U,2)) W "      Incorrect from/to sequence!" G TO
 S $P(EXCLSION("Employers",COUNT),"|",2)=Y
 G FROM
 Q
EXCHDR ;EP
 I '$D(PRINTOUT) W @IOF
 I $G(EXCLSION("Employers"))="" S EXCLSION("Employers")="ALL"
 I $G(EXCLSION("Employment Status"))="" S EXCLSION("Employment Status")="A^ALL"
 I '$D(EXCLSION) W !,"NO EXCLUSION PARAMETERS CURRENTLY IN EFFECT" Q
 W !,"EXCLUSION PARAMETERS Currently in Effect for RESTRICTING the REPORT to:"
 W !,AGLINE("EQ")
 W:$G(EXCLSION("Employment Status"))'="" !,"- Employment Status.......: ",$P($G(EXCLSION("Employment Status")),U,2)
 W:$G(EXCLSION("Effective Date"))'="" !,"- Effective Date..........: ",$G(EXCLSION("Effective Date"))
 W:$G(EXCLSION("Termination Date"))'="" !,"- Termination Date..........: ",$G(EXCLSION("Termination Date"))
 I $D(EXCLSION("Employers")) D
 .W !,"- Employers: "
 .I $P(EXCLSION("Employers"),U)="SPECIFIC EMPLOYERS" D  Q
 ..W "SPECIFIC EMPLOYERS: "
 ..S EMPREC=""
 ..F LN=1:1 S EMPREC=$O(EXCLSION("Employers",EMPREC)) Q:EMPREC=""  D
 ...W @$S(LN'=1:"!?35",1:"?35"),$P(EXCLSION("Employers",EMPREC),U,2)
 .;
 .I $P(EXCLSION("Employers"),U)="RANGE OF EMPLOYERS" D  Q
 ..W "RANGE OF EMPLOYERS: "
 ..S EMPREC=""
 ..F LN=1:1 S EMPREC=$O(EXCLSION("Employers",EMPREC)) Q:EMPREC=""  D
 ...W @$S(LN'=1:"!?35",1:"?35"),"From ",$P($P(EXCLSION("Employers",EMPREC),"|"),U,2)," to ",$P($P(EXCLSION("Employers",EMPREC),"|",2),U,2)
 .W "ALL EMPLOYERS"
 Q
DOSORT(EXCLSION) ;EP - PRINT EMPLOYEES FOR EMPLOYERS SELECTED
 S EMPLECNT=0,EMPLRCNT=0
 I $G(EXCLSION("Employers"))="ALL" D LOOP("",999999999999999)  ;DO ALL EMPLOYERS
 I $G(EXCLSION("Employers"))="SPECIFIC EMPLOYERS" D
 .S EMPREC=""
 .F  S EMPREC=$O(EXCLSION("Employers",EMPREC)) Q:EMPREC=""  D
 ..D LOOP(EMPREC-1,EMPREC+1)
 I $G(EXCLSION("Employers"))="RANGE OF EMPLOYERS" D
 .S EMPREC=""
 .F  S EMPREC=$O(EXCLSION("Employers",EMPREC)) Q:EMPREC=""  D
 ..S EMPLRBEG=$P($P(EXCLSION("Employers",EMPREC),"|"),U,2)
 ..S EMPLRBEG=$E(EMPLRBEG,1,$L(EMPLRBEG)-1)_$C($A($E(EMPLRBEG,$L(EMPLRBEG)))-1)
 ..S EMPLREND=$P($P(EXCLSION("Employers",EMPREC),"|",2),U,2)
 ..F  S EMPLRBEG=$O(^AUTNEMPL("B",EMPLRBEG)) Q:EMPLRBEG]EMPLREND  D
 ...S EMPLRREC=0
 ...F  S EMPLRREC=$O(^AUTNEMPL("B",EMPLRBEG,EMPLRREC)) Q:EMPLRREC=""  D
 ....D LOOP(EMPLRREC-1,EMPLRREC+1)
 Q
LOOP(TAREMPLR,ENDEMPLR) ;EP
 F  S TAREMPLR=$O(^AUPNPAT("AF",TAREMPLR)) Q:TAREMPLR>ENDEMPLR  Q:TAREMPLR=""  D
 .S EMPLRCNT=EMPLRCNT+1
 .S EMPLEE=""
 .F  S EMPLEE=$O(^AUPNPAT("AF",TAREMPLR,EMPLEE)) Q:EMPLEE=""  D
 ..S STATUS=$P($G(^AUPNPAT(EMPLEE,0)),U,21)
 ..I $G(EXCLSION("Employment Status"))'="",$P($G(EXCLSION("Employment Status")),U,2)'="ALL" Q:STATUS'=+$G(EXCLSION("Employment Status"))
 ..S HRN=$P($G(^AUPNPAT(EMPLEE,41,DUZ(2),0)),U,2)
 ..S EMPLEENM=$E($P($G(^DPT(EMPLEE,0)),U),1,15)
 ..S:EMPLEENM="" EMPLEENM="UNDEFINED"
 ..S EMPLRNM=$E($P($G(^AUTNEMPL(TAREMPLR,0)),U),1,15)
 ..S:EMPLRNM="" EMPLRNM="UNDEFINED"
 ..S STATUS=$P($P($P(^DD(9000001,.21,0),U,3),";",STATUS),":",2)
 ..S EMPLECNT=EMPLECNT+1
 ..S ^XTMP("AGRPTEMP",$J,EMPLRNM,EMPLEENM)=STATUS_U_HRN
 ..S ^XTMP("AGRPTEMP",$J,"EMPLOYER TOTAL")=EMPLRCNT
 ..S ^XTMP("AGRPTEMP",$J,"EMPLOYEE TOTAL")=EMPLECNT
 Q
DOPRINT(GLO) ;PRINT OUT SORTED TEMP GLOBAL
 I '$D(^XTMP("AGRPTEMP",$J)) W !,"NO RECORDS FOUND!" H 3 Q
 W !,^XTMP("AGRPTEMP",$J,"EMPLOYEE TOTAL")," RECORDS MET THE CRITERIA"
 D ^%ZIS Q:POP
 U IO
 S ESCAPE=0,PAGENO=0
 D HDR
 S EMPLECNT=^XTMP("AGRPTEMP",$J,"EMPLOYEE TOTAL")
 S EMPLRCNT=^XTMP("AGRPTEMP",$J,"EMPLOYER TOTAL")
 S EMPLRNM="EMPLOYER TOTAL"
 F EMPLRREC=1:1 S EMPLRNM=$O(^XTMP("AGRPTEMP",$J,EMPLRNM)) Q:EMPLRNM=""!(ESCAPE)  D
 .D HDR
 .S EMPLEENM=""
 .W !,$E(EMPLRNM,1,15)
 .S LINEITEM=0
 .F EMPLEREC=1:1 S EMPLEENM=$O(^XTMP("AGRPTEMP",$J,EMPLRNM,EMPLEENM)) Q:EMPLEENM=""!(ESCAPE)  D
 ..S STATUS=$P(^XTMP("AGRPTEMP",$J,EMPLRNM,EMPLEENM),U)
 ..S HRN=$P(^XTMP("AGRPTEMP",$J,EMPLRNM,EMPLEENM),U,2)
 ..S LINEITEM=LINEITEM+1
 ..W @$S(LINEITEM=1:"?20",1:"!?20"),$E(EMPLEENM,1,15),?40,HRN,?50,$P(STATUS,U)
 ..;NOTE: HEADER IS 10 LINES
 ..I $Y>(IOSL-10),(IOST[("C-")) W ! K DIR S DIR(0)="E" D ^DIR S ESCAPE=X=U D:'ESCAPE HDR W !,$E(EMPLRNM,1,15) Q
 ..I $Y>(IOSL-10) D HDR W !,$E(EMPLRNM,1,15)
 .W !?20,"========================"
 .W !?20,EMPLEREC-1
 W !!,"Number of Employers        Number of Employees"
 W !,EMPLRCNT,?25,EMPLECNT
 I (IOST[("C-")) K DIR W ! K DIR S DIR(0)="E" D ^DIR S ESCAPE=X=U D:'ESCAPE HDR Q
 D ^%ZISC
 Q
HDR ;MAIN HEADER
 S PRINTOUT=1
 W @IOF
 W !,"WARNING: Confidential Patient Information, Privacy Act Applies"
 W !,AGLINE("EQ")
 D EXCHDR
 W !,AGLINE("EQ")
 W !,"Employer",?20,"Employee",?40,"HRN",?50,"Status"
 W !,AGLINE("-")
 S LINEITEM=0
 Q
EXIT ;EP - CLEANUP VARS
 K EFFDATE,EMPLECNT,COUNT,EMPLEE,EMPLEENM,EMPLEREC,EMPLRBEG,EMPLRCNT,EMPLREND
 K EMPLRNM,EMPLRREC,EMPREC
 Q