Skip to content

Start integration of SND data into EHR #67

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 8 commits into
base: develop
Choose a base branch
from
Open
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
21 changes: 21 additions & 0 deletions resources/queries/snd/DataByCategory.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
SELECT
ad.ObjectId,
ad.PropertyId,
ad.TypeTag,
ad.FloatValue,
ad.DateTimeValue,
ad.StringValue,
ad.MvIndicator,
ad.ObjectURI,
ad.EventDataAndName,
ad.AttributeName,
ad.EventData,
ad.EventData.SuperPkgId.PkgId,
ad.EventData.EventId,
ad.Container,
pc.CategoryId as CategoryId,
pc.Description as Category,
ad.StudyLSID as LSID
FROM AttributeData ad
JOIN PkgCategoryJunction pcj ON ad.EventData.SuperPkgId.PkgId = pcj.PkgId
JOIN PkgCategories pc ON pc.CategoryId = pcj.CategoryId
24 changes: 19 additions & 5 deletions src/org/labkey/snd/query/AttributeDataTable.java
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,12 @@ public AttributeDataTable(@NotNull SNDUserSchema userSchema, ContainerFilter cf)
ExprColumn eventDataAndName = new ExprColumn(this, "EventDataAndName", new SQLFragment(ExprColumn.STR_TABLE_ALIAS + ".EventDataAndName"), JdbcType.VARCHAR);
addColumn(eventDataAndName);

ExprColumn attributeName = new ExprColumn(this, "AttributeName", new SQLFragment(ExprColumn.STR_TABLE_ALIAS + ".AttributeName"), JdbcType.VARCHAR);
addColumn(attributeName);

ExprColumn studyLSID = new ExprColumn(this, "StudyLSID", new SQLFragment(ExprColumn.STR_TABLE_ALIAS + ".StudyLSID"), JdbcType.VARCHAR);
addColumn(studyLSID);

// Inject a lookup to the EventData table
ExprColumn eventDataCol = new ExprColumn(this, "EventData", new SQLFragment(ExprColumn.STR_TABLE_ALIAS + ".EventDataId"), JdbcType.VARCHAR);
addColumn(eventDataCol);
Expand Down Expand Up @@ -111,27 +117,35 @@ protected void applyContainerFilter(ContainerFilter filter)
@NotNull
public SQLFragment getFromSQL(String alias)
{
// Need to mock up a study LSID here
String mockLsidPrefix = "'urn:lsid:" + AppProps.getInstance().getDefaultLsidAuthority() + ":Study.Data-'";
String mockLsid = getRealTable().getSqlDialect().concatenate(mockLsidPrefix,
"CAST(X.ObjectId AS VARCHAR) as StudyLSID");

// Flatten data from primary base table (exp.ObjectProperty), exp.Object, and snd.EventData
SQLFragment sql = new SQLFragment("(SELECT X.*, o.Container, o.ObjectURI, ed.EventDataId, CONCAT(ed.EventDataId,'-', pd.Name) as EventDataAndName FROM ");
SQLFragment sql = new SQLFragment("(SELECT X.*, " + mockLsid + ", o.Container, o.ObjectURI, ed.EventDataId, CONCAT(ed.EventDataId,'-', pd.Name) as EventDataAndName, pd.Name as AttributeName FROM ");
sql.append(super.getFromSQL("X"));
sql.append(" INNER JOIN ");
sql.append(OntologyManager.getTinfoObject(), "o");
sql.append(" ON x.ObjectId = o.ObjectId AND ");

// Apply the container filter
sql.append(getContainerFilter().getSQLFragment(getSchema(), new SQLFragment("o.Container")));
sql.append(" INNER JOIN ");
sql.append(OntologyManager.getTinfoPropertyDescriptor(), "pd");

// Filter to include only properties associated with packages
sql.append(" ON x.PropertyId = pd.PropertyId AND pd.PropertyURI LIKE ? INNER JOIN ");
// Note - this must be kept in sync with the PropertyURIs generated for the packages
String lsidPrefix = "urn:lsid:" + AppProps.getInstance().getDefaultLsidAuthority() + ":package-snd.Folder-%";
// Do not use jdbc parameter for lsidPrefix as it changes the query plan
sql.append(" ON x.PropertyId = pd.PropertyId AND pd.PropertyURI LIKE '" + lsidPrefix + "' INNER JOIN ");

// Filter to include only values associated with EventDatas
sql.append(SNDSchema.getInstance().getTableInfoEventData(), "ed");
sql.append(" ON ed.ObjectURI = o.ObjectURI ");
sql.append(") ");
sql.append(alias);

// Note - this must be kept in sync with the PropertyURIs generated for the packages
sql.add("urn:lsid:" + AppProps.getInstance().getDefaultLsidAuthority() + ":package-snd.Folder-%");

return sql;
}

Expand Down