#1
  1. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2016
    Posts
    16
    Rep Power
    0

    How do I get the right ProtectionOrder number and ID?


    I would like to get the correct ProtectionOrder number and InternalProtectionOrderID for the ProtectionOrder when a hearing is added or modified in a ProtectionOrder.
    Here are the conditions:
    1. ProtectionOder is not deleted i.e. <Deleted>false</Deleted>
    2. Current status = SBJO or SBJOCOR i.e. <Type Word="SBJO">Signed By Judicial Officer</Type>
    or
    <Type Word="SBJOCOR">Signed By Judicial Officer Corrected</Type>

    3. Get the ProtectionOrder where first status timestampcreate i.e <TimestampCreate>07/14/2016 09:00:25:547</TimestampCreate> has a datetime earlier than controlpoint timestamp and is either SBJO OR SBJOCOR.

    To compare controlpoint timestamp to timestampcreate, I have a function in the stylesheet (function formatDateTimeNumeric) to convert the datetime to numeric.

    To use the function I would like to use 2 variables one for TimeStamp and the other one for TimeStampCreate.
    e.g.
    <xsl:variable name="vControlPointTimestamp" select="mscef:formatDateTimeNumeric(string(/Integration/ControlPoint/@Timestamp))"/>
    and
    <xsl:variable name="vCurrentPoStatus" select="Statuses/Status[(Type/@Word='SBJOCOR') or (Type/@Word='SBJO')][mscef:formatDateTimeNumeric(mscef:fixOdysseyTimestamp(string(TimestampCreate))) &lt;=$vControlPointTimestamp][1]/Type/@Word"/>

    Expected Output
    Code:
    <NotificationEvent notificationType="ProtectionOrderHearing" internalProtectionOrderID="2552" protectionOrderNumber="1600330" hearingDate="07/14/2016" startTime="10:00 AM" settingIntegrationID="25760837" courtName="" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:fn="http://www.w3.org/2005/xpath-functions">HearingToSend</NotificationEvent>
    <NotificationEvent notificationType="ProtectionOrderHearing" internalProtectionOrderID="2552" protectionOrderNumber="1600330" hearingDate="07/14/2016" startTime="2:00 PM" settingIntegrationID="25760838" courtName="Carver County" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:fn="http://www.w3.org/2005/xpath-functions">HearingToSend</NotificationEvent>
    xslt code
    Code:
    <?xml version="1.0" encoding="UTF-8"?>
    <xsl:stylesheet version="3.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:fn="http://www.w3.org/2005/xpath-functions" xmlns:mscef="courts.state.mn.us/extfun" xmlns:msxsl="urn:schemas-microsoft-com:xslt">
    	<xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"/>
    	<xsl:template match="/">
    		<xsl:if test="Integration/Case/SecurityGroup[not(contains(@Word,'SEAL'))] or not(Integration/Case/SecurityGroup)">
    			<xsl:call-template name="ProtectionOrder"/>
    			<xsl:call-template name="ProtectionOrderHearing"/>
    		</xsl:if>
    	</xsl:template>
    	<xsl:template name="ProtectionOrder">
    		<xsl:if test="Integration/ControlPoint='SAVE-PROTECTION-ORDER'">
    			<xsl:if test="Integration/Case/CaseType/@Word='DMA'">
    				<xsl:variable name="vControlPointTimestamp" select="mscef:formatDateTimeNumeric(string(/Integration/ControlPoint/@Timestamp))"/>
    				<xsl:for-each select="Integration/ProtectionOrder[Deleted='false']">
    				<xsl:variable name="vCurrentPoStatus" select="Statuses/Status[((@Op='A') or (@Op='E'))][mscef:formatDateTimeNumeric(mscef:fixOdysseyTimestamp(string(TimestampCreate))) <=$vControlPointTimestamp][1]/Type/@Word"/>
    					<xsl:if test="($vCurrentPoStatus ='SBJO') or ($vCurrentPoStatus='SBJOCOR')">
    						<NotificationEvent notificationType="ProtectionOrder">
    							<xsl:attribute name="internalProtectionOrderID">
    								<xsl:value-of select="@InternalProtectionOrderID"/>
    							</xsl:attribute>
    							<xsl:attribute name="protectionOrderNumber">
    								<xsl:value-of select="ProtectionOrderNumber"/>
    							</xsl:attribute>
    							<xsl:choose>
    								<xsl:when test="Type/@Word='SBJOCOR'">Signed By Judicial Officer - Corrected</xsl:when>
    								<xsl:otherwise>Signed By Judicial Officer</xsl:otherwise>
    							</xsl:choose>
    						</NotificationEvent>
    					</xsl:if>
    				</xsl:for-each>
    			</xsl:if>
    		</xsl:if>
    	</xsl:template>
    	<!--  -->
    	<xsl:template name="ProtectionOrderHearing">
    		<xsl:if test="Integration/ControlPoint=('SAVE-FAM-HEARING') or ('SAVE-FAM-HEAR-CTS')">
    			<xsl:if test="Integration/Case/CaseType/@Word='DMA'">
    				<xsl:for-each select="Integration/Case">
    					<xsl:variable name="vFoundActivePO">
    					<xsl:variable name="vControlPointTimestamp" select="mscef:formatDateTimeNumeric(string(/Integration/ControlPoint/@Timestamp))"/>
    						<xsl:for-each select="/Integration/ProtectionOrder[Deleted='false']">
    							<xsl:variable name="vCurrentPoStatus" select="Statuses/Status[mscef:formatDateTimeNumeric(mscef:fixOdysseyTimestamp(string(TimestampCreate))) <=$vControlPointTimestamp][1]/Type/@Word"/>
    							<xsl:if test="($vCurrentPoStatus ='SBJO') or ($vCurrentPoStatus='SBJOCOR')">HIT</xsl:if>
    						</xsl:for-each>
    					</xsl:variable>
    					<xsl:variable name="vFoundHearingTrigger">
    						<xsl:choose>
    							<xsl:when test="count(Hearing[@Op='A'])>0">HIT</xsl:when>
    							<xsl:when test="count(Hearing[@Op='D'])>0">HIT</xsl:when>
    							<xsl:when test="count(Hearing[(@Op='E') and (CancelledReason/@Op='E')])>0">HIT</xsl:when>
    							<xsl:when test="count(Hearing[(@Op='E') and (Setting/HearingDate/@Op='E')])>0">HIT</xsl:when>
    							<xsl:when test="count(Hearing[(@Op='E') and (Setting/CourtSessionBlock/StartTime/@Op='E')])>0">HIT</xsl:when>
    							<xsl:when test="count(Hearing/Setting[@Op='A'])>0">HIT</xsl:when>
    							<xsl:when test="count(Hearing[(@Op='E') and (Setting/RescheduledType/@Op='E')])>0">HIT</xsl:when>
    							<xsl:when test="count(Hearing[(@Op='E') and (Setting/CancelledReason/@Op='E')])>0">HIT</xsl:when>
    							<xsl:when test="count(Hearing[(@Op='E') and (Setting/CourtSessionBlock/StartTime/@Op='E')])>0">HIT</xsl:when>
    						</xsl:choose>
    					</xsl:variable>
    					<xsl:if test="(contains($vFoundHearingTrigger,'HIT')) and (contains($vFoundActivePO,'HIT'))">
    						<xsl:choose>
    							<xsl:when test="count(Hearing/Setting[not(Cancelled)])>0">
    								<xsl:for-each select="Hearing/Setting[not(Cancelled)]">
    									<NotificationEvent notificationType="ProtectionOrderHearing">
    										<xsl:attribute name="internalProtectionOrderID">
    										<xsl:value-of select="//Integration/ProtectionOrder[Deleted='false'][count(Statuses/Status[(Type/@Word='SBJO') or (Type/@Word='SBJOCOR')])>0]/@InternalProtectionOrderID"/>
    										</xsl:attribute>
    										<xsl:attribute name="protectionOrderNumber">
    											<xsl:value-of select="//Integration/ProtectionOrder[Deleted='false'][count(Statuses/Status[(Type/@Word='SBJO') or (Type/@Word='SBJOCOR')])>0]/ProtectionOrderNumber"/>
    										</xsl:attribute>
    										<xsl:attribute name="hearingDate">
    											<xsl:value-of select="HearingDate"/>
    										</xsl:attribute>
    										<xsl:attribute name="startTime">
    											<xsl:value-of select="CourtSessionBlock/StartTime"/>
    										</xsl:attribute>
    										<xsl:attribute name="settingIntegrationID">
    											<xsl:value-of select="@ID"/>
    										</xsl:attribute>
    										<xsl:attribute name="courtName">
    											<xsl:value-of select="../Court/CourtName"/>
    										</xsl:attribute>
    										<xsl:text>HearingToSend</xsl:text>
    									</NotificationEvent>
    								</xsl:for-each>
    							</xsl:when>
    							<xsl:otherwise>
    								<NotificationEvent notificationType="ProtectionOrderHearing">
    									<xsl:attribute name="internalProtectionOrderID">
    										<xsl:value-of select="//Integration/ProtectionOrder[Deleted='false'][count(Statuses/Status[(Type/@Word='SBJO') or (Type/@Word='SBJOCOR')])>0]/@InternalProtectionOrderID"/>
    									</xsl:attribute>
    									<xsl:attribute name="protectionOrderNumber">
    										<xsl:value-of select="//Integration/ProtectionOrder[Deleted='false'][count(Statuses/Status[((Type/@Word='SBJO') or (Type/@Word='SBJOCOR'))])>0]/ProtectionOrderNumber"/>
    										<xsl:value-of select="//Integration/ProtectionOrder[Deleted='false'][count(Statuses/Status[(Type/@Word='SBJO') or (Type/@Word='SBJOCOR')])>0]/ProtectionOrderNumber"/>
    									</xsl:attribute>
    									<xsl:text>NoHearings</xsl:text>
    								</NotificationEvent>
    							</xsl:otherwise>
    						</xsl:choose>
    					</xsl:if>
    				</xsl:for-each>
    			</xsl:if>
    		</xsl:if>
    	</xsl:template>
    	<msxsl:script language="JScript" implements-prefix="mscef"><![CDATA[
    		
    		function formatDateTimeNumeric(sDate){
    			if(sDate.length==0){
    				return "";
    			}
    			else{
    				var oDate=new Date(sDate);
    				var str = oDate.getSeconds();
    				return "" + oDate.getFullYear().toString() + padZeroes(oDate.getMonth() + 1,2) + padZeroes(oDate.getDate(),2) + padZeroes(oDate.getHours().toString(),2) + padZeroes(oDate.getMinutes(),2) + padZeroes(oDate.getSeconds(),2);  			
    			}
    		}
    		function fixOdysseyTimestamp(sDate){
    		/* Replace the ":" between seconds and miliseconds */
    			if(sDate.length==0){
    				return "";
    			}
    			else{
    				var strParts1 = sDate.split(" ");
    				var strTime = strParts1[1];
    				var strParts2 = strTime.split(":");
    				return strParts1[0] + " " + strParts2[0] + ":" + strParts2[1] + ":" + strParts2[2];
    			}
    		}
    	]]></msxsl:script>
    </xsl:stylesheet>
    xml document
    Code:
    <Integration>
    	<ControlPoint Timestamp="7/14/2016 9:00:52 AM"/>
    	<Case>
    		<FiledDate>07/14/2016</FiledDate>
    		<CaseCategory>FAM</CaseCategory>
    		<CaseType Word="DMA">Domestic Abuse</CaseType>
    		<Hearing ID="175088126" InternalHearingEventID="1734552990">
    			<Setting ID="25760837" InternalSettingID="1625564128" Date="07/14/2016">
    				<HearingDate>07/14/2016</HearingDate>
    				<StartTime>10:00 AM</StartTime>
    				<EndTime>11:00 AM</EndTime>
    				<CourtSessionName>Ad-Hoc_10-FA-16-40</CourtSessionName>
    				<CourtSessionID ID="3862219" InternalCourtSessionID="1612936893"/>
    				<Calendar Word="10GEN">New General Carver</Calendar>
    				<CourtResource>
    					<Type Word="JUD">Judicial Officer</Type>
    					<Code Word="00727G">Abrams, Jerome B.</Code>
    				</CourtResource>
    				<CourtSessionBlock InternalCourtSessionBlockID="1615773709">
    					<StartTime>10:00 AM</StartTime>
    					<EndTime>11:00 AM</EndTime>
    				</CourtSessionBlock>
    				<InterpreterNeeded>false</InterpreterNeeded>
    				<TimestampCreate>07/14/2016 08:58:23:240</TimestampCreate>
    			</Setting>
    		</Hearing>
    		<Hearing ID="175088128" InternalHearingEventID="1734552992" Op="A">
    			<HearingType Op="A" Word="OFP">Order for Protection Hearing</HearingType>
    			<HearingTypeBaseCaseCategory>Family</HearingTypeBaseCaseCategory>
    			<Court Op="A">
    				<NodeID>111</NodeID>
    				<CourtName Op="A">Carver County</CourtName>
    				<CourtNCIC Op="A">MN010015J</CourtNCIC>
    			</Court>
    			<TimestampCreate Op="A">07/14/2016 09:00:52:680</TimestampCreate>
    			<Setting ID="25760838" InternalSettingID="1625564129" Date="07/14/2016" Op="A">
    				<HearingDate Op="A">07/14/2016</HearingDate>
    				<StartTime Op="A">2:00 PM</StartTime>
    				<EndTime Op="A">3:00 PM</EndTime>
    				<CourtSessionName>Ad-Hoc_10-FA-16-40</CourtSessionName>
    				<CourtSessionID Op="A" ID="3862221" InternalCourtSessionID="1612936894"/>
    				<Calendar Op="A" Word="10GEN">New General Carver</Calendar>
    				<CourtResource Op="A">
    					<Type Op="A" Word="JUD">Judicial Officer</Type>
    					<Code Op="A" Word="00727G">Abrams, Jerome B.</Code>
    				</CourtResource>
    				<CourtSessionBlock InternalCourtSessionBlockID="1615773710">
    					<StartTime Op="A">2:00 PM</StartTime>
    					<EndTime Op="A">3:00 PM</EndTime>
    				</CourtSessionBlock>
    				<InterpreterNeeded Op="A">false</InterpreterNeeded>
    				<TimestampCreate Op="A">07/14/2016 09:00:52:767</TimestampCreate>
    			</Setting>
    		</Hearing>
    	</Case>
    	<ProtectionOrder InternalProtectionOrderID="2551" xmlns:user="http://tylertechnologies.com">
    		<Deleted>false</Deleted>
    		<ProtectionOrderNumber>1600329</ProtectionOrderNumber>
    		<Issued>07/14/2016</Issued>
    		<Expiration>10/22/2016</Expiration>
    		<Statuses>
    			<Status>
    				<Current>true</Current>
    				<Active>No</Active>
    				<Date>07/14/2016</Date>
    				<Type Word="SUPERSEDED">Superseded</Type>
    				<TimestampCreate>07/14/2016 09:00:25:510</TimestampCreate>
    			</Status>
    			<Status>
    				<Current>false</Current>
    				<Active>Yes</Active>
    				<Date>07/14/2016</Date>
    				<Type Word="SBJO">Signed By Judicial Officer</Type>
    				<TimestampCreate>07/14/2016 08:57:54:797</TimestampCreate>
    			</Status>
    			<Status>
    				<Current>false</Current>
    				<Active>No</Active>
    				<Date>07/14/2016</Date>
    				<Type Word="DRAFT">Draft</Type>
    				<TimestampCreate>07/14/2016 08:57:39:983</TimestampCreate>
    			</Status>
    		</Statuses>
    	</ProtectionOrder>
    	<ProtectionOrder InternalProtectionOrderID="2552" xmlns:user="http://tylertechnologies.com">
    		<Deleted>false</Deleted>
    		<ProtectionOrderNumber>1600330</ProtectionOrderNumber>
    		<Issued>07/14/2016</Issued>
    		<Expiration>01/30/2017</Expiration>
    		<Statuses>
    			<Status>
    				<Current>true</Current>
    				<Active>Yes</Active>
    				<Date>07/14/2016</Date>
    				<Type Word="SBJO">Signed By Judicial Officer</Type>
    				<TimestampCreate>07/14/2016 09:00:25:547</TimestampCreate>
    			</Status>
    			<Status>
    				<Current>false</Current>
    				<Active>No</Active>
    				<Date>07/14/2016</Date>
    				<Type Word="DRAFT">Draft</Type>
    				<TimestampCreate>07/14/2016 09:00:14:380</TimestampCreate>
    			</Status>
    		</Statuses>
    	</ProtectionOrder>
    </Integration>
  2. #2
  3. Lazy Moderator
    Devshed Supreme Being (6500+ posts)

    Join Date
    Mar 2007
    Location
    Washington, USA
    Posts
    16,435
    Rep Power
    9645
    It looks like you have some stuff already in place. Is there a specific problem with it?
  4. #3
  5. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2016
    Posts
    16
    Rep Power
    0
    The problem is that when I run the xslt code, I am getting wrong output of internalProtectionOrderID="2551" and protectionOrderNumber="1600329".
    These belong to the ProtectionOrder that appears first in the xml document.
    I want to get the ProtectionOrder (second) that meets the conditions I stated in the question.
    1. Get the protectionOrder whose status is not deleted
    2. ProtectionOrder whose Statuses/Status/Type/@Word="SBJO" or Statuses/Status/Type/@Word="SBJOCOR"
    3. ProtectionOrder whose Statuses/Status/TimestampCreate is earlier than the ControlPoint TimeStamp

    The output should show the correct InternalProtectionOrderID="2552" and protectionOrderNumber="1600330"
  6. #4
  7. Lazy Moderator
    Devshed Supreme Being (6500+ posts)

    Join Date
    Mar 2007
    Location
    Washington, USA
    Posts
    16,435
    Rep Power
    9645
    Unless I'm missing something, both of those ProtectionOrders match your criteria. So why do you need it to find the second and not the first?


    And by the way, you posted fake data, right? That's not real? Or it's real but is not confidential/is public record?
  8. #5
  9. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2016
    Posts
    16
    Rep Power
    0
    The data is fake yes.
    If you look at the first ProtectionOrder it has <Type Word="SUPERSEDED">Superseded</Type> Status = SUPERSEDED with lastest Timestampcreate of 07/14/2016 09:00:25:510
    <TimestampCreate>07/14/2016 09:00:25:510</TimestampCreate> That is the latest TimestampCreate for this ProtectionOrder. So I should not get this as output.

    The second ProtectionOrder has <Type Word="SBJO">Signed By Judicial Officer</Type> with latest timestampcreate of 07/14/2016 09:00:25:547
    <TimestampCreate>07/14/2016 09:00:25:547</TimestampCreate>
    This is the ProtectionOrder I need for my output because it's TimestampCreate is the latest time and the Status is SBJO. Also this latest TimestampCreate is less (earlier) than ControlPoint TimeStamp.
  10. #6
  11. Lazy Moderator
    Devshed Supreme Being (6500+ posts)

    Join Date
    Mar 2007
    Location
    Washington, USA
    Posts
    16,435
    Rep Power
    9645
    So you want the most recent ProtectionOrder in the entire document that is still earlier than the ControlPoint? If I understand that then the problem is in finding the ProtectionOrder, which means looking at its Statuses and comparing them with both the ControlPoint as well as with the other Statuses in the document to find the most recent one.

    I have a proof of concept running but it's not proving easy to adapt to your stuff. Probably has to do with me being rusty with XSLT and not being able to test things very well (my available XSLT processor is a bit limited).

    I'm still looking but the basic idea is to loop through Statuses and find one where there isn't a more recent Status elsewhere.
    Code:
    variable $recentPO =
    	variable $control = formatDateTimeNumeric(/Integration/ControlPoint/@Timestamp)
    	for each ProtectionOrder/Status[formatDateTimeNumeric(TimestampCreate) < $control] {
    		variable $status = formatDateTimeNumeric(TimestampCreate)
    		if count(/Integration/ProtectionOrder/Statuses/Status[formatDateTimeNumeric(TimestampCreate) < $control][formatDateTimeNumeric(TimestampCreate) > $status]) = 0 {
    			copy ..
    		}
    	}
    $thisStatus seems to be unavoidable: need to be able to refer to it in the count() query. If it could be removed then the whole thing could be probably turned into a condition you could tack onto what you already have - though the result would be pretty long.

    Moving this into a JScript function could also make things easier...
  12. #7
  13. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2016
    Posts
    16
    Rep Power
    0
    This is resolved. Thank for your help

IMN logo majestic logo threadwatch logo seochat tools logo