Skip to content

fix(#0090): replace remote datasource with PouchDB views for Select2 contact search#91

Merged
hectorguillen-blip merged 2 commits into
feature/user-display-authorizationfrom
feature/fix-select2-datasource
Jun 3, 2026
Merged

fix(#0090): replace remote datasource with PouchDB views for Select2 contact search#91
hectorguillen-blip merged 2 commits into
feature/user-display-authorizationfrom
feature/fix-select2-datasource

Conversation

@hectorguillen-blip

Copy link
Copy Markdown

Description

Fixes the facility and associated contact Select2 dropdowns in the UserFormComponent, which were returning no results due to an incorrect data source.

Closes #13

Root cause

The original implementation used CHTDatasourceService with getRemoteDataContext() which requires contact_types to be configured in CHT settings to know which types to query. Most instances do not have this configured, causing the dropdowns to return empty results silently.

Changes

Select2SearchService

  • Replaced CHTDatasourceService with DbService — queries PouchDB directly
  • Uses medic-offline-freetext/contacts_by_type_freetext view for term-based search, matching the original AngularJS Select2Search service behaviour
  • Falls back gracefully if the view is missing
  • Results now display name, phone, and full parent lineage in gray — matching the original format.sender() output
  • isContactInPlace now uses db.get().get() instead of the remote API

FreetextDesignDocService

  • New service that checks for _design/medic-offline-freetext on app startup and creates it if missing
  • Registered as an APP_INITIALIZER in app.config.ts so the view is available on every environment without manual setup

app.config.ts

  • Added FreetextDesignDocService initializer

Tests

  • Updated select2search.service.spec.ts to use DbService mock instead of CHTDatasourceService

Checklist

  • Readable — follows style guide, ESLint passing
  • Tested — unit tests updated to reflect new data source
  • Backwards compatible — design doc is created automatically, no manual setup required

@hectorguillen-blip hectorguillen-blip merged commit 40e37fb into feature/user-display-authorization Jun 3, 2026
184 of 200 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants