Julian Matthews · May 19, 2022 go to post

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.

Julian Matthews · Apr 11, 2022 go to post

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")
Julian Matthews · Apr 4, 2022 go to post

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.

Julian Matthews · Apr 4, 2022 go to post

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.

Julian Matthews · Apr 1, 2022 go to post

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:

Julian Matthews · Apr 1, 2022 go to post

Hey Shamus.

My issue isn't with the actual character encoding, but the display of the characters because the management portal (being browser based) uses UTF-8.

In my initial example, if I were to write the output to a file with the the correct character encoding set, it will look fine when opened in a text editor.

Julian Matthews · Mar 24, 2022 go to post

Hey Token.

You could use ##class(%PopulateUtils).VarString() to generate the random string.

Julian Matthews · Mar 7, 2022 go to post

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.

Julian Matthews · Mar 3, 2022 go to post

I believe the privilege comes from the OS user that is launching Terminal.

Have you tried running Terminal as an Admin and seeing if runs as expected?

Julian Matthews · Feb 17, 2022 go to post

Hey Kurro.

You should be able to include the allowed source in the rule constraint:

Alternatively, you could add a rule above that looks like this:

Julian Matthews · Feb 1, 2022 go to post

Hey Stefan.

Is the file saved as a class when trying to run the formatter? I found previously that it's not enough to just set the language in a new class, but the file needs to be saved as the formatter relies on the file extension.

Julian Matthews · Dec 29, 2021 go to post

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
}
Julian Matthews · Nov 5, 2021 go to post

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.

Julian Matthews · Nov 4, 2021 go to post

Thanks John, that's very good to know about.

It's missing 1 or 2 features I like in ScreenToGif, but it's certainly going in my bookmark bar.

Julian Matthews · Nov 3, 2021 go to post

Hey Ben.

I use a program called ScreenToGif.

Since moving to remote working it has become invaluable for demonstrating functionality for apps via email or IM. However it gets the most use when I'm reporting bugs to a supplier, or in this case how I'm incorrectly using VSCode extensions smiley

I'm pretty sure it's a Windows-only app, so you may need to find an alt if you're on another OS and wish to try it out.

*edit*

As a tip, try to keep any gifs you do make for bug reporting fairly short. No one wants to be waiting 2 minutes for a gif to loop because they missed the important part!

Julian Matthews · Nov 3, 2021 go to post

Hey Brett, thank you for your help.

I have found the issue.

It looks like a file needs to be saved as a .cls first before the formatter is available for use. This differs from other languages within VSCode which just needs the language to be set for the new document.

Julian Matthews · Nov 3, 2021 go to post

Hey @Brett Saviano 
I have the Language Server extension installed, however invoking the formatter using the keyboard shortcut Shift+Alt+F ( as per the VSCode documentation you linked) gives this popup:

Julian Matthews · Nov 3, 2021 go to post

Hey Ben.

Specifically looking to be able reformat the code layout. For example, if I was working with javascript or json, I can use the keyboard command Shift+Alt+F and it will reformat the code:

However, when I attempt this with the language set to ObjectScript or ObjectScript-Class, pressing that same keyboard shortcut gives a popup stating no formatter is installed and it directs me to the Extension Marketplace

Julian Matthews · Oct 29, 2021 go to post

Hey Kurro.

To access values from your message class, you will need to alter your references to your class in your if statements.

For example, rather than just calling "CodigoProveedor", you will need to state "Document.CodigoProveedor" so that the router is looking for "CodigoProveedor" within the document received by the router.

You can test this by adding a new "When" within your Rule and use the expression editor to start type "Document.Cod" and this should then start giving you autocomplete options. For example:

As an aside (and because it's caught me out a few times) if your router is working with just custom classes and not HL7, do make sure your router is a General message router and not a HL7 message router as this can sometimes lead to odd errors.

Julian Matthews · Oct 28, 2021 go to post

Hey Yone.

Assuming you're only using ObjectScript for this, then way to achieve this would be to take your HL7 as Enslib.HL7.Message, and then loop through the segments to pull out the PID segment, and then loop through PID:3 for a match.

For example:

//loop through HL7 and find PID Segment
set SegCount = request.SegCount
for i=1:1:SegCount{
    set segment = request.GetSegmentAt(i)
    if (segment.Name="PID"){
        //Loop through PID:3
        set numCnt = segment.GetValueAt("3(*)")
        for j=1:1:numCnt{
            set P341=segment.GetValueAt("3("_j_").4.1")
            set P5=segment.GetValueAt("3("_j_").5")
            if (P341="CAC")&&(P5="JHN") {
                $$$TRACE("Match found!")
                }
        }
    }
}

Alternatively, you could create a DTL with the logic which you can from the ObjectScript, and then have the target in your DTL be something like a string container that you can then grab a result from. However that might be a bit clunky depending on your use case.

Julian Matthews · Oct 18, 2021 go to post

Hey Muhammad, I hope you are well. 

I hope you don't mind if I provide some feedback.

First, the serious feedback - It is important that reference ranges are linked to the unit of measure provided in the result. This is because a change to the units used in the source could then mean that you provide the incorrect reference range/flag. This could then in turn lead to someone misinterpreting the results in the destination system and impact the treatment of a patient.

Now to the less serious feedback - Some systems have extended the high/low flag so as to differentiate between something being slightly high, and something being extremely high. In the versions I have seen, this has been done as:

LLL - Extremely Low
LL - Severely Low
L - Moderately Low
N - Normal
H - Moderately High
HH - Severely High
HHH - Extremely High

It could make for an interesting expansion on what you have done so far.

Julian Matthews · Sep 24, 2021 go to post

Hey Rochdi.

The issue here is that you can't use the Arrow within the ON Clause and the alternative here would be to use ANSI Join syntax.

If it helps, the documentation (under Join Definitions) states that -> performs a left outer join? There's also a section further down for ON Clause if that is useful in any way.

Julian Matthews · Sep 17, 2021 go to post

Hey Sean.

I had considered using the values from Memory and Startup, but was unsure of the exact class to call it, so thank you.

I think my approach will be to use a util function which then returns a value based on SystemMode (I say based on, as I would want the same behavior even when failed over in a mirrored setting)

Julian Matthews · Sep 16, 2021 go to post

Hey Thomas.

EnableConfigItem from Ens.Director should be what you're looking for. You will need to call it twice (once to stop, and a second time to start it again).

From Terminal:

Do ##class(Ens.Director).EnableConfigItem("ConfigNameHere", 0, 1)

Do ##class(Ens.Director).EnableConfigItem("ConfigNameHere", 1, 1)

It returns a status, so you may want to evaluate the status when stopping it to ensure it stopped before trying to start it again, or report an error if it fails to stop or start.

Julian Matthews · Aug 17, 2021 go to post

Hey Eduard.

For question 3 - you could technically group them using managed alerts, as there is a function you can include in the router that is supposed to not raise an alert but instead update an existing managed alert (IsRecentManagedAlert) but this would mean getting alerted on the first message.

However, I have found this to be a bit inconsistent as it relies on a match on the AlertText and SourceConfigName within a user defined timeframe. Where this catches me out is when the alert text contains something like a timestamp, as this makes it unique so a new alert is raised anyway.

Alternatively, you could create a function that writes the alerts to an internal table, and then poll that table every x minutes to generate a single detailed alert message?

Julian Matthews · Aug 11, 2021 go to post

Hey Muhammad.

When you say validation, what exactly do you mean?

If you are interested in making sure it matches the format of ICD-10-AM codes, then you could use pattern matching to ensure it fits the expected format. At first glance, it looks to be 1 Letter + 2 Numbers + 1 period + 1 or 2 numbers. The pattern match for this would be "1A2N1"."1.2N"

For example:

USER> Set ICD10 = "K76.3"
USER> If ICD10?1A2N1"."1.2N {Write "This is ICD10"} else {write "This is not ICD10"}
This is ICD10

If you are looking to actually make sure the code is a real ICD10 code, then you would need to be able to query a data source that contains a full list of valid codes. If this is the direction you're looking to go in, then you may want to look into FHIR based terminology services to be able to query your codes against to see if they're valid? But I'm not familiar with the practicality or cost of something like that.

(ps - I have linked to the temporary documentation, however I'm not sure how long that will exist)