Skip to content

Commit 58f4e98

Browse files
authored
Merge pull request #197 from LabKey/fb_merge_24.3_to_develop
Merge discvr-24.3 to develop
2 parents 5ffb37c + 97173b7 commit 58f4e98

21 files changed

Lines changed: 394 additions & 201 deletions

File tree

LabPurchasing/resources/queries/labpurchasing/purchases.js

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,30 @@ var console = require("console");
33

44
var triggerHelper = new org.labkey.labpurchasing.LabPurchasingTriggerHelper(LABKEY.Security.currentUser.id, LABKEY.Security.currentContainer.id);
55

6+
function beforeInsert(row, errors){
7+
// The purpose of this is to allow the user to provide a string value for
8+
// vendorId or vendorName, and attempt to resolve this against known vendors:
9+
if (!row.vendorId || isNaN(row.vendorId)) {
10+
var vendorName = row.vendorName || row.vendorId;
11+
if (vendorName) {
12+
LABKEY.Query.selectRows({
13+
schemaName: 'labpurchasing',
14+
queryName: 'vendors',
15+
columns: 'rowid',
16+
filterArray: [LABKEY.Filter.create('vendorName', vendorName)],
17+
sort: '-rowid',
18+
maxRows: 1,
19+
scope: this,
20+
success: function(results) {
21+
if (results.rows.length) {
22+
row.vendorId = results.rows[0].rowId;
23+
}
24+
}
25+
})
26+
}
27+
}
28+
}
29+
630
function afterInsert(row, errors){
731
afterUpsert(row, null, errors);
832
}

LabPurchasing/resources/queries/labpurchasing/purchases/.qview.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<customView xmlns="http://labkey.org/data/xml/queryCustomView" label="All Items">
1+
<customView xmlns="http://labkey.org/data/xml/queryCustomView" label="All Items" canOverride="true">
22
<columns>
33
<column name="purchaseId"/>
44
<column name="requestor"/>

LabPurchasing/resources/queries/labpurchasing/purchases/Items To Order.qview.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<customView xmlns="http://labkey.org/data/xml/queryCustomView">
1+
<customView xmlns="http://labkey.org/data/xml/queryCustomView" canOverride="true">
22
<columns>
33
<column name="purchaseId"/>
44
<column name="requestor"/>

LabPurchasing/resources/queries/labpurchasing/purchases/Waiting for Item.qview.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<customView xmlns="http://labkey.org/data/xml/queryCustomView">
1+
<customView xmlns="http://labkey.org/data/xml/queryCustomView" canOverride="true">
22
<columns>
33
<column name="purchaseId"/>
44
<column name="requestor"/>

LabPurchasing/resources/queries/labpurchasing/referenceItems.js

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,6 @@ function beforeInsert(row, errors){
1919
if (results.rows.length) {
2020
row.vendorId = results.rows[0].rowId;
2121
}
22-
else {
23-
console.error("Unable to resolve vendor: " + vendorName);
24-
}
2522
}
2623
})
2724
}

LabPurchasing/resources/queries/labpurchasing/referenceItems/.qview.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<customView xmlns="http://labkey.org/data/xml/queryCustomView">
1+
<customView xmlns="http://labkey.org/data/xml/queryCustomView" canOverride="true">
22
<columns>
33
<column name="rowId"/>
44
<column name="vendorId"/>

PMR/build.gradle

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ dependencies {
88
BuildUtils.addLabKeyDependency(project: project, config: "modules", depProjectPath: ":server:modules:DiscvrLabKeyModules:Studies", depProjectConfig: "published", depExtension: "module")
99
BuildUtils.addLabKeyDependency(project: project, config: "modules", depProjectPath: ":server:modules:dataintegration", depProjectConfig: "published", depExtension: "module")
1010
BuildUtils.addLabKeyDependency(project: project, config: "modules", depProjectPath: ":server:modules:DiscvrLabKeyModules:discvrcore", depProjectConfig: "published", depExtension: "module")
11+
BuildUtils.addLabKeyDependency(project: project, config: "modules", depProjectPath: ":server:modules:onprcEHRModules:GeneticsCore", depProjectConfig: "published", depExtension: "module")
1112

1213
BuildUtils.addLabKeyDependency(project: project, config: "implementation", depProjectPath: ":server:modules:DiscvrLabKeyModules:Studies", depProjectConfig: "apiJarFile")
1314
BuildUtils.addLabKeyDependency(project: project, config: "implementation", depProjectPath: ":server:modules:dataintegration", depProjectConfig: "apiJarFile")
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<etl xmlns="http://labkey.org/etl/xml">
3+
<name>KinshipDataStaging</name>
4+
<description>Prepare PRIMe-seq Kinship Data for Import into PRIMe</description>
5+
<transforms>
6+
<transform id="kinship" type="TaskRefTransformStep">
7+
<taskref ref="org.labkey.pmr.etl.TriggerRemoteGeneticsImportStep">
8+
<settings>
9+
<setting name="remoteSource" value="EHR_ClinicalSource"/>
10+
</settings>
11+
</taskref>
12+
</transform>
13+
</transforms>
14+
</etl>

PMR/resources/folderTypes/PMR.folderType.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@
6464
<modules>
6565
<moduleName>PMR</moduleName>
6666
<moduleName>EHR</moduleName>
67+
<moduleName>GeneticsCore</moduleName>
6768
</modules>
6869
<defaultModule>PMR</defaultModule>
6970
</folderType>
Lines changed: 169 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,169 @@
1+
package org.labkey.pmr.etl;
2+
3+
import org.apache.commons.io.FileUtils;
4+
import org.apache.commons.lang3.StringUtils;
5+
import org.apache.hc.client5.http.classic.methods.HttpPost;
6+
import org.apache.hc.client5.http.impl.classic.CloseableHttpClient;
7+
import org.apache.hc.core5.http.HttpResponse;
8+
import org.apache.hc.core5.http.HttpStatus;
9+
import org.apache.xmlbeans.XmlException;
10+
import org.jetbrains.annotations.NotNull;
11+
import org.labkey.api.collections.CaseInsensitiveHashMap;
12+
import org.labkey.api.data.Container;
13+
import org.labkey.api.data.ContainerManager;
14+
import org.labkey.api.di.DataIntegrationService;
15+
import org.labkey.api.di.TaskRefTask;
16+
import org.labkey.api.module.Module;
17+
import org.labkey.api.module.ModuleLoader;
18+
import org.labkey.api.module.ModuleProperty;
19+
import org.labkey.api.pipeline.PipeRoot;
20+
import org.labkey.api.pipeline.PipelineJob;
21+
import org.labkey.api.pipeline.PipelineJobException;
22+
import org.labkey.api.pipeline.PipelineService;
23+
import org.labkey.api.pipeline.RecordedActionSet;
24+
import org.labkey.api.writer.ContainerUser;
25+
import org.labkey.remoteapi.CommandException;
26+
import org.labkey.remoteapi.CommandResponse;
27+
import org.labkey.remoteapi.PostCommand;
28+
29+
import java.io.File;
30+
import java.io.IOException;
31+
import java.util.Arrays;
32+
import java.util.Collections;
33+
import java.util.List;
34+
import java.util.Map;
35+
36+
public class TriggerRemoteGeneticsImportStep implements TaskRefTask
37+
{
38+
protected final Map<String, String> _settings = new CaseInsensitiveHashMap<>();
39+
protected ContainerUser _containerUser;
40+
41+
private enum Settings
42+
{
43+
remoteSource()
44+
}
45+
46+
@Override
47+
public RecordedActionSet run(@NotNull PipelineJob job) throws PipelineJobException
48+
{
49+
// First find the last successful pipeline iteration:
50+
Module ehr = ModuleLoader.getInstance().getModule("ehr");
51+
Module geneticsCore = ModuleLoader.getInstance().getModule("GeneticsCore");
52+
53+
ModuleProperty mp = ehr.getModuleProperties().get("EHRStudyContainer");
54+
String ehrContainerPath = StringUtils.trimToNull(mp.getEffectiveValue(_containerUser.getContainer()));
55+
if (ehrContainerPath == null)
56+
{
57+
throw new PipelineJobException("EHRStudyContainer has not been set");
58+
}
59+
60+
Container ehrContainer = ContainerManager.getForPath(ehrContainerPath);
61+
if (ehrContainer == null)
62+
{
63+
throw new PipelineJobException("Invalid container: " + ehrContainerPath);
64+
}
65+
66+
if (!_containerUser.getContainer().equals(ehrContainer))
67+
{
68+
throw new PipelineJobException("This ETL can only be run from the EHRStudyContainer");
69+
}
70+
71+
ModuleProperty mp2 = geneticsCore.getModuleProperties().get("KinshipDataPath");
72+
String pipeDirPath = StringUtils.trimToNull(mp2.getEffectiveValue(ehrContainer));
73+
if (pipeDirPath == null)
74+
{
75+
throw new PipelineJobException("Must provide the filepath to import data using the KinshipDataPath module property");
76+
}
77+
78+
File targetPipelineDir = new File(pipeDirPath);
79+
if (!targetPipelineDir.exists())
80+
{
81+
targetPipelineDir.mkdirs();
82+
}
83+
84+
// Then copy the file to the expected folder:
85+
PipeRoot pr = PipelineService.get().getPipelineRootSetting(ehrContainer);
86+
if (pr == null)
87+
{
88+
throw new PipelineJobException("Unable to find pipeline root for: " + ehrContainer);
89+
}
90+
91+
File sourceDir = new File(pr.getRootPath(), "/kinship/EHR Kinship Calculation");
92+
if (!sourceDir.exists())
93+
{
94+
throw new PipelineJobException("Unable to find source pipeline dir: " + sourceDir.getPath());
95+
}
96+
97+
copyReplaceFile(sourceDir, targetPipelineDir, "kinship.txt");
98+
copyReplaceFile(sourceDir, targetPipelineDir, "inbreeding.txt");
99+
100+
// Then ping the main server to import this file:
101+
DataIntegrationService.RemoteConnection rc = DataIntegrationService.get().getRemoteConnection(_settings.get(Settings.remoteSource.name()), _containerUser.getContainer(), job.getLogger());
102+
if (rc == null)
103+
{
104+
throw new PipelineJobException("Unable to find remote connection: " + _settings.get(Settings.remoteSource.name()));
105+
}
106+
107+
try
108+
{
109+
KinshipCommand command = new KinshipCommand();
110+
command.execute(rc.connection, rc.remoteContainer);
111+
}
112+
catch (CommandException | IOException e)
113+
{
114+
throw new PipelineJobException(e);
115+
}
116+
117+
return new RecordedActionSet();
118+
}
119+
120+
private static class KinshipCommand extends PostCommand<CommandResponse>
121+
{
122+
public KinshipCommand()
123+
{
124+
super("geneticscore", "importGeneticsData");
125+
}
126+
}
127+
128+
private void copyReplaceFile(File sourceDir, File targetDir, String filename) throws PipelineJobException
129+
{
130+
File sourceFile = new File(sourceDir, filename);
131+
if (!sourceFile.exists())
132+
{
133+
throw new PipelineJobException("File does not exist: " + sourceFile.getPath());
134+
}
135+
136+
File destFile = new File(targetDir, filename);
137+
if (destFile.exists())
138+
{
139+
destFile.delete();
140+
}
141+
142+
try
143+
{
144+
FileUtils.copyFile(sourceFile, destFile);
145+
}
146+
catch (IOException e)
147+
{
148+
throw new PipelineJobException(e);
149+
}
150+
}
151+
152+
@Override
153+
public List<String> getRequiredSettings()
154+
{
155+
return Collections.unmodifiableList(Arrays.asList(Settings.remoteSource.name()));
156+
}
157+
158+
@Override
159+
public void setSettings(Map<String, String> settings) throws XmlException
160+
{
161+
_settings.putAll(settings);
162+
}
163+
164+
@Override
165+
public void setContainerUser(ContainerUser containerUser)
166+
{
167+
_containerUser = containerUser;
168+
}
169+
}

0 commit comments

Comments
 (0)