Are you dealing with multiple DocTypes and Categories of messages going to Epic, or are all messages the same schema?

I know you're not crazy about a custom operation, but if you take a look at the source for EnsLib.HL7.Operation.TCPOperation, you'll see that it would be dead simple to copy/extend it, add a check for the population of the Ordering Provider field, and the logic to populate it with a default if it's empty.

From within your task, you can obtain the task's classname with $CLASSNAME() and query the %SYS.Task table using the TaskClass of your task to fetch the OutputFilename column.

If you want to use that file under your direct control, you can set "Open output file when task is running" to "yes," enter the full path of the filename, then set the previous setting back to "no." The filename will remain in the table.

If you're calling the same class under multiple Task schedules or with different configurations, the schedule values and settings are also available to help you refine your selection. Settings are stored in $LIST() format.

EDIT: You can also define a Filename property in the task class, assuming it's a custom class. It will show up as a configurable field in the task editor. That way you don't have to deal with the OutputFilename settings.

Usually, OBX segments are either defined as repeating segments or members of repeating segment groups. The syntax you'll use will vary depending on the HL7 Document Category and Structure you're using in your DTL. In HL7 2.5.1, the OBX segment itself is non-repeating, but is part of a repeating group (OBXgrp) inside another repeating group (ORCgrp) inside yet another repeating group (PIDgrpgrp).

You first need to get the count of the total number of OBX segments, which you can do by supplying the "*" character in the iteration argument to the source path's OBXgrp(). Add 1 to that, and you have your iteration for the new OBX segment.

Use that value as the iteration for the new OBX segment and populate the fields as needed, as in the example below:

The above assumes that the OBX segments are the last segments in the message. If they're not and the message requires another OBX at the very end, it's a bit more complicated ... you'd create a new segment object, populate it, then use the AppendSegment method to slap it on the end of the target:

Thanks for this! Although ... the answer shows the query running in the Management Portal, which wasn't available to me when I ran into the issue 😁

But this works:

[SQL]%SYS>>call %CSP.Session_SessionInfo()
10.     call %CSP.Session_SessionInfo()

Dumping result #1
ID      Username        Preserve        Application     Timeout LicenseId       SesProcessIdAllowEndSession
P0AtBxzbL9      jeff    0       /ih/csp/healthshare/hicg/       2025-04-30 20:47:16     jeff1
zAOMQO8MC8      UnknownUser     0       /ih/csp/documatic/      2025-04-30 20:50:53         1

Add your code snippet and I'm good to nuke some sessions even when the Management Portal is unavailable 😉

Until such time as InterSystems provides synchronization for security components across mirror members, you can save a bit of effort by exporting them on the primary and importing them on the alternate server via the ^SECURITY routine in the %SYS namespace. At least you won't need to create them manually.

You can do the same for users, roles, resources and a few other things as well. All of these have ObjectScript methods for accomplishing the same in the Security package.

There really is no list of "Standard" settings. You can use whatever section name you desire and it will appear in the list of settings for the business host in the production.

Most adapters provide the settings Basic, Connection, and Additional. However if the setting you're creating doesn't fit any of those categories, you can create your own with the "MySetting:MyCategory" format.

The documentation for creating business host settings can be found here.

EDIT: After reviewing the documentation, I discovered that there are a set of predefined categories and they're listed here.

Glad you got it working.

I feel I should mention that I specifically told you to just that 2 days ago ... quoted here:

There are a few issues with this code, but the biggest one is that you've created a clone and should be modifying the clone (pOutput) exclusively. However, you're still calling SetValueAt() against a segment pulled from pRequest.

The above notwithstanding, you're still sending the original unchanged message object (pRequest) to the target operation with the SendRequestAsync() call.

Fundamentally, you should:

  1. Create a clone of the request object pRequest (i.e. pOutput)
  2. Modify the clone, which is a mutable copy of the original message
  3. Send the modified clone (pOutput) to the target operation

You're cloning the source message inside the While loop that is iterating over segments within the message. That's not doing anything useful.

Clone the message, then iterate over its OBX segments, making whatever changes are necessary. Before sending it with SendRequestAsync(), do a pOutput.%Save().

This snippet below is completely untested and there are other enhancements I would make to it, but I'm not going to be available for a while, so here's something to play with. It's a cleaned up version of the code snippet you provided above. Note that there is not a single call to GetSegmentAt() ... it's an unnecessary extra step.

    // Message Subtype
    Set tMessageSubType = pRequest.GetValueAt("ORCgrp(1).ORC:1")
    //
    // Check if OBR:19 contains "Implant Usage (PSAS)" OR "Issued in Clinic (PSAS)"
    Set tOrderType = pRequest.GetValueAt("ORCgrp(1).OBRuniongrp.OBRunion.OBR:19(1).1")
    If ((tOrderType["Implant Usage (PSAS)") || (tOrderType["Issued in Clinic (PSAS)")) {
        // First loop: Count occurrences of "Item Number:"
        Set i = 1
        Set tItemNumberCount = 0
        While (pRequest.GetValueAt("ORCgrp(1).OBRuniongrp.OBXgrp("_i_").OBX")'="") {
            Set tOBXText = pRequest.GetValueAt("ORCgrp(1).OBRuniongrp.OBXgrp("_i_").OBX.5", .tStatus)
            //
            If (tOBXText [ "Item Number:") {
                Set tItemNumberCount = tItemNumberCount + 1
            }
            //
            If (tOBXText[ "Total Cost:") {
                Set tTotalCostSegment = i
                //$$$LOGINFO(tTotalCostSegment_" ------ "tTotalCostSegment check Total Cost")
            }
            Set i = i + 1
        }
        // Second loop: Modify OBX segments if necessary
        Set i = 1
        Set tItemNumberProcessed = 0
        Set pOutput = pRequest.%ConstructClone(1) // moved here because %ConstructClone() need only be done at the message object level.
        While (pOutput.GetValueAt("ORCgrp(1).OBRuniongrp.OBXgrp("_i_").OBX")'="") {
            Set tOBXText = pOutput.GetValueAt("ORCgrp(1).OBRuniongrp.OBXgrp("_i_").OBX.5", .tStatus) // using pOutput instead of pRequest
            If (tOBXText [ "Item Number:") {
                Set tItemNumberProcessed = tItemNumberProcessed + 1
            }
            If (tItemNumberCount > 1) && (tOBXText [ "REASON FOR REQUEST:") {
                set tOBXKey = i
                Set tOBXText=$p(tOBXText,":",2,5) /// OBX 5 text parsed to replace in OBX 5 later
                // Start replacement process
                Do pOutput.SetValueAt(tOBXText,"ORCgrp(1).OBRuniongrp.OBXgrp("_i_").OBX.5")
                $$$LOGINFO(tOBXText_" ---- OBX 5 parsed to be saved in new OBX 5") /// works
                Set tOBXTextChanged = pOutput.GetValueAt("ORCgrp(1).OBRuniongrp.OBXgrp("_i_").OBX.5")
                $$$LOGINFO(i_tOBXTextChanged_" --- i --- tOBXTextChanged, Is OBX 5 changed???")
            }
            Set i = i + 1
        }
    }
    Do pOutput.%Save()

%ConstructClone() need only be done at the message object level.

And I'm not sure why you're extracting segments to update them; you can use SetValueAt() against the message object instead a segment object ... 

For example this code:

Set tOBXSegmentpOutput = pOutput.GetSegmentAt("ORCgrp(1).OBRuniongrp.OBXgrp("_i_").OBX", .tStatus)
Do tOBXSegmentpOutput.SetValueAt(tOBXText, 5)

Is functionally identical to:

Do pOutput.SetValueAt(tOBXText,"ORCgrp(1).OBRuniongrp.OBXgrp("_i_").OBX.5")

That should help simplify the code.

You shouldn't need to do a "deep clone" for this, so the "1" argument to %ConstructClone() is optional.

Somewhere between the %ContstructClone() call and the SetValueAt() call, you'll be using the GetSegmentAt() method of the clone to get the segment object into tOBXSegmentpOutput.

The syntax of the SetValueAt() call should have the string to store as the first argument rather than the pOutput message object.

tOBXSegmentpOutput is a reference to the segment in the clone message. It should not need to be explicitly saved, and I'm pretty sure SaveData() doesn't do what you think it does anyway.