-
Notifications
You must be signed in to change notification settings - Fork 343
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
41877f1
commit 7eee8e6
Showing
3 changed files
with
103 additions
and
0 deletions.
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 |