Skip to content

Commit

Permalink
nit: cleanup for case type view
Browse files Browse the repository at this point in the history
  • Loading branch information
ajeety4 committed Jun 25, 2024
1 parent a87aa8c commit c3ed4e2
Showing 1 changed file with 8 additions and 11 deletions.
19 changes: 8 additions & 11 deletions corehq/apps/data_dictionary/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -153,31 +153,28 @@ def data_dictionary_json(request, domain, case_type_name=None):
@requires_privilege_with_fallback(privileges.DATA_DICTIONARY)
def data_dictionary_json_case_types(request, domain):
fhir_resource_type_name_by_case_type = {}
fhir_resource_prop_by_case_prop = {}
if toggles.FHIR_INTEGRATION.enabled(domain):
fhir_resource_type_name_by_case_type = load_fhir_case_type_mapping(domain)
fhir_resource_prop_by_case_prop = load_fhir_case_properties_mapping(domain)

case_type_app_module_count = get_case_type_app_module_count(domain)
used_props_by_case_type = get_used_props_by_case_type(domain)
geo_case_prop = get_geo_case_property(domain)

def _get_case_data(case_type):
module_count = case_type_app_module_count.get(case_type.name, 0)
queryset = CaseType.objects.filter(domain=domain).annotate(properties_count=Count('property'))
if not request.GET.get("load_deprecated_case_types", False) == "true":
queryset = queryset.filter(is_deprecated=False)
case_types_data = []
for case_type in queryset:
used_props = used_props_by_case_type.get(case_type.name, [])
return {
case_types_data.append({
"name": case_type.name,
"fhir_resource_type": fhir_resource_type_name_by_case_type.get(case_type),
"is_deprecated": case_type.is_deprecated,
"module_count": module_count,
"module_count": case_type_app_module_count.get(case_type.name, 0),
"is_safe_to_delete": len(used_props) == 0,
"properties_count": case_type.properties_count,
}
})

queryset = CaseType.objects.filter(domain=domain).annotate(properties_count=Count('property'))
if not request.GET.get("load_deprecated_case_types", False) == "true":
queryset = queryset.filter(is_deprecated=False)
case_types_data = [_get_case_data(case_type) for case_type in queryset]
return JsonResponse({
"case_types": case_types_data,
"geo_case_property": geo_case_prop,
Expand Down

0 comments on commit c3ed4e2

Please sign in to comment.