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 onprc_ehr/resources/etls/AvailableBlood.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,6 @@
</transform>
</transforms>
<schedule>
<cron expression="0 1,31 5-20 ? * * *"/> <!-- :01 and :31 after the hour for hours 5am through 8pm -->
<cron expression="0 5,35 5-20 ? * * *"/> <!-- :05 and :35 after the hour for hours 5am through 8pm -->
</schedule>
</etl>
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@


/*
**
** Created by
** Blasa 10/8/2025 Process to update birth record;s geogrphic origin data. The "Genetic Ancestry"
** geographic_origin information must override the birth's geographic origin values.
**

**
**
**
**
*/

CREATE Procedure onprc_ehr.p_BirthGeographicOriginUpdates

as


BEGIN

----- Process data

IF exists (select * From studydataset.c6d202_birth bir, studydataset.c6d512_geneticancestry b where bir.participantid = b.participantid
And b.enddate is null
and bir.qcstate = 18
and b.qcstate = 18
And bir.geographic_origin <> b.result
And b.result is not null
)



BEGIN

---- Update birth geographic origin

Update bir
set bir.geographic_origin = b.result,
bir.modified = getdate(),
bir.modifiedby = b.modifiedby ---- ancestry staff

From studydataset.c6d202_birth bir, studydataset.c6d512_geneticancestry b
where bir.participantid = b.participantid
And b.enddate is null
And bir.qcstate = 18
And b.qcstate = 18
And bir.geographic_origin <> b.result
And b.result is not null


If @@Error <> 0
GoTo Err_Proc

END ---- if





RETURN 0


Err_Proc:
-------Error Generated, process stopped
RETURN 1


END

GO


6 changes: 0 additions & 6 deletions onprc_ehr/resources/scripts/onprc_ehr/onprc_triggers.js
Original file line number Diff line number Diff line change
Expand Up @@ -1348,12 +1348,6 @@ exports.init = function(EHR){
}
});
});
EHR.Server.TriggerManager.registerHandlerForQuery(EHR.Server.TriggerManager.Events.BEFORE_UPSERT, 'study', 'demographics', function (helper, scriptErrors, row, oldRow) {
if (row.Id && row.geographic_origin) {
//update birth records
triggerHelper.updateBirthGeographics(row.Id, row.geographic_origin);
}
});

//Added: 10-4-2022 R.Blasa
EHR.Server.TriggerManager.registerHandler(EHR.Server.TriggerManager.Events.COMPLETE, function(event, errors, helper){
Expand Down
42 changes: 42 additions & 0 deletions onprc_ehr/resources/views/BSU_BulkEdit.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@

<!--Created 9-25-2025 R.Blasa-->


<div id="qwpDiv" />

<script type="text/javascript" nonce="<%=scriptNonce%>">

var ehrContainer = '/ONPRC/EHR';
var wp = new LABKEY.QueryWebPart({
containerPath: ehrContainer,
schemaName : 'study',
queryName : 'pairings',
showRecordSelectors : true,
renderTo: 'qwpDiv',
buttonBar: {
includeStandardButtons: true,
items:[
{text: 'Bulk Edit', requiresSelection : true, handler: function(dataRegion){
if (dataRegion) {
var url = LABKEY.ActionURL.buildURL('query', 'updateQueryRows.view', null, {
schemaName: dataRegion.schemaName,
'query.queryName': dataRegion.queryName,
dataRegionSelectionKey: dataRegion.selectionKey,
returnUrl:window.location
});
var form = dataRegion.form;
if (form && verifySelected.call(this, form, url, 'POST', 'rows')) {
submitForm(form);

}
return false;
}
}}
]
}

});
wp.render();
</script>


5 changes: 5 additions & 0 deletions onprc_ehr/resources/views/BSU_BulkEdit.view.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<view xmlns="http://labkey.org/data/xml/view" frame="none" title="BSU Pairings Bulk Edit">
<dependencies>
<dependency path="ehr.context" />
</dependencies>
</view>
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,9 @@ EHR.model.DataModelManager.registerMetadata('ASB_Services', {
schemaName: 'onprc_ehr',
queryName: 'ASB_SpecialInstructions',
displayColumn: 'value',
// columns: 'value'
keyColumn: 'value'
keyColumn: 'value',
filterArray: [
LABKEY.Filter.create('dateDisabled', null, LABKEY.Filter.Types.ISBLANK)]
},
columnConfig: {
width: 300
Expand Down
2 changes: 1 addition & 1 deletion onprc_ehr/src/org/labkey/onprc_ehr/ONPRC_EHRModule.java
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ public String getName()
@Override
public @Nullable Double getSchemaVersion()
{
return 24.013;
return 24.014;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import org.labkey.api.query.QueryService;
import org.labkey.api.security.User;

import java.util.Calendar;
import java.util.Date;


Expand All @@ -32,9 +33,14 @@ public String getEmailSubject(Container c)
{
return "Available Blood Volume Alert: " + getDateTimeFormat(c).format(new Date());
}
/* From Hugh Crank:

/* Mathematica push:
* Server mkt7: Runs at :55 from 4:55am to 7:55pm
* Server mkt8: Runs at :25 from 4:25am to 7:25pm
*
* ABV ETL:
* :05 and :35 after the hour for hours between 05:00 and 20:00
* 0 1,31 5-20 ? * * *
*/
@Override
public String getCronString()
Expand All @@ -45,44 +51,52 @@ public String getCronString()
@Override
public String getScheduleDescription()
{
return "15 minutes after every hour between 06:15 and 19:15.";
return "15 min past every hour from 06:15 to 19:15.";
}

@Override
public String getDescription()
{
return "Sends an alert on status of Available Blood Volume data from Mathematica.";
return "Sends status of available blood volume data from Mathematica.";
}

@Override
public String getMessageBodyHTML(Container c, User u)
{
StringBuilder msg = new StringBuilder();

AvailableBloodCheck(c, u, msg);

availableBloodCheck(c, u, msg);
return msg.toString();
}
/* jonesga 5/8/2024 labkeyPublic.labkeyPublic.ValidateAvailableBloodProcess
*/
protected void AvailableBloodCheck(final Container c, User u, final StringBuilder msg)

protected void availableBloodCheck(final Container c, User u, final StringBuilder msg)
{
SimpleFilter filter = new SimpleFilter(FieldKey.fromString("date"), new Date(), CompareType.DATE_GTE);
TableInfo ti = QueryService.get().getUserSchema(u, c, "onprc_ehr").getTable("ValidateAvailableBloodProcess", ContainerFilter.Type.AllFolders.create(c, u));
// ((ContainerFilterable) ti).setContainerFilter(ContainerFilter.Type.AllFolders.create(u);
TableSelector ts = new TableSelector(ti, null, null);
Calendar cal = Calendar.getInstance();
cal.add(Calendar.HOUR, -1);
Date staleTime = cal.getTime();

TableInfo ti = QueryService.get().getUserSchema(u, c, "onprc_ehr").getTable("AvailableBloodVolume", ContainerFilter.Type.AllFolders.create(c, u));

if (ti == null)
{
msg.append("<b>ERROR: Unable to access onprc_ehr.AvailableBloodVolume table.</b><br>\n");
return;
}

SimpleFilter filter = new SimpleFilter(FieldKey.fromString("datecreated"), staleTime, CompareType.LTE);
TableSelector ts = new TableSelector(ti, filter, null);
long count = ts.getRowCount();

if (count > 0)
{
msg.append("<b>The available blood volume data from Mathematica is stale.</b><br>\n");
msg.append("<p><a href='" + getExecuteQueryUrl(c, "onprc_ehr", "ValidateAvailableBloodProcess", null) + "'>Click here to view labkeyPublic.AvailableBloodVolume.</a><br>\n\n");
msg.append("</p><br><hr>");
msg.append("<b>WARNING: The available blood volume data from Mathematica is stale (last updated more than 1 hour ago).</b><br>\n");
msg.append("<p>View <a href='").append(getExecuteQueryUrl(c, "onprc_ehr", "AvailableBloodVolume", null)).append("'>onprc_ehr.AvailableBloodVolume</a>.</p>\n");
msg.append("<br>");
}
else
{
msg.append("The available blood volume data from Mathematica is current.<br><hr>");
msg.append("<p><a href='" + getExecuteQueryUrl(c, "onprc_ehr", "ValidateAvailableBloodProcess", null) + "'>Click here to view labkeyPublic.AvailableBloodVolume.</a><br>\n\n");
msg.append("</p><br><hr>");
msg.append("<b>OK:</b> The available blood volume data from Mathematica is current (updated within the last hour).<br>\n");
msg.append("<p>View <a href='").append(getExecuteQueryUrl(c, "onprc_ehr", "AvailableBloodVolume", null)).append("'>onprc_ehr.AvailableBloodVolume</a>.</p>\n");
msg.append("<br>");
}
}}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2635,54 +2635,6 @@ public void exec(ResultSet object) throws SQLException
}


public void updateBirthGeographics(String id, String geographic_origin) throws Exception
{
TableInfo ti = getTableInfo("study", "birth");
if (ti == null)
{
return;
}

Set<FieldKey> keys = new HashSet<>();
keys.add(FieldKey.fromString("Id"));
keys.add(FieldKey.fromString("geographic_origin"));
keys.add(FieldKey.fromString("lsid"));
final Map<FieldKey, ColumnInfo> colMap = QueryService.get().getColumns(ti, keys);


final List<Map<String, Object>> toUpdate = new ArrayList<>();
final List<Map<String, Object>> oldKeys = new ArrayList<>();
TableSelector ts = new TableSelector(ti, colMap.values(), new SimpleFilter(FieldKey.fromString("Id"), id, CompareType.IN), null);
ts.forEach(new Selector.ForEachBlock<>()
{
@Override
public void exec(ResultSet object) throws SQLException
{
ResultsImpl rs = new ResultsImpl(object, colMap);
String animalid = rs.getString(FieldKey.fromString("Id"));
String origin = rs.getString(FieldKey.fromString("geographic_origin"));
String lsid = rs.getString(FieldKey.fromString("lsid"));
if (origin != geographic_origin)
{
Map<String, Object> row = new CaseInsensitiveHashMap<>();
row.put("lsid", lsid);
row.put("geographic_origin", geographic_origin);
Map<String, Object> keyRow = new CaseInsensitiveHashMap<>();
keyRow.put("lsid", lsid);

oldKeys.add(keyRow);
toUpdate.add(row);

}
}
});

if (!toUpdate.isEmpty())
{
TableInfo demographics = getTableInfo("study", "birth");
demographics.getUpdateService().updateRows(_user, _container, toUpdate, oldKeys, null, getExtraContext());
}
}

//Added 9-30-2025
public String retrieveGeographic_Origin(String Id)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ public abstract class AbstractGenericONPRC_EHRTest extends AbstractGenericEHRTes
protected static String[] ROOMS = {"Room1", "Room2", "Room3"};
protected static String[] CAGES = {"A1", "B2", "A3"};
protected static String[] CATEGORY = {"Divider Change", "Event", "STP_Beh"};
protected static String[] TINFANT = {"35160", "24456", "36451"};

@Override
public List<String> getAssociatedModules()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -818,6 +818,7 @@ public void testPairingObservations() throws Exception
grid.setGridCell(1, "cage", "A1");
grid.setGridCellJS(1, "date", TIME_FORMAT.format(today));
grid.setGridCell(1, "category", CATEGORY[0]);
grid.setGridCell(1, "other_infant", TINFANT[0]);

_helper.addRecordToGrid(grid);
sleep(200);
Expand All @@ -827,6 +828,7 @@ public void testPairingObservations() throws Exception
grid.setGridCell(2, "cage", "A1");
grid.setGridCellJS(2, "date", TIME_FORMAT.format(today));
grid.setGridCell(2, "category", CATEGORY[0]);
grid.setGridCell(2, "other_infant", TINFANT[0]);

Assert.assertEquals(grid.getFieldValue(1, "pairid"), grid.getFieldValue(2, "pairid"));

Expand All @@ -843,6 +845,7 @@ public void testPairingObservations() throws Exception
grid.setGridCell(3, "cage", "A2");
grid.setGridCellJS(3, "date", TIME_FORMAT.format(today));
grid.setGridCell(3, "category", CATEGORY[0]);
grid.setGridCell(3, "other_infant", TINFANT[0]);

grid.setGridCell(3, "lowestcage", "A1");
sleep(100);
Expand Down