Skip to content

Commit

Permalink
Exclude ICD11 entries that does not have a meta_chapter_short from …
Browse files Browse the repository at this point in the history
…search instead for not loading in redis table (#2248)
  • Loading branch information
sainak committed Jun 7, 2024
1 parent a4d24b6 commit 37ab926
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 8 deletions.
5 changes: 4 additions & 1 deletion care/facility/api/viewsets/icd.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,10 @@ def list(self, request):
except (ValueError, TypeError):
limit = 20

query = [ICD11.has_code == 1]
query = [
ICD11.has_code == 1,
ICD11.chapter != "null", # noqa: E711
]
if q := request.query_params.get("query"):
query.append(ICD11.vec % query_builder(q))

Expand Down
12 changes: 5 additions & 7 deletions care/facility/static_data/icd11.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class ICD11Object(TypedDict):
class ICD11(BaseRedisModel):
id: int = Field(primary_key=True)
label: str
chapter: str
chapter: str = Field(index=True)
has_code: int = Field(index=True)

vec: str = Field(index=True, full_text_search=True)
Expand All @@ -28,25 +28,23 @@ def get_representation(self) -> ICD11Object:
return {
"id": self.id,
"label": self.label,
"chapter": self.chapter,
"chapter": self.chapter if self.chapter != "null" else "",
}


def load_icd11_diagnosis():
print("Loading ICD11 Diagnosis into the redis cache...", end="", flush=True)

icd_objs = (
ICD11Diagnosis.objects.filter(meta_chapter_short__isnull=False)
.order_by("id")
.values_list("id", "label", "meta_chapter_short")
icd_objs = ICD11Diagnosis.objects.order_by("id").values_list(
"id", "label", "meta_chapter_short"
)
paginator = Paginator(icd_objs, 5000)
for page_number in paginator.page_range:
for diagnosis in paginator.page(page_number).object_list:
ICD11(
id=diagnosis[0],
label=diagnosis[1],
chapter=diagnosis[2],
chapter=diagnosis[2] or "null",
has_code=1 if re.match(DISEASE_CODE_PATTERN, diagnosis[1]) else 0,
vec=diagnosis[1].replace(".", "\\.", 1),
).save()
Expand Down

0 comments on commit 37ab926

Please sign in to comment.