From 00eea213ca6705779fe5f64b56551a5f76f12500 Mon Sep 17 00:00:00 2001 From: Rithvik Nishad Date: Thu, 25 Jan 2024 11:56:04 +0530 Subject: [PATCH] Load all icd11 records to redis; search filter by `has_code` (#1852) --- care/facility/api/viewsets/icd.py | 2 +- care/facility/static_data/icd11.py | 13 +++++++------ 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/care/facility/api/viewsets/icd.py b/care/facility/api/viewsets/icd.py index 8551774943..886348c8cf 100644 --- a/care/facility/api/viewsets/icd.py +++ b/care/facility/api/viewsets/icd.py @@ -26,7 +26,7 @@ def list(self, request): except (ValueError, TypeError): limit = 20 - query = [] + query = [ICD11.has_code == 1] if q := request.query_params.get("query"): query.append(ICD11.label % query_builder(q)) diff --git a/care/facility/static_data/icd11.py b/care/facility/static_data/icd11.py index c0582e6f18..f33b2e6371 100644 --- a/care/facility/static_data/icd11.py +++ b/care/facility/static_data/icd11.py @@ -21,6 +21,7 @@ class ICD11(BaseRedisModel): id: int = Field(primary_key=True) label: str = Field(index=True, full_text_search=True) chapter: str + has_code: int = Field(index=True) def get_representation(self) -> ICD11Object: return { @@ -39,12 +40,12 @@ def load_icd11_diagnosis(): paginator = Paginator(icd_objs, 5000) for page_number in paginator.page_range: for diagnosis in paginator.page(page_number).object_list: - if re.match(DISEASE_CODE_PATTERN, diagnosis[1]): - ICD11( - id=diagnosis[0], - label=diagnosis[1], - chapter=diagnosis[2] or "", - ).save() + ICD11( + id=diagnosis[0], + label=diagnosis[1], + chapter=diagnosis[2] or "", + has_code=1 if re.match(DISEASE_CODE_PATTERN, diagnosis[1]) else 0, + ).save() Migrator().run() print("Done")