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

SDES2EDITAPREQ.m

Go to the documentation of this file.
SDES2EDITAPREQ ;ALB/BWF,JAS,JAS,TJB/JAS,BWF,JAS - EDIT APPOINTMENT REQUEST ; OCT 7, 2024
 ;;5.3;Scheduling;**869,871,873,875,890,893**;Aug 13, 1993;Build 6
 ;;Per VHA Directive 6402, this routine should not be modified
 ;
 Q
 ; RPC: SDES2 EDIT APPT REQ
 ;
 ; SDCONTEXT INPUT
 ;
 ;S SDCONTEXT("ACHERON AUDIT ID") = Up to 40 Character unique ID number. Ex: 11d9dcc6-c6a2-4785-8031-8261576fca37
 ;S SDCONTEXT("USER DUZ") = The DUZ of the user taking action in the calling application.
 ;S SDCONTEXT("USER SECID") = The SECID of the user taking action in the calling application.
 ;S SDCONTEXT("PATIENT DFN") = The DFN/IEN of the target patient from the calling application.
 ;S SDCONTEXT("PATIENT ICN") = The ICN of the target patient from the calling application.
 ;
 ; REQUEST INPUT FORMAT
 ;
 ;S REQUEST("REQUEST IEN")=""                               REQ
 ;S REQUEST("DFN")=""                                       REQ
 ;S REQUEST("APPOINTMENT TYPE")=""                          OPT - APPOINTMENT TYPE - can be the Name or IEN
 ;S REQUEST("PATIENT INDICATED DATE")=""                    REQ - when editing a child, this is the new pid date for the child
 ;S REQUEST("PRIORITY")=""                                  REQ
 ;S REQUEST("REQUESTED BY")=""                              REQ
 ;S REQUEST("CLINIC IEN")=""                                OPT/REQ  \
 ;S REQUEST("PRIMARY AMIS")=""                              OPT/REQ---> Either CLINIC IEN or PRIMARY AMIS/CREDIT PRIMARY AMIS must be defined
 ;S REQUEST("CREDIT AMIS")=""                               OPT/REQ  /
 ;S REQUEST("STATION NUMBER")=""                            OPT/REQ -- > Either STATION NUMBER or INSTITUTION NAME is REQUIRED
 ;S REQUEST("INSTITUTION NAME")=""                          OPT/REQ --/
 ;S REQUEST("PROVIDER IEN")=""                              OPT (Required if 'REQUESTED BY' is 'PROVIDER')
 ;S REQUEST("PRIORITY GROUP")=""                            OPT
 ;S REQUEST("SERVICE CONNECTED")=""                         OPT (This is for PRIORITY; 1 OR 0, if passed)
 ;S REQUEST("SERVICE CONNECTED PERCENTAGE")=""              OPT
 ;S REQUEST("MODALITY")=""                                  OPT
 ;S REQUEST("PATIENT STATUS")=""                            OPT
 ;S REQUEST("VAOS GUID")=""                                 OPT
 ;S REQUEST("TIME SENSITIVE")=""                            OPT
 ;S REQUEST("REQUEST COMMENT")=""                           OPT
 ;S REQUEST("PATIENT COMMENT")=""                           OPT
 ;S REQUEST("PATIENT PREFERRED START DATE",1)=""            OPT
 ;S REQUEST("PATIENT PREFERRED END DATE",1)=""              OPT
 ;S REQUEST("PATIENT PREFERRED START DATE",2)=""            OPT
 ;S REQUEST("PATIENT PREFERRED END DATE",2)=""              OPT
 ;S REQUEST("PATIENT PREFERRED START DATE",3)=""            OPT
 ;S REQUEST("PATIENT PREFERRED END DATE",3)=""              OPT
 ;S REQUEST("MRTC","PARENT REQUEST")=""                     OPT
 ;S REQUEST("DUPLICATE REASON")=""                          OPT - The reason a duplicate appointment request is being made
 ;
EDITREQUEST(JSONRETURN,SDCONTEXT,REQUEST) ;
 N REQIEN,ERRORS,RETURN,INSTITUTIONIEN,EDITUSER,FILEDATA
 ;
 D VALCONTEXT^SDES2VALCONTEXT(.ERRORS,.SDCONTEXT)
 I $D(ERRORS) S ERRORS("Request",1)="" D BUILDJSON^SDES2JSON(.JSONRETURN,.ERRORS) Q
 S EDITUSER=$S($G(SDCONTEXT("USER DUZ"))'="":SDCONTEXT("USER DUZ"),1:DUZ)
 ;
 M FILEDATA=REQUEST
 D VALIDATE(.REQUEST,.FILEDATA,.INSTITUTIONIEN,.ERRORS)
 I $D(ERRORS) S ERRORS("Request",1)="" D BUILDJSON^SDES2JSON(.JSONRETURN,.ERRORS) Q
 ;
 S RETURN("Request","IEN")=$$BUILDER(.FILEDATA,.INSTITUTIONIEN,$G(SDCONTEXT("ACHERON AUDIT ID")),EDITUSER)
 ;
 D BUILDJSON^SDES2JSON(.JSONRETURN,.RETURN)
 Q
 ;
VALIDATE(REQUEST,FILEDATA,INSTITUTIONIEN,ERRORS) ;
 N VALRETURN,VALREQUESTIEN,CLINICIEN,CURPID,CHILDIEN
 ;
 ; Validate required fields
 ; request ien
 S VALREQUESTIEN=""
 D VALFILEIEN^SDES2VALUTIL(.VALRETURN,.ERRORS,409.85,$G(REQUEST("REQUEST IEN")),1,,3,4)
 I VALRETURN S VALREQUESTIEN=$G(REQUEST("REQUEST IEN"))
 ; DFN
 D VALFILEIEN^SDES2VALUTIL(.VALRETURN,.ERRORS,2,$G(REQUEST("DFN")),1,,1,2,229,"DFN")
 I VALRETURN,VALREQUESTIEN,$$GET1^DIQ(409.85,$G(REQUEST("REQUEST IEN")),.01,"I")'=$G(REQUEST("DFN")) D ERRLOG^SDES2JSON(.ERRORS,534)
 ;
 ; if this is a parent request - no editing
 I VALREQUESTIEN D
 .I $$GET1^DIQ(409.85,VALREQUESTIEN,41,"I"),'$$GET1^DIQ(409.85,VALREQUESTIEN,43.8,"I") D ERRLOG^SDES2JSON(.ERRORS,52,"Cannot edit a parent MRTC request.")
 ;
 I $D(REQUEST("APPOINTMENT TYPE")) D
 .D VALFIELD^SDES2VALUTIL(.VALRETURN,.ERRORS,409.85,8.7,$G(REQUEST("APPOINTMENT TYPE")),0,,,180)
 .S FILEDATA("APPOINTMENT TYPE")=$G(VALRETURN(409.85,8.7,"I"))
 ;
 ; validate clinic
 I $D(REQUEST("CLINIC IEN")) D VALFILEIEN^SDES2VALUTIL(.VALRETURN,.ERRORS,44,$G(REQUEST("CLINIC IEN")),1,,,19)
 I $D(REQUEST("CLINIC IEN"))!($D(REQUEST("PRIMARY AMIS"))) D
 .I $D(REQUEST("CLINIC IEN")),$G(REQUEST("CLINIC IEN"))="",$D(REQUEST("PRIMARY AMIS")),$G(REQUEST("PRIMARY AMIS"))="" D ERRLOG^SDES2JSON(.ERRORS,530)
 .; CLINIC IEN or PRIMARY AMIS is allowed, NOT both
 .I $G(REQUEST("CLINIC IEN"))'="",($G(REQUEST("PRIMARY AMIS"))'=""!($G(REQUEST("CREDIT AMIS"))'="")) D ERRLOG^SDES2JSON(.ERRORS,202)
 .; cannot have credit amis with no primary amis
 .I $G(REQUEST("CREDIT AMIS"))'="",$D(REQUEST("PRIMARY AMIS")),$G(REQUEST("PRIMARY AMIS"))="" D ERRLOG^SDES2JSON(.ERRORS,234)
 .I $G(REQUEST("PRIMARY AMIS"))'="" D VALPRIMAMIS^SDES2CRTAPREQ(.ERRORS,.REQUEST,.FILEDATA)
 .I $G(REQUEST("CREDIT AMIS"))'="" D VALCREDITAMIS^SDES2CRTAPREQ(.ERRORS,.REQUEST,.FILEDATA)
 .I $G(REQUEST("PRIMARY AMIS"))'="",$G(REQUEST("CREDIT AMIS"))'="" D CONDAMISCHECK^SDES2VAL44(.ERRORS,$G(REQUEST("PRIMARY AMIS")),$G(REQUEST("CREDIT AMIS")))
 ;
 I $D(REQUEST("PATIENT INDICATED DATE")) D
 .S FILEDATA("PATIENT INDICATED DATE")=$$VALISODTTM^SDES2VALISODTTM(.ERRORS,$G(REQUEST("PATIENT INDICATED DATE")),$G(REQUEST("CLINIC IEN")),1,159,160,229,,,"PATIENT INDICATED DATE")
 .I VALREQUESTIEN,$$DUPPIDCHK^SDES2CANCELAPPT(VALREQUESTIEN,$G(FILEDATA("PATIENT INDICATED DATE"))) D ERRLOG^SDES2JSON(.ERRORS,545)
 ;
 I $D(REQUEST("PRIORITY")) D
 .D VALFIELD^SDES2VALUTIL(.VALRETURN,.ERRORS,409.85,10,$G(REQUEST("PRIORITY")),1,,457,211,229,,,"PRIORITY")
 .I VALRETURN S FILEDATA("PRIORITY")=$G(VALRETURN(409.85,10,"I"))
 ;
 I $D(REQUEST("REQUESTED BY")) D
 .D VALFIELD^SDES2VALUTIL(.VALRETURN,.ERRORS,409.85,11,$G(REQUEST("REQUESTED BY")),1,,62,198)
 .I VALRETURN D
 ..S FILEDATA("REQUESTED BY")=$G(VALRETURN(409.85,11,"I"))
 ..I $G(FILEDATA("REQUESTED BY"))=1 D  Q
 ...D VALFILEIEN^SDES2VALUTIL(.VALRETURN,.ERRORS,200,$G(REQUEST("PROVIDER IEN")),1,,53,54,229,,,"PROVIDER IEN")
 ;
 I $D(REQUEST("STATION NUMBER"))!($D(REQUEST("INSTITUTION NAME"))) D
 .S INSTITUTIONIEN=$$STATIONTOINST(.ERRORS,$G(REQUEST("STATION NUMBER")),$G(REQUEST("INSTITUTION NAME")))
 ;
 ; Validate optional fields
 I $D(REQUEST("VAOS GUID")) D VALFIELD^SDES2VALUTIL(.VALRETURN,.ERRORS,409.85,5)
 I $D(REQUEST("MODALITY")) D
 .D VALFIELD^SDES2VALUTIL(.VALRETURN,.ERRORS,409.85,6,$G(REQUEST("MODALITY")),,,,224) Q:'VALRETURN
 .S FILEDATA("MODALITY")=$G(VALRETURN(409.85,6,"I"))
 ;
 I $D(REQUEST("PRIORITY GROUP")) D
 .D VALFIELD^SDES2VALUTIL(.VALRETURN,.ERRORS,409.85,10.5,$G(REQUEST("PRIORITY GROUP")),,,,199) Q:'VALRETURN
 .S FILEDATA("PRIORITY GROUP")=$G(VALRETURN(409.85,10.5,"I"))
 ;
 I $D(REQUEST("SERVICE CONNECTED")) D
 .D VALFIELD^SDES2VALUTIL(.VALRETURN,.ERRORS,409.85,15,$G(REQUEST("SERVICE CONNECTED")),,,,200)
 .S FILEDATA("SERVICE CONNECTED")=$G(VALRETURN(409.85,15,"I"))
 ;
 I $D(REQUEST("SERVICE CONNECTED PERCENTAGE")) D
 .D VALFIELD^SDES2VALUTIL(.VALRETURN,.ERRORS,409.85,14,$G(REQUEST("SERVICE CONNECTED PERCENTAGE")),,,,201) Q:'VALRETURN
 .;I $G(FILEDATA("SERVICE CONNECTED"))=0,+$G(REQUEST("SERVICE CONNECTED PERCENTAGE")) D ERRLOG^SDES2JSON(.ERRORS,232)
 ;
 I $D(REQUEST("PATIENT STATUS")) D
 .D VALFIELD^SDES2VALUTIL(.VALRETURN,.ERRORS,409.85,.02,$G(REQUEST("PATIENT STATUS")),,,,203) Q:'VALRETURN
 .S FILEDATA("PATIENT STATUS")=$G(VALRETURN(409.85,.02,"I"))
 ;
 I $D(REQUEST("PATIENT PREFERRED START DATE"))!$D(REQUEST("PATIENT PREFERRED END DATE")) D VALIDATEDATEPREF^SDES2CRTAPREQ(.ERRORS,.REQUEST)
 ;
 I $D(REQUEST("REQUEST COMMENT")) D
 .D VALFIELD^SDES2VALUTIL(.VALRETURN,.ERRORS,409.85,25,$G(REQUEST("REQUEST COMMENT")),,,,443)
 ;
 I $D(REQUEST("TIME SENSITIVE")) D
 .D VALFIELD^SDES2VALUTIL(.VALRETURN,.ERRORS,409.85,47,$G(REQUEST("TIME SENSITIVE")))
 .I VALRETURN S FILEDATA("TIME SENSITIVE")=$G(VALRETURN(409.85,47,"I"))
 ;
 I $G(REQUEST("REQUEST COMMENT"))]"" D VALFIELD^SDES2VALUTIL(.VALRETURN,.ERRORS,409.85,25,$G(REQUEST("REQUEST COMMENT")),,,,443)
 ;
 I $G(REQUEST("DUPLICATE REASON"))]"" D VALFIELD^SDES2VALUTIL(.VALRETURN,.ERRORS,409.85,51,$G(REQUEST("DUPLICATE REASON")),,,,593)
 ;
 ; if this is a child request validate child/parent linkage and PID date uniqueness
 I VALREQUESTIEN,$G(REQUEST("MRTC","PARENT REQUEST"))'="" D
 .D VALFILEIEN^SDES2VALUTIL(.VALRETURN,.ERRORS,409.85,$G(REQUEST("MRTC","PARENT REQUEST")),1) Q:'VALRETURN
 .I VALRETURN D
 ..I $$GET1^DIQ(409.85,$G(REQUEST("MRTC","PARENT REQUEST")),.01,"I")'=$G(REQUEST("DFN")) D ERRLOG^SDES2JSON(.ERRORS,533)
 .; Make sure this child is linked to this parent record
 .I '$D(^SDEC(409.85,$G(REQUEST("MRTC","PARENT REQUEST")),2,"B",VALREQUESTIEN)) D ERRLOG^SDES2JSON(.ERRORS,546)
 .S CHILDIEN=0
 .F  S CHILDIEN=$O(^SDEC(409.85,REQUEST("MRTC","PARENT REQUEST"),2,"B",CHILDIEN)) Q:'CHILDIEN  D
 ..Q:CHILDIEN=VALREQUESTIEN
 ..I $G(FILEDATA("PATIENT INDICATED DATE"))>0,$$GET1^DIQ(409.85,CHILDIEN,22,"I")=$G(FILEDATA("PATIENT INDICATED DATE")) D
 ...D ERRLOG^SDES2JSON(.ERRORS,545)
 Q
 ;
BUILDER(REQUEST,INSTITUTIONIEN,EAS,EDITUSER) ;
 N FDA,FDAERR,RETURNIEN,REQIEN,ORIGPID
 S REQIEN=$G(REQUEST("REQUEST IEN"))_","
 S ORIGPID=$$GET1^DIQ(409.85,REQIEN,22,"I")
 I $D(REQUEST("PATIENT STATUS")) S FDA(409.85,REQIEN,.02)=$G(REQUEST("PATIENT STATUS"))
 I $D(INSTITUTIONIEN) S FDA(409.85,REQIEN,2)=$G(INSTITUTIONIEN)
 I $D(REQUEST("REQUEST SUB TYPE")) S FDA(409.85,REQIEN,4)=$G(REQUEST("REQUEST SUB TYPE"))
 I $D(REQUEST("VAOS GUID")) S FDA(409.85,REQIEN,5)=$G(REQUEST("VAOS GUID"))
 I $D(REQUEST("MODALITY")) S FDA(409.85,REQIEN,6)=$G(REQUEST("MODALITY"))
 I $D(REQUEST("CLINIC IEN"))!($D(REQUEST("PRIMARY AMIS"))) D
 .S FDA(409.85,REQIEN,8)=$G(REQUEST("CLINIC IEN"))
 .S FDA(409.85,REQIEN,8.5)=$G(REQUEST("PRIMARY AMIS"))
 .S FDA(409.85,REQIEN,8.6)=$G(REQUEST("CREDIT AMIS"))
 I $D(REQUEST("APPOINTMENT TYPE")) S FDA(409.85,REQIEN,8.7)=$G(REQUEST("APPOINTMENT TYPE"))
 I $D(REQUEST("PRIORITY")) S FDA(409.85,REQIEN,10)=$G(REQUEST("PRIORITY"))
 I $D(REQUEST("PRIORITY GROUP")) S FDA(409.85,REQIEN,10.5)=$G(REQUEST("PRIORITY GROUP"))
 I $D(REQUEST("REQUESTED BY")) S FDA(409.85,REQIEN,11)=$G(REQUEST("REQUESTED BY"))
 I $D(REQUEST("PROVIDER IEN")) S FDA(409.85,REQIEN,12)=$G(REQUEST("PROVIDER IEN"))
 I $D(REQUEST("SERVICE CONNECTED PERCENTAGE")) S FDA(409.85,REQIEN,14)=$G(REQUEST("SERVICE CONNECTED PERCENTAGE"))
 I $D(REQUEST("SERVICE CONNECTED")) S FDA(409.85,REQIEN,15)=$G(REQUEST("SERVICE CONNECTED"))
 ; Removed the update to PID since it occurs in ADDPIDHISTORY as well and the Original PID is needed for ADDPIDHISTORY
 ;I $D(REQUEST("PATIENT INDICATED DATE")) S FDA(409.85,REQIEN,22)=$G(REQUEST("PATIENT INDICATED DATE"))
 I $D(REQUEST("REQUEST COMMENT")) S FDA(409.85,REQIEN,25)=$TR($G(REQUEST("REQUEST COMMENT")),"^"," ")
 I $D(REQUEST("TIME SENSITIVE")) S FDA(409.85,REQIEN,47)=$G(REQUEST("TIME SENSITIVE"))
 I $D(REQUEST("DUPLICATE REASON")) S FDA(409.85,REQIEN,51)=$G(REQUEST("DUPLICATE REASON"))
 S FDA(409.85,REQIEN,100)=$G(EAS)
 D FILE^DIE(,"FDA","FDAERR") K FDA
 ;
 ; 409.85 COMMENTS AUDIT multiple
 I $G(REQUEST("REQUEST COMMENT"))'="" D
 . S FDA(409.8527,"+1,"_REQIEN,.01)=$$NOW^XLFDT
 . S FDA(409.8527,"+1,"_REQIEN,1)=EDITUSER
 . S FDA(409.8527,"+1,"_REQIEN,2)=$TR($G(REQUEST("REQUEST COMMENT")),"^"," ")
 . D UPDATE^DIE("","FDA") K FDA
 ;
 D ADDPIDHISTORY^SDES2CRTAPREQ($G(REQUEST("REQUEST IEN")),$G(REQUEST("PATIENT INDICATED DATE")),EDITUSER)
 ;
 I $D(REQUEST("PATIENT COMMENT"))!($D(REQUEST("PATIENT PREFERRED START DATE"))) D BUILDCOMMENTS(.REQUEST,$G(REQUEST("REQUEST IEN")))
 ;
 ; if PATIENT INDICATED DATE is passed in, and PARENT REQUEST is defined, update the MRTC CALC PREF DATES on the parent request
 I $D(REQUEST("PATIENT INDICATED DATE")),$G(REQUEST("MRTC","PARENT REQUEST")) D
 .;D EDITMRTCPID(.REQUEST,$G(REQUEST("REQUEST IEN")))
 .D EDITPRNTPIDMULT(.REQUEST,$G(REQUEST("MRTC","PARENT REQUEST")),ORIGPID)
 ;
 ;I $D(REQUEST("MRTC","CHILD REQUEST"))!($D(REQUEST("MRTC","MRTC APPOINTMENT"))) D EDITMRTCLINKS(.REQUEST,$G(REQUEST("REQUEST IEN")))
 ;
 D AUDIT($G(REQUEST("REQUEST IEN")),$G(REQUEST("CLINIC IEN")),$G(REQUEST("PRIMARY AMIS")),EDITUSER)
 ;
 Q $G(REQUEST("REQUEST IEN"))
 ;
BUILDAPPTDATA(REQIEN,APPTDATETIME,CLINICIEN,SERVCONNPERC,SERVCONN,APPTTYPE,EAS,USER) ;
 N FDA,FDAERR
 S REQIEN=$G(REQIEN)_","
 S FDA(409.85,REQIEN,8.7)=$G(APPTTYPE)
 S FDA(409.85,REQIEN,13)=$G(APPTDATETIME)
 S FDA(409.85,REQIEN,13.1)=$P($$NOW^XLFDT,".",1)
 S FDA(409.85,REQIEN,13.2)=$G(CLINICIEN)
 S FDA(409.85,REQIEN,13.3)=$$GET1^DIQ(44,$G(CLINICIEN),3,"I") ; appt institution ;
 S FDA(409.85,REQIEN,13.4)=$$GET1^DIQ(44,$G(CLINICIEN),8,"I") ; appt stop code
 S FDA(409.85,REQIEN,13.6)=$$GET1^DIQ(40.8,$$GET1^DIQ(44,$G(CLINICIEN),3.5,"I"),1,"I") ; appt station number
 S FDA(409.85,REQIEN,13.7)=$G(USER)
 S FDA(409.85,REQIEN,13.8)="R" ; 'R' FOR Scheduled/Kept;
 S FDA(409.85,REQIEN,14)=$G(SERVCONNPERC)
 S FDA(409.85,REQIEN,15)=$G(SERVCONN)
 S FDA(409.85,REQIEN,100)=$G(EAS)
 S FDA(409.85,REQIEN,19)=$P($$NOW^XLFDT,".",1)
 S FDA(409.85,REQIEN,20)=$G(USER)
 S FDA(409.85,REQIEN,21)=$$FIND1^DIC(409.853,,"B","REMOVED/SCHEDULED-ASSIGNED")
 S FDA(409.85,REQIEN,23)="C"
 D FILE^DIE(,"FDA","FDAERR") K FDA
 ;
 N PARENTIEN
 S PARENTIEN=$$GET1^DIQ(409.85,REQIEN_",",43.8,"I")
 I PARENTIEN D
 . N CHILDIEN,FOUND
 . S CHILDIEN="",FOUND=0
 . F  S CHILDIEN=$O(^SDEC(409.85,PARENTIEN,2,"B",CHILDIEN)) Q:(CHILDIEN="")!(FOUND)  D
 . . S FOUND=($$GET1^DIQ(409.85,CHILDIEN_",",23,"E")="OPEN")
 . I 'FOUND D
 . . S FDA(409.85,PARENTIEN_",",23)="C"
 . . D FILE^DIE(,"FDA","ERROR") K FDA
 Q
 ;
 N NUM,FDA,FDAERR,SUBIEN
 S SUBIEN=0,NUM=0
 F  S SUBIEN=$O(^SDEC(409.85,REQIEN,2,SUBIEN)) Q:'SUBIEN  D
 .S NUM=NUM+1
 .S FDA(409.852,SUBIEN_","_REQIEN_",",.01)=$G(REQUEST("MRTC","CHILD REQUEST",NUM))
 .S FDA(409.852,SUBIEN_","_REQIEN_",",.02)=$G(REQUEST("MRTC","MRTC APPOINTMENT",NUM))
 .D FILE^DIE(,"FDA","FDAERR") K FDA
 Q
 ;
EDITMRTCPID(REQUEST,REQIEN) ;
 N NUM,FDA,FDAERR,SUBIEN
 S SUBIEN=0,NUM=0
 F  S SUBIEN=$O(^SDEC(409.85,REQIEN,5,SUBIEN)) Q:'SUBIEN  D
 .S NUM=NUM+1
 .S FDA(409.851,SUBIEN_","_REQIEN_",",.01)=$G(REQUEST("MRTC","PATIENT INDICATED DATE",NUM))
 .D FILE^DIE(,"FDA","FDAERR") K FDA
 Q
 ; Update the parent MRTC CAL PREF DATE for the child being edited.
EDITPRNTPIDMULT(REQUEST,PARENTIEN,ORIGPID) ;
 N NUM,FDA,FDAERR,SUBIEN,OLDPIDIEN
 S SUBIEN=0,NUM=0
 S OLDPIDIEN=$O(^SDEC(409.85,PARENTIEN,5,"B",ORIGPID,0)) Q:'OLDPIDIEN
 S FDA(409.851,OLDPIDIEN_","_PARENTIEN_",",.01)=$G(REQUEST("PATIENT INDICATED DATE"))
 D FILE^DIE(,"FDA","FDAERR") K FDA
 Q
 ;
 N FDA,FDAERR,SUBIEN
 S SUBIEN=$O(^SDEC(409.85,REQIEN,2,"B",REQUEST("MRTC","CHILD REQUEST"),0))
 S FDA(409.852,SUBIEN_","_REQIEN_",",.02)=$G(REQUEST("MRTC","MRTC APPOINTMENT"))
 D UPDATE^DIE(,"FDA",,"FDAERR") K FDA
 Q
 ;
BUILDMRTCPID(REQUEST,REQIEN) ; called from SDESCREATEAPPT after appt is made from mrtc child
 N FDA,FDAERR,SDPID
 S SDPID=$G(REQUEST("MRTC","PATIENT INDICATED DATE"))
 S:SDPID="" SDPID=$$GET1^DIQ(409.85,REQIEN,22,"I")
 Q:$O(^SDEC(409.85,REQIEN,5,"B",SDPID,0))
 S FDA(409.851,"+1,"_REQIEN_",",.01)=SDPID
 D UPDATE^DIE(,"FDA",,"FDAERR") K FDA
 Q
 ;
BUILDCOMMENTS(REQUEST,REQIEN) ;
 N REQCOMMS,NUM,NUM2,DONE,PREFDATES,PATCOMMS,RANGE,DATERANGE1,DATERANGE2,DATERANGE3,EDITPATCOM
 S NUM=0
 I $D(REQUEST("PATIENT COMMENT")) D
 .N PC S PC="PATIENT COMMENT"
 .I $G(REQUEST(PC))'["Patient preferred date range" S EDITPATCOM(1)=$G(REQUEST(PC)) D WP^DIE(409.85,REQIEN_",",60,"","EDITPATCOM") Q
 .S EDITPATCOM(1)=$P($G(REQUEST(PC)),"Patient preferred date range",1)
 .S DATERANGE1=$P($G(REQUEST(PC)),"Patient preferred date range",2) I $L($G(DATERANGE1)) S EDITPATCOM(2)="Patient preferred date range"_$P($G(REQUEST(PC)),"Patient preferred date range",2)
 .S DATERANGE2=$P($G(REQUEST(PC)),"Patient preferred date range",3) I $L($G(DATERANGE2)) S EDITPATCOM(3)="Patient preferred date range"_$P($G(REQUEST(PC)),"Patient preferred date range",3)
 .S DATERANGE3=$P($G(REQUEST(PC)),"Patient preferred date range",4) I $L($G(DATERANGE3)) S EDITPATCOM(4)="Patient preferred date range"_$P($G(REQUEST(PC)),"Patient preferred date range",4)
 .D WP^DIE(409.85,REQIEN_",",60,"","EDITPATCOM")
 Q
 ;
AUDIT(REQIEN,CLINICIEN,STOPCODE,USER) ;
 N FDA,FDAERR
 S FDA(409.8545,"+1,"_REQIEN_",",.01)=$$NOW^XLFDT
 S FDA(409.8545,"+1,"_REQIEN_",",1)=$G(USER)
 S FDA(409.8545,"+1,"_REQIEN_",",2)=$G(CLINICIEN)
 S FDA(409.8545,"+1,"_REQIEN_",",3)=$G(STOPCODE)
 D UPDATE^DIE("","FDA",,"FDAERR") K FDA
 Q
 ;
STATIONTOINST(ERRORS,STATIONNUM,INSTNAME) ; station number has precedence over institution name
 N INSTITUTIONIEN
 I STATIONNUM="",INSTNAME="" D ERRLOG^SDES2JSON(.ERRORS,204) Q 0
 I STATIONNUM="",INSTNAME'="" D
 .S INSTITUTIONIEN=$$FIND1^DIC(4,"","X",INSTNAME,"B") I 'INSTITUTIONIEN D ERRLOG^SDES2JSON(.ERRORS,205)
 I STATIONNUM'="" S INSTITUTIONIEN=$$FIND1^DIC(4,"","X",STATIONNUM,"D") I 'INSTITUTIONIEN D ERRLOG^SDES2JSON(.ERRORS,197) Q 0
 Q INSTITUTIONIEN
 ;