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
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package org.labkey.GeneticsCore.etl;

import org.apache.commons.lang3.StringUtils;
import org.apache.xmlbeans.XmlException;
import org.jetbrains.annotations.NotNull;
import org.labkey.GeneticsCore.GeneticsCoreModule;
import org.labkey.api.data.Container;
Expand All @@ -17,6 +16,8 @@
import org.labkey.api.security.permissions.UpdatePermission;
import org.labkey.api.view.UnauthorizedException;
import org.labkey.api.writer.ContainerUser;
import org.labkey.vfs.FileLike;
import org.labkey.vfs.FileSystemLike;

import java.io.File;
import java.util.Collections;
Expand Down Expand Up @@ -64,19 +65,19 @@ public RecordedActionSet run(@NotNull PipelineJob job) throws PipelineJobExcepti
throw new PipelineJobException("Must provide the filepath to import data using the KinshipDataPath module property");
}

File pipeDir = new File(pipeDirPath);
FileLike pipeDir = FileSystemLike.wrapFile(new File(pipeDirPath));
if (!pipeDir.exists())
{
throw new PipelineJobException("Path does not exist: " + pipeDir.getPath());
}

File kinship = new File(pipeDir, "kinship.txt");
FileLike kinship = pipeDir.resolveChild("kinship.txt");
if (!kinship.exists())
{
throw new PipelineJobException("File does not exist: " + kinship.getPath());
}

File inbreeding = new File(pipeDir, "inbreeding.txt");
FileLike inbreeding = pipeDir.resolveChild("inbreeding.txt");
if (!inbreeding.exists())
{
throw new PipelineJobException("File does not exist: " + inbreeding.getPath());
Expand All @@ -94,7 +95,7 @@ public List<String> getRequiredSettings()
}

@Override
public void setSettings(Map<String, String> settings) throws XmlException
public void setSettings(Map<String, String> settings)
{

}
Expand Down
100 changes: 19 additions & 81 deletions onprc_billing/src/org/labkey/onprc_billing/pipeline/BillingTask.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
*/
package org.labkey.onprc_billing.pipeline;

import au.com.bytecode.opencsv.CSVWriter;
import org.apache.commons.lang3.time.DateUtils;
import org.jetbrains.annotations.NotNull;
import org.labkey.api.collections.CaseInsensitiveHashMap;
Expand All @@ -25,10 +24,8 @@
import org.labkey.api.data.DbSchema;
import org.labkey.api.data.DbScope;
import org.labkey.api.data.Results;
import org.labkey.api.data.ResultsImpl;
import org.labkey.api.data.RuntimeSQLException;
import org.labkey.api.data.SQLFragment;
import org.labkey.api.data.Selector;
import org.labkey.api.data.SimpleFilter;
import org.labkey.api.data.SqlSelector;
import org.labkey.api.data.Table;
Expand All @@ -49,10 +46,6 @@
import org.labkey.api.util.GUID;
import org.labkey.onprc_billing.ONPRC_BillingSchema;

import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
Expand Down Expand Up @@ -105,11 +98,9 @@ public List<String> getProtocolActionNames()
}

@Override
public PipelineJob.Task createTask(PipelineJob job)
public BillingTask createTask(PipelineJob job)
{
BillingTask task = new BillingTask(this, job);

return task;
return new BillingTask(this, job);
}

@Override
Expand Down Expand Up @@ -198,43 +189,6 @@ private BillingPipelineJobSupport getSupport()
return (BillingPipelineJobSupport)getJob();
}

private void writeToTsv(String fileName, List<Map<String, Object>> rows, String[] headers, String[] colNames) throws PipelineJobException
{
File csvFile = new File(getSupport().getAnalysisDir(), fileName + ".txt");
if (csvFile.exists())
throw new PipelineJobException("There is already a file with path: " + csvFile.getPath());

try
{
csvFile.createNewFile();

try (CSVWriter csv = new CSVWriter(new FileWriter(csvFile), '\t'))
{
csv.writeNext(headers);

if (!rows.isEmpty())
{
for (Map<String, Object> row : rows)
{
String[] toWrite = new String[colNames.length];
int i = 0;
for (String colName: colNames)
{
toWrite[i] = getString(row.get(colName));
i++;
}

csv.writeNext(toWrite);
}
}
}
}
catch (IOException e)
{
throw new PipelineJobException(e);
}
}

private String _invoiceId = null;

private String getOrCreateInvoiceRunRecord() throws PipelineJobException
Expand Down Expand Up @@ -312,7 +266,7 @@ private String getOrCreateInvoiceRunRecord() throws PipelineJobException
"quantity", "unitCost", "totalcost",
"rateId", "exemptionId", "creditaccountid", "comment", "transactionType", "sourceRecord", "chargeCategory"};

private void writeToInvoicedItems(List<Map<String, Object>> rows, String category, String[] colNames, String queryName, boolean allowNullProject) throws PipelineJobException
private void writeToInvoicedItems(List<Map<String, Object>> rows, String[] colNames, String queryName, boolean allowNullProject) throws PipelineJobException
{
assert colNames.length >= invoicedItemsCols.length;

Expand All @@ -323,7 +277,7 @@ private void writeToInvoicedItems(List<Map<String, Object>> rows, String categor
TableInfo invoicedItems = ONPRC_BillingSchema.getInstance().getSchema().getTable(ONPRC_BillingSchema.TABLE_INVOICED_ITEMS);
for (Map<String, Object> row : rows)
{
CaseInsensitiveHashMap toInsert = new CaseInsensitiveHashMap();
CaseInsensitiveHashMap<Object> toInsert = new CaseInsensitiveHashMap<>();
toInsert.put("container", getJob().getContainer().getId());
toInsert.put("createdby", getJob().getUser().getUserId());
toInsert.put("created", new Date());
Expand Down Expand Up @@ -373,24 +327,6 @@ private void writeToInvoicedItems(List<Map<String, Object>> rows, String categor
}
}

private String getString(Object val)
{
if (val == null)
{
return "";
}
else if (val instanceof Date)
{
return _dateFormat.format(val);
}
else if (val instanceof Number)
{
return val.toString();
}

return val.toString();
}

private void leaseFeeProcessing(Container ehrContainer) throws PipelineJobException
{
getJob().getLogger().info("Caching Lease Fees");
Expand Down Expand Up @@ -434,7 +370,7 @@ private void leaseFeeProcessing(Container ehrContainer) throws PipelineJobExcept

getJob().getLogger().info(rows.size() + " rows found");

writeToInvoicedItems(rows, "Lease Fees", colNames, queryName, false);
writeToInvoicedItems(rows, colNames, queryName, false);
getJob().getLogger().info("Finished Caching Lease Fees");
}

Expand Down Expand Up @@ -467,20 +403,22 @@ private List<Map<String, Object>> getRowList(Container c, String schemaName, Str
ts.setNamedParameters(params);

final List<Map<String, Object>> rows = new ArrayList<>();
ts.forEach(new Selector.ForEachBlock<>()
try (Results results = ts.getResults())
{
@Override
public void exec(ResultSet object) throws SQLException
while (results.next())
{
Results rs = new ResultsImpl(object, colKeys);
Map<String, Object> ret = new HashMap<>();
for (FieldKey fk : colKeys.keySet())
for (Map.Entry<FieldKey, ColumnInfo> entry: colKeys.entrySet())
{
ret.put(fk.toString(), rs.getObject(fk));
ret.put(entry.getKey().toString(), entry.getValue().getValue(results));
}
rows.add(ret);
}
});
}
catch (SQLException e)
{
throw new RuntimeSQLException(e);
}

return rows;
}
Expand Down Expand Up @@ -531,7 +469,7 @@ private void perDiemProcessing(Container ehrContainer) throws PipelineJobExcepti
List<Map<String, Object>> rows = getRowList(ehrContainer, "onprc_billing", queryName, colNames, params);
getJob().getLogger().info(rows.size() + " rows found");

writeToInvoicedItems(rows, "Per Diems", colNames, queryName, false);
writeToInvoicedItems(rows, colNames, queryName, false);
getJob().getLogger().info("Finished Caching Per Diem Fees");
}

Expand Down Expand Up @@ -583,7 +521,7 @@ private void slaPerDiemProcessing() throws PipelineJobException
List<Map<String, Object>> rows = getRowList(slaContainer, "onprc_billing", queryName, colNames, params);
getJob().getLogger().info(rows.size() + " rows found");

writeToInvoicedItems(rows, "Small Lab Animal Per Diems", colNames, queryName, false);
writeToInvoicedItems(rows, colNames, queryName, false);
getJob().getLogger().info("Finished Caching Per Diem Fees");
}

Expand Down Expand Up @@ -629,7 +567,7 @@ private void proceduresProcessing(Container ehrContainer) throws PipelineJobExce
List<Map<String, Object>> rows = getRowList(ehrContainer, "onprc_billing", queryName, colNames, params);
getJob().getLogger().info(rows.size() + " rows found");

writeToInvoicedItems(rows, "Procedure Fees", colNames, queryName, false);
writeToInvoicedItems(rows, colNames, queryName, false);
getJob().getLogger().info("Finished Caching Procedure Fees");
}

Expand Down Expand Up @@ -675,7 +613,7 @@ private void labworkProcessing(Container ehrContainer) throws PipelineJobExcepti
List<Map<String, Object>> rows = getRowList(ehrContainer, "onprc_billing", queryName, colNames, params);
getJob().getLogger().info(rows.size() + " rows found");

writeToInvoicedItems(rows, "Labwork Fees", colNames, queryName, false);
writeToInvoicedItems(rows, colNames, queryName, false);
getJob().getLogger().info("Finished Caching Labwork Fees");
}

Expand Down Expand Up @@ -718,7 +656,7 @@ private void miscChargesProcessing(Container ehrContainer) throws PipelineJobExc
List<Map<String, Object>> rows = getRowList(ehrContainer, "onprc_billing", MISC_CHARGES_QUERY, colNames, params);
getJob().getLogger().info(rows.size() + " rows found");

writeToInvoicedItems(rows, "Other Charges", colNames, MISC_CHARGES_QUERY, true);
writeToInvoicedItems(rows, colNames, MISC_CHARGES_QUERY, true);

getJob().getLogger().info("Finished Caching Other Charges");
}
Expand Down