-
Notifications
You must be signed in to change notification settings - Fork 86
O3-5343: Support Billing v2 in the Initializer module #311
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
Merged
Merged
Changes from 1 commit
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
b0dfca4
O3-5343: Support Billing v2 in the Initializer module
wikumChamith 2a36db5
O3-5343: Support Billing v2 in the Initializer module
wikumChamith ca0b060
O3-5343: Support Billing v2 in the Initializer module
wikumChamith e844e95
O3-5343: Support Billing v2 in the Initializer module
wikumChamith 43597db
O3-5343: Support Billing v2 in the Initializer module
wikumChamith 6595cd7
O3-5343: Support Billing v2 in the Initializer module
wikumChamith 29ef619
O3-5343: Support Billing v2 in the Initializer module
wikumChamith File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
60 changes: 60 additions & 0 deletions
60
...7/src/main/java/org/openmrs/module/initializer/api/billing/BillableServicesCsvParser.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,60 @@ | ||
| package org.openmrs.module.initializer.api.billing; | ||
|
|
||
| import org.apache.commons.lang3.StringUtils; | ||
| import org.openmrs.annotation.OpenmrsProfile; | ||
| import org.openmrs.module.billing.api.BillableServiceService; | ||
| import org.openmrs.module.billing.api.model.BillableService; | ||
| import org.openmrs.module.initializer.Domain; | ||
| import org.openmrs.module.initializer.api.BaseLineProcessor; | ||
| import org.openmrs.module.initializer.api.CsvLine; | ||
| import org.openmrs.module.initializer.api.CsvParser; | ||
| import org.springframework.beans.factory.annotation.Autowired; | ||
| import org.springframework.beans.factory.annotation.Qualifier; | ||
|
|
||
| @OpenmrsProfile(modules = { "billing:2.0.0 - 9.*" }) | ||
| public class BillableServicesCsvParser extends CsvParser<BillableService, BaseLineProcessor<BillableService>> { | ||
|
|
||
| private final BillableServiceService billableServiceService; | ||
|
|
||
| private final BillableServicesLineProcessor billableServicesLineProcessor; | ||
|
|
||
| @Autowired | ||
| public BillableServicesCsvParser(@Qualifier("billableServiceService") BillableServiceService billableServiceService, | ||
| BillableServicesLineProcessor billableServicesLineProcessor) { | ||
| super(billableServicesLineProcessor); | ||
| this.billableServiceService = billableServiceService; | ||
| this.billableServicesLineProcessor = billableServicesLineProcessor; | ||
| } | ||
|
|
||
| @Override | ||
| public Domain getDomain() { | ||
| return Domain.BILLABLE_SERVICES; | ||
| } | ||
|
|
||
| @Override | ||
| public BillableService bootstrap(CsvLine line) throws IllegalArgumentException { | ||
| String uuid = line.getUuid(); | ||
|
|
||
| BillableService billableService = billableServiceService.getBillableServiceByUuid(uuid); | ||
|
|
||
| if (billableService == null) { | ||
| billableService = new BillableService(); | ||
| if (!StringUtils.isEmpty(uuid)) { | ||
| billableService.setUuid(uuid); | ||
| } | ||
| } | ||
|
|
||
| return billableService; | ||
| } | ||
|
|
||
| @Override | ||
| public BillableService save(BillableService instance) { | ||
| return billableServiceService.saveBillableService(instance); | ||
| } | ||
|
|
||
| @Override | ||
| protected void setLineProcessors(String version) { | ||
| lineProcessors.clear(); | ||
| lineProcessors.add(billableServicesLineProcessor); | ||
| } | ||
| } | ||
56 changes: 56 additions & 0 deletions
56
...c/main/java/org/openmrs/module/initializer/api/billing/BillableServicesLineProcessor.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,56 @@ | ||
| package org.openmrs.module.initializer.api.billing; | ||
|
|
||
| import org.apache.commons.lang3.StringUtils; | ||
| import org.openmrs.annotation.OpenmrsProfile; | ||
| import org.openmrs.api.ConceptService; | ||
| import org.openmrs.module.billing.api.model.BillableService; | ||
| import org.openmrs.module.billing.api.model.BillableServiceStatus; | ||
| import org.openmrs.module.initializer.api.BaseLineProcessor; | ||
| import org.openmrs.module.initializer.api.CsvLine; | ||
| import org.openmrs.module.initializer.api.utils.Utils; | ||
| import org.springframework.beans.factory.annotation.Autowired; | ||
| import org.springframework.beans.factory.annotation.Qualifier; | ||
|
|
||
| /** | ||
| * This is the first level line processor for Billable Services | ||
| */ | ||
| @OpenmrsProfile(modules = { "billing:2.0.0 - 9.*" }) | ||
| public class BillableServicesLineProcessor extends BaseLineProcessor<BillableService> { | ||
|
|
||
| protected static final String HEADER_NAME = "service name"; | ||
|
|
||
| protected static final String HEADER_DESC = "short name"; | ||
|
|
||
| protected static final String HEADER_SERVICE = "concept"; | ||
|
|
||
| protected static final String HEADER_SERVICE_TYPE = "service type"; | ||
|
|
||
| protected static final String HEADER_SERVICE_STATUS = "service status"; | ||
|
|
||
| private final ConceptService conceptService; | ||
|
|
||
| @Autowired | ||
| public BillableServicesLineProcessor(@Qualifier("conceptService") ConceptService conceptService) { | ||
| super(); | ||
| this.conceptService = conceptService; | ||
| } | ||
|
|
||
| @Override | ||
| public BillableService fill(BillableService billableService, CsvLine line) throws IllegalArgumentException { | ||
| billableService.setName(line.get(HEADER_NAME, true)); | ||
| billableService.setShortName(line.getString(HEADER_DESC)); | ||
|
|
||
| String service = line.get(HEADER_SERVICE, true); | ||
| billableService.setConcept(Utils.fetchConcept(service, conceptService)); | ||
|
|
||
| String serviceType = line.get(HEADER_SERVICE_TYPE, true); | ||
| billableService.setServiceType(Utils.fetchConcept(serviceType, conceptService)); | ||
|
|
||
| String serviceStatus = line.getString(HEADER_SERVICE_STATUS); | ||
| billableService.setServiceStatus( | ||
| StringUtils.isNotBlank(serviceStatus) ? BillableServiceStatus.valueOf(serviceStatus.toUpperCase()) | ||
| : BillableServiceStatus.ENABLED); | ||
|
|
||
| return billableService; | ||
| } | ||
| } |
15 changes: 15 additions & 0 deletions
15
api-2.7/src/main/java/org/openmrs/module/initializer/api/billing/BillableServicesLoader.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
| @@ -0,0 +1,15 @@ | ||||||
| package org.openmrs.module.initializer.api.billing; | ||||||
|
|
||||||
| import org.openmrs.annotation.OpenmrsProfile; | ||||||
| import org.openmrs.module.billing.api.model.BillableService; | ||||||
| import org.openmrs.module.initializer.api.loaders.BaseCsvLoader; | ||||||
| import org.springframework.beans.factory.annotation.Autowired; | ||||||
|
|
||||||
| @OpenmrsProfile(modules = { "billing:1.1.0 - 9.*" }) | ||||||
|
||||||
| @OpenmrsProfile(modules = { "billing:1.1.0 - 9.*" }) | |
| @OpenmrsProfile(modules = { "billing:2.0.0 - 9.*" }) |
51 changes: 51 additions & 0 deletions
51
api-2.7/src/main/java/org/openmrs/module/initializer/api/billing/CashPointsCsvParser.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,51 @@ | ||
| package org.openmrs.module.initializer.api.billing; | ||
|
|
||
| import org.apache.commons.lang3.StringUtils; | ||
| import org.openmrs.annotation.OpenmrsProfile; | ||
| import org.openmrs.module.billing.api.ICashPointService; | ||
| import org.openmrs.module.billing.api.model.CashPoint; | ||
| import org.openmrs.module.initializer.Domain; | ||
| import org.openmrs.module.initializer.api.BaseLineProcessor; | ||
| import org.openmrs.module.initializer.api.CsvLine; | ||
| import org.openmrs.module.initializer.api.CsvParser; | ||
| import org.springframework.beans.factory.annotation.Autowired; | ||
| import org.springframework.beans.factory.annotation.Qualifier; | ||
|
|
||
| @OpenmrsProfile(modules = { "billing:2.0.0 - 9.*" }) | ||
| public class CashPointsCsvParser extends CsvParser<CashPoint, BaseLineProcessor<CashPoint>> { | ||
|
|
||
| private final ICashPointService iCashPointService; | ||
|
|
||
| @Autowired | ||
| public CashPointsCsvParser(@Qualifier("cashierCashPointService") ICashPointService iCashPointService, | ||
| CashPointsLineProcessor processor) { | ||
| super(processor); | ||
| this.iCashPointService = iCashPointService; | ||
| } | ||
|
|
||
| @Override | ||
| public Domain getDomain() { | ||
| return Domain.CASH_POINTS; | ||
| } | ||
|
|
||
| @Override | ||
| public CashPoint bootstrap(CsvLine line) throws IllegalArgumentException { | ||
| String uuid = line.getUuid(); | ||
| CashPoint cashPoint = null; | ||
| if (StringUtils.isNotBlank(uuid)) { | ||
| cashPoint = iCashPointService.getByUuid(uuid); | ||
| } | ||
| if (cashPoint == null) { | ||
| cashPoint = new CashPoint(); | ||
| if (StringUtils.isNotBlank(uuid)) { | ||
| cashPoint.setUuid(uuid); | ||
| } | ||
| } | ||
| return cashPoint; | ||
| } | ||
|
|
||
| @Override | ||
| public CashPoint save(CashPoint instance) { | ||
| return iCashPointService.save(instance); | ||
| } | ||
| } |
36 changes: 36 additions & 0 deletions
36
...2.7/src/main/java/org/openmrs/module/initializer/api/billing/CashPointsLineProcessor.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,36 @@ | ||
| package org.openmrs.module.initializer.api.billing; | ||
|
|
||
| import org.openmrs.annotation.OpenmrsProfile; | ||
| import org.openmrs.api.LocationService; | ||
| import org.openmrs.module.billing.api.model.CashPoint; | ||
| import org.openmrs.module.initializer.api.BaseLineProcessor; | ||
| import org.openmrs.module.initializer.api.CsvLine; | ||
| import org.openmrs.module.initializer.api.utils.Utils; | ||
| import org.springframework.beans.factory.annotation.Autowired; | ||
| import org.springframework.beans.factory.annotation.Qualifier; | ||
|
|
||
| @OpenmrsProfile(modules = { "billing:2.0.0 - 9.*" }) | ||
| public class CashPointsLineProcessor extends BaseLineProcessor<CashPoint> { | ||
|
|
||
| protected static final String HEADER_DESCRIPTION = "description"; | ||
|
|
||
| protected static final String HEADER_LOCATION = "location"; | ||
|
|
||
| private final LocationService locationService; | ||
|
|
||
| @Autowired | ||
| public CashPointsLineProcessor(@Qualifier("locationService") LocationService locationService) { | ||
| super(); | ||
| this.locationService = locationService; | ||
| } | ||
|
|
||
| @Override | ||
| public CashPoint fill(CashPoint cashPoint, CsvLine line) throws IllegalArgumentException { | ||
| cashPoint.setName(line.get(HEADER_NAME, true)); | ||
| cashPoint.setDescription(line.getString(HEADER_DESCRIPTION)); | ||
| String location = line.get(HEADER_LOCATION, true); | ||
| cashPoint.setLocation(Utils.fetchLocation(location, locationService)); | ||
|
|
||
| return cashPoint; | ||
| } | ||
| } |
16 changes: 16 additions & 0 deletions
16
api-2.7/src/main/java/org/openmrs/module/initializer/api/billing/CashPointsLoader.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,16 @@ | ||
| package org.openmrs.module.initializer.api.billing; | ||
|
|
||
| import org.openmrs.annotation.OpenmrsProfile; | ||
| import org.openmrs.module.billing.api.model.CashPoint; | ||
| import org.openmrs.module.initializer.api.loaders.BaseCsvLoader; | ||
| import org.springframework.beans.factory.annotation.Autowired; | ||
|
|
||
| @OpenmrsProfile(modules = { "billing:2.0.0 - 9.*" }) | ||
| public class CashPointsLoader extends BaseCsvLoader<CashPoint, CashPointsCsvParser> { | ||
|
|
||
| @Autowired | ||
| public void setParser(CashPointsCsvParser parser) { | ||
| this.parser = parser; | ||
| } | ||
|
|
||
| } |
48 changes: 48 additions & 0 deletions
48
api-2.7/src/main/java/org/openmrs/module/initializer/api/billing/PaymentModesCsvParser.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,48 @@ | ||
| package org.openmrs.module.initializer.api.billing; | ||
|
|
||
| import org.apache.commons.lang3.StringUtils; | ||
| import org.openmrs.annotation.OpenmrsProfile; | ||
| import org.openmrs.module.billing.api.IPaymentModeService; | ||
| import org.openmrs.module.billing.api.model.PaymentMode; | ||
| import org.openmrs.module.initializer.Domain; | ||
| import org.openmrs.module.initializer.api.BaseLineProcessor; | ||
| import org.openmrs.module.initializer.api.CsvLine; | ||
| import org.openmrs.module.initializer.api.CsvParser; | ||
| import org.springframework.beans.factory.annotation.Autowired; | ||
| import org.springframework.beans.factory.annotation.Qualifier; | ||
|
|
||
| @OpenmrsProfile(modules = { "billing:2.0.0 - 9.*" }) | ||
| public class PaymentModesCsvParser extends CsvParser<PaymentMode, BaseLineProcessor<PaymentMode>> { | ||
|
|
||
| private final IPaymentModeService paymentModeService; | ||
|
|
||
| @Autowired | ||
| public PaymentModesCsvParser(@Qualifier("cashierPaymentModeService") IPaymentModeService paymentModeService, | ||
| PaymentModesLineProcessor processor) { | ||
| super(processor); | ||
| this.paymentModeService = paymentModeService; | ||
| } | ||
|
|
||
| @Override | ||
| public Domain getDomain() { | ||
| return Domain.PAYMENT_MODES; | ||
| } | ||
|
|
||
| @Override | ||
| public PaymentMode bootstrap(CsvLine line) throws IllegalArgumentException { | ||
| String uuid = line.getUuid(); | ||
| PaymentMode paymentMode = paymentModeService.getByUuid(uuid); | ||
| if (paymentMode == null) { | ||
| paymentMode = new PaymentMode(); | ||
| if (StringUtils.isNotBlank(uuid)) { | ||
| paymentMode.setUuid(uuid); | ||
| } | ||
| } | ||
| return paymentMode; | ||
| } | ||
|
|
||
| @Override | ||
| public PaymentMode save(PaymentMode instance) { | ||
| return paymentModeService.save(instance); | ||
| } | ||
| } |
44 changes: 44 additions & 0 deletions
44
...7/src/main/java/org/openmrs/module/initializer/api/billing/PaymentModesLineProcessor.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,44 @@ | ||
| package org.openmrs.module.initializer.api.billing; | ||
|
|
||
| import org.apache.commons.lang3.StringUtils; | ||
| import org.openmrs.annotation.OpenmrsProfile; | ||
| import org.openmrs.module.billing.api.model.PaymentMode; | ||
| import org.openmrs.module.initializer.api.BaseLineProcessor; | ||
| import org.openmrs.module.initializer.api.CsvLine; | ||
|
|
||
| @OpenmrsProfile(modules = { "billing:2.0.0 - 9.*" }) | ||
| public class PaymentModesLineProcessor extends BaseLineProcessor<PaymentMode> { | ||
|
|
||
| protected static final String HEADER_ATTRIBUTES = "attributes"; | ||
|
|
||
| public PaymentModesLineProcessor() { | ||
| super(); | ||
| } | ||
|
|
||
| @Override | ||
| public PaymentMode fill(PaymentMode paymentMode, CsvLine line) throws IllegalArgumentException { | ||
| paymentMode.setName(line.get(HEADER_NAME, true)); | ||
|
|
||
| String attributes = line.get(HEADER_ATTRIBUTES, false); | ||
| if (StringUtils.isNotBlank(attributes)) { | ||
| if (paymentMode.getAttributeTypes() != null) { | ||
| paymentMode.getAttributeTypes().clear(); | ||
| } | ||
| for (String attribute : attributes.split(BaseLineProcessor.LIST_SEPARATOR)) { | ||
| String[] parts = attribute.trim().split("::"); | ||
| if (parts.length > 3) { | ||
| paymentMode.addAttributeType(parts[0].trim(), parts[1].trim(), parts[2].trim(), | ||
| Boolean.parseBoolean(parts[3].trim())); | ||
| } else if (parts.length > 2) { | ||
| paymentMode.addAttributeType(parts[0].trim(), parts[1].trim(), parts[2].trim(), false); | ||
| } else if (parts.length > 1) { | ||
| paymentMode.addAttributeType(parts[0].trim(), parts[1].trim(), null, false); | ||
| } else { | ||
| paymentMode.addAttributeType(parts[0].trim(), null, null, false); | ||
| } | ||
| } | ||
| } | ||
|
|
||
| return paymentMode; | ||
| } | ||
| } |
15 changes: 15 additions & 0 deletions
15
api-2.7/src/main/java/org/openmrs/module/initializer/api/billing/PaymentModesLoader.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,15 @@ | ||
| package org.openmrs.module.initializer.api.billing; | ||
|
|
||
| import org.openmrs.annotation.OpenmrsProfile; | ||
| import org.openmrs.module.billing.api.model.PaymentMode; | ||
| import org.openmrs.module.initializer.api.loaders.BaseCsvLoader; | ||
| import org.springframework.beans.factory.annotation.Autowired; | ||
|
|
||
| @OpenmrsProfile(modules = { "billing:2.0.0 - 9.*" }) | ||
| public class PaymentModesLoader extends BaseCsvLoader<PaymentMode, PaymentModesCsvParser> { | ||
|
|
||
| @Autowired | ||
| public void setParser(PaymentModesCsvParser parser) { | ||
| this.parser = parser; | ||
| } | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since you mentioned "Billing v2 now requires OpenMRS Core 2.7.8-SNAPSHOT”, shouldn’t we add that requirement as well?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No need to add that. Billing module won't even start if we are using a core version lower than 2.7.8-SNAPSHOT
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I understand that. Won’t it be better to add that, especially since this requirement would get documented.