Skip to content

Commit

Permalink
Fix Valueset language preferance, questionnaire response filters and …
Browse files Browse the repository at this point in the history
…more
  • Loading branch information
vigneshhari committed Jan 6, 2025
1 parent d010b8c commit 1de306c
Show file tree
Hide file tree
Showing 6 changed files with 32 additions and 15 deletions.
2 changes: 2 additions & 0 deletions care/emr/api/viewsets/questionnaire_response.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
5 changes: 3 additions & 2 deletions care/emr/api/viewsets/valueset.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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"])
Expand Down
2 changes: 1 addition & 1 deletion care/emr/fhir/resources/code_concept.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
26 changes: 19 additions & 7 deletions care/emr/fhir/resources/valueset.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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",
Expand All @@ -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
Expand Down
11 changes: 6 additions & 5 deletions care/emr/models/valueset.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
1 change: 1 addition & 0 deletions care/facility/models/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,4 @@
from .prescription import * # noqa
from .resources import * # noqa
from .shifting import * # noqa
from .stats import * # noqa

0 comments on commit 1de306c

Please sign in to comment.