SDAMUTDT ;BPOIFO/JFW-Scheduling Encapsulation Utilities ; 5/17/04 1:00pm
;;5.3;Scheduling;**266,1015**;13 Aug 1993;Build 21
;
;*****************************************************************
; CHANGE LOG
;
; DATE PATCH DESCRIPTION
;-------- ---------- -----------------------------------------
;1/24/06 SD*5.3*413 ROUTINE COMPLETED
;
;*****************************************************************
;
FMTGMT(SDFMDT) ;convert internal fileman format to extended GMT
;initialize variables
;*****************************************************************
;INPUT SDFMDT - Fileman date/time
;OUTPUT -1 error occurred in translation
; GMT date/time in ISO 8601 extended format (No Errors)
;*****************************************************************
N SDDTM,SDGMT,SDTIME,SDOFFSET
S SDDTM=$$FMTHL7^XLFDT(SDFMDT)
Q:SDDTM<0 -1
;extract out date and convert to ISO 8601 extended format
S SDGMT=$E(SDDTM,1,4)_"-"_$E(SDDTM,5,6)_"-"_$E(SDDTM,7,8)
;if time is included, extract and convert to ISO 8601 external format
I $L(SDDTM)>8 D
.S SDTIME=$E(+SDDTM,9,99),SDOFFSET=$$TZ^XLFDT()
.;determine if seconds are included in time
.I $L(SDTIME)<5 D
..;no seconds included in date/time
..S SDGMT=SDGMT_"T"_$E(SDDTM,9,10)_":"_$E(SDDTM,11,99)
.;seconds included in date/time
.E S SDGMT=SDGMT_"T"_$E(SDTIME,1,2)_":"_$E(SDTIME,3,4)_":"_$E(SDTIME,5,6)_SDOFFSET
Q SDGMT
;
GMTTFM(SDGMTDT) ;convert ISO 8601 extended GMT date/time to fileman format
;initialize variables
;*****************************************************************
;INPUT SDGMTDT - ISO 8601 extended GMT date/time
;OUTPUT -1 error occurred in translation
; FM date/time (No Errors)
;*****************************************************************
N SDFM,SDTIME,SDOFFSET,SDFMDTM,X,Y,%DT
;get offset for VistA Instance
S SDOFFSET=$$TZ^XLFDT()
;pattern match date(/time) for correctness
Q:((SDGMTDT["T")&'(SDGMTDT?4N1"-"2N1"-"2N1"T"2N1":"2N.E)) -1
Q:((SDGMTDT'["T")&'(SDGMTDT?4N1"-"2N1"-"2N)) -1
;extract out date, removing punctuation
S SDFM=$E(SDGMTDT,1,4)_$E(SDGMTDT,6,7)_$E(SDGMTDT,9,10)
;set parameters to validate date/time
S %DT="TXS"
;extract out time if entered, removing all punctuation except for TZ offset
I SDGMTDT>10 D
.S SDTIME=$P($E(SDGMTDT,12,99),$E(SDOFFSET,1,1))
.;exclude time if 0's else FMTE returns previous date with .24
.Q:((SDTIME["00:00")!(SDTIME["00:00:00"))
.;determine if seconds are included in time
.I $L(SDTIME)<6 D
..;no seconds include in date/time
..S SDFM=SDFM_$E(SDGMTDT,12,13)_$E(SDGMTDT,15,99)
.;seconds included in date/time
.E S SDFM=SDFM_$E(SDTIME,1,2)_$E(SDTIME,4,5)_$E(SDTIME,7,8)_"-"_SDOFFSET
;convert date(/time) from HL7 format back to Fileman
S SDFMDTM=$$HL7TFM^XLFDT(SDFM)
Q:SDFMDTM<0 SDFMDTM ;error occurred in conversion
;check validity of date (including leap year check)
S X=$$FMTE^XLFDT(SDFMDTM)
D ^%DT
Q:Y<0 -1 ;date(/time) not valid
Q SDFMDTM
;
SDAPIERR() ; SDAPI Error Messages.
;*****************************************************************
;INPUT N/A
;OUTPUT Extrinsic call returns error message
;*****************************************************************
N SDERR S SDERR=$O(^TMP($J,"SDAMA301",""))
I SDERR="" Q ""
I +SDERR=101 Q "Error 101: The Appointment Database is not currently available. Please try again later."
I +SDERR=115 Q "Error 115: Appointment request contains invalid values. Please contact National Help Desk."
Q "Error 117: An error has occurred, check the RSA Error Log."
;
SDAMUTDT ;BPOIFO/JFW-Scheduling Encapsulation Utilities ; 5/17/04 1:00pm
+1 ;;5.3;Scheduling;**266,1015**;13 Aug 1993;Build 21
+2 ;
+3 ;*****************************************************************
+4 ; CHANGE LOG
+5 ;
+6 ; DATE PATCH DESCRIPTION
+7 ;-------- ---------- -----------------------------------------
+8 ;1/24/06 SD*5.3*413 ROUTINE COMPLETED
+9 ;
+10 ;*****************************************************************
+11 ;
FMTGMT(SDFMDT) ;convert internal fileman format to extended GMT
+1 ;initialize variables
+2 ;*****************************************************************
+3 ;INPUT SDFMDT - Fileman date/time
+4 ;OUTPUT -1 error occurred in translation
+5 ; GMT date/time in ISO 8601 extended format (No Errors)
+6 ;*****************************************************************
+7 NEW SDDTM,SDGMT,SDTIME,SDOFFSET
+8 SET SDDTM=$$FMTHL7^XLFDT(SDFMDT)
+9 IF SDDTM<0
QUIT -1
+10 ;extract out date and convert to ISO 8601 extended format
+11 SET SDGMT=$EXTRACT(SDDTM,1,4)_"-"_$EXTRACT(SDDTM,5,6)_"-"_$EXTRACT(SDDTM,7,8)
+12 ;if time is included, extract and convert to ISO 8601 external format
+13 IF $LENGTH(SDDTM)>8
Begin DoDot:1
+14 SET SDTIME=$EXTRACT(+SDDTM,9,99)
SET SDOFFSET=$$TZ^XLFDT()
+15 ;determine if seconds are included in time
+16 IF $LENGTH(SDTIME)<5
Begin DoDot:2
+17 ;no seconds included in date/time
+18 SET SDGMT=SDGMT_"T"_$EXTRACT(SDDTM,9,10)_":"_$EXTRACT(SDDTM,11,99)
End DoDot:2
+19 ;seconds included in date/time
+20 IF '$TEST
SET SDGMT=SDGMT_"T"_$EXTRACT(SDTIME,1,2)_":"_$EXTRACT(SDTIME,3,4)_":"_$EXTRACT(SDTIME,5,6)_SDOFFSET
End DoDot:1
+21 QUIT SDGMT
+22 ;
GMTTFM(SDGMTDT) ;convert ISO 8601 extended GMT date/time to fileman format
+1 ;initialize variables
+2 ;*****************************************************************
+3 ;INPUT SDGMTDT - ISO 8601 extended GMT date/time
+4 ;OUTPUT -1 error occurred in translation
+5 ; FM date/time (No Errors)
+6 ;*****************************************************************
+7 NEW SDFM,SDTIME,SDOFFSET,SDFMDTM,X,Y,%DT
+8 ;get offset for VistA Instance
+9 SET SDOFFSET=$$TZ^XLFDT()
+10 ;pattern match date(/time) for correctness
+11 IF ((SDGMTDT["T")&'(SDGMTDT?4N1"-"2N1"-"2N1"T"2N1"
QUIT -1
+12 IF ((SDGMTDT'["T")&'(SDGMTDT?4N1"-"2N1"-"2N))
QUIT -1
+13 ;extract out date, removing punctuation
+14 SET SDFM=$EXTRACT(SDGMTDT,1,4)_$EXTRACT(SDGMTDT,6,7)_$EXTRACT(SDGMTDT,9,10)
+15 ;set parameters to validate date/time
+16 SET %DT="TXS"
+17 ;extract out time if entered, removing all punctuation except for TZ offset
+18 IF SDGMTDT>10
Begin DoDot:1
+19 SET SDTIME=$PIECE($EXTRACT(SDGMTDT,12,99),$EXTRACT(SDOFFSET,1,1))
+20 ;exclude time if 0's else FMTE returns previous date with .24
+21 IF ((SDTIME["00
QUIT
+22 ;determine if seconds are included in time
+23 IF $LENGTH(SDTIME)<6
Begin DoDot:2
+24 ;no seconds include in date/time
+25 SET SDFM=SDFM_$EXTRACT(SDGMTDT,12,13)_$EXTRACT(SDGMTDT,15,99)
End DoDot:2
+26 ;seconds included in date/time
+27 IF '$TEST
SET SDFM=SDFM_$EXTRACT(SDTIME,1,2)_$EXTRACT(SDTIME,4,5)_$EXTRACT(SDTIME,7,8)_"-"_SDOFFSET
End DoDot:1
+28 ;convert date(/time) from HL7 format back to Fileman
+29 SET SDFMDTM=$$HL7TFM^XLFDT(SDFM)
+30 ;error occurred in conversion
IF SDFMDTM<0
QUIT SDFMDTM
+31 ;check validity of date (including leap year check)
+32 SET X=$$FMTE^XLFDT(SDFMDTM)
+33 DO ^%DT
+34 ;date(/time) not valid
IF Y<0
QUIT -1
+35 QUIT SDFMDTM
+36 ;
SDAPIERR() ; SDAPI Error Messages.
+1 ;*****************************************************************
+2 ;INPUT N/A
+3 ;OUTPUT Extrinsic call returns error message
+4 ;*****************************************************************
+5 NEW SDERR
SET SDERR=$ORDER(^TMP($JOB,"SDAMA301",""))
+6 IF SDERR=""
QUIT ""
+7 IF +SDERR=101
QUIT "Error 101: The Appointment Database is not currently available. Please try again later."
+8 IF +SDERR=115
QUIT "Error 115: Appointment request contains invalid values. Please contact National Help Desk."
+9 QUIT "Error 117: An error has occurred, check the RSA Error Log."
+10 ;