Question
· Jul 1, 2019

Query Help On RawContent in EnsLib_HL7.Message table

Request for getting Audit/Reporting info.
The ask is for a count of inbound messages by distinct identifier.

My challenge is getting the unique identifer out of the RawContent column in the EnsLib_HL7 table.

Wondering if a temp table can be created to store the value then do a join?

In the below example I am wanting to use the 999998 value in the PID.


Name              RawContent
ADT_A01             MSH||||||||
                 PID|||9904319776^^^ACMEHOSPITAL^MRN~991051441^^^ACMEHIE^MPIID~999998^^^BLUECLUE^BEKEY|
                 |BACON^CHRIS^P^


I am able to get the counts of the events but stumped on doing for the distinct value in PID.
select Name, 
sum(case when Name='ADT_A01' then 1 else 0 end) as Total_ADT_A01,
sum(case when Name='ADT_A03' then 1 else 0 end) as Total_ADT_A03,
sum(case when Name='ADT_A04' then 1 else 0 end) as Total_ADT_A04
from EnsLib_HL7.Message
where Name in ('ADT_A01','ADT_A04','ADT_A03')
group by Name

Discussion (4)0
Log in or sign up to continue

Hi Ed,

If you have the Show Query option enabled in Message Viewer, you can build your criteria for extracting the message data there, then click the button to see the SQL it generates. The default EnsLib.HL7.SearchTable indexes the Patient ID, but it includes PID:2.1, PID:3.1 (all iterations) and PID:4.1 (all iterations). If you're searching for specific IDs or ranges you may get unintended duplicates.

You don't need a custom SearchTable to filter the messages, but it sure helps.

If you don't have it enabled, you can turn it on for your production's namespace:

USER > zn "PROD"
PROD > set ^Ens.Debug("UtilEnsMessages","sql")=1

The Message Viewer is a powerful tool and gives you access for query and display of every HL7 field. The SQL it generates should put you on the right track.