# Assistance with Reporting Using Existing Definitions

**URL:** <https://talk.openmrs.org/t/assistance-with-reporting-using-existing-definitions/14456>\
**Category:** Development\
**Tags:** reporting\
**Created:** [December 6, 2017, 3:37pm UTC](https://talk.openmrs.org/t/assistance-with-reporting-using-existing-definitions/14456 "2017-12-06T15:37:04Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![ssmusoke](https://talk.openmrs.org/user_avatar/talk.openmrs.org/ssmusoke/32/8020_2.png) [@ssmusoke](https://talk.openmrs.org/u/ssmusoke)\
**Post date:** [December 6, 2017, 3:37pm UTC](https://talk.openmrs.org/t/assistance-with-reporting-using-existing-definitions/14456/1 "2017-12-06T15:37:05Z")

</div>

I would like to do the following via inbuilt cohort definitions or data definitions without having to revert to SQL. I already have my cohort of patients

1. What types of encounters they have

2. How many visits grouped by encounter type

@mseaton @mksd

---

<div class="post-metadata">

**Author:** ![mksrom](https://talk.openmrs.org/user_avatar/talk.openmrs.org/mksrom/32/20221_2.png) [@mksrom](https://talk.openmrs.org/u/mksrom)\
**Post date:** [December 8, 2017, 8:01am UTC](https://talk.openmrs.org/t/assistance-with-reporting-using-existing-definitions/14456/2 "2017-12-08T08:01:45Z")

</div>

Hi @ssmusoke ,

It has been few months since I looked into the Reporting module so I am not 100% confident, but here is what I would do:

I would create a report with a [PatientDataSetDefinition](https://github.com/mekomsolutions/openmrs-module-reporting/blob/master/api/src/main/java/org/openmrs/module/reporting/dataset/definition/PatientDataSetDefinition.java) filtered with your cohort definition to display one line per patient.

> 1. What types of encounters they have

In order to list the encounter types per patient I think you have to create a **EncounterTypeForPatientDataDefinition** to retrieve the Encounter Types of a Patient. There is the [EncounterTypeDataDefinition](https://github.com/mekomsolutions/openmrs-module-reporting/blob/master/api/src/main/java/org/openmrs/module/reporting/data/encounter/definition/EncounterTypeDataDefinition.java) but it is not a “per patient” definition, so I am not sure that can be used on your **PatientDataSetDefinition**.

@mseaton is this above correct?

> 1. How many visits grouped by encounter type

Do you want this to be ‘per patient’, ie, in the same report as in point 1? Or is this another report such as one line per encounter type?

Hope the above makes sense.

Romain

---

<div class="post-metadata">

**Author:** ![mseaton](https://talk.openmrs.org/user_avatar/talk.openmrs.org/mseaton/32/8088_2.png) [@mseaton](https://talk.openmrs.org/u/mseaton)\
**Post date:** [December 20, 2017, 5:11pm UTC](https://talk.openmrs.org/t/assistance-with-reporting-using-existing-definitions/14456/3 "2017-12-20T17:11:55Z")

</div>

@ssmusoke, if you need high performance, then I would likely advise writing a custom PatientDataDefinition or using a SqlPatientDataDefinition.

You can achieve the “What encounter types a patient has” by:

1. Using an EncountersForPatientDataDefinition - this will give you a List of all Encounters for the patient
2. Running this through a CollectionConverter which uses a PropertyConverter on each element of the List

For achieving the “How many encounters grouped by encounter type”, you could reuse query #1 above, and run it through a different CollectionConverter (which you would need to write), which returned a Map from Encounter Type name -\> Integer.

Mike
