Skip to content

[ENG-513] Add missing fields to datapoints for template support#3677

Open
rithviknishad wants to merge 4 commits into
ohcnetwork:developfrom
rithviknishad:ENG-513-add-all-other-missing-fields-to-datapoints-for-template-support
Open

[ENG-513] Add missing fields to datapoints for template support#3677
rithviknishad wants to merge 4 commits into
ohcnetwork:developfrom
rithviknishad:ENG-513-add-all-other-missing-fields-to-datapoints-for-template-support

Conversation

@rithviknishad

@rithviknishad rithviknishad commented Jun 4, 2026

Copy link
Copy Markdown
Member

Proposed Changes

Adds the following fields to datapoints for template support:

  • encounter -> diagnostic_report.status
  • encounter -> diagnostic_report.category (ValueSet)
  • encounter -> symptoms.severity
  • encounter -> allergy_intolerance.category
  • encounter -> allergy_intolerance.allergy_intolerance_type
  • encounter -> diagnosis.severity
  • encounter -> medication_prescriptions.name
  • encounter -> medication_prescriptions.tags
  • encounter -> service_request.note
  • encounter -> service_request.occurance
  • encounter -> service_request.patient_instruction
  • encounter -> service_request.tags

Summary by CodeRabbit

  • New Features

    • Added severity fields for diagnoses and symptoms
    • Exposed category and type for allergy/intolerance records
    • Tag-based displays for medication prescriptions and service requests
    • Service requests now include occurrence date/time, patient instructions, tags, and notes
  • Improvements

    • Clearer diagnostic report status labels
    • More consistent display/preview formatting and unified empty-value handling across related fields

@rithviknishad rithviknishad requested a review from a team as a code owner June 4, 2026 11:51
@coderabbitai

coderabbitai Bot commented Jun 4, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Walkthrough

Adds display lookup dictionaries and new mapped fields across allergy_intolerance, diagnosis, diagnostic_report, medication, service_request, and symptom context builders; introduces Queryset-based tag sub-contexts for medication prescriptions and service requests and standardizes empty-string fallbacks.

Changes

EMR Context Builder Enhancements

Layer / File(s) Summary
Allergy intolerance context fields and display mappings
care/emr/reports/context_builder/data_points/allergy_intolerance.py
Adds CATEGORY_DISPLAY and ALLERGY_INTOLERANCE_TYPE_DISPLAY. AllergyIntoleranceContextBuilder gains category and allergy_intolerance_type fields; clinical_status, verification_status, and criticality mappings now use display dicts with title-case fallback and return "" when unset.
Diagnosis context fields and severity display mapping
care/emr/reports/context_builder/data_points/diagnosis.py
Adds SEVERITY_DISPLAY and a severity field with display/preview mapping. Refactors clinical_status and verification_status mappings to a compact conditional form while preserving display-dict lookup and empty-string fallback.
Diagnostic report context fields and status display mapping
care/emr/reports/context_builder/data_points/diagnostic_report.py
Adds STATUS_DISPLAY and updates status mapping to use it with title-case fallback or "". category extraction now safely reads c.category.get('display') only when c.category exists.
Symptom context fields and severity display mapping
care/emr/reports/context_builder/data_points/symptom.py
Adds SEVERITY_DISPLAY and severity field using the display mapping with title-case fallback and empty-string when unset. Refactors clinical_status and verification_status mappings to consistently return "" when source values are absent while using display lookups.
Medication prescription tag context builder and status enhancements
care/emr/reports/context_builder/data_points/medication.py
Imports TagConfig/TagFilter. Adds MedicationPrescriptionTagContextBuilder to resolve tags from parent_context.tags. Introduces MEDICATION_PRESCRIPTION_STATUS_DISPLAY (includes "ended"), updates status mapping and preview_value, and adds tags field wired to the tag context builder.
Service request tag context builder and field enhancements
care/emr/reports/context_builder/data_points/service_request.py
Imports TagConfig/TagFilter. Adds ServiceRequestTagContextBuilder to fetch TagConfig rows by parent_context.tags. Updates status, intent, category, priority mappings to return "" when falsy. Adds occurance, patient_instruction, tags (targeting the tag builder), and note fields.
TagFilter export and patient/encounter refactors
care/emr/reports/context_builder/filters/*, care/emr/reports/context_builder/data_points/patient.py, care/emr/reports/context_builder/data_points/encounter.py
Adds filters/tag_filter.py with TagFilter, re-exports it from filters.__init__. Replaces local TagFilter in patient.py with shared import and refactors several Field(mapping=...) lambdas into multi-line conditional forms without changing outputs. Adjusts encounter imports to use shared TagFilter.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Possibly related PRs

Suggested reviewers

  • vigneshhari
🚥 Pre-merge checks | ✅ 3 | ❌ 2

❌ Failed checks (1 warning, 1 inconclusive)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
Description check ❓ Inconclusive The description covers the proposed changes with a detailed checklist of added fields, but lacks information about tests, documentation updates, and linting status as specified in the template. Consider completing the merge checklist items and explicitly confirming test coverage, documentation updates, and linting completion status.
✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately summarizes the main objective of adding missing fields to datapoints for template support, which is clearly reflected in all the file changes.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@greptile-apps

greptile-apps Bot commented Jun 4, 2026

Copy link
Copy Markdown
Contributor

Greptile Summary

This PR exposes additional data-point fields across six context builders to support template rendering: status and category on diagnostic reports, severity on symptoms and diagnoses, category and allergy_intolerance_type on allergy intolerances, name/tags/status display on medication prescriptions, and note/occurance/patient_instruction/tags on service requests.

  • diagnosis.py and symptom.py: The new severity field's mapping uses c.severity.title() as a dict default, which is evaluated eagerly — calling .title() on None at runtime when the nullable model field is unset.
  • diagnostic_report.py: The category field's mapping reads from c.code (the title JSON field) instead of c.category, so it will always return the same text as title.

Confidence Score: 3/5

Three of the six changed files contain correctness bugs that will produce wrong or crashing behavior in production; the remaining three files look correct.

The severity mapping in both diagnosis.py and symptom.py will raise AttributeError whenever a record has a null severity (allowed by the schema), breaking any template render that iterates over those datapoints. The category field in diagnostic_report.py silently reads the wrong JSON field, so every rendered category will display the title text instead.

care/emr/reports/context_builder/data_points/diagnosis.py, care/emr/reports/context_builder/data_points/symptom.py, and care/emr/reports/context_builder/data_points/diagnostic_report.py need fixes before merging.

Important Files Changed

Filename Overview
care/emr/reports/context_builder/data_points/diagnosis.py Adds severity field to DiagnosisContextBuilder; the mapping crashes with AttributeError when the model field is null (null=True in the schema).
care/emr/reports/context_builder/data_points/symptom.py Adds severity field to SymptomsContextBuilder with the same null-pointer bug as diagnosis.py — crashes when severity is null.
care/emr/reports/context_builder/data_points/diagnostic_report.py Adds status and category fields; the category mapping incorrectly reads from code (same as the title field) instead of the model's category JSONField, so it will always produce the wrong value.
care/emr/reports/context_builder/data_points/allergy_intolerance.py Adds category and allergy_intolerance_type fields with proper null-guarded mappings; also reformats existing lambdas to use parenthesised conditional expressions.
care/emr/reports/context_builder/data_points/medication.py Adds name, tags, and a proper display mapping for status to MedicationPrescriptionContextBuilder; introduces MedicationPrescriptionTagContextBuilder via the existing TagFilter pattern.
care/emr/reports/context_builder/data_points/service_request.py Adds note, occurance, patient_instruction, and tags to ServiceRequestBaseContextBuilder; occurance display label perpetuates the pre-existing model-level spelling error.

Reviews (1): Last reviewed commit: "ENG-513 Add all other missing fields to ..." | Re-trigger Greptile

Comment thread care/emr/reports/context_builder/data_points/diagnosis.py Outdated
Comment thread care/emr/reports/context_builder/data_points/symptom.py Outdated
Comment thread care/emr/reports/context_builder/data_points/diagnostic_report.py
Comment thread care/emr/reports/context_builder/data_points/service_request.py Outdated

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 5

🧹 Nitpick comments (1)
care/emr/reports/context_builder/data_points/medication.py (1)

189-189: ⚡ Quick win

Use an immutable backend container to satisfy Ruff RUF012.

Line 189 and Line 216 use a mutable class attribute list for __filterset_backends__; Ruff is (predictably) unhappy here. Switch both to tuples.

Proposed diff
 class MedicationPrescriptionTagContextBuilder(QuerysetContextBuilder):
     filterset_class = TagFilter
-    __filterset_backends__ = [filters.DjangoFilterBackend]
+    __filterset_backends__ = (filters.DjangoFilterBackend,)
@@
 class MedicationPrescriptionContextBuilder(QuerysetContextBuilder):
     filterset_class = MedicationPrescriptionReportFilter
-    __filterset_backends__ = [filters.DjangoFilterBackend]
+    __filterset_backends__ = (filters.DjangoFilterBackend,)
As per coding guidelines, "`**/*.py`: Use Ruff for linting and formatting Python code (replaces black, isort, flake8)".

Also applies to: 216-216

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@care/emr/reports/context_builder/data_points/medication.py` at line 189, The
class attribute __filterset_backends__ is currently a mutable list (e.g.,
__filterset_backends__ = [filters.DjangoFilterBackend]) which triggers Ruff
RUF012; change both occurrences to use an immutable tuple instead (e.g.,
__filterset_backends__ = (filters.DjangoFilterBackend,)) so the attribute is
immutable—update the two spots where __filterset_backends__ is defined in
medication.py accordingly.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@care/emr/reports/context_builder/data_points/diagnosis.py`:
- Around line 62-66: The severity Field mapping can raise AttributeError when
Condition.severity is None because the default expression c.severity.title() is
evaluated eagerly; update the mapping lambda for severity in diagnosis.py (and
similarly in symptom.py) to guard against null/empty values like the
clinical_status / verification_status pattern: check if c.severity is truthy
first, use SEVERITY_DISPLAY.get(c.severity, c.severity.title()) when present,
otherwise return None or an appropriate empty string; reference symbols: the
severity Field, mapping lambda, SEVERITY_DISPLAY, and Condition.severity.

In `@care/emr/reports/context_builder/data_points/service_request.py`:
- Line 119: Replace the misspelled display label "Occurance" with the correct
spelling "Occurrence" in the service request data point definition; locate the
display="Occurance" occurrence in
care/emr/reports/context_builder/data_points/service_request.py (the data point
or dict where display is set to "Occurance") and update it to
display="Occurrence" so templates show the correct word.
- Around line 58-60: get_context currently returns
TagConfig.objects.filter(id__in=self.parent_context.tags) which can leak tags
across tenants; change get_context to include the tenant/facility/org
discriminator from parent_context in the filter (e.g. add
facility_id=self.parent_context.facility_id or
organization_id=self.parent_context.organization_id or use a
parent_context-provided tenant filter method) so the query becomes a filtered
lookup by both id__in=self.parent_context.tags and the same tenant scope used
elsewhere in the app (refer to get_context, TagConfig.objects.filter and
self.parent_context.tags to locate where to add the extra filter).
- Line 49: Replace the mutable list assigned to __filterset_backends__ with an
immutable tuple in both classes: change
ServiceRequestTagContextBuilder.__filterset_backends__ and
ServiceRequestBaseContextBuilder.__filterset_backends__ from
[filters.DjangoFilterBackend] to (filters.DjangoFilterBackend,) so Ruff RUF012
is satisfied; ensure the trailing comma is present to create a single-element
tuple.

In `@care/emr/reports/context_builder/data_points/symptom.py`:
- Around line 63-67: The severity Field's mapping currently calls
c.severity.title() without null-check, which can raise AttributeError if
c.severity is None; update the mapping lambda used in the severity Field to
guard against missing values (mirror the pattern used by the other status
fields) by returning a default/empty string or using c.severity.title() only
when c.severity is truthy, and otherwise falling back to the SEVERITY_DISPLAY
lookup or a safe default; modify the mapping lambda and keep references to
SEVERITY_DISPLAY and the severity Field to locate the change.

---

Nitpick comments:
In `@care/emr/reports/context_builder/data_points/medication.py`:
- Line 189: The class attribute __filterset_backends__ is currently a mutable
list (e.g., __filterset_backends__ = [filters.DjangoFilterBackend]) which
triggers Ruff RUF012; change both occurrences to use an immutable tuple instead
(e.g., __filterset_backends__ = (filters.DjangoFilterBackend,)) so the attribute
is immutable—update the two spots where __filterset_backends__ is defined in
medication.py accordingly.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: 0d777b4d-0f1e-40f7-91bf-94a5542e3657

📥 Commits

Reviewing files that changed from the base of the PR and between dd4f997 and 5a76594.

📒 Files selected for processing (6)
  • care/emr/reports/context_builder/data_points/allergy_intolerance.py
  • care/emr/reports/context_builder/data_points/diagnosis.py
  • care/emr/reports/context_builder/data_points/diagnostic_report.py
  • care/emr/reports/context_builder/data_points/medication.py
  • care/emr/reports/context_builder/data_points/service_request.py
  • care/emr/reports/context_builder/data_points/symptom.py

Comment thread care/emr/reports/context_builder/data_points/diagnosis.py
Comment thread care/emr/reports/context_builder/data_points/service_request.py
Comment thread care/emr/reports/context_builder/data_points/service_request.py
Comment thread care/emr/reports/context_builder/data_points/service_request.py Outdated
Comment thread care/emr/reports/context_builder/data_points/symptom.py
@vigneshhari

Copy link
Copy Markdown
Member

@rithviknishad i see a lot of coderabbit comments open, please resolve them with valid reasoning

@vigneshhari

Copy link
Copy Markdown
Member

@nandkishorr to review

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@care/emr/reports/context_builder/filters/__init__.py`:
- Line 1: Replace the wildcard re-export in __init__.py by importing and
exporting TagFilter explicitly: change the import from .tag_filter to import
TagFilter (from .tag_filter import TagFilter) and add an explicit __all__ =
["TagFilter"] so downstream imports continue to work and Ruff F403 is resolved;
locate the file's existing wildcard import and update it to reference the
TagFilter symbol from tag_filter.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: 586df43d-26a8-439e-9ff1-88e00085fc64

📥 Commits

Reviewing files that changed from the base of the PR and between 79e6719 and 5d36818.

📒 Files selected for processing (6)
  • care/emr/reports/context_builder/data_points/encounter.py
  • care/emr/reports/context_builder/data_points/medication.py
  • care/emr/reports/context_builder/data_points/patient.py
  • care/emr/reports/context_builder/data_points/service_request.py
  • care/emr/reports/context_builder/filters/__init__.py
  • care/emr/reports/context_builder/filters/tag_filter.py
✅ Files skipped from review due to trivial changes (1)
  • care/emr/reports/context_builder/data_points/encounter.py
🚧 Files skipped from review as they are similar to previous changes (2)
  • care/emr/reports/context_builder/data_points/medication.py
  • care/emr/reports/context_builder/data_points/service_request.py

@@ -0,0 +1 @@
from .tag_filter import *

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟠 Major

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
set -euo pipefail

# 1) Confirm no wildcard re-export remains
rg -n 'from \.tag_filter import \*' care/emr/reports/context_builder/filters/__init__.py || true

# 2) Confirm explicit export exists
rg -n 'from \.tag_filter import TagFilter|__all__\s*=\s*\["TagFilter"\]' care/emr/reports/context_builder/filters/__init__.py

# 3) Re-run Ruff on the touched package
ruff check care/emr/reports/context_builder/filters/__init__.py care/emr/reports/context_builder/filters/tag_filter.py

Repository: ohcnetwork/care

Length of output: 87


Replace the wildcard re-export in care/emr/reports/context_builder/filters/__init__.py (Ruff F403 / CI blocker)

__init__.py still has from .tag_filter import * (Ruff F403), so lint is still failing. Export TagFilter explicitly so downstream imports keep working without tripping Ruff.

Suggested fix
-from .tag_filter import *
+from .tag_filter import TagFilter
+
+__all__ = ["TagFilter"]
🧰 Tools
🪛 GitHub Actions: Lint Code Base / 0_lint.txt

[error] 1-1: pre-commit hook 'ruff-check' failed (exit code 1). Ruff reported F403: 'from .tag_filter import * used; unable to detect undefined names'.

🪛 GitHub Actions: Lint Code Base / lint

[error] 1-1: Ruff (ruff-check) failed: F403 'from .tag_filter import * used; unable to detect undefined names'.

🪛 Ruff (0.15.15)

[error] 1-1: from .tag_filter import * used; unable to detect undefined names

(F403)

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@care/emr/reports/context_builder/filters/__init__.py` at line 1, Replace the
wildcard re-export in __init__.py by importing and exporting TagFilter
explicitly: change the import from .tag_filter to import TagFilter (from
.tag_filter import TagFilter) and add an explicit __all__ = ["TagFilter"] so
downstream imports continue to work and Ruff F403 is resolved; locate the file's
existing wildcard import and update it to reference the TagFilter symbol from
tag_filter.

Sources: Coding guidelines, Linters/SAST tools, Pipeline failures

@codecov

codecov Bot commented Jun 9, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 95.12195% with 2 lines in your changes missing coverage. Please review.
✅ Project coverage is 76.72%. Comparing base (c8070f3) to head (5d36818).
⚠️ Report is 9 commits behind head on develop.

Files with missing lines Patch % Lines
.../reports/context_builder/data_points/medication.py 90.90% 1 Missing ⚠️
...rts/context_builder/data_points/service_request.py 91.66% 1 Missing ⚠️
Additional details and impacted files
@@             Coverage Diff             @@
##           develop    #3677      +/-   ##
===========================================
+ Coverage    76.69%   76.72%   +0.02%     
===========================================
  Files          479      481       +2     
  Lines        22992    23030      +38     
  Branches      2379     2379              
===========================================
+ Hits         17634    17670      +36     
- Misses        4804     4806       +2     
  Partials       554      554              

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants