Thembelani Mlalazi · Oct 13, 2017 go to post

[@Sean Connelly] managed to do as per your suggestion but the problem persist. The messages are rooted to the process but are not going any further to the business operation .My business operation is using the EnsLib.EDI.XML.Operation.FileOperation is this the problem and if it is what's the right one to use

[@ vitaliy.Serdtsev] have change my code as per your suggestion still not writing to a file I get  <PARAMETER>zWrite^%Stream.FileBinary.1

Thembelani Mlalazi · Nov 14, 2017 go to post

@Robert Cemper thank you but I am trying to avoid using the object classes to create this as I will be processing a lot of  different files and will end up with a lot of classes

Thembelani Mlalazi · Nov 15, 2017 go to post

@Marc Mundt I have read around the topic but still cannot figure out how to read an xml to %ZEN.proxyObject would mind please giving us an example to work with I am  still new to this thank you

Thanks for the advice have changed my code but come to a problem while reading my stream as there seems to an error with the XSLT XML Transformer Error: SAXParseException  I do not seems to see what the problem is as I tested my XLT with the XLT Transform Wizard and it all worked fine could you please have a look at the xml and the XLT and see if you can spot where I am going wrong thanks in advance

XML

<Message><Header><Code>HOT</Code><Date>2017-12-08 11:22:34.658</Date></Header><Body><Code>HOT</Code><Name>SIDE</Name><Type>AADULT</Type><Sec>MSec</Sec><ardge>Adult</ardge><Nder>F</Nder><TBC>21</TBC><BO>14</BO><DBOC>0</DBOC><LBC>5</LBC><AB>2</AB></Body><Body><Code>HOT</Code><Name>DARS</Name><Type>AADULT</Type><Sec>MSec</Sec><ardge>OADULT</ardge><Nder>U</Nder><TBC>20</TBC><BO>16</BO><DBOC>0</DBOC><LBC>2</LBC><AB>2</AB></Body><Body><Code>HOT</Code><Name>ENTLE</Name><Type>AADULT</Type><Sec>MSec</Sec><ardge>Adult</ardge><Nder>M</Nder><TBC>22</TBC><BO>18</BO><DBOC>0</DBOC><LBC>3</LBC><AB>1</AB></Body><Body><Code>HOT</Code><Name>ROOXED</Name><Type>AADULT</Type><Sec>MSec</Sec><ardge>OADULT</ardge><Nder>U</Nder><TBC>17</TBC><BO>7</BO><DBOC>0</DBOC><LBC/><AB>9</AB></Body><Body><Code>HOT</Code><Name>DUK</Name><Type>AADULT</Type><Sec>MSec</Sec><ardge>Adult</ardge><Nder>F</Nder><TBC>20</TBC><BO>17</BO><DBOC>0</DBOC><LBC>1</LBC><AB>2</AB></Body><Body><Code>HOT</Code><Name>DALE</Name><Type>AADULT</Type><Sec>MSec</Sec><ardge>Adult</ardge><Nder>M</Nder><TBC>18</TBC><BO>15</BO><DBOC>0</DBOC><LBC>2</LBC><AB/></Body><Body><Code>HOT</Code><Name>DAN</Name><Type>AADULT</Type><Sec>MSec</Sec><ardge>OADULT</ardge><Nder>U</Nder><TBC>16</TBC><BO>8</BO><DBOC>0</DBOC><LBC/><AB>8</AB></Body><Body><Code>HOT</Code><Name>DUN</Name><Type>AADULT</Type><Sec>MSec</Sec><ardge>Adult</ardge><Nder>U</Nder><TBC>2</TBC><BO>0</BO><DBOC>0</DBOC><LBC>1</LBC><AB>1</AB></Body><Body><Code>HOT</Code><Name>DUW</Name><Type>AADULT</Type><Sec>MSec</Sec><ardge>Adult</ardge><Nder>U</Nder><TBC>3</TBC><BO>2</BO><DBOC>0</DBOC><LBC>1</LBC><AB/></Body><Body><Code>HOT</Code><Name>DUM</Name><Type>AADULT</Type><Sec>MSec</Sec><ardge>OADULT</ardge><Nder>U</Nder><TBC>22</TBC><BO>18</BO><DBOC>0</DBOC><LBC>2</LBC><AB>2</AB></Body><Body><Code>HOT</Code><Name>DUR</Name><Type>AADULT</Type><Sec>MSec</Sec><ardge>Adult</ardge><Nder>U</Nder><TBC>16</TBC><BO>13</BO><DBOC>0</DBOC><LBC>2</LBC><AB/></Body></Message>

 

XSLT

<?xml version="1.0"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
    <xsl:output method="text" indent="yes"/>
    <xsl:template match="/*[node()]">
        <xsl:text>{</xsl:text><xsl:text>&#xa;</xsl:text>
        <xsl:apply-templates select="." mode="detect" />
  <xsl:text>&#xa;</xsl:text>
        <xsl:text>}</xsl:text>
    </xsl:template>
    <xsl:template match="*" mode="detect">
        <xsl:choose>
            <xsl:when test="name(preceding-sibling::*[1]) = name(current()) and name(following-sibling::*[1]) != name(current())">
                    <xsl:apply-templates select="." mode="obj-content" />
     <xsl:text>&#xa;</xsl:text>
                <xsl:text>]</xsl:text>
                <xsl:if test="count(following-sibling::*[name() != name(current())]) &gt; 0">, </xsl:if>
            </xsl:when>
            <xsl:when test="name(preceding-sibling::*[1]) = name(current())">
                    <xsl:apply-templates select="." mode="obj-content" />
                    <xsl:if test="name(following-sibling::*) = name(current())">, </xsl:if>
            </xsl:when>
            <xsl:when test="following-sibling::*[1][name() = name(current())]">
                <xsl:text>"</xsl:text><xsl:value-of select="name()"/><xsl:text>" : [</xsl:text>
        <xsl:text>&#xa;</xsl:text>
                    <xsl:apply-templates select="." mode="obj-content" /><xsl:text>, </xsl:text>
     <xsl:text>&#xa;</xsl:text>
            </xsl:when>
            <xsl:when test="count(./child::*) > 0 or count(@*) > 0">
                <xsl:text>"</xsl:text><xsl:value-of select="name()"/>" : <xsl:apply-templates select="." mode="obj-content" />
                <xsl:if test="count(following-sibling::*) &gt; 0">, </xsl:if>
            </xsl:when>
            <xsl:when test="count(./child::*) = 0">
                <xsl:text>"</xsl:text><xsl:value-of select="name()"/>" : "<xsl:apply-templates select="."/><xsl:text>"</xsl:text>
                <xsl:if test="count(following-sibling::*) &gt; 0">, </xsl:if>
    <xsl:text>&#xa;</xsl:text>
            </xsl:when>
        </xsl:choose>
    </xsl:template>
    <xsl:template match="*" mode="obj-content">
     <xsl:text>&#xa;</xsl:text>
        <xsl:text>{</xsl:text>
  <xsl:text>&#xa;</xsl:text>
            <xsl:apply-templates select="@*" mode="attr" />
            <xsl:if test="count(@*) &gt; 0 and (count(child::*) &gt; 0 or text())">, </xsl:if>
            <xsl:apply-templates select="./*" mode="detect" />
            <xsl:if test="count(child::*) = 0 and text() and not(@*)">
                <xsl:text>"</xsl:text><xsl:value-of select="name()"/>" : "<xsl:value-of select="text()"/><xsl:text>"</xsl:text>
            </xsl:if>
            <xsl:if test="count(child::*) = 0 and text() and @*">
                <xsl:text>"text" : "</xsl:text><xsl:value-of select="text()"/><xsl:text>"</xsl:text>
            </xsl:if>
        <xsl:text>}</xsl:text>
        <xsl:if test="position() &lt; last()">, </xsl:if>
    </xsl:template>
    <xsl:template match="@*" mode="attr">
        <xsl:text>"</xsl:text><xsl:value-of select="name()"/>" : "<xsl:value-of select="."/><xsl:text>"</xsl:text>
        <xsl:if test="position() &lt; last()">,</xsl:if>
    </xsl:template>
    <xsl:template match="node/@TEXT | text()" name="removeBreaks">
        <xsl:param name="pText" select="normalize-space(.)"/>
        <xsl:choose>
            <xsl:when test="not(contains($pText, '&#xA;'))"><xsl:copy-of select="$pText"/></xsl:when>
            <xsl:otherwise>
                <xsl:value-of select="concat(substring-before($pText, '&#xD;&#xA;'), ' ')"/>
                <xsl:call-template name="removeBreaks">
                    <xsl:with-param name="pText" select="substring-after($pText, '&#xD;&#xA;')"/>
                </xsl:call-template>
            </xsl:otherwise>
        </xsl:choose>
    </xsl:template>
</xsl:stylesheet>
Thembelani Mlalazi · Dec 14, 2017 go to post

@Eduard Lebedyuk

sorry man given the above XLT how can I get the following Json

{
"Body" : [

{
"Code" : "HOT",
"Name" : "SIDE",
"Type" : "AADULT",
"Sec" : "MSec",
"ardge" : "Adult",
"Nder" : "F",
"TBC" : "21",
"BO" : "14",
"DBOC" : "0",
"LBC" : "5",
"AB" : "2"
},

{
"Code" : "HOT",
"Name" : "DARS",
"Type" : "AADULT",
"Sec" : "MSec",
"ardge" : "OADULT",
"Nder" : "U",
"TBC" : "20",
"BO" : "16",
"DBOC" : "0",
"LBC" : "2",
"AB" : "2"
}
]
"Code" : "HOT",
"Date" : "2017-12-08 11:22:34.658",
}

Thembelani Mlalazi · Dec 20, 2017 go to post

@Fabian Haupt I need help if Xpath will achieve what I am trying to do  so be it what I want is something generic for any XML to be processed if Xpath Has a generic way fine

Thembelani Mlalazi · Dec 20, 2017 go to post

@eduard.lebeduk I am not using %XML.Reader hence the reason I need to find the alternative of reading the record open and close element I am trying to do away with creating object classes

so far when I run my code in cache I get this error <INVALID OREF>zXmlToJSONnode+3^SharpJSONToXML.1 and I would like to know the equivalent in cache for that method if you look at it

@Robert Cemper

Thembelani Mlalazi · Jan 15, 2018 go to post

@David Foard In  your Rule on the when  condition select the  (Document.RecordMapper.Property) make show you are referencing a record mapper on the constraint of the rule

Thembelani Mlalazi · Jan 15, 2018 go to post

On the condition I would like to do something like this but I do not get the opportunity to actual get to the schema that I would like to reference to get to that. Message will be the root of my xml document Header an element with attribute Action @Robert Cemper

Thembelani Mlalazi · Jan 15, 2018 go to post

@Jeffrey.Drumn Assuming I got this right He is trying to get to reference a property from a record mapper that will work just fine here is an example

TestEnvironment.Record being my record mapper class and the Document.wardAge being my property (WARDAGE)

Thembelani Mlalazi · Jan 31, 2018 go to post

@Dmitry Maslennikov I have  done this for starters but got an error ^
<INVALID OREF>zTalkToTheWorld

here is my code

Method TalkToTheWorld()
{
 Set httprequest=##class(%Net.HttpRequest).%New()
 Set httprequest.Server="https://maps.googleapis.com/maps/api/distancematrix/json?origins=BRISTOL&destinations=LONDON&key=TZhydlRg6-dUm-EoIuees43456rtyu7 "
 Do httprequest.Get("/")
 Do httprequest.HttpResponse.OutputToDevice()
 Do httprequest.Get("/cache/")
 Do httprequest.HttpResponse.OutputToDevice()
}
Thembelani Mlalazi · Mar 12, 2018 go to post

@Scott Roth  have tried your suggestion still same problem .Under Data Settings I have a query "SELECT ID FROM dbs.DBS WHERE Status='Pending'" and the above code just in case I did not do it right please advise

Thembelani Mlalazi · Mar 13, 2018 go to post

@Sean Connelly thanks I have tried your suggestions both but still not writing anything to a file and  no file is being created am I missing anything please advise thanks in advance

Thembelani Mlalazi · Mar 13, 2018 go to post

@Sean Connelly

Class TOpp Extends Ens.BusinessOperation
{
Parameter ADAPTER = "EnsLib.SQL.OutboundAdapter";
Property Adapter As EnsLib.SQL.OutboundAdapter;
Parameter INVOCATION = "Queue";
Method CheckRequests(pRequest As Ens.Request, Output pResponse As Ens.Response) As %Status
{
 set query= ";with apt as"
 _"("
 _" Select ac.ClientID from AmsAppointmentContact ac join AmsAppointment a on a.SequenceID = ac.SequenceID where"
 _"  a.AppointmentDate > CAST(DATEADD(M,-6,GETDATE()) AS DATE) and a.CancellationDateTime is null "
 _" ),"
 _" ref as"
 _"("
 _" select ClientID"
 _"  from"
 _" ( select ROW_NUMBER() OVER(PARTITION BY ClientID ORDER BY ReferralNumber) rn, * from AmsReferral"
 _"   where DischargeDateTime is null) a"
 _"  where rn = 1 "
 _" ),"
 _"  inp as"
 _" ("
 _" select ClientID"
 _" from"
 _"("
 _" select ROW_NUMBER() OVER (PARTITION BY ClientID ORDER BY EventNumber) as rn,* from ImsEvent"
 _" where DischargeDate is null) a "
 _"  where rn = 1"
 _" ),"
 _" cohort as "
 _" (select ClientID from "
 _" ( "
 _" select row_number() OVER(PARTITION BY ClientID ORDER BY ClientID) as rn,ClientID from "
 _" (select * from apt"
 _" union all "
 _"  select * from ref "
 _"  union all "
 _"  select * from inp) a) b where rn=1 "
 _" ) "
 _" select '10' as recType, c.ClientID, CONVERT(VARCHAR(8), c.DateOfBirth, 112) as DOB, '' as u1, '' as u2, ISNULL(c.NNN, '') as NNN,"
 _" cn.Surname, '' as u3, cn.GivenName1, '' as u4, g.SpineCode as Gender,"
 _" '' as a1,'' as a2,'' as a3,'' as a4,'' as a5 ,ca.PostCode,'' as p1,'' as p2,'' as p3,'' as p4,'' as p5,'ZZ99' as p6, ch.GPCode, ch.PracticeCode,'' as u5,'' as u6 "
 _" from ClientIndex c left join ClientName cn on cn.ClientID = c.ClientID left join ClientAddress ca on ca.ClientID = c.ClientID left join ClientHealthCareProvider ch on c.ClientID = ch.ClientID "
 _" left join GenGender g on g.Code = c.Gender join cohort on cohort.ClientID = c.ClientID where "
  _" c.DateOfDeath is null and ca.ToDate is null and ca.AddressGroup = 1 and cn.AliasType = '1' and ch.ToDate is null and c.NonClient = 0"
 
 set file = ##class(%Stream.FileCharacter).%New()
 set fileName="C:\File\123.txt"
 set sc=""
  do file.LinkToFile(fileName)
  while 'file.AtEnd {
 
  set rs = ##class(%SQL.Statement).%ExecDirect(, query)
  set sc = rs.%DisplayFormatted(100,file)
}
 quit sc
 
}
XData MessageMap
{
<MapItems>
  <MapItem MessageType="Ens.Request">
    <Method>CheckRequests</Method>
  </MapItem>
</MapItems>
}
}
Thembelani Mlalazi · Mar 19, 2018 go to post

@Robert Cemper Have tried changing that as per your suggestion but seem not to get it working do you have another suggestion on how I can approach this was wondering is there a function like select to stream to do this