-
Notifications
You must be signed in to change notification settings - Fork 344
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
Add Devices Spec #2815
Open
vigneshhari
wants to merge
20
commits into
develop
Choose a base branch
from
vigneshhari/devices
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Add Devices Spec #2815
Changes from 1 commit
Commits
Show all changes
20 commits
Select commit
Hold shift + click to select a range
7eee8e6
Added Base spec for devices
vigneshhari 32ffbc8
Adding Devices Spec
vigneshhari 1750029
Added Perform Action
vigneshhari 9debe8d
Added Perform Action
vigneshhari 0122beb
Added API Base
vigneshhari 073ae05
Merge branch 'develop' of github.com:ohcnetwork/care into vigneshhari…
vigneshhari 3708edc
Added more API's
vigneshhari f6101e5
Added more API's
vigneshhari 0c3caa6
Added more API's
vigneshhari 928a6dd
Linting issues
vigneshhari ca09db1
added tests
DraKen0009 9e5e4d7
Merge branch 'develop' into vigneshhari/devices
DraKen0009 a24061d
updated some authz
DraKen0009 c17890b
Fix permissions
vigneshhari d8ffda4
Add Example for device integration
vigneshhari 037b4be
Fix bug
vigneshhari b99c435
Add Service Model
vigneshhari 7423e67
Fix Linting
vigneshhari 0fca43e
Add managing organization to view
vigneshhari a7913cd
Add managing organization to retrieve
vigneshhari File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
from django.contrib.postgres.fields import ArrayField | ||
from django.db import models | ||
|
||
from care.emr.models import EMRBaseModel | ||
|
||
|
||
class Device(EMRBaseModel): | ||
# Device Data | ||
identifier = models.CharField(max_length=1024, null=True, blank=True) | ||
status = models.CharField(max_length=14) | ||
availability_status = models.CharField(max_length=14) | ||
manufacturer = models.CharField(max_length=1024) | ||
manufacture_date = models.DateTimeField(null=True, blank=True) | ||
expiration_date = models.DateTimeField(null=True, blank=True) | ||
lot_number = models.CharField(max_length=1024, null=True, blank=True) | ||
serial_number = models.CharField(max_length=1024, null=True, blank=True) | ||
registered_name = models.CharField(max_length=1024, null=True, blank=True) | ||
user_friendly_name = models.CharField(max_length=1024, null=True, blank=True) | ||
model_number = models.CharField(max_length=1024, null=True, blank=True) | ||
part_number = models.CharField(max_length=1024, null=True, blank=True) | ||
contact = models.JSONField(default=dict) | ||
care_type = models.CharField(max_length=1024, null=True, blank=True) | ||
|
||
# Relations | ||
facility = models.ForeignKey("facility.Facility", on_delete=models.CASCADE) | ||
managing_organization = models.ForeignKey( | ||
"emr.FacilityOrganization", on_delete=models.SET_NULL, null=True, blank=True | ||
) | ||
current_location = models.ForeignKey( | ||
"emr.FacilityLocation", on_delete=models.SET_NULL, null=True, blank=True | ||
) | ||
current_encounter = models.ForeignKey( | ||
"emr.Encounter", on_delete=models.SET_NULL, null=True, blank=True | ||
) | ||
|
||
# metadata | ||
facility_organization_cache = ArrayField(models.IntegerField(), default=list) | ||
|
||
|
||
class DeviceEncounterHistory(EMRBaseModel): | ||
device = models.ForeignKey("emr.Device", on_delete=models.CASCADE) | ||
encounter = models.ForeignKey("emr.Encounter", on_delete=models.CASCADE) | ||
start = models.DateTimeField() | ||
end = models.DateTimeField(null=True, blank=True) | ||
|
||
|
||
class DeviceLocationHistory(EMRBaseModel): | ||
device = models.ForeignKey("emr.Device", on_delete=models.CASCADE) | ||
location = models.ForeignKey("emr.FacilityLocation", on_delete=models.CASCADE) | ||
start = models.DateTimeField() | ||
end = models.DateTimeField(null=True, blank=True) | ||
|
||
|
||
class DeviceServiceHistory(EMRBaseModel): | ||
device = models.ForeignKey( | ||
Device, on_delete=models.PROTECT, null=False, blank=False | ||
) | ||
serviced_on = models.DateField(default=None, null=True, blank=False) | ||
note = models.TextField(default="", null=True, blank=True) | ||
edit_history = models.JSONField(default=list) |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
class DeviceTypeBase: | ||
def handle_create(self, request_data, obj): | ||
""" | ||
Handle Creates, the original source request along with the base object created is passed along. | ||
Update the obj as needed and create any extra metadata needed. This method is called within a transaction | ||
""" | ||
return obj | ||
|
||
def handle_update(self, request_data, obj): | ||
""" | ||
Handle Updates, the original source request along with the base object updated is passed along. | ||
Update the obj as needed and create any extra metadata needed. This method is called within a transaction | ||
""" | ||
return obj | ||
|
||
def handle_delete(self, obj): | ||
""" | ||
Handle Deletes, the object to be deleted is passed along. | ||
Perform validation or any other changes required here | ||
""" | ||
return obj | ||
|
||
def list(self, obj): | ||
""" | ||
Return Extra metadata for the given obj for lists, N+1 queries is okay, caching is recommended for performance | ||
""" | ||
return {} | ||
|
||
def retrieve(self, obj): | ||
""" | ||
Return Extra metadata for the given obj during retrieves | ||
""" | ||
return {} | ||
|
||
|
||
class InternalQuestionnaireRegistry: | ||
_device_types = {} | ||
|
||
@classmethod | ||
def register(cls, device_type, device_class) -> None: | ||
if not issubclass(device_class, DeviceTypeBase): | ||
raise ValueError("The provided class is not a subclass of DeviceTypeBase") | ||
cls._device_types[device_type] = device_class | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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
Address potential thread safety concerns with mutable class variables
Modifying a class-level mutable variable like
_device_types
without synchronization can lead to race conditions in a multi-threaded environment. It might be prudent to implement thread safety measures when registering device types.You can enhance thread safety by using a threading lock:
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.
@coderabbitai can you give examples of multithreaded use cases
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.
@sainak In this context, thread safety might actually be unnecessary. Here's why:
If you do need runtime registration (which would be unusual), a better pattern would be:
But I'd be curious to know if you have any use cases where you need to register device types after the application has started?
✏️ Learnings added