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 all 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
33 changes: 16 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,7 @@ 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.CharField(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 All @@ -166,6 +164,13 @@ def validate_qr_code_id(self, value):
return value

def validate(self, attrs):
if (
"asset_class" in attrs
and attrs["asset_class"] not in Asset.get_asset_class_choices()
):
error = f"{attrs['asset_class']} is not a valid asset class"
raise ValidationError(error)

user = self.context["request"].user
if "location" in attrs:
location = get_object_or_404(
Expand Down Expand Up @@ -233,8 +238,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 +416,12 @@ 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

type = ChoiceField(
choices=action_choices(),
choices=[
choice
for asset_class in AssetClasses.all()
for choice in asset_class.value.get_action_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.

35 changes: 19 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,15 @@ 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.value.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)
return queryset.distinct()


Expand Down Expand Up @@ -398,6 +392,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:
return Response(
{
"error": f"Cannot operate asset: Plugin for {asset.asset_class} is not installed",
},
status=status.HTTP_400_BAD_REQUEST,
)

asset_class: BaseAssetIntegration = AssetClasses[asset.asset_class].value(
{
**asset.meta,
Expand Down Expand Up @@ -466,14 +469,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', '0468_alter_facilitypatientstatshistory_unique_together_and_more'),
]
Comment on lines +10 to +12
Copy link

Choose a reason for hiding this comment

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

💡 Codebase verification

Oh, I see what happened with those migration numbers...

It seems the migration is actually referencing a non-existent file. The dependency points to '0468_alter_facilitypatientstatshistory_unique_together_and_more', but that file doesn't exist in the codebase. The correct migration appears to be '0469_alter_facilitypatientstatshistory_unique_together_and_more'.

  • The migration dependency should be updated to point to migration '0467_alter_hospitaldoctors_area' instead, as that's the actual predecessor in the sequence.
🔗 Analysis chain

Interesting choice of migration numbering there...

The migration depends on '0468_alter_facilitypatientstatshistory_unique_together_and_more' while being numbered 0468 itself. This could potentially cause confusion in the migration history.

Let's check the migration history:

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Check for duplicate migration numbers
fd --type f "0468.*\.py$" "care/facility/migrations/" --exec echo "{}"

Length of output: 144


Script:

#!/bin/bash
# Let's check the content of migrations directory to see the sequence
fd --type f "046[7-9].*\.py$" "care/facility/migrations/" --exec echo "{}"

# And peek into the content of the previous migration
cat care/facility/migrations/0468_alter_facilitypatientstatshistory_unique_together_and_more.py

Length of output: 522

🧰 Tools
🪛 Ruff (0.8.2)

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)


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)]),
),
]
Loading