Skip to content

feat(interactions): add medicine interaction checker#1754

Open
shashank03-dev wants to merge 3 commits into
RatLoopz:mainfrom
shashank03-dev:feat/issue-1734-interaction-checker
Open

feat(interactions): add medicine interaction checker#1754
shashank03-dev wants to merge 3 commits into
RatLoopz:mainfrom
shashank03-dev:feat/issue-1734-interaction-checker

Conversation

@shashank03-dev

@shashank03-dev shashank03-dev commented Jun 12, 2026

Copy link
Copy Markdown
Contributor

🛑 STOP: Assignment & File Scope Check

  • I am assigned to this issue.
  • I verified that this PR ONLY touches the required files.

Warning

PRs with unrelated files will not be reviewed and may be closed.

📋 PR Summary & Link

📸 Proof of Work (Screenshots / Logs)

Important

No Pull Request will be merged without proof of testing!

  • Frontend/UI changes: You MUST attach screenshots or screen recordings (GIFs/Videos) showing the UI changes.

Please drag & drop your screenshots/GIFs here:

sahidawa-pr-1754-interaction-warnings

Expected screenshot: /en/compare with three selected medicines, the Interaction warnings panel, and visible High Risk, Moderate, and Safe tags.

Local checks run:

NODE_PATH=/home/user/sahidawa-india/node_modules:/home/user/sahidawa-india/apps/api/node_modules node /home/user/sahidawa-india/node_modules/jest/bin/jest.js --config jest.config.js --runInBand tests/interactions.test.ts
NODE_OPTIONS=--experimental-vm-modules NODE_PATH=/home/user/sahidawa-india/node_modules:/home/user/sahidawa-india/apps/web/node_modules node /home/user/sahidawa-india/node_modules/jest/bin/jest.js --config jest.config.cjs --runInBand tests/compare-interactions.test.tsx

🏷️ PR Type

  • 🐛 type: bug
  • type: feature
  • 📖 type: docs
  • 🧪 type: testing
  • 🔒 type: security
  • type: performance
  • 🎨 type: design
  • ♻️ type: refactor
  • 🛠️ type: devops
  • type: accessibility

✅ Checklist

  • My PR has a linked issue (Closes #123)
  • I have pulled the latest main and resolved any conflicts

@dipexplorer

Copy link
Copy Markdown
Member

@shashank03-dev, we can't merge this as-is due to a major N+1 query issue in the backend. In apps/api/src/routes/interactions.ts, await findInteraction(drugA, drugB) is being executed inside a nested for loop. If a user selects 6 medicines, this will trigger 15 separate, sequential database queries. This will cause serious performance bottlenecks in production.

Plz refactor this logic. Instead of querying inside the loop, fetch all interactions in a single database call by passing all the selected drug IDs to a .in() query, and then filter/map the results locally in memory.

Let me know once u push the fix.

@dipexplorer dipexplorer added the type:testing Unit tests, integration tests label Jun 13, 2026
@shashank03-dev

Copy link
Copy Markdown
Contributor Author

yoh @dipexplorer, I have pushed the fix for the N+1 query issue and i'm sorry about the logic which was previously implemented by me.

Earlier, the GET /api/v1/interactions endpoint was calling findInteraction() inside the nested medicine-pair loop. I refactored it so the endpoint now fetches all matching interaction records in one database query using the selected generic medicine names, then maps the pair results in memory.

I also updated the API test to check that the endpoint only does one drug_interactions lookup for multiple selected medicines, so this should not regress back to per-pair queries.

Verified locally:

  • apps/api/tests/interactions.test.ts passed
  • apps/web/tests/compare-interactions.test.tsx passed

The branch is updated with the fix now.

@shashank03-dev shashank03-dev force-pushed the feat/issue-1734-interaction-checker branch from d8e30e0 to b583065 Compare June 14, 2026 10:37
@shashank03-dev

Copy link
Copy Markdown
Contributor Author

@dipexplorer updated this branch and force-pushed latest changes.

What changed:

  • rebased feat/issue-1734-interaction-checker onto current main
  • fixed compare page localization regressions by reusing existing translated strings
  • adjusted the compare interaction test for the rebased UI copy
  • removed stale @ts-nocheck usage and tightened the admin cache chart dynamic typings so lint/build pass on current main

Local verification:

  • npm run lint -w web
  • npm run build
  • npm test -w web -- --runInBand tests/compare-interactions.test.tsx
  • npm test -w apps/api -- --runInBand tests/interactions.test.ts

Please review and merge if everything looks good.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

good first issue Good for newcomers gssoc:approved Approved for gssoc level:advanced 55 pts level:beginner 20 pts quality:exceptional multiplier x1.5 type:bug Something isn't working type:feature New feature or request type:testing Unit tests, integration tests

Projects

Status: 📥 Backlog

Development

Successfully merging this pull request may close these issues.

feat(web): build medicine-to-medicine side effect interaction checker

2 participants