Skip to content

Commit

Permalink
Merge branch 'master' into issue#1255
Browse files Browse the repository at this point in the history
  • Loading branch information
rithviknishad authored May 23, 2023
2 parents 4f4577b + a7b46d2 commit f4456e1
Show file tree
Hide file tree
Showing 5 changed files with 158 additions and 1 deletion.
2 changes: 2 additions & 0 deletions care/facility/api/viewsets/asset.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
from care.utils.assetintegration.base import BaseAssetIntegration
from care.utils.assetintegration.hl7monitor import HL7MonitorAsset
from care.utils.assetintegration.onvif import OnvifAsset
from care.utils.assetintegration.ventilator import VentilatorAsset
from care.utils.cache.cache_allowed_facilities import get_accessible_facilities
from care.utils.filters.choicefilter import CareChoiceFilter, inverse_choices
from care.utils.queryset.asset_location import get_asset_location_queryset
Expand Down Expand Up @@ -217,6 +218,7 @@ def actionChoices():
actions: list[enum.Enum] = [
OnvifAsset.OnvifActions,
HL7MonitorAsset.HL7MonitorActions,
VentilatorAsset.VentilatorActions,
]
choices = []
for action in actions:
Expand Down
107 changes: 107 additions & 0 deletions care/facility/migrations/0356_auto_20230523_1304.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
# Generated by Django 2.2.11 on 2023-05-23 07:34

import care.utils.models.validators
import django.contrib.postgres.fields.jsonb
from django.db import migrations, models


class Migration(migrations.Migration):
dependencies = [
("facility", "0355_auto_20230512_1122"),
]

operations = [
migrations.AlterField(
model_name="asset",
name="asset_class",
field=models.CharField(
blank=True,
choices=[
("ONVIF", "onvif"),
("HL7MONITOR", "hl7monitor"),
("VENTILATOR", "ventilator"),
],
default=None,
max_length=20,
null=True,
),
),
migrations.AlterField(
model_name="asset",
name="meta",
field=django.contrib.postgres.fields.jsonb.JSONField(
blank=True,
default=dict,
validators=[
care.utils.models.validators.JSONFieldSchemaValidator(
{
"$schema": "http://json-schema.org/draft-07/schema#",
"anyOf": [
{"$ref": "#/definitions/onvif"},
{"$ref": "#/definitions/hl7monitor"},
{"$ref": "#/definitions/empty"},
],
"definitions": {
"empty": {
"additionalProperties": False,
"type": "object",
},
"hl7monitor": {
"additionalProperties": False,
"properties": {
"asset_type": {"type": "string"},
"insecure_connection": {"type": "boolean"},
"local_ip_address": {"type": "string"},
"middleware_hostname": {"type": "string"},
},
"required": ["local_ip_address"],
"type": "object",
},
"onvif": {
"additionalProperties": False,
"properties": {
"asset_type": {"type": "string"},
"camera_access_key": {"type": "string"},
"camera_type": {"type": "string"},
"insecure_connection": {"type": "boolean"},
"local_ip_address": {"type": "string"},
"middleware_hostname": {"type": "string"},
},
"required": [
"local_ip_address",
"camera_access_key",
],
"type": "object",
},
"ventilator": {
"additionalProperties": False,
"properties": {
"asset_type": {"type": "string"},
"insecure_connection": {"type": "boolean"},
"local_ip_address": {"type": "string"},
"middleware_hostname": {"type": "string"},
},
"required": ["local_ip_address"],
"type": "object",
},
},
}
)
],
),
),
migrations.AlterField(
model_name="fileupload",
name="file_type",
field=models.IntegerField(
choices=[
(1, "PATIENT"),
(2, "CONSULTATION"),
(3, "SAMPLE_MANAGEMENT"),
(4, "CLAIM"),
(5, "DISCHARGE_SUMMARY"),
],
default=1,
),
),
]
19 changes: 18 additions & 1 deletion care/facility/models/json_schema/asset.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,18 @@
"additionalProperties": False,
}

VENTILATOR_META = {
"type": "object",
"required": ["local_ip_address"],
"properties": {
"local_ip_address": {"type": "string"},
"middleware_hostname": {"type": "string"},
"asset_type": {"type": "string"},
"insecure_connection": {"type": "boolean"},
},
"additionalProperties": False,
}

ONVIF_META = {
"type": "object",
"required": ["local_ip_address", "camera_access_key"],
Expand All @@ -33,5 +45,10 @@
{"$ref": "#/definitions/hl7monitor"},
{"$ref": "#/definitions/empty"},
],
"definitions": {"onvif": ONVIF_META, "hl7monitor": HL7_META, "empty": EMPTY_META},
"definitions": {
"onvif": ONVIF_META,
"hl7monitor": HL7_META,
"ventilator": VENTILATOR_META,
"empty": EMPTY_META,
},
}
2 changes: 2 additions & 0 deletions care/utils/assetintegration/asset_classes.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@

from care.utils.assetintegration.hl7monitor import HL7MonitorAsset
from care.utils.assetintegration.onvif import OnvifAsset
from care.utils.assetintegration.ventilator import VentilatorAsset


class AssetClasses(enum.Enum):
ONVIF = OnvifAsset
HL7MONITOR = HL7MonitorAsset
VENTILATOR = VentilatorAsset
29 changes: 29 additions & 0 deletions care/utils/assetintegration/ventilator.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import enum

from rest_framework.exceptions import ValidationError

from care.utils.assetintegration.base import BaseAssetIntegration


class VentilatorAsset(BaseAssetIntegration):
_name = "ventilator"

class VentilatorActions(enum.Enum):
GET_VITALS = "get_vitals"

def __init__(self, meta):
try:
super().__init__(meta)
except KeyError as e:
raise ValidationError(
dict((key, f"{key} not found in asset metadata") for key in e.args)
)

def handle_action(self, action):
action_type = action["type"]

if action_type == self.VentilatorActions.GET_VITALS.value:
request_params = {"device_id": self.host}
return self.api_get(self.get_url("vitals"), request_params)

raise ValidationError({"action": "invalid action type"})

0 comments on commit f4456e1

Please sign in to comment.