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

BQIPTREP.m

Go to the documentation of this file.
BQIPTREP ;VNGT/HS/ALA - Patient Reproductive Factors ; 06 May 2008  7:40 PM
 ;;2.3;ICARE MANAGEMENT SYSTEM;;Apr 18, 2012;Build 59
 ;
REP(DATA,DFN) ; EP -- BQI PATIENT REPRODUCTIVE FACS
 ;
 ;Description - all the reproductive factors that a patient has
 ;
 ;Input
 ;  DFN - Patient internal entry number
 ;
 NEW UID,II,RDATA,BQINT,BQEXT,SEX,RFLMP,RFGRAV,RFPARI,RFFTB,RFPTB
 NEW RFEDCDT,RFAMENS,RFAMENP,RFDESDS,RFEDCMD,RFCFPM,RFLD,RDES,RDATA,AGE,N
 NEW RCFPMDB,RCFPMDE,RFECTPG,RFEDCMDT,RFLMPD,RFSPBOR,RFTABOR,RPCON,RPCONDT
 NEW RPHIS,RPHISDT,VER,RFLIVC,RFCPREG,RFPRDT,RFDT,RPCONMBG,RFCFPMDT
 NEW RFCOIT,RFMULPRT,RFSXTRMA,ACTIVE,RFFPBDT,RFFPEDT,RFFPMT,RFLACT
 ;
 S UID=$S($G(ZTSK):"Z"_ZTSK,1:$J)
 S DATA=$NA(^TMP("BQIPTREP",UID))
 K @DATA
 ;
 S II=0
 NEW $ESTACK,$ETRAP S $ETRAP="D ERR^BQIPTREP D UNWIND^%ZTER" ; SAC 2006 2.2.3.3.2
 ;
 S SEX=$$GET1^DIQ(2,DFN_",",.02,"I"),AGE=$$AGE^BQIAGE(DFN)
 I SEX'="F" D  Q
 . S @DATA@(II)="I00010RESULT^T00080MESSAGE"_$C(30)
 . S II=II+1,@DATA@(II)="-1^RPC Failed: Patient is not Female"_$C(30)
 . S II=II+1,@DATA@(II)=$C(31)
 ;
 S RDATA=""
 S @DATA@(II)="T00010COLUMN_NAME^T00045COLUMN_DESC^T00120COLUMN_VALUE^D00015DATE_LAST_MODIFIED^T00075PRV_LAST_MODIFIED"_$C(30)
 ; Get data from file
 D GETS^DIQ(9000017,DFN_",","*","I","BQINT")
 D GETS^DIQ(9000017,DFN_",","*","E","BQEXT")
 S RFLMP=$$FMTE^BQIUL1($G(BQINT(9000017,DFN_",",2,"I"))) I RFLMP'="" S RDATA=1
 S RFLMPD=$$FMTE^BQIUL1($G(BQINT(9000017,DFN_",",2.1,"I"))) I RFLMPD'="" S RDATA=1,RFDT("RFLMP")=RFLMPD
 ;
 ; Check the version of software
 S VER=$$VERSION^XPDUTL("IHS PCC SUITE")
 I VER<2.0 D
 . S RFEDCDT=$$FMTE^BQIUL1($G(BQINT(9000017,DFN_",",4,"I"))) I RFEDCDT'="" S RDATA=1
 . S RFEDCMD=$G(BQEXT(9000017,DFN_",",4.05,"E")) I RFEDCMD'="" S RDATA=1
 . S RFEDCMDT=$$FMTE^BQIUL1($G(BQINT(9000017,DFN_",",4.1,"I"))) I RFEDCMDT'="" S RDATA=1
 . S RPHIS=$G(BQEXT(9000017,DFN_",",1,"E")) I RPHIS'="" S RDATA=1
 . S RPHISDT=$$FMTE^BQIUL1($G(BQINT(9000017,DFN_",",1.1,"I"))) I RPHISDT'="" S RDATA=1
 . S RPCONDT=$$FMTE^BQIUL1($G(BQINT(9000017,DFN_",",3.1,"I"))) I RPCONDT'="" S RDATA=1
 . S RPCONMBG=$$FMTE^BQIUL1($G(BQINT(9000017,DFN_",",3.05,"I"))) I RPCONMBG'="" S RDATA=1
 . S RPCON=$G(BQEXT(9000017,DFN_",",3,"E")) I RPCON'="" S RDATA=1
 I VER>1.0 D
 . S RFGRAV=$G(BQEXT(9000017,DFN_",",1103,"E"))
 . I RFGRAV'="" S RDATA=1,RFDT("RFGRAV")=$$FMTE^BQIUL1($G(BQINT(9000017,DFN_",",1104,"I")))
 . S RFLACT=$G(BQEXT(9000017,DFN_",",2.01,"E")),ACTIVE("RFLACT")=""
 . I RFLACT'="" S RDATA=1,RFDT("RFLACT")=$$FMTE^BQIUL1($G(BQINT(9000017,DFN_",",2.02,"I")))
 . S RFPARI=$G(BQEXT(9000017,DFN_",",1105,"E"))
 . I RFPARI'="" S RDATA=1,RFDT("RFPARI")=$$FMTE^BQIUL1($G(BQINT(9000017,DFN_",",1106,"I")))
 . S RFFTB=$G(BQEXT(9000017,DFN_",",1107,"E"))
 . I RFFTB'="" S RDATA=1,RFDT("RFFTB")=$$FMTE^BQIUL1($G(BQINT(9000017,DFN_",",1108,"I")))
 . S RFPTB=$G(BQEXT(9000017,DFN_",",1109,"E"))
 . I RFPTB'="" S RDATA=1,RFDT("RFPTB")=$$FMTE^BQIUL1($G(BQINT(9000017,DFN_",",1110,"I")))
 . S RFECTPG=$G(BQEXT(9000017,DFN_",",1111,"E"))
 . I RFECTPG'="" S RDATA=1,RFDT("RFECTPG")=$$FMTE^BQIUL1($G(BQINT(9000017,DFN_",",1112,"I")))
 . S RFTABOR=$G(BQEXT(9000017,DFN_",",1131,"E"))
 . I RFTABOR'="" S RDATA=1,RFDT("RFTABOR")=$$FMTE^BQIUL1($G(BQINT(9000017,DFN_",",1132,"I")))
 . S RFSPBOR=$G(BQEXT(9000017,DFN_",",1133,"E"))
 . I RFSPBOR'="" S RDATA=1,RFDT("RFSPBOR")=$$FMTE^BQIUL1($G(BQINT(9000017,DFN_",",1134,"I")))
 . S RFLIVC=$G(BQEXT(9000017,DFN_",",1113,"E"))
 . I RFLIVC'="" S RDATA=1,RFDT("RFLIVC")=$$FMTE^BQIUL1($G(BQINT(9000017,DFN_",",1114,"I")))
 . I $E($$GET1^DID(9000017,1101,"","LABEL"),1)'="*" D
 .. S RFCPREG=$G(BQEXT(9000017,DFN_",",1101,"E")),ACTIVE("RFCPREG")=""
 .. I RFCPREG'="" S RDATA=1,RFDT("RFCPREG")=$$FMTE^BQIUL1($G(BQINT(9000017,DFN_",",1102,"I")))
 .. I RFCPREG="YES" D  ;Only display EDC if current pregnancy status is YES
 ... I $E($$GET1^DID(9000017,4,"","LABEL"),1)="*" S INACTIVE("RFEDCDT")="",INACTIVE("RFEDCMD")=""
 ... I $E($$GET1^DID(9000017,4,"","LABEL"),1)'="*" D
 .... S RFEDCDT=$$FMTE^BQIUL1($G(BQINT(9000017,DFN_",",4,"I"))) I RFEDCDT'="" S RDATA=1
 .... S RFEDCMD=$G(BQINT(9000017,DFN_",",4.05,"I"))_$C(28)_$G(BQEXT(9000017,DFN_",",4.05,"E")) I RFEDCMD'=$C(28) S RDATA=1
 .... ;S RFPRDT=$$FMTE^BQIUL1($G(BQINT(9000017,DFN_",",1102,"I"))) I RFPRDT'="" S RDATA=1
 . I $E($$GET1^DID(9000017,1101,"","LABEL"),1)="*" D
 .. S RFEDCDT=$$FMTE^BQIUL1($G(BQINT(9000017,DFN_",",4,"I"))) I RFEDCDT'="" S RDATA=1
 .. S RFEDCMD=$G(BQEXT(9000017,DFN_",",4.05,"E")) I RFEDCMD'="" S RDATA=1
 .. S RFDT("RFEDCDT")=$$FMTE^BQIUL1($G(BQINT(9000017,DFN_",",4.1,"I")))
 . I $E($$GET1^DID(9000017,1117,"","LABEL"),1)'="*" D
 .. S RFAMENS=$G(BQEXT(9000017,DFN_",",1117,"E")),ACTIVE("RFAMENS")=""
 .. I RFAMENS'="" S RDATA=1,RFDT("RFAMENS")=$$FMTE^BQIUL1($G(BQINT(9000017,DFN_",",1118,"I")))
 . I $E($$GET1^DID(9000017,1121,"","LABEL"),1)'="*" D
 .. S RFAMENP=$G(BQEXT(9000017,DFN_",",1121,"E")),ACTIVE("RFAMENP")=""
 .. I RFAMENP'="" S RDATA=1,RFDT("RFAMENP")=$$FMTE^BQIUL1($G(BQINT(9000017,DFN_",",1122,"I")))
 . I $E($$GET1^DID(9000017,1127,"","LABEL"),1)'="*" D
 .. S RFDESDS=$G(BQEXT(9000017,DFN_",",1127,"E")),ACTIVE("RFDESDS")=""
 .. I RFDESDS'="" S RDATA=1,RFDT("RFDESDS")=$$FMTE^BQIUL1($G(BQINT(9000017,DFN_",",1128,"I")))
 . I $E($$GET1^DID(9000017,1119,"","LABEL"),1)'="*" D
 .. S RFCOIT=$G(BQEXT(9000017,DFN_",",1119,"E")),ACTIVE("RFCOIT")=""
 .. I RFCOIT'="" S RDATA=1,RFDT("RFCOIT")=$$FMTE^BQIUL1($G(BQINT(9000017,DFN_",",1120,"I")))
 . I $E($$GET1^DID(9000017,1125,"","LABEL"),1)'="*" D
 .. S RFMULPRT=$G(BQEXT(9000017,DFN_",",1125,"E")),ACTIVE("RFMULPRT")=""
 .. I RFMULPRT'="" S RDATA=1,RFDT("RFMULPRT")=$$FMTE^BQIUL1($G(BQINT(9000017,DFN_",",1126,"I")))
 . I $E($$GET1^DID(9000017,1123,"","LABEL"),1)'="*" D
 .. S RFSXTRMA=$G(BQEXT(9000017,DFN_",",1123,"E")),ACTIVE("RFSXTRMA")=""
 .. I RFSXTRMA'="" S RDATA=1,RFDT("RFSXTRMA")=$$FMTE^BQIUL1($G(BQINT(9000017,DFN_",",1124,"I")))
 . ;
 . ; Contraceptive Methods
 . S RFCFPM=""
 . I $E($$GET1^DID(9000017,2101,"","LABEL"),1)="*" D
 .. S RFCFPM=$G(BQEXT(9000017,DFN_",",3,"E"))
 .. S RFCFPMDT=$$FMTE^BQIUL1($G(BQINT(9000017,DFN_",",3.05,"I")))
 .. S RFDT("RFCFPM")=$$FMTE^BQIUL1($G(BQINT(9000017,DFN_",",3.1,"I")))
 . I $E($$GET1^DID(9000017,2101,"","LABEL"),1)'="*" S N=0 D
 .. ;S (ACTIVE("RFFPMT"),ACTIVE("RFFPBDT"),ACTIVE("RFFPEDT"))=""
 .. F  S N=$O(^AUPNREP(DFN,2101,N)) Q:'N  D
 ... NEW DA,IENS
 ... S DA(1)=DFN,DA=N,IENS=$$IENS^DILF(.DA)
 ... I $$GET1^DIQ(9000017.02101,IENS,.05,"E")'="" Q
 ... S RFFPBDT=$$GET1^DIQ(9000017.02101,IENS,.02,"I") I RFFPBDT'="" S RDATA=1
 ... S RFCFUPD=$$GET1^DIQ(9000017.02101,IENS,.04,"I")
 ... S RFCMCMT=$$GET1^DIQ(9000017.02101,IENS,.06,"3")
 ... ;S RFFPEDT=$$GET1^DIQ(9000017.02101,IENS,.03,"I") I RFFPEDT'="" S RDATA=1
 ... ;I RFFPBDT="",RFFPEDT="" Q
 ... ;S RFFPMT=$$GET1^DIQ(9000017.02101,IENS,.01,"E")_"("_$$FMTE^BQIUL1(RFFPBDT)_"-"_$$FMTE^BQIUL1(RFFPEDT)_")"
 ... S RFCFPM=$$GET1^DIQ(9000017.02101,IENS,.01,"E")_$S(RFCMCMT'="":" ("_RFCMCMT_")",1:"")
 ... S RFCFPMDT=$$FMTE^BQIUL1(RFFPBDT),RFDT("RFCFPM")=$$FMTE^BQIUL1(RFCFUPD)
 I 'RDATA,AGE<10 D  Q
 . S @DATA@(II)="I00010RESULT^T00080MESSAGE"_$C(30)
 . S II=II+1,@DATA@(II)="-1^RPC Failed: Patient is less than 10 years of age"_$C(30)
 . S II=II+1,@DATA@(II)=$C(31)
 ;
 I VER<2.0 D  G DONE
 . S II=II+1,@DATA@(II)="DFN^Patient^"_DFN_U_U_$C(30)
 . S II=II+1,@DATA@(II)="RFLMP^Last Menstrual Period (LMP)^"_RFLMP_U_RFLMPD_U_$C(30)
 . S II=II+1,@DATA@(II)="RFEDCMD^EDC^"_RFEDCMD_U_RFEDCMDT_U_$C(30)
 . S II=II+1,@DATA@(II)="RPHIS^Reproductive History^"_RPHIS_U_RPHISDT_U_$C(30)
 . S II=II+1,@DATA@(II)="RPCON^Contraception Method^"_RPCON_U_RPCONDT_U_$C(30)
 . S II=II+1,@DATA@(II)="RPCONMBG^Current Contraception Begun^"_RPCONMBG_U_$C(30)
 . ;S II=II+1,@DATA@(II)="RPHIS^Reproductive History^"_RPHIS_U_RPHISDT_$C(30)
 . ;S II=II+1,@DATA@(II)="RFLMP^Last Menstrual Period (LMP)^"_RFLMP_U_RFLMPD_U_$C(30)
 . ;S II=II+1,@DATA@(II)="RPCON^Contraception Method^"_RPCON_U_RPCONDT_U_$C(30)
 . ;S II=II+1,@DATA@(II)="RFEDCMD^EDC Method^"_RFEDCMD_U_RFEDCMDT_U_$C(30)
 . ;S II=II+1,@DATA@(II)="RFEDCDT^Estimated Date of Confinement (EDC) Date^"_RFEDCDT_U_RFEDCMDT_U_$C(30)
 ;
 D RDES
 D:$D(ACTIVE) ACTIVATE(.ACTIVE)
 F RFLD="DFN","RFLMP","RFCPREG","RFLACT","RFCFPM","RFCFPMDT","RFEDDDT","RFEDCMD" I $D(@RFLD) S II=II+1,@DATA@(II)=RFLD_U_RDES(RFLD)_U_@RFLD_U_$G(RFDT(RFLD))_U_$C(30)
 ;F RFLD="DFN","RFLMP","RFCFPM","RFCFPMDT","RFEDCDT","RFEDCMD" I $D(@RFLD) S II=II+1,@DATA@(II)=RFLD_U_RDES(RFLD)_U_@RFLD_U_$G(RFDT(RFLD))_U_$C(30)
 F RFLD="RFGRAV","RFFTB","RFPTB" I $D(@RFLD) S II=II+1,@DATA@(II)=RFLD_U_RDES(RFLD)_U_@RFLD_U_$G(RFDT(RFLD))_U_$C(30)
 F RFLD="RFSPBOR","RFTABOR","RFECTPG","RFLIVC" I $D(@RFLD) S II=II+1,@DATA@(II)=RFLD_U_RDES(RFLD)_U_@RFLD_U_$G(RFDT(RFLD))_U_$C(30)
 F RFLD="RFPARI" I $D(@RFLD) S II=II+1,@DATA@(II)=RFLD_U_RDES(RFLD)_U_@RFLD_U_$G(RFDT(RFLD))_U_$C(30)
 ;F RFLD="RFCPREG" I $D(@RFLD) S II=II+1,@DATA@(II)=RFLD_U_RDES(RFLD)_U_@RFLD_U_$G(RFDT(RFLD))_U_$C(30)
 F RFLD="RFAMENS","RFCOIT","RFAMENP","RFDESDS" I $D(@RFLD) S II=II+1,@DATA@(II)=RFLD_U_RDES(RFLD)_U_@RFLD_U_$G(RFDT(RFLD))_U_$C(30)
 F RFLD="RFMULPRT","RFSXTRMA" I $D(@RFLD) S II=II+1,@DATA@(II)=RFLD_U_RDES(RFLD)_U_@RFLD_U_$G(RFDT(RFLD))_U_$C(30)
 ;F RFLD="RFLACT" I $D(@RFLD) S II=II+1,@DATA@(II)=RFLD_U_RDES(RFLD)_U_@RFLD_U_$G(RFDT(RFLD))_U_$C(30)
 ;
DONE ;
 S II=II+1,@DATA@(II)=$C(31)
 Q
 ;
RDES ; Load report descriptions
 S RDES("DFN")="Patient"
 S RDES("RFLMP")="Last Menstrual Period (LMP)"
 S RDES("RFGRAV")="Total Number of Pregnancies"
 S RDES("RFPARI")="Multiple Births"
 S RDES("RFFTB")="Full Term Births"
 S RDES("RFPTB")="Premature Births"
 S RDES("RFECTPG")="Ectopic Pregnancies"
 S RDES("RFTABOR")="Abortions, Induced"
 S RDES("RFSPBOR")="Abortions, Spontaneous"
 S RDES("RFLIVC")="Living Children"
 S RDES("RFCPREG")="Current Pregnancy Status"
 ;S RDES("RFPRDT")="Pregnancy Status ""as of"" date"
 S RDES("RFLACT")="Lactation Status"
 S RDES("RFEDCDT")="Estimated Due Date"
 S RDES("RFEDCMD")="EDD Method"
 S RDES("RFAMENS")="Age at First Menses"
 S RDES("RFAMENP")="Age at Menopause Onset"
 S RDES("RFDESDS")="DES Daughter Status"
 S RDES("RFCFPM")="Current Contraception Method"
 S RDES("RFCFPMDT")="Current Contraception Begun"
 S RDES("RFCOIT")="Age at first sexual intercouse"
 S RDES("RFMULPRT")="Multiple Sexual Partners?"
 S RDES("RFSXTRMA")="History of Sexual Trauma?"
 S RDES("RFEDDDT")="Definitive EDD"
 Q
 ;
ACTIVATE(ACTIVE) ;
 ; ACTIVE = array of CODE name references to make active at 90506.31,.11
 ; each element in the array maps to the CODE defined at 90506.31,.07
 ; logic activates the fields in DISPLAY COLUMNS subfile of the ICARE FILE DEFINITION 
 ; for the REPRODUCTIVE FACTORS entry including the FAMILY PLANNING METHOD subfile entry of REPRODUCTIVE FACTORS
 N RFCODE,VDEFILE,VDEFDA,RFCDDA,VDEFIENS,DA
 S (VDEFDA,RFCDDA)=0,RFCODE=""
 F VDEFILE="9000017","9000017.02101" D
 . S VDEFDA=$O(^BQI(90506.3,"C",VDEFILE,"")) Q:'VDEFDA
 . S DA(1)=VDEFDA
 . F  S RFCODE=$O(ACTIVE(RFCODE)) Q:RFCODE=""  D
 .. S RFCDDA=+$O(^BQI(90506.3,VDEFDA,10,"AC",RFCODE,"")) Q:'RFCDDA
 .. S DA=RFCDDA,VDEFIENS=$$IENS^DILF(.DA)
 .. ;S BQINEW(90506.31,VDEFIENS,.11)=$S($G(ACTIVE):"@",1:1)
 .. S BQINEW(90506.31,VDEFIENS,.11)="@"
 .. K ACTIVE(RFCODE)
 . F  S RFCODE=$O(INACTIVE(RFCODE)) Q:RFCODE=""  D
 .. S RFCDDA=+$O(^BQI(90506.3,VDEFDA,10,"AC",RFCODE,"")) Q:'RFCDDA
 .. S DA=RFCDDA,VDEFIENS=$$IENS^DILF(.DA)
 .. S BQINEW(90506.31,VDEFIENS,.11)=1
 .. K INACTIVE(RFCODE)
 D FILE^DIE("","BQINEW","ERROR")
 Q
 ; 
ERR ;
 D ^%ZTER
 NEW Y,ERRDTM
 S Y=$$NOW^XLFDT() X ^DD("DD") S ERRDTM=Y
 S BMXSEC="Recording that an error occurred at "_ERRDTM
 I $D(II),$D(DATA) S II=II+1,@DATA@(II)=$C(31)
 Q