I have to admit, I'm not familiar with where that code has come from, so it's difficult to comment on the syntax.

That said, I think I can confidently say that your first line has the OBXgrp hard coded to the first repetition, but the second line has it set to k2. You will want a for each for the OBXgrp and a seperate one for the NTEs within the OBXgrp.

Hey Ciaran.

To overcome the issue of multiple ORCs overwriting your PIDgrp NTE in your copy, you will likely need to maintain a separate count of what is being copied over.

So you could look to do something similar to: (pay specific attention to actions 2, 9, and 10) 

Which would then give the following result:

You could then take it a step further by setting the value of your PIDgrp NTE to your count value before incrementing it:

Which would then give you:

As a warning, I did find that the DTL building went a bit weird when it comes to the auto-applying of the key counts. So I was adding a For Each on a repeating field and it assigned a key of say k1, then when adding the sets within the for each loop, it would randomly use k2 or k3 in the field. it might just be a limitation of how I was building things up, but it's one to keep an eye out for as it'll give you unexpected results if it happens to you. Good luck :)

Hey Ephraim.

I have thrown together a task which should do what you need. The code is a bit verbose and could be cut down a touch, but hopefully it's human readable enough for you to pick out what its doing.

Effectively, it takes the current date to then grab a date from last month, and then gets the first and last date of that month to then use in the audit method.

Class Demo.Tasks.MonthlyAudit Extends %SYS.Task.Definition
{

Method OnTask() As %Status
{
    Set tSC = $$$OK

    //Get Current Date
    Set CurentDatetime = $ZDATETIME($HOROLOG,3)

    //The report needs to be for last month, so get a date from last month based on todays date
    Set LastMonth = $SYSTEM.SQL.DATEADD("MM",-1,CurentDatetime)

    //Get last Day of last month As Horolog
    Set LastDayHoro =  $SYSTEM.SQL.LASTDAY(LastMonth)

    //Convert Horolog into a Date
    Set LastMonthEnd = $ZDATETIME(LastDayHoro,3)

    //Get First Day of Last Month
    Set LastMonthStart = $SYSTEM.SQL.DATEPART("YYYY",LastMonthEnd)_"-"_$SYSTEM.SQL.DATEPART("MM",LastMonthEnd)_"-01"

    //Switch to the %SYS Namespace
    ZNspace "%SYS"

    Set tSC = ##class(%SYS.Audit).Export("AuditExport.xml",,,LastMonthStart_" 00:00:00",LastMonthEnd_" 23:59:59")

    Quit tSC
}

}

Then, when setting the task up, I would set it to run on the first Monday of the Month, and it will grab everything from the previous month.

Hey Ephraim.

You will see from looking at the classmethod being called that there is a start date parameter which was left blank by Michael so that it will export everything up to the end date.

In your case, you could do the following to fulfil your example:

##class(%SYS.Audit).Export("AuditExport.xml",,,"2022-03-01 00:00:00","2022-04-11 23:59:59")

However this will only be useful to your specific date range, which is where Michaels use of $ZDT and $H come into play.

If you wanted to execute the task and have it return the last 30 days, you could do this:

##class(%SYS.Audit).Export("AuditExport.xml",,,$zdt($h-30,3)_" 00:00:00",$zdt($h,3)_" 23:59:59")

Hey Shamus. I do appreciate you replying, however I may not be being clear in my original question.

Even if I have the correct settings in the Business Service, if the content format is one that conflicts with UTF-8, the display within the management portal will show as per my examples because the browser is trying to display non UTF-8 content as UTF-8. My original question was asking how others work with this.

If you spot my second top-level comment, you will see that I had looked into using the browser to change the http content-type header, but that the major browsers no longer support such a feature.

I'm guessing my only option is to export a message and then review the content there.

Hey Shamus.

I'm back to eat some humble pie!

Turns out, I had confused myself early on and wrongly believed that Windows-1252/Latin1 were the same and I had my service set to Latin 1. This was then creating a scenario where I was digging myself into a hole of bad information.

In fact, they are almost the same except for the exact characters I was using in my example. These code points are used by Latin-1 as control codes, and when Windows-1252 is mislabeled as Latin-1 they get lost...

Thanks again for replying to my initial question and comments.

I have looked at how I can change the behavior of the browser, but it seems that the big 3 (well, two) no longer have this feature. Here is an article giving some back story.

Basically, Chrome used to have the option to manually overwrite the encoding type, but this was removed (however there are some 3rd party extensions out there to replace this feature, but I feel uncomfortable using random 3rd party extensions around healthcare data)

Firefox also used to have this feature, but they replaced it with a tool that attempts to repair the character encoding, however it didn't do a great job as it decided it was "IBM866" so the content looked like this:

Hey Leon.

The element of this issue that is perplexing me is that there is a difference between the RAW and Full view.

Could you try sending a sample message to a HL7 File operation with the charset set to UTF-8? I'm curious to know if the characters display as expected, stay as the ANSI character, or become something else.

I am wondering if the ANSI displaying in just the Full message viewer is contained to just the display of the full message, and any issues you are seeing in a destination system are a separate but similar issue with character encoding.

Hey Yuri.

Depending on the context, this answer I gave for a similar question may be relevant:

...you can pass ..Adapter.ExecuteQuery() a snapshot object (EnsLib.SQL.Snapshot) which will then get populated rather than a getting a result set returned. With this populated snapshot object, you can then iterate through it using its Next() method just like the result set, but then you can use its Rewind() method. 

For example:

Set Snapshot = ##Class(EnsLib.SQL.Snapshot).%New()
Set sql = "SELECT * FROM MY_TABLE WHERE X= '"_Y_"'"
Set status = ..Adapter.ExecuteQuery(Snapshot, sql)
While Snapshot.Next(){
  //First run through of snapshot
}
Do Snapshot.Rewind()
While Snapshot.Next(){
  //Second run through of snapshot
}

Hey Nicola.

As an alternative to Davids response, you can pass ..Adapter.ExecuteQuery() a snapshot object (EnsLib.SQL.Snapshot) which will then get populated rather than a getting a result set returned. With this populated snapshot object, you can then iterate through it using its Next() method just like the result set, but then you can use its Rewind() method. 

For example:

Set Snapshot = ##Class(EnsLib.SQL.Snapshot).%New()
Set sql = "SELECT * FROM MY_TABLE WHERE X= '"_Y_"'"
Set status = ..Adapter.ExecuteQuery(Snapshot, sql)
While Snapshot.Next(){
  //First run through of snapshot
}
Do Snapshot.Rewind()
While Snapshot.Next(){
  //Second run through of snapshot
}

Something to be mindful of - as I'm passing ..Adapter.ExecuteQuery() an object rather than trying to get it to output something, the period before the variable is intentionally missing in my example.