diff --git a/care/emr/api/viewsets/questionnaire_response.py b/care/emr/api/viewsets/questionnaire_response.py index 745a8e1c51..5189333cca 100644 --- a/care/emr/api/viewsets/questionnaire_response.py +++ b/care/emr/api/viewsets/questionnaire_response.py @@ -62,4 +62,6 @@ def get_queryset(self): if "questionnaire_slugs" in self.request.GET: questionnaire_slugs = self.request.GET.get("questionnaire_slugs").split(",") queryset = queryset.filter(questionnaire__slug__in=questionnaire_slugs) + if "only_unstructured" in self.request.GET: + queryset = queryset.filter(structured_response_type__isnull=True) return queryset diff --git a/care/emr/api/viewsets/valueset.py b/care/emr/api/viewsets/valueset.py index 5765d5d1f6..3c1df915d4 100644 --- a/care/emr/api/viewsets/valueset.py +++ b/care/emr/api/viewsets/valueset.py @@ -13,6 +13,7 @@ class ExpandRequest(BaseModel): search: str = "" count: int = Field(10, gt=0, lt=100) + display_language: str = "en-gb" class ValueSetViewSet(EMRModelViewSet): @@ -42,8 +43,8 @@ def get_serializer_class(self): @extend_schema(request=ExpandRequest, responses={200: None}, methods=["POST"]) @action(detail=True, methods=["POST"]) def expand(self, request, *args, **kwargs): - request_params = ExpandRequest(**request.data) - results = self.get_object().search(**request_params.model_dump()) + request_params = ExpandRequest(**request.data).model_dump() + results = self.get_object().search(**request_params) return Response({"results": [result.model_dump() for result in results]}) @extend_schema(request=Coding, responses={200: None}, methods=["POST"]) diff --git a/care/emr/fhir/resources/code_concept.py b/care/emr/fhir/resources/code_concept.py index 31e0c1f329..7572c02d77 100644 --- a/care/emr/fhir/resources/code_concept.py +++ b/care/emr/fhir/resources/code_concept.py @@ -23,9 +23,9 @@ class MinimalCodeConcept(BaseModel): display: str system: str code: str + designation: list | None = None class CodeConcept(MinimalCodeConcept): name: str property: dict - designation: dict diff --git a/care/emr/fhir/resources/valueset.py b/care/emr/fhir/resources/valueset.py index 33c841ea78..5bba40f906 100644 --- a/care/emr/fhir/resources/valueset.py +++ b/care/emr/fhir/resources/valueset.py @@ -14,11 +14,14 @@ class ValueSetFilterValidation(BaseModel): class ValueSetResource(ResourceManger): - allowed_properties = ["include", "exclude", "search", "count"] + allowed_properties = ["include", "exclude", "search", "count", "display_language"] def serialize(self, result): return MinimalCodeConcept( - system=result["system"], code=result["code"], display=result["display"] + system=result["system"], + code=result["code"], + display=result["display"], + designation=result.get("designation", []), ) def validate_filter(self): @@ -51,11 +54,19 @@ def lookup(self, code: Coding): def search(self): parameters = [] - for key in self._filters: - if key == "search" and self._filters[key]: - parameters.append({"name": "filter", "valueString": self._filters[key]}) - if key == "count": - parameters.append({"name": "count", "valueInteger": self._filters[key]}) + if self._filters.get("search"): + parameters.append( + {"name": "filter", "valueString": self._filters["search"]} + ) + if "count" in self._filters: + parameters.append({"name": "count", "valueInteger": self._filters["count"]}) + if "display_language" in self._filters: + parameters.append( + { + "name": "displayLanguage", + "valueString": self._filters["display_language"], + } + ) parameters.append( { "name": "valueSet", @@ -68,6 +79,7 @@ def search(self): }, } ) + parameters.append({"name": "includeDesignations", "valueBoolean": True}) request_json = {"resourceType": "Parameters", "parameter": parameters} full_result = self.query("POST", "ValueSet/$expand", request_json) # TODO Add Exception Handling diff --git a/care/emr/models/valueset.py b/care/emr/models/valueset.py index 5d846ccf20..88d0c7f0fc 100644 --- a/care/emr/models/valueset.py +++ b/care/emr/models/valueset.py @@ -30,15 +30,16 @@ def create_composition(self): systems[system]["exclude"].append(exclude.model_dump(exclude_defaults=True)) return systems - def search(self, search="", count=10): + def search(self, search="", count=10, display_language=None): systems = self.create_composition() results = [] for system in systems: - results.extend( - ValueSetResource() - .filter(search=search, count=count, **systems[system]) - .search() + temp = ValueSetResource().filter( + search=search, count=count, **systems[system] ) + if display_language: + temp = temp.filter(display_language=display_language) + results.extend(temp.search()) return results def lookup(self, code): diff --git a/care/facility/models/__init__.py b/care/facility/models/__init__.py index e58dccb90e..74f28d5801 100644 --- a/care/facility/models/__init__.py +++ b/care/facility/models/__init__.py @@ -21,3 +21,4 @@ from .prescription import * # noqa from .resources import * # noqa from .shifting import * # noqa +from .stats import * # noqa