Skip to content

Commit

Permalink
Merge pull request #191 from LabKey/fb_merge_23.11_to_develop
Browse files Browse the repository at this point in the history
Merge discvr-23.11 to develop
  • Loading branch information
bbimber authored Mar 11, 2024
2 parents 035cd6c + 117366f commit 9b93c56
Show file tree
Hide file tree
Showing 10 changed files with 259 additions and 28 deletions.
6 changes: 6 additions & 0 deletions LDK/src/org/labkey/ldk/query/DefaultTableCustomizer.java
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,12 @@ public DefaultTableCustomizer(MultiValuedMap<String, String> props)
@Override
public void customize(TableInfo table)
{
if (table.isLocked())
{
_log.debug("DefaultTableCustomizer called on a locked table: " + table.getPublicSchemaName() + " / " + table.getName(), new Exception());
return;
}

if (table instanceof SchemaTableInfo)
_log.error("Table customizer is being passed a SchemaTableInfo for: " + table.getPublicSchemaName() + "." + table.getPublicName());
else if (table instanceof AbstractTableInfo)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
package org.labkey.api.laboratory;

import org.jetbrains.annotations.Nullable;
import org.labkey.api.data.Container;
import org.labkey.api.module.Module;
import org.labkey.api.security.User;


public class DemographicsProvider
{
private final Module _owningModule;
private final String _schemaName;
private final String _queryName;
private final String _subjectField;

public DemographicsProvider(Module owningModule, String schemaName, String queryName, String subjectField)
{
_owningModule = owningModule;
_schemaName = schemaName;
_queryName = queryName;
_subjectField = subjectField;
}

public String getSchema()
{
return _schemaName;
}

public String getQuery()
{
return _queryName;
}

public String getSubjectField()
{
return _subjectField;
}

public @Nullable String getMotherField()
{
return null;
}

public @Nullable String getFatherField()
{
return null;
}

public @Nullable String getSexField()
{
return null;
}

public boolean isAvailable(Container c, User u)
{
return c.getActiveModules().contains(_owningModule);
}

public String getLabel()
{
return getSchema() + "." + getQuery();
}

public boolean isValidForPedigree()
{
return getMotherField() != null && getFatherField() != null && getSexField() != null;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
*/
package org.labkey.api.laboratory;

import org.jetbrains.annotations.Nullable;
import org.json.JSONObject;
import org.labkey.api.assay.AssayProvider;
import org.labkey.api.data.Container;
Expand Down Expand Up @@ -116,6 +117,12 @@ static public void setInstance(LaboratoryService instance)

abstract public void registerTableCustomizer(Module owner, Class<? extends TableCustomizer> customizerClass, String schemaName, String queryName);

abstract public void registerDemographicsProvider(DemographicsProvider provider);

abstract public List<DemographicsProvider> getDemographicsProviders(Container c, User u);

abstract public @Nullable DemographicsProvider getDemographicsProviderByName(Container c, User u, String name);

public static enum NavItemCategory
{
samples(),
Expand Down
45 changes: 45 additions & 0 deletions laboratory/resources/web/laboratory/field/PedigreeSelectorField.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
Ext4.define('Laboratory.field.PedigreeSelectorField', {
extend: 'LABKEY.ext4.ComboBox',
alias: 'widget.laboratory-pedigreeselectorfield',

forceSelection: true,
typeAhead: true,
queryMode: 'local',
triggerAction: 'all',

initComponent: function(){
Ext4.apply(this, {
displayField: 'value',
valueField: 'value',
store: {
type: 'array',
fields: ['value']
}
});

this.callParent(arguments);

this.loadData();
},

loadData: function(){
LABKEY.Ajax.request({
url: LABKEY.ActionURL.buildURL('laboratory', 'getDemographicsProviders', Laboratory.Utils.getQueryContainerPath()),
method : 'POST',
scope: this,
failure: LDK.Utils.getErrorCallback(),
success: LABKEY.Utils.getCallbackWrapper(function(response){
console.log(response);
Ext4.Array.forEach(response.providers, function(d){
if (d.isValidForPedigree) {
this.store.add(this.store.createModel({value: d.label}));
}
}, this);
}, this)
});
},

getToolParameterValue : function(){
return this.getSubmitValue();
}
});
60 changes: 33 additions & 27 deletions laboratory/resources/web/laboratory/panel/WorkbookHeaderPanel.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,43 +6,49 @@
*/
Ext4.define('Laboratory.panel.WorkbookHeaderPanel', {
extend: 'LDK.panel.WebpartPanel',
panelTitle: 'Details',

initComponent: function(){
Ext4.apply(this, {
title: 'Details',
title: this.panelTitle,
defaults: {
border: false
},
items: [{
html: 'Description:',
style: 'font-weight: bold;'
},
this.getFieldCfg('description', this.description)
,{
html: 'Materials:',
style: 'font-weight: bold;padding-top: 10px;'
},
this.getFieldCfg('materials', this.materials)
,{
html: 'Methods:',
style: 'font-weight: bold;padding-top: 10px;'
},
this.getFieldCfg('methods', this.methods)
,{
html: 'Results:',
style: 'font-weight: bold;padding-top: 10px;'
},
this.getFieldCfg('results', this.results)
,{
html: 'Tags:',
style: 'font-weight: bold;padding-top: 10px;'
},
this.getTagFieldCfg()
]
items: this.getPanelItems()
});

this.callParent(arguments);
},

getPanelItems: function() {
return [{
html: 'Description:',
style: 'font-weight: bold;'
},
this.getFieldCfg('description', this.description)
,{
html: 'Materials:',
style: 'font-weight: bold;padding-top: 10px;'
},
this.getFieldCfg('materials', this.materials)
,{
html: 'Methods:',
style: 'font-weight: bold;padding-top: 10px;'
},
this.getFieldCfg('methods', this.methods)
,{
html: 'Results:',
style: 'font-weight: bold;padding-top: 10px;'
},
this.getFieldCfg('results', this.results)
,{
html: 'Tags:',
style: 'font-weight: bold;padding-top: 10px;'
},
this.getTagFieldCfg()
];
},

getTagFieldCfg: function(){
var cfg = {
layout: 'hbox',
Expand Down
27 changes: 27 additions & 0 deletions laboratory/src/org/labkey/laboratory/LaboratoryController.java
Original file line number Diff line number Diff line change
Expand Up @@ -773,6 +773,33 @@ public ApiResponse execute(UpdateWorkbookForm form, BindException errors) throws
}
}

@RequiresPermission(ReadPermission.class)
public class GetDemographicsProvidersAction extends ReadOnlyApiAction<Object>
{
@Override
public ApiResponse execute(Object form, BindException errors) throws Exception
{
Map<String, Object> results = new HashMap<>();

Container target = getContainer().isWorkbook() ? getContainer().getParent() : getContainer();

JSONArray providers = new JSONArray();

LaboratoryService.get().getDemographicsProviders(target, getUser()).forEach(d -> {
JSONObject json = new JSONObject();
json.put("label", d.getLabel());
json.put("isValidForPedigree", d.isValidForPedigree());

providers.put(json);
});

results.put("success", true);
results.put("providers", providers);

return new ApiSimpleResponse(results);
}
}

@RequiresPermission(UpdatePermission.class)
public class UpdateWorkbookTagsAction extends MutatingApiAction<UpdateWorkbookForm>
{
Expand Down
2 changes: 2 additions & 0 deletions laboratory/src/org/labkey/laboratory/LaboratoryModule.java
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
import org.labkey.api.view.template.ClientDependency;
import org.labkey.api.writer.ContainerUser;
import org.labkey.laboratory.notification.LabSummaryNotification;
import org.labkey.laboratory.query.LaboratoryDemographicsProvider;
import org.labkey.laboratory.query.WorkbookModel;
import org.labkey.laboratory.security.LaboratoryAdminRole;

Expand Down Expand Up @@ -162,6 +163,7 @@ protected void doStartupAfterSpringConfig(ModuleContext moduleContext)
LaboratoryService.get().registerDataProvider(new LaboratoryDataProvider(this));
LaboratoryService.get().registerDataProvider(new SampleTypeDataProvider());
LaboratoryService.get().registerDataProvider(new ExtraDataSourcesDataProvider(this));
LaboratoryService.get().registerDemographicsProvider(new LaboratoryDemographicsProvider());

DetailsURL details = DetailsURL.fromString("/laboratory/siteLabSettings.view");
details.setContainerContext(ContainerManager.getSharedContainer());
Expand Down
34 changes: 34 additions & 0 deletions laboratory/src/org/labkey/laboratory/LaboratoryServiceImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

import org.apache.logging.log4j.Logger;
import org.apache.logging.log4j.LogManager;
import org.jetbrains.annotations.Nullable;
import org.json.JSONObject;
import org.labkey.api.assay.AssayFileWriter;
import org.labkey.api.assay.AssayProvider;
Expand All @@ -35,6 +36,7 @@
import org.labkey.api.exp.api.ExpRun;
import org.labkey.api.exp.api.ExperimentService;
import org.labkey.api.laboratory.DataProvider;
import org.labkey.api.laboratory.DemographicsProvider;
import org.labkey.api.laboratory.LaboratoryService;
import org.labkey.api.laboratory.NavItem;
import org.labkey.api.laboratory.TabbedReportItem;
Expand Down Expand Up @@ -80,6 +82,7 @@ public class LaboratoryServiceImpl extends LaboratoryService
private final Map<String, Map<String, List<ButtonConfigFactory>>> _assayButtons = new CaseInsensitiveHashMap<>();
private final Map<String, DataProvider> _dataProviders = new HashMap<>();
private final Map<String, Map<String, List<Pair<Module, Class<? extends TableCustomizer>>>>> _tableCustomizers = new CaseInsensitiveHashMap<>();
private final List<DemographicsProvider> _demographicsProviders = new ArrayList<>();

public static final String DEMOGRAPHICS_PROPERTY_CATEGORY = "laboratory.demographicsSource";
public static final String DATASOURCE_PROPERTY_CATEGORY = "laboratory.additionalDataSource";
Expand Down Expand Up @@ -677,4 +680,35 @@ private TableCustomizer instantiateCustomizer(Class<? extends TableCustomizer> c

return null;
}

@Override
public void registerDemographicsProvider(DemographicsProvider provider)
{
_demographicsProviders.add(provider);
}

@Override
public List<DemographicsProvider> getDemographicsProviders(final Container c, final User u)
{
return _demographicsProviders.stream().filter(d -> d.isAvailable(c, u)).toList();
}

@Override
public @Nullable DemographicsProvider getDemographicsProviderByName(Container c, User u, String name)
{
if (name == null)
{
throw new IllegalArgumentException("The DemographicsProvider name cannot be null");
}

for (DemographicsProvider d : getDemographicsProviders(c, u))
{
if (name.equals(d.getLabel()))
{
return d;
}
}

return null;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package org.labkey.laboratory.query;

import org.jetbrains.annotations.Nullable;
import org.labkey.api.laboratory.DemographicsProvider;
import org.labkey.api.module.ModuleLoader;
import org.labkey.laboratory.LaboratoryModule;
import org.labkey.laboratory.LaboratorySchema;

public class LaboratoryDemographicsProvider extends DemographicsProvider
{
public LaboratoryDemographicsProvider()
{
super(ModuleLoader.getInstance().getModule(LaboratoryModule.class), LaboratoryModule.SCHEMA_NAME, LaboratorySchema.TABLE_SUBJECTS, "subjectname");
}

@Nullable
@Override
public String getMotherField()
{
return "mother";
}

@Nullable
@Override
public String getFatherField()
{
return "father";
}

@Nullable
@Override
public String getSexField()
{
return "gender";
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
}
%>
<%
JspView me = (JspView) HttpView.currentView();
JspView<?> me = (JspView<?>) HttpView.currentView();
WorkbookModel model = (WorkbookModel)me.getModelBean();
Integer workbookId = model.getWorkbookId();
String wpId = "wp_" + me.getWebPartRowId();
Expand Down

0 comments on commit 9b93c56

Please sign in to comment.