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")