Skip to content
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

Labs #2642

Draft
wants to merge 15 commits into
base: develop
Choose a base branch
from
Draft

Labs #2642

wants to merge 15 commits into from

Conversation

khavinshankar
Copy link
Member

@khavinshankar khavinshankar commented Dec 9, 2024

Resolves ohcnetwork/care_fe#8683
Frontend ohcnetwork/care_fe#9260

Added basic flow of creating a lab order till getting the results.

Still filters and permissions are pending.

Summary by CodeRabbit

Release Notes

  • New Features

    • Introduced DiagnosticReportViewSet, ServiceRequestViewSet, and SpecimenViewSet to manage diagnostic reports, service requests, and specimens, respectively.
    • Added automated specimen creation upon the creation of a service request.
  • Bug Fixes

    • Enhanced error handling for specimen creation to ensure proper validation.
  • Documentation

    • Improved API documentation for new endpoints and data models.
  • Database Migrations

    • Added new models for DiagnosticReport, ServiceRequest, and Specimen, along with necessary fields and relationships.

@khavinshankar khavinshankar requested a review from a team as a code owner December 9, 2024 07:12
Copy link

coderabbitai bot commented Dec 9, 2024

Important

Review skipped

Draft detected.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

📝 Walkthrough
📝 Walkthrough
📝 Walkthrough

Walkthrough

The changes introduce several new files and classes to enhance the functionality of the EMR system. Notable additions include DiagnosticReportViewSet, ServiceRequestViewSet, and SpecimenViewSet, which extend EMRModelViewSet to manage diagnostic reports, service requests, and specimens, respectively. Each viewset incorporates methods for handling specific operations, such as creating and processing observations or service requests. Additionally, new models for DiagnosticReport, ServiceRequest, and Specimen are established, along with various utility classes and value sets for better data management and validation.

Changes

File Path Change Summary
care/emr/api/viewsets/diagnostic_report.py Added DiagnosticReportViewSet class and observations method for handling diagnostic reports.
care/emr/api/viewsets/service_request.py Added ServiceRequestViewSet class and clean_create_data method for service request handling.
care/emr/api/viewsets/specimen.py Added SpecimenViewSet class with methods for specimen management.
care/emr/apps.py Added ready method in EMRConfig to import signals on app startup.
care/emr/fhir/resources/concept_map.py Introduced ConceptMapResource class and methods for managing FHIR concept maps.
care/emr/fhir/utils.py Enhanced parse_fhir_parameter_output function for better parameter handling.
care/emr/migrations/0005_servicerequest.py Added ServiceRequest model with various fields for service requests.
care/emr/migrations/0006_specimen.py Added Specimen model with fields for specimen attributes.
care/emr/migrations/0019_diagnosticreport.py Added DiagnosticReport model with various fields for diagnostic report attributes.
care/emr/migrations/0020_servicerequest_location_specimen_condition_and_more.py Added and altered fields in ServiceRequest, Specimen, and DiagnosticReport models.
care/emr/models/diagnostic_report.py Introduced DiagnosticReport model class with fields for report attributes.
care/emr/models/service_request.py Introduced ServiceRequest model class with fields for service request attributes.
care/emr/models/specimen.py Introduced Specimen model class with fields for specimen attributes.
care/emr/resources/diagnostic_report/spec.py Added classes for diagnostic report specifications and validation.
care/emr/resources/service_request/spec.py Added classes for service request specifications and validation.
care/emr/resources/specimen/spec.py Added classes for specimen specifications and processing details.
care/emr/signals/auto_create_specimen.py Added functionality to create a specimen automatically upon service request creation.
config/api_router.py Registered new viewsets for diagnostic reports, service requests, and specimens in the API router.

Poem

In the EMR realm, new features arise,
With reports and requests, oh what a surprise!
Specimens and signals, all neatly in place,
A system so tidy, it’s winning the race!
So here’s to the changes, both big and small,
In this digital world, we’re having a ball! 🎉


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR. (Beta)
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@khavinshankar khavinshankar marked this pull request as draft December 9, 2024 07:12
Copy link

codecov bot commented Dec 9, 2024

Codecov Report

Attention: Patch coverage is 75.87354% with 145 lines in your changes missing coverage. Please review.

Please upload report for BASE (vigneshhari/health-details@82ccb89). Learn more about missing BASE report.

Files with missing lines Patch % Lines
care/emr/api/viewsets/specimen.py 40.27% 43 Missing ⚠️
care/emr/resources/diagnostic_report/spec.py 74.07% 28 Missing ⚠️
care/emr/api/viewsets/diagnostic_report.py 51.61% 15 Missing ⚠️
care/emr/resources/specimen/spec.py 85.85% 13 Missing and 1 partial ⚠️
care/emr/signals/auto_create_specimen.py 40.90% 13 Missing ⚠️
care/emr/resources/service_request/spec.py 87.75% 12 Missing ⚠️
care/emr/fhir/utils.py 0.00% 10 Missing ⚠️
care/emr/fhir/resources/concept_map.py 83.33% 7 Missing ⚠️
care/emr/api/viewsets/service_request.py 76.92% 3 Missing ⚠️
Additional details and impacted files
@@                      Coverage Diff                      @@
##             vigneshhari/health-details    #2642   +/-   ##
=============================================================
  Coverage                              ?   71.21%           
=============================================================
  Files                                 ?      264           
  Lines                                 ?    14796           
  Branches                              ?     1875           
=============================================================
  Hits                                  ?    10537           
  Misses                                ?     3864           
  Partials                              ?      395           

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

external_id=self.results_interpreter
)

obj.save()
Copy link
Member

Choose a reason for hiding this comment

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

Dont call this here, if this is needed create a new abstraction for this.

priority: str

category: Coding | None
code: Coding
Copy link
Member

Choose a reason for hiding this comment

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

Can be dict as well

@vigneshhari
Copy link
Member

@coderabbitai reivew

Copy link

coderabbitai bot commented Dec 9, 2024

@vigneshhari: Sure, I'll take a look at your changes.

✅ Actions performed

Review triggered.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 12

🧹 Outside diff range and nitpick comments (15)
care/emr/signals/auto_create_specimen.py (2)

61-61: Unnecessary return statement at the end of the function

The return statement on line 61 may not be necessary, as signal receiver functions typically do not require returning a value.

Consider removing the return specimen statement to keep the code clean.


16-16: Address the TODO comment

There's a TODO to change the trigger to when the billing is done. You might want to prioritize implementing this change to align with the intended workflow.

Would you like assistance in updating the trigger mechanism?

care/emr/models/diagnostic_report.py (1)

32-38: You might want to use on_delete=models.SET_NULL for performer and results_interpreter

Using on_delete=models.CASCADE could lead to unintended deletion of DiagnosticReport records if a User is deleted. Setting on_delete=models.SET_NULL would preserve the DiagnosticReport while allowing the User to be removed.

Apply the following diff to implement this suggestion:

        performer = models.ForeignKey(
            User,
-           on_delete=models.CASCADE,
+           on_delete=models.SET_NULL,
            null=True,
            blank=True,
            related_name="performed_diagnostic_report",
        )
        results_interpreter = models.ForeignKey(
            User,
-           on_delete=models.CASCADE,
+           on_delete=models.SET_NULL,
            null=True,
            blank=True,
            related_name="interpreted_diagnostic_report",
        )

Also applies to: 39-45

care/emr/api/viewsets/specimen.py (1)

33-38: Optimize Query in get_object Method

The Q objects in the get_object method can be simplified for better readability.

Consider simplifying the query like this:

 return get_object_or_404(
     self.get_queryset(),
-    Q(external_id__iexact=self.kwargs[self.lookup_field])
-    | Q(identifier=self.kwargs[self.lookup_field])
-    | Q(accession_identifier=self.kwargs[self.lookup_field]),
+    Q(
+        external_id__iexact=self.kwargs[self.lookup_field],
+        identifier=self.kwargs[self.lookup_field],
+        accession_identifier=self.kwargs[self.lookup_field],
+    ),
 )
care/emr/migrations/0020_servicerequest_location_specimen_condition_and_more.py (1)

11-120: Consistent Use of Double Quotes Preferred

Static analysis indicates that single quotes are used, whereas double quotes are preferred according to the project's style guidelines. Replacing single quotes with double quotes will improve consistency.

Consider running an autoformatter or applying this diff:

- field=models.UUIDField(blank=True, null=True),
+ field=models.UUIDField(blank=True, null=True),

(Note: The actual diff would be extensive due to many lines; using an autoformatter is recommended.)

🧰 Tools
🪛 Ruff (0.8.0)

11-11: Single quotes found but double quotes preferred

Replace single quotes with double quotes

(Q000)


11-11: Single quotes found but double quotes preferred

Replace single quotes with double quotes

(Q000)


12-12: Single quotes found but double quotes preferred

Replace single quotes with double quotes

(Q000)


12-12: Single quotes found but double quotes preferred

Replace single quotes with double quotes

(Q000)


18-18: Single quotes found but double quotes preferred

Replace single quotes with double quotes

(Q000)


19-19: Single quotes found but double quotes preferred

Replace single quotes with double quotes

(Q000)


23-23: Single quotes found but double quotes preferred

Replace single quotes with double quotes

(Q000)


24-24: Single quotes found but double quotes preferred

Replace single quotes with double quotes

(Q000)


28-28: Single quotes found but double quotes preferred

Replace single quotes with double quotes

(Q000)


29-29: Single quotes found but double quotes preferred

Replace single quotes with double quotes

(Q000)


33-33: Single quotes found but double quotes preferred

Replace single quotes with double quotes

(Q000)


34-34: Single quotes found but double quotes preferred

Replace single quotes with double quotes

(Q000)


35-35: Single quotes found but double quotes preferred

Replace single quotes with double quotes

(Q000)


38-38: Single quotes found but double quotes preferred

Replace single quotes with double quotes

(Q000)


39-39: Single quotes found but double quotes preferred

Replace single quotes with double quotes

(Q000)


43-43: Single quotes found but double quotes preferred

Replace single quotes with double quotes

(Q000)


44-44: Single quotes found but double quotes preferred

Replace single quotes with double quotes

(Q000)


45-45: Single quotes found but double quotes preferred

Replace single quotes with double quotes

(Q000)


48-48: Single quotes found but double quotes preferred

Replace single quotes with double quotes

(Q000)


49-49: Single quotes found but double quotes preferred

Replace single quotes with double quotes

(Q000)


53-53: Single quotes found but double quotes preferred

Replace single quotes with double quotes

(Q000)


54-54: Single quotes found but double quotes preferred

Replace single quotes with double quotes

(Q000)


55-55: Single quotes found but double quotes preferred

Replace single quotes with double quotes

(Q000)


58-58: Single quotes found but double quotes preferred

Replace single quotes with double quotes

(Q000)


59-59: Single quotes found but double quotes preferred

Replace single quotes with double quotes

(Q000)


60-60: Single quotes found but double quotes preferred

Replace single quotes with double quotes

(Q000)


60-60: Single quotes found but double quotes preferred

Replace single quotes with double quotes

(Q000)


63-63: Single quotes found but double quotes preferred

Replace single quotes with double quotes

(Q000)


64-64: Single quotes found but double quotes preferred

Replace single quotes with double quotes

(Q000)


65-65: Single quotes found but double quotes preferred

Replace single quotes with double quotes

(Q000)


65-65: Single quotes found but double quotes preferred

Replace single quotes with double quotes

(Q000)


68-68: Single quotes found but double quotes preferred

Replace single quotes with double quotes

(Q000)


69-69: Single quotes found but double quotes preferred

Replace single quotes with double quotes

(Q000)


70-70: Single quotes found but double quotes preferred

Replace single quotes with double quotes

(Q000)


73-73: Single quotes found but double quotes preferred

Replace single quotes with double quotes

(Q000)


74-74: Single quotes found but double quotes preferred

Replace single quotes with double quotes

(Q000)


75-75: Single quotes found but double quotes preferred

Replace single quotes with double quotes

(Q000)


75-75: Single quotes found but double quotes preferred

Replace single quotes with double quotes

(Q000)


78-78: Single quotes found but double quotes preferred

Replace single quotes with double quotes

(Q000)


79-79: Single quotes found but double quotes preferred

Replace single quotes with double quotes

(Q000)


80-80: Single quotes found but double quotes preferred

Replace single quotes with double quotes

(Q000)


83-83: Single quotes found but double quotes preferred

Replace single quotes with double quotes

(Q000)


84-84: Single quotes found but double quotes preferred

Replace single quotes with double quotes

(Q000)


85-85: Single quotes found but double quotes preferred

Replace single quotes with double quotes

(Q000)


85-85: Single quotes found but double quotes preferred

Replace single quotes with double quotes

(Q000)


88-88: Single quotes found but double quotes preferred

Replace single quotes with double quotes

(Q000)


89-89: Single quotes found but double quotes preferred

Replace single quotes with double quotes

(Q000)


90-90: Single quotes found but double quotes preferred

Replace single quotes with double quotes

(Q000)


90-90: Single quotes found but double quotes preferred

Replace single quotes with double quotes

(Q000)


93-93: Single quotes found but double quotes preferred

Replace single quotes with double quotes

(Q000)


94-94: Single quotes found but double quotes preferred

Replace single quotes with double quotes

(Q000)


95-95: Single quotes found but double quotes preferred

Replace single quotes with double quotes

(Q000)


95-95: Single quotes found but double quotes preferred

Replace single quotes with double quotes

(Q000)


98-98: Single quotes found but double quotes preferred

Replace single quotes with double quotes

(Q000)


99-99: Single quotes found but double quotes preferred

Replace single quotes with double quotes

(Q000)


100-100: Single quotes found but double quotes preferred

Replace single quotes with double quotes

(Q000)


103-103: Single quotes found but double quotes preferred

Replace single quotes with double quotes

(Q000)


104-104: Single quotes found but double quotes preferred

Replace single quotes with double quotes

(Q000)


105-105: Single quotes found but double quotes preferred

Replace single quotes with double quotes

(Q000)


105-105: Single quotes found but double quotes preferred

Replace single quotes with double quotes

(Q000)


108-108: Single quotes found but double quotes preferred

Replace single quotes with double quotes

(Q000)


109-109: Single quotes found but double quotes preferred

Replace single quotes with double quotes

(Q000)


110-110: Single quotes found but double quotes preferred

Replace single quotes with double quotes

(Q000)


113-113: Single quotes found but double quotes preferred

Replace single quotes with double quotes

(Q000)


114-114: Single quotes found but double quotes preferred

Replace single quotes with double quotes

(Q000)


115-115: Single quotes found but double quotes preferred

Replace single quotes with double quotes

(Q000)


115-115: Single quotes found but double quotes preferred

Replace single quotes with double quotes

(Q000)


118-118: Single quotes found but double quotes preferred

Replace single quotes with double quotes

(Q000)


119-119: Single quotes found but double quotes preferred

Replace single quotes with double quotes

(Q000)


120-120: Single quotes found but double quotes preferred

Replace single quotes with double quotes

(Q000)


120-120: Single quotes found but double quotes preferred

Replace single quotes with double quotes

(Q000)

care/emr/resources/specimen/spec.py (1)

233-236: Specify optional field types explicitly for clarity

The note field has a default value of None, but its type is Annotation without indicating that it's optional. To enhance code clarity and prevent potential issues, consider specifying the field type as Annotation | None.

Apply this diff to update the field type:

-    note: Annotation = Field(
+    note: Annotation | None = Field(
         default=None,
         description="Comments made about the specimen while received at the laboratory",
     )
care/emr/api/viewsets/service_request.py (1)

19-23: Confirm user authentication before accessing external_id

Assigning clean_data["requester"] = request.user.external_id assumes that the user is authenticated. Although the viewset likely enforces authentication, it's prudent to ensure that request.user is indeed an authenticated user to prevent potential exceptions.

Consider adding an assertion or condition:

 def clean_create_data(self, request, *args, **kwargs):
     clean_data = super().clean_create_data(request, *args, **kwargs)

+    assert request.user.is_authenticated, "User must be authenticated"
     clean_data["requester"] = request.user.external_id
     return clean_data
care/emr/resources/diagnostic_report/valueset.py (1)

11-19: I see we're being quite... generous with our code acceptance

While using the HL7 v2-0074 system is correct, the valueset accepts any code from it without constraints. It might be nice to specify which diagnostic report categories we actually support.

Consider adding specific codes to the include:

 ValueSetInclude(
     system="http://terminology.hl7.org/CodeSystem/v2-0074",
+    concept=[
+        {"code": "LAB", "display": "Laboratory"},
+        {"code": "RAD", "display": "Radiology"}
+    ]
 )
care/emr/resources/specimen/valueset.py (2)

13-15: Mysterious SNOMED CT concepts

I see we're using SNOMED CT concept "123038009", but what does it mean? I'm sure everyone just memorizes SNOMED CT codes in their spare time, but maybe we could add a comment?

Consider adding a descriptive comment:

 system="http://snomed.info/sct",
-filter=[{"property": "concept", "op": "is-a", "value": "123038009"}],
+# 123038009 represents "Specimen (specimen)"
+filter=[{"property": "concept", "op": "is-a", "value": "123038009"}],

50-52: Living dangerously with unversioned terminology

Using HL7 terminology without version constraints? That's... brave. What could possibly go wrong?

Consider adding version constraints:

 ValueSetInclude(
     system="http://terminology.hl7.org/CodeSystem/v2-0493",
+    version="2.9.0"  # or whichever version you're targeting
 )
care/emr/models/service_request.py (1)

40-42: That TODO comment looks quite comfortable there

The TODO comment about making location a foreign key should probably be addressed sooner rather than later. Would you like me to help create an issue for tracking this?

care/emr/resources/service_request/valueset.py (2)

33-39: Ah, mysterious SNOMED CT codes without comments. How... cryptic.

These SNOMED CT codes would benefit from comments explaining their meanings. Not everyone memorizes medical codes in their spare time.

                 concept=[
-                    {"code": "108252007"},
-                    {"code": "363679005"},
-                    {"code": "409063005"},
-                    {"code": "409073007"},
-                    {"code": "387713003"},
+                    {"code": "108252007"},  # Laboratory procedure
+                    {"code": "363679005"},  # Imaging
+                    {"code": "409063005"},  # Counseling
+                    {"code": "409073007"},  # Education
+                    {"code": "387713003"},  # Surgical procedure
                 ],

13-14: Three different places for the same URLs? How... interesting.

Consider centralizing these system URLs in a constants file to avoid potential typos and make updates easier.

Create a new file care/emr/constants.py:

class TerminologySystem:
    LOINC = "http://loinc.org"
    SNOMED = "http://snomed.info/sct"

Also applies to: 32-32, 57-58

care/emr/migrations/0006_specimen.py (1)

31-31: Add index to collected_at field for better query performance.

Since collected_at is likely to be frequently queried for filtering and sorting specimens, it should be indexed.

Apply this diff:

-        ('collected_at', models.DateTimeField(blank=True, null=True)),
+        ('collected_at', models.DateTimeField(blank=True, db_index=True, null=True)),
🧰 Tools
🪛 Ruff (0.8.0)

31-31: Single quotes found but double quotes preferred

Replace single quotes with double quotes

(Q000)

care/emr/migrations/0005_servicerequest.py (1)

34-35: Add indexes to datetime fields for query optimization.

The occurrence_datetime and authored_on fields are likely to be frequently queried for filtering and sorting service requests. Consider adding indexes to improve query performance.

Apply this diff:

-        ('occurrence_datetime', models.DateTimeField(blank=True, null=True)),
+        ('occurrence_datetime', models.DateTimeField(blank=True, db_index=True, null=True)),
-        ('authored_on', models.DateTimeField(blank=True, null=True)),
+        ('authored_on', models.DateTimeField(blank=True, db_index=True, null=True)),

Also applies to: 38-38

🧰 Tools
🪛 Ruff (0.8.0)

34-34: Single quotes found but double quotes preferred

Replace single quotes with double quotes

(Q000)


35-35: Single quotes found but double quotes preferred

Replace single quotes with double quotes

(Q000)

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between 87ba737 and 97a0fcd.

📒 Files selected for processing (23)
  • care/emr/api/viewsets/diagnostic_report.py (1 hunks)
  • care/emr/api/viewsets/service_request.py (1 hunks)
  • care/emr/api/viewsets/specimen.py (1 hunks)
  • care/emr/apps.py (1 hunks)
  • care/emr/fhir/resources/concept_map.py (1 hunks)
  • care/emr/fhir/utils.py (1 hunks)
  • care/emr/migrations/0005_servicerequest.py (1 hunks)
  • care/emr/migrations/0006_specimen.py (1 hunks)
  • care/emr/migrations/0018_merge_0006_specimen_0017_alter_questionnaire_slug.py (1 hunks)
  • care/emr/migrations/0019_diagnosticreport.py (1 hunks)
  • care/emr/migrations/0020_servicerequest_location_specimen_condition_and_more.py (1 hunks)
  • care/emr/models/diagnostic_report.py (1 hunks)
  • care/emr/models/service_request.py (1 hunks)
  • care/emr/models/specimen.py (1 hunks)
  • care/emr/resources/diagnostic_report/spec.py (1 hunks)
  • care/emr/resources/diagnostic_report/valueset.py (1 hunks)
  • care/emr/resources/service_request/spec.py (1 hunks)
  • care/emr/resources/service_request/valueset.py (1 hunks)
  • care/emr/resources/specimen/spec.py (1 hunks)
  • care/emr/resources/specimen/valueset.py (1 hunks)
  • care/emr/signals/__init__.py (1 hunks)
  • care/emr/signals/auto_create_specimen.py (1 hunks)
  • config/api_router.py (2 hunks)
✅ Files skipped from review due to trivial changes (1)
  • care/emr/signals/init.py
🧰 Additional context used
🪛 Ruff (0.8.0)
care/emr/migrations/0005_servicerequest.py

12-12: Single quotes found but double quotes preferred

Replace single quotes with double quotes

(Q000)


12-12: Single quotes found but double quotes preferred

Replace single quotes with double quotes

(Q000)


13-13: Single quotes found but double quotes preferred

Replace single quotes with double quotes

(Q000)


13-13: Single quotes found but double quotes preferred

Replace single quotes with double quotes

(Q000)


19-19: Single quotes found but double quotes preferred

Replace single quotes with double quotes

(Q000)


21-21: Single quotes found but double quotes preferred

Replace single quotes with double quotes

(Q000)


21-21: Single quotes found but double quotes preferred

Replace single quotes with double quotes

(Q000)


22-22: Single quotes found but double quotes preferred

Replace single quotes with double quotes

(Q000)


23-23: Single quotes found but double quotes preferred

Replace single quotes with double quotes

(Q000)


24-24: Single quotes found but double quotes preferred

Replace single quotes with double quotes

(Q000)


25-25: Single quotes found but double quotes preferred

Replace single quotes with double quotes

(Q000)


26-26: Single quotes found but double quotes preferred

Replace single quotes with double quotes

(Q000)


27-27: Single quotes found but double quotes preferred

Replace single quotes with double quotes

(Q000)


28-28: Single quotes found but double quotes preferred

Replace single quotes with double quotes

(Q000)


29-29: Single quotes found but double quotes preferred

Replace single quotes with double quotes

(Q000)


30-30: Single quotes found but double quotes preferred

Replace single quotes with double quotes

(Q000)


31-31: Single quotes found but double quotes preferred

Replace single quotes with double quotes

(Q000)


32-32: Single quotes found but double quotes preferred

Replace single quotes with double quotes

(Q000)


33-33: Single quotes found but double quotes preferred

Replace single quotes with double quotes

(Q000)


34-34: Single quotes found but double quotes preferred

Replace single quotes with double quotes

(Q000)


35-35: Single quotes found but double quotes preferred

Replace single quotes with double quotes

(Q000)


36-36: Single quotes found but double quotes preferred

Replace single quotes with double quotes

(Q000)


37-37: Single quotes found but double quotes preferred

Replace single quotes with double quotes

(Q000)


38-38: Single quotes found but double quotes preferred

Replace single quotes with double quotes

(Q000)


39-39: Single quotes found but double quotes preferred

Replace single quotes with double quotes

(Q000)


40-40: Single quotes found but double quotes preferred

Replace single quotes with double quotes

(Q000)


41-41: Single quotes found but double quotes preferred

Replace single quotes with double quotes

(Q000)


41-41: Single quotes found but double quotes preferred

Replace single quotes with double quotes

(Q000)


42-42: Single quotes found but double quotes preferred

Replace single quotes with double quotes

(Q000)


42-42: Single quotes found but double quotes preferred

Replace single quotes with double quotes

(Q000)


43-43: Single quotes found but double quotes preferred

Replace single quotes with double quotes

(Q000)


44-44: Single quotes found but double quotes preferred

Replace single quotes with double quotes

(Q000)


44-44: Single quotes found but double quotes preferred

Replace single quotes with double quotes

(Q000)


47-47: Single quotes found but double quotes preferred

Replace single quotes with double quotes

(Q000)

care/emr/migrations/0006_specimen.py

12-12: Single quotes found but double quotes preferred

Replace single quotes with double quotes

(Q000)


12-12: Single quotes found but double quotes preferred

Replace single quotes with double quotes

(Q000)


13-13: Single quotes found but double quotes preferred

Replace single quotes with double quotes

(Q000)


13-13: Single quotes found but double quotes preferred

Replace single quotes with double quotes

(Q000)


19-19: Single quotes found but double quotes preferred

Replace single quotes with double quotes

(Q000)


21-21: Single quotes found but double quotes preferred

Replace single quotes with double quotes

(Q000)


21-21: Single quotes found but double quotes preferred

Replace single quotes with double quotes

(Q000)


22-22: Single quotes found but double quotes preferred

Replace single quotes with double quotes

(Q000)


23-23: Single quotes found but double quotes preferred

Replace single quotes with double quotes

(Q000)


24-24: Single quotes found but double quotes preferred

Replace single quotes with double quotes

(Q000)


25-25: Single quotes found but double quotes preferred

Replace single quotes with double quotes

(Q000)


26-26: Single quotes found but double quotes preferred

Replace single quotes with double quotes

(Q000)


27-27: Single quotes found but double quotes preferred

Replace single quotes with double quotes

(Q000)


28-28: Single quotes found but double quotes preferred

Replace single quotes with double quotes

(Q000)


29-29: Single quotes found but double quotes preferred

Replace single quotes with double quotes

(Q000)


30-30: Single quotes found but double quotes preferred

Replace single quotes with double quotes

(Q000)


31-31: Single quotes found but double quotes preferred

Replace single quotes with double quotes

(Q000)


32-32: Single quotes found but double quotes preferred

Replace single quotes with double quotes

(Q000)


33-33: Single quotes found but double quotes preferred

Replace single quotes with double quotes

(Q000)


34-34: Single quotes found but double quotes preferred

Replace single quotes with double quotes

(Q000)


35-35: Single quotes found but double quotes preferred

Replace single quotes with double quotes

(Q000)


35-35: Single quotes found but double quotes preferred

Replace single quotes with double quotes

(Q000)


36-36: Single quotes found but double quotes preferred

Replace single quotes with double quotes

(Q000)


36-36: Single quotes found but double quotes preferred

Replace single quotes with double quotes

(Q000)


39-39: Single quotes found but double quotes preferred

Replace single quotes with double quotes

(Q000)

care/emr/migrations/0019_diagnosticreport.py

12-12: Single quotes found but double quotes preferred

Replace single quotes with double quotes

(Q000)


12-12: Single quotes found but double quotes preferred

Replace single quotes with double quotes

(Q000)


13-13: Single quotes found but double quotes preferred

Replace single quotes with double quotes

(Q000)


13-13: Single quotes found but double quotes preferred

Replace single quotes with double quotes

(Q000)


19-19: Single quotes found but double quotes preferred

Replace single quotes with double quotes

(Q000)


21-21: Single quotes found but double quotes preferred

Replace single quotes with double quotes

(Q000)


21-21: Single quotes found but double quotes preferred

Replace single quotes with double quotes

(Q000)


22-22: Single quotes found but double quotes preferred

Replace single quotes with double quotes

(Q000)


23-23: Single quotes found but double quotes preferred

Replace single quotes with double quotes

(Q000)


24-24: Single quotes found but double quotes preferred

Replace single quotes with double quotes

(Q000)


25-25: Single quotes found but double quotes preferred

Replace single quotes with double quotes

(Q000)


26-26: Single quotes found but double quotes preferred

Replace single quotes with double quotes

(Q000)


27-27: Single quotes found but double quotes preferred

Replace single quotes with double quotes

(Q000)


28-28: Single quotes found but double quotes preferred

Replace single quotes with double quotes

(Q000)


29-29: Single quotes found but double quotes preferred

Replace single quotes with double quotes

(Q000)


30-30: Single quotes found but double quotes preferred

Replace single quotes with double quotes

(Q000)


31-31: Single quotes found but double quotes preferred

Replace single quotes with double quotes

(Q000)


32-32: Single quotes found but double quotes preferred

Replace single quotes with double quotes

(Q000)


33-33: Single quotes found but double quotes preferred

Replace single quotes with double quotes

(Q000)


34-34: Single quotes found but double quotes preferred

Replace single quotes with double quotes

(Q000)


35-35: Single quotes found but double quotes preferred

Replace single quotes with double quotes

(Q000)


36-36: Single quotes found but double quotes preferred

Replace single quotes with double quotes

(Q000)


36-36: Single quotes found but double quotes preferred

Replace single quotes with double quotes

(Q000)


37-37: Single quotes found but double quotes preferred

Replace single quotes with double quotes

(Q000)


37-37: Single quotes found but double quotes preferred

Replace single quotes with double quotes

(Q000)


38-38: Single quotes found but double quotes preferred

Replace single quotes with double quotes

(Q000)


39-39: Single quotes found but double quotes preferred

Replace single quotes with double quotes

(Q000)


39-39: Single quotes found but double quotes preferred

Replace single quotes with double quotes

(Q000)


40-40: Single quotes found but double quotes preferred

Replace single quotes with double quotes

(Q000)


41-41: Single quotes found but double quotes preferred

Replace single quotes with double quotes

(Q000)


41-41: Single quotes found but double quotes preferred

Replace single quotes with double quotes

(Q000)


42-42: Single quotes found but double quotes preferred

Replace single quotes with double quotes

(Q000)


42-42: Single quotes found but double quotes preferred

Replace single quotes with double quotes

(Q000)


45-45: Single quotes found but double quotes preferred

Replace single quotes with double quotes

(Q000)

care/emr/migrations/0020_servicerequest_location_specimen_condition_and_more.py

11-11: Single quotes found but double quotes preferred

Replace single quotes with double quotes

(Q000)


11-11: Single quotes found but double quotes preferred

Replace single quotes with double quotes

(Q000)


12-12: Single quotes found but double quotes preferred

Replace single quotes with double quotes

(Q000)


12-12: Single quotes found but double quotes preferred

Replace single quotes with double quotes

(Q000)


18-18: Single quotes found but double quotes preferred

Replace single quotes with double quotes

(Q000)


19-19: Single quotes found but double quotes preferred

Replace single quotes with double quotes

(Q000)


23-23: Single quotes found but double quotes preferred

Replace single quotes with double quotes

(Q000)


24-24: Single quotes found but double quotes preferred

Replace single quotes with double quotes

(Q000)


28-28: Single quotes found but double quotes preferred

Replace single quotes with double quotes

(Q000)


29-29: Single quotes found but double quotes preferred

Replace single quotes with double quotes

(Q000)


33-33: Single quotes found but double quotes preferred

Replace single quotes with double quotes

(Q000)


34-34: Single quotes found but double quotes preferred

Replace single quotes with double quotes

(Q000)


35-35: Single quotes found but double quotes preferred

Replace single quotes with double quotes

(Q000)


38-38: Single quotes found but double quotes preferred

Replace single quotes with double quotes

(Q000)


39-39: Single quotes found but double quotes preferred

Replace single quotes with double quotes

(Q000)


43-43: Single quotes found but double quotes preferred

Replace single quotes with double quotes

(Q000)


44-44: Single quotes found but double quotes preferred

Replace single quotes with double quotes

(Q000)


45-45: Single quotes found but double quotes preferred

Replace single quotes with double quotes

(Q000)


48-48: Single quotes found but double quotes preferred

Replace single quotes with double quotes

(Q000)


49-49: Single quotes found but double quotes preferred

Replace single quotes with double quotes

(Q000)


53-53: Single quotes found but double quotes preferred

Replace single quotes with double quotes

(Q000)


54-54: Single quotes found but double quotes preferred

Replace single quotes with double quotes

(Q000)


55-55: Single quotes found but double quotes preferred

Replace single quotes with double quotes

(Q000)


58-58: Single quotes found but double quotes preferred

Replace single quotes with double quotes

(Q000)


59-59: Single quotes found but double quotes preferred

Replace single quotes with double quotes

(Q000)


60-60: Single quotes found but double quotes preferred

Replace single quotes with double quotes

(Q000)


60-60: Single quotes found but double quotes preferred

Replace single quotes with double quotes

(Q000)


63-63: Single quotes found but double quotes preferred

Replace single quotes with double quotes

(Q000)


64-64: Single quotes found but double quotes preferred

Replace single quotes with double quotes

(Q000)


65-65: Single quotes found but double quotes preferred

Replace single quotes with double quotes

(Q000)


65-65: Single quotes found but double quotes preferred

Replace single quotes with double quotes

(Q000)


68-68: Single quotes found but double quotes preferred

Replace single quotes with double quotes

(Q000)


69-69: Single quotes found but double quotes preferred

Replace single quotes with double quotes

(Q000)


70-70: Single quotes found but double quotes preferred

Replace single quotes with double quotes

(Q000)


73-73: Single quotes found but double quotes preferred

Replace single quotes with double quotes

(Q000)


74-74: Single quotes found but double quotes preferred

Replace single quotes with double quotes

(Q000)


75-75: Single quotes found but double quotes preferred

Replace single quotes with double quotes

(Q000)


75-75: Single quotes found but double quotes preferred

Replace single quotes with double quotes

(Q000)


78-78: Single quotes found but double quotes preferred

Replace single quotes with double quotes

(Q000)


79-79: Single quotes found but double quotes preferred

Replace single quotes with double quotes

(Q000)


80-80: Single quotes found but double quotes preferred

Replace single quotes with double quotes

(Q000)


83-83: Single quotes found but double quotes preferred

Replace single quotes with double quotes

(Q000)


84-84: Single quotes found but double quotes preferred

Replace single quotes with double quotes

(Q000)


85-85: Single quotes found but double quotes preferred

Replace single quotes with double quotes

(Q000)


85-85: Single quotes found but double quotes preferred

Replace single quotes with double quotes

(Q000)


88-88: Single quotes found but double quotes preferred

Replace single quotes with double quotes

(Q000)


89-89: Single quotes found but double quotes preferred

Replace single quotes with double quotes

(Q000)


90-90: Single quotes found but double quotes preferred

Replace single quotes with double quotes

(Q000)


90-90: Single quotes found but double quotes preferred

Replace single quotes with double quotes

(Q000)


93-93: Single quotes found but double quotes preferred

Replace single quotes with double quotes

(Q000)


94-94: Single quotes found but double quotes preferred

Replace single quotes with double quotes

(Q000)


95-95: Single quotes found but double quotes preferred

Replace single quotes with double quotes

(Q000)


95-95: Single quotes found but double quotes preferred

Replace single quotes with double quotes

(Q000)


98-98: Single quotes found but double quotes preferred

Replace single quotes with double quotes

(Q000)


99-99: Single quotes found but double quotes preferred

Replace single quotes with double quotes

(Q000)


100-100: Single quotes found but double quotes preferred

Replace single quotes with double quotes

(Q000)


103-103: Single quotes found but double quotes preferred

Replace single quotes with double quotes

(Q000)


104-104: Single quotes found but double quotes preferred

Replace single quotes with double quotes

(Q000)


105-105: Single quotes found but double quotes preferred

Replace single quotes with double quotes

(Q000)


105-105: Single quotes found but double quotes preferred

Replace single quotes with double quotes

(Q000)


108-108: Single quotes found but double quotes preferred

Replace single quotes with double quotes

(Q000)


109-109: Single quotes found but double quotes preferred

Replace single quotes with double quotes

(Q000)


110-110: Single quotes found but double quotes preferred

Replace single quotes with double quotes

(Q000)


113-113: Single quotes found but double quotes preferred

Replace single quotes with double quotes

(Q000)


114-114: Single quotes found but double quotes preferred

Replace single quotes with double quotes

(Q000)


115-115: Single quotes found but double quotes preferred

Replace single quotes with double quotes

(Q000)


115-115: Single quotes found but double quotes preferred

Replace single quotes with double quotes

(Q000)


118-118: Single quotes found but double quotes preferred

Replace single quotes with double quotes

(Q000)


119-119: Single quotes found but double quotes preferred

Replace single quotes with double quotes

(Q000)


120-120: Single quotes found but double quotes preferred

Replace single quotes with double quotes

(Q000)


120-120: Single quotes found but double quotes preferred

Replace single quotes with double quotes

(Q000)

care/emr/migrations/0018_merge_0006_specimen_0017_alter_questionnaire_slug.py

9-9: Single quotes found but double quotes preferred

Replace single quotes with double quotes

(Q000)


9-9: Single quotes found but double quotes preferred

Replace single quotes with double quotes

(Q000)


10-10: Single quotes found but double quotes preferred

Replace single quotes with double quotes

(Q000)


10-10: Single quotes found but double quotes preferred

Replace single quotes with double quotes

(Q000)

🔇 Additional comments (11)
care/emr/api/viewsets/diagnostic_report.py (1)

30-57: LGTM

The observations method is well implemented and correctly handles the creation of observations associated with the diagnostic report.

care/emr/migrations/0019_diagnosticreport.py (1)

1-48: Ignore style warnings in auto-generated migration files

Static analysis suggests replacing single quotes with double quotes. While this is accurate, since this migration file is auto-generated by Django, it's advisable to leave it as is to avoid any unnecessary complications.

🧰 Tools
🪛 Ruff (0.8.0)

12-12: Single quotes found but double quotes preferred

Replace single quotes with double quotes

(Q000)


12-12: Single quotes found but double quotes preferred

Replace single quotes with double quotes

(Q000)


13-13: Single quotes found but double quotes preferred

Replace single quotes with double quotes

(Q000)


13-13: Single quotes found but double quotes preferred

Replace single quotes with double quotes

(Q000)


19-19: Single quotes found but double quotes preferred

Replace single quotes with double quotes

(Q000)


21-21: Single quotes found but double quotes preferred

Replace single quotes with double quotes

(Q000)


21-21: Single quotes found but double quotes preferred

Replace single quotes with double quotes

(Q000)


22-22: Single quotes found but double quotes preferred

Replace single quotes with double quotes

(Q000)


23-23: Single quotes found but double quotes preferred

Replace single quotes with double quotes

(Q000)


24-24: Single quotes found but double quotes preferred

Replace single quotes with double quotes

(Q000)


25-25: Single quotes found but double quotes preferred

Replace single quotes with double quotes

(Q000)


26-26: Single quotes found but double quotes preferred

Replace single quotes with double quotes

(Q000)


27-27: Single quotes found but double quotes preferred

Replace single quotes with double quotes

(Q000)


28-28: Single quotes found but double quotes preferred

Replace single quotes with double quotes

(Q000)


29-29: Single quotes found but double quotes preferred

Replace single quotes with double quotes

(Q000)


30-30: Single quotes found but double quotes preferred

Replace single quotes with double quotes

(Q000)


31-31: Single quotes found but double quotes preferred

Replace single quotes with double quotes

(Q000)


32-32: Single quotes found but double quotes preferred

Replace single quotes with double quotes

(Q000)


33-33: Single quotes found but double quotes preferred

Replace single quotes with double quotes

(Q000)


34-34: Single quotes found but double quotes preferred

Replace single quotes with double quotes

(Q000)


35-35: Single quotes found but double quotes preferred

Replace single quotes with double quotes

(Q000)


36-36: Single quotes found but double quotes preferred

Replace single quotes with double quotes

(Q000)


36-36: Single quotes found but double quotes preferred

Replace single quotes with double quotes

(Q000)


37-37: Single quotes found but double quotes preferred

Replace single quotes with double quotes

(Q000)


37-37: Single quotes found but double quotes preferred

Replace single quotes with double quotes

(Q000)


38-38: Single quotes found but double quotes preferred

Replace single quotes with double quotes

(Q000)


39-39: Single quotes found but double quotes preferred

Replace single quotes with double quotes

(Q000)


39-39: Single quotes found but double quotes preferred

Replace single quotes with double quotes

(Q000)


40-40: Single quotes found but double quotes preferred

Replace single quotes with double quotes

(Q000)


41-41: Single quotes found but double quotes preferred

Replace single quotes with double quotes

(Q000)


41-41: Single quotes found but double quotes preferred

Replace single quotes with double quotes

(Q000)


42-42: Single quotes found but double quotes preferred

Replace single quotes with double quotes

(Q000)


42-42: Single quotes found but double quotes preferred

Replace single quotes with double quotes

(Q000)


45-45: Single quotes found but double quotes preferred

Replace single quotes with double quotes

(Q000)

care/emr/api/viewsets/specimen.py (1)

104-104: Confirm Append Operation on specimen.note

Ensure that specimen.note is initialized as a list before appending to it. If specimen.note can be None, this might raise an exception.

Double-check the initialization of specimen.note to prevent a potential AttributeError.

care/emr/resources/service_request/spec.py (2)

179-179: Data Type Flexibility for code Field

As previously mentioned, the code field could accept a dict in addition to a Coding instance to provide flexibility in how the data is passed.


168-168: Potential Issue with requester Field Assignment

Ensure that self.requester contains a valid UUID that corresponds to an existing User. If self.requester is not provided or invalid, this will raise an exception.

Confirm that self.requester is always provided and valid, or add appropriate error handling.

care/emr/resources/diagnostic_report/spec.py (1)

149-166: Avoid calling obj.save() within perform_extra_deserialization

Calling obj.save() inside perform_extra_deserialization can lead to unexpected behavior, especially if this method is intended only for deserialization logic. It's better to handle object saving outside this method to maintain clean separation of concerns.

care/emr/apps.py (1)

9-10: Import signals in ready method cautiously

While importing care.emr.signals in the ready method registers your signal handlers appropriately, ensure that the import doesn't inadvertently execute code that should only run once or under specific conditions.

care/emr/resources/diagnostic_report/valueset.py (1)

29-37: Oh, interesting choice with the LOINC system

Using LOINC is perfect for diagnostic report codes, but accepting any LOINC code might be a bit... adventurous. Perhaps we could be more specific about which codes are relevant to our use case?

Let's check if other parts of the codebase have any LOINC code restrictions:

Consider adding specific LOINC codes that are relevant to your diagnostic reports.

✅ Verification successful

Let's see if there are any specific LOINC code patterns or validations being enforced elsewhere in the codebase.


Well, it seems our LOINC implementation is... consistently unrestricted

Looking at the codebase, I notice we're quite... generous with our LOINC code acceptance everywhere. The pattern of unrestricted LOINC systems appears in observations, service requests, and diagnostic reports. While it's not technically wrong, it's just interesting how we're trusting all LOINC codes equally.

  • care/emr/resources/observation/valueset.py uses unrestricted LOINC
  • care/emr/resources/service_request/valueset.py follows the same pattern
  • care/emr/signals/auto_create_specimen.py does filter specific codes, but only for specimen creation

The current implementation aligns with the codebase's general approach, so while my suggestion about restricting codes remains valid for future improvements, it's not inconsistent with the existing patterns.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Search for LOINC code validations or restrictions
rg -i "loinc" --type py

Length of output: 889


Script:

#!/bin/bash
# Let's check if there are any specific LOINC codes being used or validated
rg -i "loinc.*code" -B 2 -A 2 --type py

# Also check for any code validation patterns
ast-grep --pattern 'system = "http://loinc.org"' 
ast-grep --pattern 'system="http://loinc.org"'

Length of output: 1009

config/api_router.py (1)

164-168: LGTM! The route registrations follow existing patterns.

The new routes for service requests, specimens, and diagnostic reports are properly registered with consistent naming conventions and URL patterns.

care/emr/migrations/0018_merge_0006_specimen_0017_alter_questionnaire_slug.py (2)

6-14: LGTM! The merge migration looks... adequate.

The migration structure follows Django's conventions for merge migrations, with the expected empty operations list. I suppose we can't ask for more from an auto-generated file.

🧰 Tools
🪛 Ruff (0.8.0)

9-9: Single quotes found but double quotes preferred

Replace single quotes with double quotes

(Q000)


9-9: Single quotes found but double quotes preferred

Replace single quotes with double quotes

(Q000)


10-10: Single quotes found but double quotes preferred

Replace single quotes with double quotes

(Q000)


10-10: Single quotes found but double quotes preferred

Replace single quotes with double quotes

(Q000)


8-11: Verify migration dependencies order

Let's make absolutely sure these migrations are in the correct order, shall we? We wouldn't want any... unfortunate surprises during deployment.

✅ Verification successful

Migration dependencies look... perfectly fine, actually

The dependencies form a clear, linear progression:

  • 0006_specimen.py depends on 0005_servicerequest
  • 0017_alter_questionnaire_slug.py depends on 0016_questionnaire_slug
  • Both parent migrations exist and have their own valid dependency chains
  • The merge migration 0018 correctly combines these two parallel branches

Perhaps the concern was unnecessary, but better safe than sorry, right?

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify migration dependencies and detect potential conflicts

# Check for any circular dependencies or ordering issues
fd --extension py . care/emr/migrations/ --exec grep -l "class Migration" {} \; | while read -r file; do
    echo "=== $file ==="
    grep -A 5 "dependencies = \[" "$file"
done

# Verify that both parent migrations exist
if ! [ -f "care/emr/migrations/0006_specimen.py" ]; then
    echo "ERROR: Missing parent migration 0006_specimen.py"
fi
if ! [ -f "care/emr/migrations/0017_alter_questionnaire_slug.py" ]; then
    echo "ERROR: Missing parent migration 0017_alter_questionnaire_slug.py"
fi

Length of output: 8581

🧰 Tools
🪛 Ruff (0.8.0)

9-9: Single quotes found but double quotes preferred

Replace single quotes with double quotes

(Q000)


9-9: Single quotes found but double quotes preferred

Replace single quotes with double quotes

(Q000)


10-10: Single quotes found but double quotes preferred

Replace single quotes with double quotes

(Q000)


10-10: Single quotes found but double quotes preferred

Replace single quotes with double quotes

(Q000)

Comment on lines +43 to +46
if len(specimen_matches) == 0:
return ValidationError(
f"No Specimen found for the given Service Request code {instance.code}"
)
Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue

Raise exceptions instead of returning them

The ValidationError should be raised, not returned, to properly signal an error condition.

Apply the following diff to fix the issue:

-        return ValidationError(
+        raise ValidationError(
             f"No Specimen found for the given Service Request code {instance.code}"
         )
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
if len(specimen_matches) == 0:
return ValidationError(
f"No Specimen found for the given Service Request code {instance.code}"
)
if len(specimen_matches) == 0:
raise ValidationError(
f"No Specimen found for the given Service Request code {instance.code}"
)


from pydantic.main import BaseModel

from care.emr.fhir.resources.base import ResourceManger
Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue

Typo: ResourceManger should be ResourceManager

It seems that ResourceManger is misspelled in both the import statement and the class definition. Correcting this will prevent potential ImportErrors and ensure consistency.

Apply this diff to fix the typo:

-from care.emr.fhir.resources.base import ResourceManger
+from care.emr.fhir.resources.base import ResourceManager

...

-class ConceptMapResource(ResourceManger):
+class ConceptMapResource(ResourceManager):

Also applies to: 9-9

@@ -0,0 +1,142 @@
from datetime import UTC, datetime
Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue

Ensure Compatibility of datetime.now(UTC)

The use of UTC from the datetime module requires Python 3.11 or later. To maintain compatibility with earlier versions, consider importing timezone from datetime and using timezone.utc.

Apply this diff to ensure compatibility:

-from datetime import UTC, datetime
+from datetime import datetime, timezone

...

-    specimen.collected_at = datetime.now(UTC)
+    specimen.collected_at = datetime.now(timezone.utc)

...

-    specimen.dispatched_at = datetime.now(UTC)
+    specimen.dispatched_at = datetime.now(timezone.utc)

...

-    specimen.received_at = datetime.now(UTC)
+    specimen.received_at = datetime.now(timezone.utc)

...

-            note.time = DateTime(datetime.now(UTC).isoformat())
+            note.time = DateTime(datetime.now(timezone.utc).isoformat())

...

-                if not process.time:
-                    process.time = datetime.now(UTC)
+                if not process.time:
+                    process.time = datetime.now(timezone.utc)

Also applies to: 52-52, 74-74, 99-99, 103-103, 127-127

Comment on lines 145 to 146
"category", cls.model_fields["category"].json_schema_extra["slug"], value
)
Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue

Handling of None Values in Validators

The validators for category, code, and as_needed_for do not account for None values. This could raise a TypeError if these fields are optional and None is passed.

Modify the validators to handle None values gracefully:

 @field_validator("category")
 @classmethod
 def validate_category(cls, value: str):
+    if value is None:
+        return value
     return validate_valueset(
         "category", cls.model_fields["category"].json_schema_extra["slug"], value
     )

Repeat similar adjustments for validate_code and validate_as_needed_for.

Also applies to: 152-153, 159-162

Comment on lines 25 to 30
if "valueBoolean" in parameter:
value = parameter["valueBoolean"]
if "valueCode" in parameter:
value = parameter["valueCode"]
if "valueCoding" in parameter:
value = parameter["valueCoding"]
Copy link

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

How trusting of our input data

While adding support for new value types is great, we might want to add some validation. You know, just in case someone sends us something... unexpected.

Consider adding type validation and error handling:

 if "valueBoolean" in parameter:
+    if not isinstance(parameter["valueBoolean"], bool):
+        raise ValueError(f"Expected boolean value, got {type(parameter['valueBoolean'])}")
     value = parameter["valueBoolean"]

Committable suggestion skipped: line range outside the PR's diff.

Comment on lines +10 to +12
status = models.CharField(max_length=100, null=True, blank=True)
intent = models.CharField(max_length=100, null=True, blank=True)
priority = models.CharField(max_length=100, null=True, blank=True)
Copy link

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

I see we're being quite... flexible with our data validation

The status, intent, and priority fields could benefit from some constraints. Perhaps we could add choices to prevent invalid values? Just a thought.

-    status = models.CharField(max_length=100, null=True, blank=True)
-    intent = models.CharField(max_length=100, null=True, blank=True)
-    priority = models.CharField(max_length=100, null=True, blank=True)
+    STATUS_CHOICES = [
+        ('draft', 'Draft'),
+        ('active', 'Active'),
+        ('completed', 'Completed'),
+        ('cancelled', 'Cancelled'),
+    ]
+    INTENT_CHOICES = [
+        ('proposal', 'Proposal'),
+        ('plan', 'Plan'),
+        ('order', 'Order'),
+    ]
+    PRIORITY_CHOICES = [
+        ('routine', 'Routine'),
+        ('urgent', 'Urgent'),
+        ('asap', 'ASAP'),
+        ('stat', 'STAT'),
+    ]
+    status = models.CharField(max_length=100, choices=STATUS_CHOICES)
+    intent = models.CharField(max_length=100, choices=INTENT_CHOICES)
+    priority = models.CharField(max_length=100, choices=PRIORITY_CHOICES)
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
status = models.CharField(max_length=100, null=True, blank=True)
intent = models.CharField(max_length=100, null=True, blank=True)
priority = models.CharField(max_length=100, null=True, blank=True)
STATUS_CHOICES = [
('draft', 'Draft'),
('active', 'Active'),
('completed', 'Completed'),
('cancelled', 'Cancelled'),
]
INTENT_CHOICES = [
('proposal', 'Proposal'),
('plan', 'Plan'),
('order', 'Order'),
]
PRIORITY_CHOICES = [
('routine', 'Routine'),
('urgent', 'Urgent'),
('asap', 'ASAP'),
('stat', 'STAT'),
]
status = models.CharField(max_length=100, choices=STATUS_CHOICES)
intent = models.CharField(max_length=100, choices=INTENT_CHOICES)
priority = models.CharField(max_length=100, choices=PRIORITY_CHOICES)

Comment on lines +33 to +51
collected_at = models.DateTimeField(null=True, blank=True)

dispatched_by = models.ForeignKey(
User,
on_delete=models.CASCADE,
null=True,
blank=True,
related_name="dispatched_specimen",
)
dispatched_at = models.DateTimeField(null=True, blank=True)

received_by = models.ForeignKey(
User,
on_delete=models.CASCADE,
null=True,
blank=True,
related_name="received_specimen",
)
received_at = models.DateTimeField(null=True, blank=True)
Copy link

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Timestamps without validation? Living dangerously, I see.

The collected, dispatched, and received timestamps should maintain a logical order.

Consider adding a custom clean method:

def clean(self):
    super().clean()
    if self.dispatched_at and self.collected_at and self.dispatched_at < self.collected_at:
        raise ValidationError("Specimen cannot be dispatched before collection")
    if self.received_at and self.dispatched_at and self.received_at < self.dispatched_at:
        raise ValidationError("Specimen cannot be received before dispatch")

identifier = models.CharField(max_length=100, null=True, blank=True)
accession_identifier = models.CharField(max_length=100, null=True, blank=True)

status = models.CharField(max_length=100, null=True, blank=True)
Copy link

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Another unrestricted status field? How... consistent.

The status field should have predefined choices to ensure valid transitions.

-    status = models.CharField(max_length=100, null=True, blank=True)
+    STATUS_CHOICES = [
+        ('available', 'Available'),
+        ('unavailable', 'Unavailable'),
+        ('unsatisfactory', 'Unsatisfactory'),
+        ('entered_in_error', 'Entered in Error'),
+    ]
+    status = models.CharField(max_length=100, choices=STATUS_CHOICES, default='available')
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
status = models.CharField(max_length=100, null=True, blank=True)
STATUS_CHOICES = [
('available', 'Available'),
('unavailable', 'Unavailable'),
('unsatisfactory', 'Unsatisfactory'),
('entered_in_error', 'Entered in Error'),
]
status = models.CharField(max_length=100, choices=STATUS_CHOICES, default='available')

Comment on lines +26 to +27
('history', models.JSONField(default=dict)),
('meta', models.JSONField(default=dict)),
Copy link

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Consider using immutable default values for JSON fields.

The history, processing, and note fields use mutable objects (dict and list) as default values, which could lead to shared state issues across instances.

Apply this diff to use immutable defaults:

-        ('history', models.JSONField(default=dict)),
+        ('history', models.JSONField(default=dict)),
-        ('processing', models.JSONField(blank=True, default=list, null=True)),
+        ('processing', models.JSONField(blank=True, default=list, null=True)),
-        ('note', models.JSONField(blank=True, default=list, null=True)),
+        ('note', models.JSONField(blank=True, default=list, null=True)),

Also applies to: 32-33, 39-40

🧰 Tools
🪛 Ruff (0.8.0)

26-26: Single quotes found but double quotes preferred

Replace single quotes with double quotes

(Q000)


27-27: Single quotes found but double quotes preferred

Replace single quotes with double quotes

(Q000)

Comment on lines +26 to +27
('history', models.JSONField(default=dict)),
('meta', models.JSONField(default=dict)),
Copy link

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Use immutable defaults for JSON fields to prevent shared state issues.

Several JSON fields use mutable objects as default values, which could lead to unexpected behavior.

Apply this diff:

-        ('history', models.JSONField(default=dict)),
+        ('history', models.JSONField(default=dict)),
-        ('code', models.JSONField(default=dict)),
+        ('code', models.JSONField(default=dict)),
-        ('occurrence_timing', models.JSONField(blank=True, default=dict, null=True)),
+        ('occurrence_timing', models.JSONField(blank=True, default=dict, null=True)),
-        ('as_needed_for', models.JSONField(blank=True, null=True)),
+        ('as_needed_for', models.JSONField(blank=True, default=dict, null=True)),
-        ('note', models.JSONField(blank=True, default=list, null=True)),
+        ('note', models.JSONField(blank=True, default=list, null=True)),

Also applies to: 32-32, 35-35, 37-37, 39-39

🧰 Tools
🪛 Ruff (0.8.0)

26-26: Single quotes found but double quotes preferred

Replace single quotes with double quotes

(Q000)


27-27: Single quotes found but double quotes preferred

Replace single quotes with double quotes

(Q000)

@yash-learner yash-learner mentioned this pull request Dec 9, 2024
14 tasks
Base automatically changed from vigneshhari/health-details to develop December 31, 2024 06:37
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