Display regimen rows in DrugOGram display control in descending order

We want to display regiment rows in descending order as shown in screenshotDrugOGram display control

There is groovy support with /var/www/bahmni_config/openmrs/treatmentRegimenExtension/TreatmentRegimenExtension.groovy which will be executed before DrugOGram( chronicTreatmentChart) display control displayed.

It is not possible to override the display of regimen rows since TreatmentRegimen has an inbuilt comparator.

public class TreatmentRegimen {
private Set<EncounterTransaction.Concept> headers = new LinkedHashSet<>();
private SortedSet<RegimenRow> rows = new TreeSet<>(new RegimenRow.RegimenComparator());

public Set<EncounterTransaction.Concept> getHeaders() {
    return headers;
}.................

We are planning to add a method in TreatmentRegimen to set rows (overloading method) along with a comparator like this.

void setRows(Collection<RegimenRow> regimenRows, Comparator<RegimenRow> comparator) {
    this.rows = new TreeSet<>(comparator);
    this.rows.addAll(regimenRows);
}

@darius @angshuonline @mksrom @binduak @snehabagri @vmalini @mohit @vinisha

As per the @angshuonline this new method(when called from Groovy) will change the order of the regimen rows which is like anti-pattern i.e. changing the state of the passed in parameter.

I feel groovy extension in bahmni is meant for it, it is up to the groovy writers to do whatever they want with the object passed. I hope that is the reason why groovy extension is called as last point in our controllers Eg: ObsToObsFlowSheetController, DrugOGramController

@mksrom Any thoughts around it?

We are planning to do it in front-end after brainstorming internally.

@angshuonline @snehabagri

The following property provided for chronicTreatmentChart config.

"regimenDescendingOrder": true

If regimenDescendingOrder is

  • true -> Regimen rows displayed in descending order
  • false -> Regimen rows displayed in ascending order (default behavior)

If regimenDescendingOrder property is not available, the display control falls back to default behavior i.e. shows regimen rows in ascending order

Since the controls is already specific to regimen, consider alt name for configuration element.

  • dateSort : “desc”

Obviously this assumes that the regimen chart can be sorted and make sense only to be sorted by date.