-
Notifications
You must be signed in to change notification settings - Fork 331
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
base: develop
Are you sure you want to change the base?
Labs #2642
Conversation
Important Review skippedDraft detected. Please check the settings in the CodeRabbit UI or the You can disable this status message by setting the 📝 Walkthrough📝 Walkthrough📝 WalkthroughWalkthroughThe changes introduce several new files and classes to enhance the functionality of the EMR system. Notable additions include Changes
Poem
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? 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
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)
Other keywords and placeholders
CodeRabbit Configuration File (
|
Codecov ReportAttention: Patch coverage is
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. |
external_id=self.results_interpreter | ||
) | ||
|
||
obj.save() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Dont call this here, if this is needed create a new abstraction for this.
priority: str | ||
|
||
category: Coding | None | ||
code: Coding |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can be dict as well
@coderabbitai reivew |
@vigneshhari: Sure, I'll take a look at your changes. ✅ Actions performedReview triggered.
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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 functionThe 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 commentThere'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 useon_delete=models.SET_NULL
forperformer
andresults_interpreter
Using
on_delete=models.CASCADE
could lead to unintended deletion ofDiagnosticReport
records if aUser
is deleted. Settingon_delete=models.SET_NULL
would preserve theDiagnosticReport
while allowing theUser
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 inget_object
MethodThe
Q
objects in theget_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 PreferredStatic 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 clarityThe
note
field has a default value ofNone
, but its type isAnnotation
without indicating that it's optional. To enhance code clarity and prevent potential issues, consider specifying the field type asAnnotation | 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 accessingexternal_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 thatrequest.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 acceptanceWhile 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 conceptsI 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 terminologyUsing 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 thereThe 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 tocollected_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
andauthored_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
📒 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 LOINCcare/emr/resources/service_request/valueset.py
follows the same patterncare/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 on0005_servicerequest
0017_alter_questionnaire_slug.py
depends on0016_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)
if len(specimen_matches) == 0: | ||
return ValidationError( | ||
f"No Specimen found for the given Service Request code {instance.code}" | ||
) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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 ImportError
s 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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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
"category", cls.model_fields["category"].json_schema_extra["slug"], value | ||
) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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
care/emr/fhir/utils.py
Outdated
if "valueBoolean" in parameter: | ||
value = parameter["valueBoolean"] | ||
if "valueCode" in parameter: | ||
value = parameter["valueCode"] | ||
if "valueCoding" in parameter: | ||
value = parameter["valueCoding"] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🛠️ 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.
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) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🛠️ 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.
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) |
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) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🛠️ 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) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🛠️ 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.
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') |
('history', models.JSONField(default=dict)), | ||
('meta', models.JSONField(default=dict)), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🛠️ 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)
('history', models.JSONField(default=dict)), | ||
('meta', models.JSONField(default=dict)), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🛠️ 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)
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
DiagnosticReportViewSet
,ServiceRequestViewSet
, andSpecimenViewSet
to manage diagnostic reports, service requests, and specimens, respectively.Bug Fixes
Documentation
Database Migrations
DiagnosticReport
,ServiceRequest
, andSpecimen
, along with necessary fields and relationships.