Encounter Search: Unique combinations of the Patient and the EncounterType per Encounter

Hi,

I am working on a dashboard that displays a few counters and I am somewhat stuck in a particular one. I would like to know: “All encounters uniquely(based on the encounter_type) recorded for patients”

i.e. I would like to get a count of all the unique combinations of the patient and the encounter_type per encounter.

A sql translation of the problem statement could be:

SELECT SUM(x1.enc_type) AS total_encounter FROM patient INNER JOIN (SELECT DISTINCT (encounter_type), patient_id, COUNT(DISTINCT (encounter_type)) AS enc_type FROM encounterEncounter Search: Unique combinations of the Patient and the EncounterType per Encounter GROUP BY encounter_type , patient_id) x1 ON patient.patient_id = x1.patient_id;

Is there an existing service that I might use for this? I tried using the EncounterSearchCriteria but wasn’t quite able to get the desired results.

Many thanks! @sameermotwani11 @prateektiwari

Hi @dkayiwa @mogoodrich , Any ideas here?

Are you looking for something like this?

select patient_id, encounter_type, count(encounter_type) as encounter_count from encounter group by patient_id, encounter_type

Hi @dkayiwa

No, currently we are looking for a sum of all the unique interactions recorded all patients. This would mean a single response where each encounter-type is given a weight of either one or zero. Finally, we add all of them to get a number in response.

For example, if there are 4 encounter types and say 100 patients in a system and 5000 encounters have been recorded, multiple forms/encounters per encounter type are expected. The use case here is to make a dashboard that tells us how many unique interactions have been there.

SELECT 
    SUM(x1.enc_type) AS total_encounter
FROM
    patient
        INNER JOIN
    (SELECT DISTINCT
        (encounter_type),
            patient_id,
            COUNT(DISTINCT (encounter_type)) AS enc_type
    FROM
        encounter
    GROUP BY encounter_type , patient_id) x1 ON patient.patient_id = x1.patient_id;

We are looking to avoid the usage of native queries here, is there a better way to do it?

No, currently we are looking for a sum of all the unique interactions recorded all patients. This would mean a single response where each encounter-type is given a weight of either one or zero. Finally we add add all of them to get a number in response. Is there a better way to do it instead of using native queries ?

In other words, are you saying that what you so far have works well and you are just asking for a better way of accomplishing the same?