Medical Search
Today, I added the search medical institution page. This is the same as the search case page but, searches for medical institutions (hospitals, pharmacies, diagnosis centers). To implement this, the module django_simple_search
is used.
from django_simple_search import search_filter def search_medical(request): queries = request.GET.get('q') if queries is not None: search_fields = ['username', 'address', 'mobile_no', 'emergency_mobile', 'pin_code', 'other_info'] split_queries = queries.split() users = None for query in split_queries: current_users = User.objects.filter( search_filter(search_fields, query), is_active=True, groups__name__in=['hospital', 'pharmacy', 'diagnosis_center'], ) if users is None: users = current_users else: users = users.union(current_users) return render(request, 'cases/search-medical.html', {'users': users, 'search_term': queries}) else: return render(request, 'cases/search-medical.html')
In short, the query string is passed via the URL (like https://example.com?q=kolkata). I grab this query string using request.GET.get('q')
. After that, it is split into multiple queries (for example, 'Hello World'
will be split into 'Hello'
and World
and thus be two different queries). Then, I query the User
model using search_filter
for all the queries and at the end, they are unionized and passed to the template.
This marks the end of all feature implementation I had in mind at the start of the hackathon. Let me know if you have any features that you would like to see in the web app! 😄
Try It Out
To try it out, please create a patient account here and a medical account here (note that admin has to approve the medical accounts, so please wait a bit or you can also use the admin account mentioned below!).
Alternatively, you can use the following demo medical accounts:
- devto-hospital
- devto-diag
- devto-pharmacy
the patient account:
- devto-patient
and the admin account:
- devto
Password for all of them is: medidocpass@abc
I would love to hear your feedback! Let me know what you think in the comments.
Top comments (0)