Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion nirc_ehr/resources/data/editable_lookups.tsv
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ ehr_lookups observation_areas Clinical Observation Areas Clinical observation ar
ehr_lookups obstetric_observations Clinical Obstetric Observations Obstetric Observations Fixed Values.
ehr_lookups ocular_observations Clinical Ocular Observations Ocular Observations Fixed Values.
ehr_lookups ocular_problem Clinical Ocular Problem Clinical observation fixed values.
ehr_lookups pairing_formation_types Pairing Formation Type value
ehr_lookups pairing_formation_types Behavior Pairing Formation Type Pairing formation values.
ehr_lookups pairing_goal Behavior Pairing Goal Used in pairing dataset.
ehr_lookups pairing_reason Behavior Introduction Reason Used in pairing dataset.
ehr_lookups pairing_observation Behavior Interaction Summary Used in pairing dataset.
Expand Down
1 change: 0 additions & 1 deletion nirc_ehr/resources/queries/study/aliases.sql
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,3 @@ UNION
SELECT Id,
Alias as alias
FROM study.alias where Id.demographics.calculated_status != 'Alive - In Progress'
'
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
<metadata>
<tables xmlns="http://labkey.org/data/xml">
<table tableName="treatmentSchedule" tableDbType="NOT_IN_DB">
<javaCustomizer class="org.labkey.nirc_ehr.table.NIRC_EHRCustomizer" />
<tableTitle>Treatment Schedule</tableTitle>
<tableUrl>/EHR/treatmentDetails.view?key=${lsid}</tableUrl>
<pkColumnName>primaryKey</pkColumnName>
Expand Down
1 change: 0 additions & 1 deletion nirc_ehr/resources/queries/study/treatmentSchedule.sql
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ JOIN(
timestampdiff('SQL_TSI_DAY', cast(t1.dateOnly AS timestamp), dr.dateOnly) + 1 AS daysElapsed,
t1.enddate,
t1.code,
t1.treatmentRecord,
t1.volume,
t1.vol_units,
t1.concentration,
Expand Down
123 changes: 33 additions & 90 deletions nirc_ehr/src/org/labkey/nirc_ehr/table/NIRC_EHRCustomizer.java
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@
import org.labkey.api.ehr.security.EHRDataEntryPermission;
import org.labkey.api.ehr.security.EHRVeterinarianPermission;
import org.labkey.api.ehr.table.FixedWidthDisplayColumn;
import org.labkey.api.ehr.table.TreatmentLinkConfig;
import org.labkey.api.ehr.table.TreatmentLinkDisplayColumnFactory;
import org.labkey.api.exp.api.StorageProvisioner;
import org.labkey.api.exp.property.Domain;
import org.labkey.api.gwt.client.FacetingBehaviorType;
Expand Down Expand Up @@ -67,6 +69,10 @@

public class NIRC_EHRCustomizer extends AbstractTableCustomizer
{
private static final TreatmentLinkConfig RECORD_TREATMENT = TreatmentLinkConfig.builder()
.formTypes("Behavior", "Behavioral Rounds", "Bulk Behavior Entry")
.build();

public UserSchema getEHRUserSchema(AbstractTableInfo ds, String name)
{
Container ehrContainer = EHRService.get().getEHRStudyContainer(ds.getUserSchema().getContainer());
Expand Down Expand Up @@ -131,6 +137,11 @@ public void customize(TableInfo table)
customizeTreatmentOrder(ti);
}

if (matches(ti, "study", "treatmentSchedule"))
{
customizeTreatmentSchedule(ti);
}

if (matches(ti, "study", "prc_order"))
{
customizeProcedureOrder(ti);
Expand Down Expand Up @@ -896,15 +907,17 @@ private void ensureSortColumn(AbstractTableInfo ti, ColumnInfo baseColumn)

private void customizeHousingTable(AbstractTableInfo ti)
{
// ehr_lookups.cage is unique on (Container, Location), so the cage subqueries below must be container-scoped;
// a second EHR folder defining the same location would otherwise make them return multiple rows.
Container lookupContainer = EHRService.get().getEHRStudyContainer(ti.getUserSchema().getContainer());
if (lookupContainer == null)
lookupContainer = ti.getUserSchema().getContainer(); // as DefaultEHRCustomizer does

if (ti.getColumn("room") == null && ti.getColumn("cage") != null)
{
UserSchema us = getUserSchema(ti, "ehr_lookups");
if (us != null)
{
SQLFragment roomSql = new SQLFragment("(SELECT room FROM ehr_lookups.cage WHERE location = " + ExprColumn.STR_TABLE_ALIAS + ".cage)");
ExprColumn roomCol = new ExprColumn(ti, "room", roomSql, JdbcType.VARCHAR, ti.getColumn("cage"));
ti.addColumn(roomCol);
}
SQLFragment roomSql = new SQLFragment("(SELECT room FROM ehr_lookups.cage WHERE Container = ? AND location = " + ExprColumn.STR_TABLE_ALIAS + ".cage)", lookupContainer);
ExprColumn roomCol = new ExprColumn(ti, "room", roomSql, JdbcType.VARCHAR, ti.getColumn("cage"));
ti.addColumn(roomCol);

ensureSortColumn(ti, ti.getColumn("room"));
}
Expand All @@ -913,8 +926,8 @@ private void customizeHousingTable(AbstractTableInfo ti)
TableInfo realTable = getRealTable(ti);
if (realTable != null && realTable.getColumn("participantid") != null && realTable.getColumn("date") != null && realTable.getColumn("enddate") != null)
{
SQLFragment roomSql = new SQLFragment(realTable.getSqlDialect().getDateDiff(Calendar.DATE, "{fn curdate()}", "COALESCE((SELECT max(h2.enddate) as d FROM " + realTable.getSelectName() + " h2 LEFT JOIN ehr_lookups.cage cg ON h2.cage = cg.location " +
"WHERE h2.enddate IS NOT NULL AND h2.enddate <= " + ExprColumn.STR_TABLE_ALIAS + ".date AND h2.participantid = " + ExprColumn.STR_TABLE_ALIAS + ".participantid AND cg.room != (SELECT room FROM ehr_lookups.cage WHERE location = " + ExprColumn.STR_TABLE_ALIAS + ".cage)), " + ExprColumn.STR_TABLE_ALIAS + ".date)"));
SQLFragment roomSql = new SQLFragment(realTable.getSqlDialect().getDateDiff(Calendar.DATE, "{fn curdate()}", "COALESCE((SELECT max(h2.enddate) as d FROM " + realTable.getSelectName() + " h2 LEFT JOIN ehr_lookups.cage cg ON h2.cage = cg.location AND cg.Container = ? " +
"WHERE h2.enddate IS NOT NULL AND h2.enddate <= " + ExprColumn.STR_TABLE_ALIAS + ".date AND h2.participantid = " + ExprColumn.STR_TABLE_ALIAS + ".participantid AND cg.room != (SELECT room FROM ehr_lookups.cage WHERE Container = ? AND location = " + ExprColumn.STR_TABLE_ALIAS + ".cage)), " + ExprColumn.STR_TABLE_ALIAS + ".date)"), lookupContainer, lookupContainer);
ExprColumn roomCol = new ExprColumn(ti, "daysInRoom", roomSql, JdbcType.INTEGER, realTable.getColumn("participantid"), realTable.getColumn("date"), realTable.getColumn("enddate"));
roomCol.setLabel("Days In Room");
ti.addColumn(roomCol);
Expand Down Expand Up @@ -1065,88 +1078,18 @@ private void customizeTreatmentOrder(AbstractTableInfo ti)
{
WrappedColumn col = new WrappedColumn(ti.getColumn("objectid"), "treatmentRecord");
col.setLabel("Record Treatment");
col.setDisplayColumnFactory(new DisplayColumnFactory() {

@Override
public DisplayColumn createRenderer(final ColumnInfo colInfo)
{
return new DataColumn(colInfo){

@Override
public void renderGridCellContents(RenderContext ctx, HtmlWriter out)
{
String objectid = (String)getBoundColumn().getValue(ctx);
Date date = (Date)ctx.get("date");
String caseid = (String)ctx.get("caseid");
String category = (String)ctx.get("category");
ActionURL url = new ActionURL("ehr", "dataEntryForm", ti.getUserSchema().getContainer());
if (!ti.getUserSchema().getContainer().hasPermission(ti.getUserSchema().getUser(), EHRClinicalEntryPermission.class))
return;

if (category.equals("Behavior"))
{
if (caseid != null)
{
url.addParameter("formType", "Behavioral Rounds");
url.addParameter("caseid", caseid);
}
else
{
url.addParameter("formType", "Bulk Behavior Entry");
}
}
else
{
if (caseid != null)
{
url.addParameter("formType", "Clinical Rounds");
url.addParameter("caseid", caseid);
}
else
{
url.addParameter("formType", "medicationTreatment");
}
}

url.addParameter("treatmentid", objectid);
url.addParameter("scheduledDate", date.toString());

String returnUrl = new ActionURL("ehr", "animalHistory", ti.getUserSchema().getContainer()) + "#inputType:none&showReport:0&activeReport:clinMedicationSchedule";
url.addParameter("returnUrl", returnUrl);

out.write(LinkBuilder.labkeyLink("Record Treatment", url).target("_blank"));
}

@Override
public void addQueryFieldKeys(Set<FieldKey> keys)
{
super.addQueryFieldKeys(keys);
keys.add(getBoundColumn().getFieldKey());
keys.add(FieldKey.fromString("date"));
keys.add(FieldKey.fromString("caseid"));
keys.add(FieldKey.fromString("category"));
}

@Override
public boolean isSortable()
{
return false;
}

@Override
public boolean isFilterable()
{
return false;
}
col.setDisplayColumnFactory(TreatmentLinkDisplayColumnFactory.forOrder(RECORD_TREATMENT));
ti.addColumn(col);
}
}

@Override
public boolean isEditable()
{
return false;
}
};
}
});
private void customizeTreatmentSchedule(AbstractTableInfo ti)
{
if (ti.getColumn("treatmentRecord") == null && ti.getColumn("objectid") != null)
{
WrappedColumn col = new WrappedColumn(ti.getColumn("objectid"), "treatmentRecord");
col.setLabel("Record Treatment");
col.setDisplayColumnFactory(TreatmentLinkDisplayColumnFactory.forSchedule(RECORD_TREATMENT));
ti.addColumn(col);
}
}
Expand Down
Loading
Loading