-
Notifications
You must be signed in to change notification settings - Fork 106
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
Expose the RUMER data through the API #7262
Expose the RUMER data through the API #7262
Conversation
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 looked at the code and it looks fine. Very nice to have the key functionality moved into a dedicated function so it can be used for the REST API and the Rumer report.
I tested it with bhima_test and was able to get it to work with the following URL:
http://localhost:8080/api/stock/rumer?depotUuid=F9CAEB16168443C5A6C447DBAC1DF296&start_date=2023-09-01&end_date=2023-09-31
Here are some changes I suggest:
- Remove the /api/ from the REST URL for this query
- Add an integration regression test for the new URL. For an example, see
test/integration/inventory/lot_schedule.js
in PR 7205 .
server/config/routes.js
Outdated
@@ -909,6 +909,9 @@ exports.configure = function configure(app) { | |||
app.get('/reports/stock/assign', stockReports.stockAssignReport); | |||
app.get('/reports/stock/satisfaction_rate_report', stockReports.satisfactionRateReport); | |||
|
|||
// stock api for inter-operability | |||
app.get('/api/stock/rumer', stockReports.rumerApi.getData); |
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.
It is good to add a route for this, but I suggest removing the /api/ part of the URL. None of our other REST urls use it and it does not seem necessary.
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.
@jmcameron I am okay with your proposal to remove the part /api
in the URL, do you have some suggestions since the route returns only data to be consumed by tiers clients?
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.
Will /stock/rumer
work?
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 would approach this from a different angle. Instead of thinking of this as a separate API, I have always thought of every BHIMA route as part of the BHIMA API, and we have been trying to follow REST conventions for the most part.
From a REST perspective, I would ask "what is the required parameter?" Since it is a depotUuid
in this case, I would put that in the URL and call this depots/:uuid/rumer
. That way, we can think about is as "this is the RUMER report for the depot identified by depotUuid
".
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.
@jniles the function used in the API route is also used elsewhere so we do not have the freedom to make this change on the endpoint route definition without modifying other modules.
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 don't have a lot of time to review the code changes, but I've done what I can.
Overall, I really like the direction of this PR - it reuses the same functions for multiple report and I think that is excellent. I agree with @jmcameron's review that it should have some integration tests.
Great work!
(318, 'Job Titles Management','TREE.TITLE','',57, '/titles'); | ||
|
||
CALL add_column_if_missing('employee', 'title_employee_id', 'TINYINT(1) NOT NULL DEFAULT 0'); | ||
ALTER TABLE `employee` ADD CONSTRAINT `employee__title_employee` FOREIGN KEY (`title_employee_id`) REFERENCES `title_employee` (`id`); | ||
-- ALTER TABLE `employee` ADD CONSTRAINT `employee__title_employee` FOREIGN KEY (`title_employee_id`) REFERENCES `title_employee` (`id`); |
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 think this might be important later.. so we might at least want to add a TODO about trying to fix it during the next release. I know it was one of the last changes @lomamech made.
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.
Thank you @jniles
@@ -1,5 +1,9 @@ | |||
/* v1.28.x */ | |||
|
|||
-- Fix the constraint fails | |||
DELETE ru FROM role_unit ru JOIN unit u ON u.id = ru.unit_id WHERE u.`path` = "/admin/odk-settings"; |
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.
Great catch!
params.start_date = moment(new Date(params.start_date)).format('YYYY-MM-DD'); | ||
params.end_date = moment(new Date(params.end_date)).format('YYYY-MM-DD'); | ||
|
||
const startDate = parseInt(moment(params.start_date).format('DD'), 10); |
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.
This is a bit complicated to read. I propose you use moment.diff()
to make it a bit simpler since you are using moment anyway. Something like:
const numDays = moment(params.end_date).diff(params.start_date, 'days');
for (let i = 0; i <= numDays; i++) {
headerReport.push(i);
}
Or something similar (you might have to add or subtract 1 from i
).
46e4ba1
to
c6d111b
Compare
@jmcameron could you review my PR? Please |
I'm testing it now. |
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.
Unless you have a strong reason for allowing both depotUuid
and depot_uuid
, I encourage you to use only depot_uuid
to avoid confusion and simplify the code.
I tested with all the tests (including E2E tests) with bhima_test and it worked fine. I also tested this API manually with a large production database and it seems to work correctly.
Other than the minor issue of the depot uuid parameter name, I think this is ready to merge.
*/ | ||
async function getData(reqQuery) { | ||
const params = reqQuery; | ||
params.depotUuid = params.depotUuid || params.depot_uuid; |
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 suggest choosing one depot UUID parameter name or the other. Since the dates are line start_date
, I suggest allowing only depot_uuid
. Don't forget to modify the PR description with the updated parameter name.
data.header = headerReport; | ||
|
||
const parameterOpeningStock = { | ||
depot_uuid : params.depotUuid, |
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.
Switch to params.depot_uuid
}; | ||
|
||
const parameterEndingStock = { | ||
depot_uuid : params.depotUuid, |
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.
params.depot_uuid
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.
The function is already used by the RUMER report module, so I do not want to change currently codes on the client or some existing modules
@@ -21,7 +21,7 @@ CREATE TABLE `title_employee` ( | |||
UNIQUE KEY `title_1` (`title_txt`) | |||
) ENGINE=InnoDB DEFAULT CHARACTER SET = utf8mb4 DEFAULT COLLATE = utf8mb4_unicode_ci; | |||
|
|||
INSERT INTO unit VALUES | |||
INSERT IGNORE INTO unit VALUES |
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.
👍
@@ -0,0 +1,89 @@ | |||
/* global expect, agent */ |
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.
Thanks for adding this!
bors r+ |
Build succeeded! The publicly hosted instance of bors-ng is deprecated and will go away soon. If you want to self-host your own instance, instructions are here. If you want to switch to GitHub's built-in merge queue, visit their help page. |
This PR is about the expose the route :
/api/stock/rumer
This route requires as parameters
This API route returns data like this:

Where data

configurationData
contains information about stock of each inventory concerned:And

dailyConsumption
contains for each days of the given period, information about stock entry, exit and balance:Example:
GET <SERVER_ADDRESS>/api/stock/rumer?depotUuid=0918809809BA11ED9604061E16E213FC&start_date=2023-09-01&end_date=2023-09-30
The corresponding report in BHIMA is:
