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

BGOREP1.m

Go to the documentation of this file.
BGOREP1 ; IHS/BAO/TMD - Manage REPRODUCTIVE FACTORS ;08-May-2014 14:11;du
 ;;1.1;BGO COMPONENTS;**10,11,14**;Mar 20, 2007;Build 2
 ; Returns reproductive history as a single string
 ; Patch 5 updates the expanded history logic to prevent error on an empty element.
 ; Patch 6 updates to use new field formats for repro history
LAC(RET,CNT,DFN) ;EP get lactation data
 N REP,LAC,LACDT,LACPR
 S REP=$G(^AUPNREP(DFN,2))
 S LAC=$$EXTERNAL^DILFD(FNUM,2.01,,$P(REP,U,1))
 S LACDT=$P(REP,U,2)
 S LACDT=$$FMTDATE^BGOUTL(LACDT)
 S LACPR=$$EXTERNAL^DILFD(FNUM,2.03,,$P(REP,U,3))
 S CNT=CNT+1
 S @RET@(CNT)="B"_U_LAC_U_LACPR_U_LACDT
 Q
MEN(RET,CNT,DFN) ;get menstrual data
 N REP,MA,CA,MENO,DES,DESDT,MAD,CAD,MENOD
 S REP=$G(^AUPNREP(DFN,11))
 S MA=$$EXTERNAL^DILFD(FNUM,1117,,$P(REP,U,17))
 S MAD=$P(REP,U,18)
 S MAD=$$FMTDATE^BGOUTL(MAD)
 S CA=$$EXTERNAL^DILFD(FNUM,1119,,$P(REP,U,19))
 S CAD=$P(REP,U,20)
 S CAD=$$FMTDATE^BGOUTL(CAD)
 S MENO=$$EXTERNAL^DILFD(FNUM,1121,,$P(REP,U,21))
 S MENOD=$P(REP,U,22)
 S MENOD=$$FMTDATE^BGOUTL(MENOD)
 S CNT=CNT+1
 S @RET@(CNT)="M"_U_MA_U_MAD_U_CA_U_CAD_U_MENO_U_MENOD
 S DES=$$EXTERNAL^DILFD(FNUM,1127,,$P(REP,U,27))
 S DESDT=$P($G(^AUPNREP(DFN,11)),U,28)
 S DESDT=$$FMTDATE^BGOUTL(DESDT)
 S CNT=CNT+1
 S @RET@(CNT)="D"_U_DES_U_DESDT
 Q
EDD(RET,CNT,DFN) ;Get pregnancy data
 N REP,LMP,LMPPR,LMPDT,ULTRA,ULTPR,ULTDT,CLIN,CLINPR,CLINDT,UN,UNPR,UNDT,EDD,EDDPR,EDDDT
 N PREG,PREGDT,PREGPR,LMPCO,ULTCO,DEFCO,UNCO,CLINCO,EDDCO
 S REP=$G(^AUPNREP(DFN,13))
 S PREG=$P($G(^AUPNREP(DFN,11)),U,1)
 S PREG=$$EXTERNAL^DILFD(FNUM,1101,,PREG)
 S PREGDT=$P($G(^AUPNREP(DFN,11)),U,2)
 S PREGDT=$$FMTDATE^BGOUTL(PREGDT)
 S PREGPR=$P($G(^AUPNREP(DFN,11)),U,35)
 S PREGPR=$$EXTERNAL^DILFD(FNUM,1304,,PREGPR)
 ;EDD by LMP
 S LMP=$P(REP,U,2)
 S LMP=$$FMTDATE^BGOUTL(LMP)
 S LMPDT=$P(REP,U,3)
 S LMPDT=$$FMTDATE^BGOUTL(LMPDT)
 S LMPPR=$$EXTERNAL^DILFD(FNUM,1304,,$P(REP,U,4))
 S LMPCO=$P($G(^AUPNREP(DFN,14)),U,1)
 ;EDD by ultrasound
 S ULTRA=$P(REP,U,5)
 S ULTRA=$$FMTDATE^BGOUTL(ULTRA)
 S ULTDT=$P(REP,U,6)
 S ULTDT=$$FMTDATE^BGOUTL(ULTDT)
 S ULTPR=$$EXTERNAL^DILFD(FNUM,1307,,$P(REP,U,7))
 S ULTCO=$P($G(^AUPNREP(DFN,14)),U,2)
 ;EDD by clinical parameters
 S CLIN=$P(REP,U,8)
 S CLIN=$$FMTDATE^BGOUTL(CLIN)
 S CLINDT=$P(REP,U,9)
 S CLINDT=$$FMTDATE^BGOUTL(CLINDT)
 S CLINPR=$$EXTERNAL^DILFD(FNUM,1310,,$P(REP,U,10))
 S CLINCO=$P($G(^AUPNREP(DFN,15)),U,1)
 S EDD=$P(REP,U,11)
 S EDD=$$FMTDATE^BGOUTL(EDD)
 ;S EDD=$$EXTERNAL^DILFD(FNUM,1311,,$P(REP,U,11))
 S EDDDT=$P(REP,U,12)
 S EDDDT=$$FMTDATE^BGOUTL(EDDDT)
 S EDDPR=$$EXTERNAL^DILFD(FNUM,1313,,$P(REP,U,13))
 S EDDCO=$P($G(^AUPNREP(DFN,15)),U,2)
 ;EDD by unknown methods
 S UN=$P(REP,U,14)
 S UN=$$FMTDATE^BGOUTL(UN)
 S UNDT=$P(REP,U,15)
 S UNDT=$$FMTDATE^BGOUTL(UNDT)
 S UNPR=$$EXTERNAL^DILFD(FNUM,1316,,$P(REP,U,16))
 S UNCO=$P($G(^AUPNREP(DFN,16)),U,1)
 S CNT=CNT+1
 S @RET@(CNT)="P"_U_PREG_U_PREGPR_U_PREGDT
 S CNT=CNT+1
 S @RET@(CNT)="E"_U_EDD_U_EDDPR_U_EDDDT_U_EDDCO_U_LMP_U_LMPPR_U_LMPDT_U_LMPCO_U_ULTRA_U_ULTPR_U_ULTDT_U_ULTCO_U_CLIN_U_CLINPR_U_CLINDT_U_CLINCO_U_UN_U_UNPR_U_UNDT_U_UNCO
 Q
CONT(RET,CNT,DFN) ; Get contraceptive data
 N I,NODE,NAME,CNAME,CHK,CBEGUN,STRING,REC,FNUM
 S STRING="",CHK=0
 S I=0 F  S I=$O(^AUPNREP(DFN,2101,I)) Q:I=""!('+I)  D
 .S NODE=$G(^AUPNREP(DFN,2101,I,0))
 .Q:$D(^AUPNREP(DFN,2101,I,1))>0
 .S CHK=CHK+1
 .I $P(NODE,U,3)="" D
 ..S NAME=$P(NODE,U,1),CBEGUN=$P(NODE,U,2)
 ..S CBEGUN=$$FMTDATE^BGOUTL(CBEGUN)
 ..S CNAME=$P($G(^AUTTCM(NAME,0)),U,1)
 ..I CNAME="OTHER" S CNAME=CNAME_"-"_$P(NODE,U,6)
 ..I STRING="" S STRING=CNAME_";"_CBEGUN
 ..E  S STRING=STRING_"^"_CNAME_";"_CBEGUN
 I CHK=0 D
 .;S FNUM=$$FNUM^BGOREP
 .;S REC=$G(^AUPNREP(DFN,0))
 .;S CNAME=$$EXTERNAL^DILFD(FNUM,3,,$P(REC,U,6))
 .;S CBEGUN=$P(REC,U,7)
 .;S CBEGUN=$$FMTDATE^BGOUTL(CBEGUN)
 .;I CNAME'="" S STRING=CNAME_";"_CBEGUN
 S CNT=CNT+1
 S @RET@(CNT)="C"_U_STRING
 Q
CONTALL(RET,DFN) ;EP for RPC call to get all contrceptive data
 ; Input DFN of patient
 ;Output string:
 ;IEN of subfile [1] ^ method [2] ^ date started [3] ^ date ended [4] ^ reason DC [5] ^ comment [6]
 N CNT,NODE,I,J,NAME,CNAME,BEGUN,CDATE,STRING,ARRAY,CEND,COMM,CREA
 K ARRAY
 S RET=$$TMPGBL^BGOUTL
 S STRING="",CNT=0
 S I=0 F  S I=$O(^AUPNREP(DFN,2101,I)) Q:I=""!('+I)  D
 .Q:$D(^AUPNREP(DFN,2101,I,1))>0
 .S NODE=$G(^AUPNREP(DFN,2101,I,0))
 .I NODE'="" D
 ..S NAME=$P(NODE,U,1)
 ..S CDATE=$P(NODE,U,2)
 ..S CBEGUN=$$FMTDATE^BGOUTL(CDATE)
 ..S CNAME=$P($G(^AUTTCM(NAME,0)),U,1)
 ..S CEND=$P(NODE,U,3)
 ..S CEND=$$FMTDATE^BGOUTL(CEND)
 ..S CREA=$P(NODE,U,5)
 ..S COMM=$P(NODE,U,6)
 ..S ARRAY(9999999-CDATE,I)=I_U_CNAME_U_CBEGUN_U_CEND_U_CREA_U_COMM
 I '$D(ARRAY) S @RET@(1)="" Q
 I $D(ARRAY)>0 D
 .S I=0 F  S I=$O(ARRAY(I)) Q:I=""  D
 ..S J=0 F  S J=$O(ARRAY(I,J)) Q:J=""  D
 ...S CNT=CNT+1
 ...S @RET@(CNT)=$G(ARRAY(I,J))
 Q
 ;Set items into the contracepton multiple
 ;Input= DFN - patient
 ;DATA= array of items to be edited/stored in this format
 ;  (n)= IEN of subfile (if edit) [1] ^ Type of contraception [2] ^ date start [3] ^ date end [4] ^ reason DC [5] ^ comment [6]
SETCONT(RET,DFN,DATA) ;EP
 N I,FNUM,NEW,AIEN,IENS,NODE,CON,CONB,CIEN,CONE,CONDC,COM,TODAY,FDA,IEN,ERR
 S RET="",FNUM=$$FNUM^BGOREP
 S TODAY=$$DT^XLFDT
 S DFN=+DFN
 I '$D(^DPT(DFN,0)) S RET=$$ERR^BGOUTL(1001) Q
 I $P(^DPT(DFN,0),U,2)'="F" S RET=$$ERR^BGOUTL(1052) Q
 S NEW='$D(^AUPNREP(DFN))
 I NEW D
 .S IENS="+1,"
 .S FDA(9000017,"+1,",.01)=DFN
 .S IEN(1)=DFN
 .S FDA(9000017,"+1,",1.1)=TODAY
 .D UPDATE^DIE("","FDA","IEN","ERR")
 .I $D(IEN(1)) S RET=""
 .I $D(ERR) S RET="Unable to store patient"
 S I="" F  S I=$O(DATA(I)) Q:I=""!(RET'="")  D
 .K FDA
 .S NODE=$G(DATA(I))
 .S FNUM=9000017.02101
 .Q:$P(NODE,U,2)=""
 .I $P(NODE,U,1)="" D NEW Q
 .E  S AIEN=$P(NODE,U,1)_","_DFN_","
 .S FDA=$NA(FDA(FNUM,AIEN))
 .S CON=$P(NODE,U,2)
 .S:$L(CON) @FDA@(.01)=CON
 .S CONB=$$SDATE($P(NODE,U,3))
 .S:$L(CONB) @FDA@(.02)=CONB
 .S CONE=$$SDATE($P(NODE,U,4))
 .I CONE="" S CONE="@"
 .S @FDA@(.03)=CONE
 .S @FDA@(.04)=$$FMTE^XLFDT(DT)
 .S CONDC=$P(NODE,U,5)
 .S:$L(CONDC) @FDA@(.05)=CONDC
 .S COM=$P(NODE,U,6)
 .S:$L(COM) @FDA@(.06)=COM
 .S RET=$$UPDATE^BGOUTL(.FDA,"E@")
 .D:'$D(ERR) EVT^BGOREP(DFN,1)
 S:'$D(ERR) RET=DFN
 Q
SDATE(IDATE) ;Format date
 N DATA,MO,DAY
 S DAY=$E(IDATE,4,5)
 S MO=$E(IDATE,1,2)
 I DAY="00"&(MO="00") S DATA=$E(IDATE,7,10) Q DATA
 I DAY="00" S DATA=MO_"/"_$E(IDATE,7,10) Q DATA
 E  S DATA=IDATE
 Q DATA
NEW ;Add new one
 N APCDCMI,APCDREPI,DA,DIC,DIE,X,CON,CONB,CONE,COM,CONDC
 S APCDREPI=DFN
 S CON=$P(NODE,U,2)
 S CON=$O(^AUTTCM("B",CON,""))
 Q:CON=""
 S DIC(0)="AEMQ"
 S DIC="^AUPNREP("_APCDREPI_",2101,"
 S DA(1)=APCDREPI
 S DIC("P")=$P(^DD(9000017,2101,0),U,2)
 S X=CON
 S DIE("NO^")=1
 S DIC("DR")=""
 K DD,D0,DO
 D FILE^DICN
 S CONB=$P(NODE,U,3)
 S CONE=$P(NODE,U,4)
 I CONE="" S CONE="@"
 S CONDC=$P(NODE,U,5)
 S COM=$P(NODE,U,6)
 S DIE("NO^")=1
 S (APCDY,DA)=+Y,DA(1)=APCDREPI,DR=".02///"_CONB_";.03///"_CONE_";.04///^S X=$$FMTE^XLFDT(DT)"_";.05///"_CONDC_";.06///"_COM
 S DIE="^AUPNREP("_APCDREPI_",2101,",DIE("NO^")=1
 D ^DIE
 K DIE,DR,DA
 D EVT^BGOREP(DFN,1)
 Q
DELCONT(RET,DFN,INP) ;EP-
 N RET,SIEN,DIE,DA,IEN,APCDY,APCDCM,IENS,FDA,REA,COMM
 S RET=""
 Q:'DFN
 Q:$P(INP,U,1)=""
 ;K DIC,DA,DR
 S APCDY=$P(INP,U,1)
 S REA=$P(INP,U,7)
 S COMM=$P(INP,U,8)
 I REA="" S REA="ENTERED IN ERROR"
 ;S DA=APCDY,DA(1)=DFN,DR=".01///@"
 ;S DIE="^AUPNREP("_DFN_",2101,"
 ;D ^DIE
 S SIEN=APCDY_","_DFN_","
 S FDA(9000017.02101,SIEN,1.01)=DUZ
 S FDA(9000017.02101,SIEN,1.02)=$$NOW^XLFDT
 S FDA(9000017.02101,SIEN,1.03)=REA
 S FDA(9000017.02101,SIEN,1.04)=COMM
 D FILE^DIE("","FDA","ERR")
 S DA=APCDY,DA(1)=DFN D MULTOSET^APCDRF
 K DA
 D EVT^BGOREP(DFN,2)
 Q