Is it possible to filter/search DB objects based on a role. ie, If a person has been created with the role of CHW is one able to filter only the CHW’s
Hi @robinmurphy
The question is not completely clear for me, could you please confirm if my understanding is correct?
- you want to query the database directly
- you want a query that will return users that have a specific user role
Further questions would be: is this question about querying CouchDb or Postgres? is this a query that you wish to run frequently? Are you interested in getting the user-settings documents or the contact documents associated with these users?
Thanks!
After I’ve looked at your other forum posts, I’m inclined to believe you were actually referring to forms dropdowns filtering users by role. Is that right?
Hi Diana,
Thank you for taking the time to get back to me, and apologies for the delay.
What we’re trying to achieve is:
In the xlsx file and for a contact place
hierarchy item, where one can define a primary contact
, would it be possible to filter the results returned from the db:person
on a specific person role
?
Where role
is a self defined data field present in the person form with one of the following values NPO rep
, Team lead
, CHW
.
The reason for doing so is:
We only want the people that are relevant to a certain hierarchy structure to be available for selection.
Hi @robinmurphy
Unfortunately, I don’t believe that is possible now.
Is it maybe an option you differentiate the “roles” by contact type: define different hierarchy person types, one for each “role” and refine your db:object
to only offer options of the desired contact type?
Hi @diana,
We do plan on creating a different form for each person in each place level of the hierarchy.
I’ve only seen the contact_type
field in the db for the contact places
, not the people
, is that then something we will need to track ourselves?
Or am I misunderstanding?
Apologies, I’m unsure as the to the implementation of the suggestion.
I’m still quite new and getting to grips with how everything fits together.
Hi @robinmurphy
A contact type can be either a place
or a person
. By default it’s a place
, but there a property that you can set on the type so it is designated as a person
- the field is actually called person
: .contact_types | Community Health Toolkit
This way you can create multiple person types, for example: patient, chw, supervisor, facility_manager, and so on, and you can use these types as db:object “filters” in your forms.
Hi @diana
We have created a Team Area
person called Team Lead
which can be found here.
It was included in the contact hierarchy with the person
property set to true
as suggested, see screenshot attached.
That in turn yielded the attached database entry, which contains the contact_type
property mentioned.
What I am unsure is, in the Team Area
form, how to use this contact_type
property to filter a db:object entry to only include people created as “team_lead”. Would you perhaps be able to provide an example?
Hi @robinmurphy
You would just use it just like you would any other contact type, you set a field type to db:team_lead
in your form.
Can you please try that?
Hi @diana
As suggested I’ve changed the Team Area
person contact entry from db:person
to db_team_lead
.
Unfortunately it yields the following error:
pyxform.errors.PyXFormError: Unknown question type 'db:team_lead'
The form in question can be found here.
Hi @robinmurphy
Could you please try the approach detailed in the documentation: Input data available in forms | Community Health Toolkit ?
There is a similar thread on the forum that might also provide some details about form selectors for configurable contact types: pyxform.errors.PyXFormError: Unknown question type 'db:supervisor' - #2 by uensal
Hi @diana
Thank your for the links provided. It seems to work, but only if a new person is created outside of the place form flow.
What I’ve noticed is:
The database entry created for the create contact
step inside a place
form and the + new person
form outside of the place
seems to yield a different type
property value.
One being "type": "person"
and the other being "type": "contact"
, which one is the correct type?
See attached screenshots (the first screenshot being the primary contact created in place form flow, and the second screenshot is created after the fact with the add person flow).
These items also appear in different summary blocks (see third screenshot).
It also seems to affect the select-contact type-team_lead
to either return an item or blank.
For your perusal the Team Area and Team Leader forms.
Hi.
"type": "contact"
is correct for custom contact types, with the actual type being saved in the contact_type
property. "type": "person"
is historic, and only exists for backwards compatibility.
That seemed to have done it, thank you for the help
The Team Area and Team Leader forms that satisfy the requirement.