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

Removing everything related to camera in favour of camera plugin #2610

Open
wants to merge 22 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 10 commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
51a7a40
added a camera plugin application
DraKen0009 Nov 17, 2024
3b6f32e
added a camera plugin application
DraKen0009 Nov 17, 2024
3939d06
merged conflicts
DraKen0009 Nov 17, 2024
d30ec6a
merged conflicts
DraKen0009 Nov 17, 2024
6128345
merged conflicts resolved
DraKen0009 Nov 17, 2024
c4a8904
removed camera related code
DraKen0009 Nov 20, 2024
d3c5b14
removed camera related code
DraKen0009 Nov 20, 2024
b29def8
asset model updates for making asset data dynamic
DraKen0009 Nov 20, 2024
75d4204
update plug configs
DraKen0009 Nov 22, 2024
90e8259
resolved merge conflicts
DraKen0009 Nov 22, 2024
e7c774e
resolve code rabbit comments
DraKen0009 Nov 22, 2024
122b92f
Merge branch 'develop' into adding-camera-plugin
DraKen0009 Nov 25, 2024
38d5196
Merge branch 'develop' into adding-camera-plugin
rithviknishad Nov 26, 2024
6d4bf27
revert removing reference to old camera preset model
rithviknishad Nov 26, 2024
11b6367
Merge branch 'refs/heads/master' into adding-camera-plugin
DraKen0009 Nov 29, 2024
19c2b74
fixed classname field in serializer to be dynamic
DraKen0009 Nov 29, 2024
8d4581f
fixed member function addition
DraKen0009 Nov 29, 2024
5a6a8fa
Merge branch 'ohcnetwork:develop' into adding-camera-plugin
DraKen0009 Dec 4, 2024
85eb618
Merge branch 'master' into adding-camera-plugin
DraKen0009 Dec 16, 2024
88003ae
Merge branch 'adding-camera-plugin' of draken:DraKen0009/care into ad…
DraKen0009 Dec 16, 2024
2e72d44
Merge branch 'master' into adding-camera-plugin
DraKen0009 Dec 28, 2024
421400a
fixed migrations
DraKen0009 Dec 28, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 10 additions & 17 deletions care/facility/api/serializers/asset.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,6 @@
)
from care.users.api.serializers.user import UserBaseMinimumSerializer
from care.utils.assetintegration.asset_classes import AssetClasses
from care.utils.assetintegration.hl7monitor import HL7MonitorAsset
from care.utils.assetintegration.onvif import OnvifAsset
from care.utils.assetintegration.ventilator import VentilatorAsset
from care.utils.models.validators import MiddlewareDomainAddressValidator
from care.utils.queryset.facility import get_facility_queryset
from care.utils.serializers.fields import ChoiceField
Expand Down Expand Up @@ -144,6 +141,9 @@ class AssetSerializer(ModelSerializer):
id = UUIDField(source="external_id", read_only=True)
status = ChoiceField(choices=StatusChoices, read_only=True)
asset_type = ChoiceField(choices=AssetTypeChoices)
asset_class = serializers.ChoiceField(
choices=Asset.get_asset_class_choices(), required=False
)
location_object = AssetLocationSerializer(source="current_location", read_only=True)
location = UUIDField(write_only=True, required=True)
last_service = AssetServiceSerializer(read_only=True)
Expand Down Expand Up @@ -233,8 +233,9 @@ def validate(self, attrs):
)
.filter(
asset_class__in=[
AssetClasses.ONVIF.name,
AssetClasses.HL7MONITOR.name,
member.name
for member in AssetClasses.all()
if member.value.can_be_linked_to_asset_bed # need better naming
],
current_location__facility=current_location.facility_id,
resolved_middleware_hostname=middleware_hostname,
Expand Down Expand Up @@ -410,19 +411,11 @@ class Meta:


class AssetActionSerializer(Serializer):
def action_choices():
actions = [
OnvifAsset.OnvifActions,
HL7MonitorAsset.HL7MonitorActions,
VentilatorAsset.VentilatorActions,
]
choices = []
for action in actions:
choices += [(e.value, e.name) for e in action]
return choices

choices = []
for asset_class in AssetClasses.all():
choices.append(asset_class.value.get_action_choices())
DraKen0009 marked this conversation as resolved.
Show resolved Hide resolved
type = ChoiceField(
choices=action_choices(),
choices=choices,
required=True,
)
data = JSONField(required=False)
Expand Down
27 changes: 16 additions & 11 deletions care/facility/api/serializers/bed.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,11 +121,16 @@ def validate(self, attrs):
raise ValidationError(
{"non_field_errors": "Asset is already linked to bed"}
)
if asset.asset_class not in [
AssetClasses.HL7MONITOR.name,
AssetClasses.ONVIF.name,
]:
raise ValidationError({"asset": "Asset is not a monitor or camera"})

valid_asset_classes = [
member.name
for member in AssetClasses.all()
if member.value.can_be_linked_to_asset_bed()
]
if asset.asset_class not in valid_asset_classes:
raise ValidationError(
{"asset": "This Asset Class cannot be linked to a bed"}
)
attrs["asset"] = asset
attrs["bed"] = bed
if asset.current_location.facility.id != bed.facility.id:
Expand Down Expand Up @@ -315,6 +320,11 @@ def create(self, validated_data) -> ConsultationBed:
if assets_ids := validated_data.pop("assets", None):
# we check assets in use here as they might have been in use in
# the previous bed
exclude_asset_classes = [
member.name
for member in AssetClasses.all()
if not member.value.can_be_linked_to_consultation_bed()
]
assets = (
Asset.objects.annotate(
is_in_use=Exists(
Expand All @@ -330,12 +340,7 @@ def create(self, validated_data) -> ConsultationBed:
external_id__in=assets_ids,
current_location__facility=consultation.facility_id,
)
.exclude(
asset_class__in=[
AssetClasses.HL7MONITOR.name,
AssetClasses.ONVIF.name,
]
)
.exclude(asset_class__in=exclude_asset_classes)
.values_list("external_id", flat=True)
)
not_found_assets = set(assets_ids) - set(assets)
Expand Down
49 changes: 0 additions & 49 deletions care/facility/api/serializers/camera_preset.py

This file was deleted.

33 changes: 17 additions & 16 deletions care/facility/api/viewsets/asset.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,6 @@

logger = logging.getLogger(__name__)


inverse_asset_type = inverse_choices(AssetTypeChoices)
inverse_asset_status = inverse_choices(StatusChoices)

Expand Down Expand Up @@ -202,20 +201,13 @@ def filter_in_use_by_consultation(self, queryset, _, value):

def filter_is_permanent(self, queryset, _, value):
if value not in EMPTY_VALUES:
movable_assets = [
member.name for member in AssetClasses.all() if not member.is_movable
]
if value:
queryset = queryset.filter(
asset_class__in=[
AssetClasses.ONVIF.name,
AssetClasses.HL7MONITOR.name,
]
)
queryset = queryset.filter(asset_class__in=movable_assets)
else:
queryset = queryset.exclude(
asset_class__in=[
AssetClasses.ONVIF.name,
AssetClasses.HL7MONITOR.name,
]
)
queryset = queryset.exclude(asset_class__in=movable_assets)
Copy link

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Variable naming inconsistency with 'movable_assets'

It appears that movable_assets actually contains asset classes where member.is_movable is False, meaning they are non-movable assets. Perhaps renaming the variable to non_movable_assets would improve clarity.

return queryset.distinct()


Expand Down Expand Up @@ -398,6 +390,15 @@ def operate_assets(self, request, *args, **kwargs):
or asset.current_location.middleware_address
or asset.current_location.facility.middleware_address
)
available_asset_classes = [asset.name for asset in AssetClasses.all()]
if asset.asset_class not in available_asset_classes:
Response(
{
"error": f"Install {asset.asset_class}'s plugins to use it",
},
status=status.HTTP_400_BAD_REQUEST,
)

DraKen0009 marked this conversation as resolved.
Show resolved Hide resolved
asset_class: BaseAssetIntegration = AssetClasses[asset.asset_class].value(
{
**asset.meta,
Expand Down Expand Up @@ -466,14 +467,14 @@ def list(self, request, *args, **kwargs):
{"middleware_hostname": "Invalid middleware hostname"},
status=status.HTTP_400_BAD_REQUEST,
)

queryset = (
self.get_queryset()
.filter(
current_location__facility=self.request.user.facility,
asset_class__in=[
AssetClasses.ONVIF.name,
AssetClasses.HL7MONITOR.name,
member.name
for member in AssetClasses.all()
if member.value.can_be_linked_to_asset_bed() # better naming required
],
)
.annotate(
Expand Down
63 changes: 0 additions & 63 deletions care/facility/api/viewsets/camera_preset.py

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# Generated by Django 5.1.2 on 2024-11-20 20:53

import care.facility.models.json_schema.asset
import care.utils.models.validators
from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('facility', '0467_alter_hospitaldoctors_area'),
]

operations = [
migrations.AlterField(
model_name='asset',
name='asset_class',
field=models.CharField(blank=True, default=None, max_length=20, null=True),
),
migrations.AlterField(
model_name='asset',
name='meta',
field=models.JSONField(blank=True, default=dict, validators=[care.utils.models.validators.DynamicJSONFieldSchemaValidator(care.facility.models.json_schema.asset.get_dynamic_asset_meta)]),
),
]
1 change: 0 additions & 1 deletion care/facility/models/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
from .ambulance import * # noqa
from .asset import * # noqa
from .bed import * # noqa
from .camera_preset import * # noqa
Copy link
Member

@rithviknishad rithviknishad Nov 26, 2024

Choose a reason for hiding this comment

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

removing this now will cause a pending make migration as 0 references are there to the old CameraPreset model now. lets remove it in the second part PR where we would be deleting the old model.

image

from .daily_round import * # noqa
from .encounter_symptom import * # noqa
from .events import * # noqa
Expand Down
Loading