Skip to content

Commit 9225d3c

Browse files
authored
Allow registering multiple InvoicedItemsProcessingService impls (#1102)
1 parent 24e3793 commit 9225d3c

File tree

5 files changed

+41
-19
lines changed

5 files changed

+41
-19
lines changed
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
-- ehr.Project.Created and ehr.Project.Modified are NULL on SQL Server but NOT NULL on PostgreSQL. Set the NULL values
2+
-- and switch the columns to NOT NULL to match PostgreSQL.
3+
UPDATE ehr.Project SET Created = COALESCE(diCreated, GETDATE()) WHERE Created IS NULL;
4+
UPDATE ehr.Project SET Modified = COALESCE(diModified, GETDATE()) WHERE Modified IS NULL;
5+
6+
ALTER TABLE ehr.Project ALTER COLUMN Created DATETIME NOT NULL;
7+
ALTER TABLE ehr.Project ALTER COLUMN Modified DATETIME NOT NULL;

ehr/src/org/labkey/ehr/EHRModule.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ public String getName()
135135
@Override
136136
public @Nullable Double getSchemaVersion()
137137
{
138-
return 26.001;
138+
return 26.002;
139139
}
140140

141141
@Override

ehr_billing/api-src/org/labkey/api/ehr_billing/pipeline/InvoicedItemsProcessingService.java

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,32 +22,45 @@
2222
import org.labkey.api.data.SimpleFilter;
2323
import org.labkey.api.data.TableInfo;
2424
import org.labkey.api.data.TableSelector;
25+
import org.labkey.api.module.Module;
2526
import org.labkey.api.pipeline.PipelineJobException;
2627
import org.labkey.api.query.FieldKey;
2728
import org.labkey.api.query.QueryService;
2829
import org.labkey.api.security.User;
29-
import org.labkey.api.services.ServiceRegistry;
3030
import org.labkey.api.util.Pair;
3131

3232
import java.util.Collections;
3333
import java.util.Date;
3434
import java.util.List;
3535
import java.util.Map;
36+
import java.util.concurrent.CopyOnWriteArrayList;
3637

3738
/**
3839
* Service to get a list of queries to be processed during a Billing Run. The listing is a collection of
3940
* BillingPipelineJobProcess objects that define what schema.query to execute and the mapping from that query's
4041
* columns to the ehr_billing.invoicedItem table's columns.
4142
* Additionally, get center specific generated invoice number.
42-
*
43-
* Currently registered server wide but should allow multiple co-existing services and resolve per container's active modules
4443
*/
4544
public interface InvoicedItemsProcessingService
4645
{
46+
record Registration(String moduleName, InvoicedItemsProcessingService impl){}
47+
48+
List<Registration> REGISTRATION_LIST = new CopyOnWriteArrayList<>();
49+
50+
static void register(Module module, InvoicedItemsProcessingService impl)
51+
{
52+
REGISTRATION_LIST.addFirst(new Registration(module.getName(), impl));
53+
}
54+
4755
@Nullable
48-
static InvoicedItemsProcessingService get()
56+
static InvoicedItemsProcessingService get(Container billingContainer)
4957
{
50-
return ServiceRegistry.get().getService(InvoicedItemsProcessingService.class);
58+
// Return the service implementation based on the registering module being active in the provided container
59+
return REGISTRATION_LIST.stream()
60+
.filter(reg -> billingContainer.hasActiveModuleByName(reg.moduleName()))
61+
.map(Registration::impl)
62+
.findFirst()
63+
.orElse(null);
5164
}
5265

5366
/** @return the inputs to the billing process that are capable of generating charges */

ehr_billing/src/org/labkey/ehr_billing/EHR_BillingController.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ public ApiResponse execute(BillingPipelineForm form, BindException errors)
104104
throw new PipelineJobException("Cannot create a billing run with the same start and end date");
105105
}
106106

107-
InvoicedItemsProcessingService processingService = InvoicedItemsProcessingService.get();
107+
InvoicedItemsProcessingService processingService = InvoicedItemsProcessingService.get(EHR_BillingManager.get().getBillingContainer(getContainer()));
108108
if (null != processingService)
109109
{
110110
Pair<String,String> previousInvoice = processingService.verifyBillingRunPeriod(getUser(), getContainer(), form.getStartDate(), form.getEndDate());

ehr_billing/src/org/labkey/ehr_billing/pipeline/BillingTask.java

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -78,11 +78,13 @@
7878
public class BillingTask extends PipelineJob.Task<BillingTask.Factory>
7979
{
8080
private final static DbSchema EHR_BILLING_SCHEMA = EHR_BillingSchema.getInstance().getSchema();
81-
private final static InvoicedItemsProcessingService processingService = InvoicedItemsProcessingService.get();
81+
82+
private final InvoicedItemsProcessingService _processingService;
8283

8384
protected BillingTask(Factory factory, PipelineJob job)
8485
{
8586
super(factory, job);
87+
_processingService = InvoicedItemsProcessingService.get(EHR_BillingManager.get().getBillingContainer(job.getContainer()));
8688
}
8789

8890
public static class Factory extends AbstractTaskFactory<AbstractTaskFactorySettings, Factory>
@@ -148,16 +150,16 @@ public RecordedActionSet run() throws PipelineJobException
148150
{
149151
getOrCreateInvoiceRunRecord();
150152
loadTransactionNumber();
151-
processingService.setBillingStartDate(getSupport().getStartDate());
153+
_processingService.setBillingStartDate(getSupport().getStartDate());
152154

153155
if (null != _previousInvoice)
154156
{
155-
processingService.processBillingRerun(_invoiceId, _invoiceRowId, getSupport().getStartDate(), getSupport().getEndDate(), getNextTransactionNumber(), user, billingContainer, getJob().getLogger());
157+
_processingService.processBillingRerun(_invoiceId, _invoiceRowId, getSupport().getStartDate(), getSupport().getEndDate(), getNextTransactionNumber(), user, billingContainer, getJob().getLogger());
156158
}
157159
else
158160
{
159161

160-
for (BillingPipelineJobProcess process : processingService.getProcessList())
162+
for (BillingPipelineJobProcess process : _processingService.getProcessList())
161163
{
162164
Container billingRunContainer = process.isUseEHRContainer() ? ehrContainer : billingContainer;
163165
runProcessing(process, billingRunContainer);
@@ -166,7 +168,7 @@ public RecordedActionSet run() throws PipelineJobException
166168

167169
updateInvoiceTable(billingContainer);
168170

169-
processingService.performAdditionalProcessing(_invoiceId, user, container);
171+
_processingService.performAdditionalProcessing(_invoiceId, user, container);
170172

171173
transaction.commit();
172174
}
@@ -278,7 +280,7 @@ private String getOrCreateInvoiceRunRecord() throws PipelineJobException
278280
@Nullable
279281
private String getOrCreateInvoiceRecord(Map<String, Object> row, Date endDate) throws PipelineJobException
280282
{
281-
String invoiceNumber = processingService.getInvoiceNum(row, endDate);
283+
String invoiceNumber = _processingService.getInvoiceNum(row, endDate);
282284
if (null != invoiceNumber)
283285
{
284286
try
@@ -499,25 +501,25 @@ private void runProcessing(BillingPipelineJobProcess process, Container billingR
499501

500502
// get cost
501503
Double unitCost = ci.getUnitCost();
502-
procedureRow.put(processingService.getUnitCostColName(), unitCost);
504+
procedureRow.put(_processingService.getUnitCostColName(), unitCost);
503505

504506
// total cost
505507
Double totalCost = unitCost * (Double) procedureRow.get("quantity");
506-
procedureRow.put(processingService.getTotalCostColName(), totalCost);
508+
procedureRow.put(_processingService.getTotalCostColName(), totalCost);
507509

508510
// calculate total cost with additional/other rate (ex. tier rate for WNPRC)
509511
Double otherRate = (Double) procedureRow.get("otherRate");
510512
Double unitCostWithOtherRate;
511513
double totalCostWithOtherRate;
512514
if (null != otherRate &&
513-
null != processingService.getAdditionalUnitCostColName() &&
514-
null != processingService.getAdditionalTotalCostColName())
515+
null != _processingService.getAdditionalUnitCostColName() &&
516+
null != _processingService.getAdditionalTotalCostColName())
515517
{
516518
unitCostWithOtherRate = unitCost + (unitCost * otherRate);
517-
procedureRow.put(processingService.getAdditionalUnitCostColName(), unitCostWithOtherRate);
519+
procedureRow.put(_processingService.getAdditionalUnitCostColName(), unitCostWithOtherRate);
518520

519521
totalCostWithOtherRate = unitCostWithOtherRate * (Double) procedureRow.get("quantity");
520-
procedureRow.put(processingService.getAdditionalTotalCostColName(), totalCostWithOtherRate);
522+
procedureRow.put(_processingService.getAdditionalTotalCostColName(), totalCostWithOtherRate);
521523
}
522524
}
523525
writeToInvoicedItems(process, procedureRows, getSupport());

0 commit comments

Comments
 (0)