How to create a hierarchy of contact from parent to child?

how to create a heirarchy of mohp, district, community and household ?

Hi @durga.tukilogic ,

Could you please try specifying the hierarchy in base_settings.json file which you can find in app_settings folder of your project? You can list your hierarchy in place_hierarchy_types. May be you can try adding something like below in the base_settings.json:

"place_hierarchy_types": [
    "mohp",
    "district",
    "community",
    "household"
  ],

How to create role for this heirarchy and i have added this heirarchy on base_settings.json still not working.

Still the heirarchy i am not getting in my role part

In base_settings.json, you need to specify the hierarchy under contact_types. Please see the hierarchy reference here:

If you want to look at examples of how it is done, you can find some below:

Although the file name is app_settings.json in the first example, you can use the same code for contact_types in base_settings.json as well. The settings will eventually get compiled into the app_settings.json file with the compile-app-settings action of the cht-conf tool.

1 Like

Roles can be defined independently of the hierarchy. To create a new role, you need to add it to a section called .roles in the app settings file (preferably base_settings.json). Here is the reference document:

You can also add roles and give them permissions from the App Management page. However, these roles can be overwritten when you upload new settings. So please make sure that you add them to the settings file too. One way to do this could be:

  1. Create/edit roles and permissions from App Management page and click on Submit.
  2. Go to the Backup app code tab on the app management page
  3. Click on Download current settings
  4. Copy the roles and permissions from the downloaded copy of your settings file to your settings file.

I have a follow up to this question. I have followed the guide to Set Hierarchy and updated my app_setting.json successfully

{
      "id": "district_hospital",
      "name_key": "contact.type.district_hospital",
      "group_key": "contact.type.district_hospital.plural",
      "create_key": "contact.type.district_hospital.new",
      "edit_key": "contact.type.place.edit",
      "icon": "medic-district-hospital",
      "create_form": "form:contact:district_hospital:create",
      "edit_form": "form:contact:district_hospital:edit"
    }
INFO compile-app-settings complete. 
INFO Starting action: backup-app-settings… 
INFO backup-app-settings complete. 
INFO Starting action: upload-app-settings… 
INFO Settings updated successfully 
INFO upload-app-settings complete. 
INFO All actions completed. 

My understanding of adding this contact_type is I would have district_hospital as an “entity” I can create

My expectation was if I click the Blue + sign in addition to the two options below, I would also have the option to create a new district hospital.

contact

Is my understanding correct ?

Hi @Ben_Kiarie

Great question! Which blue icon are you clicking?
I believe the blue icon, right now, will only allow to create contact types that have the currently viewed contact as a parent, and you can create the contact type that does not have a parent from the main contacts list - there should be a separate button in the lower part of the contacts list on the LeftHandSide

  1. My bad :slight_smile: I should have been clear which blue icon I am talking about. The blue Icon I am referring to is the circular one on the right.

  2. You mention there should be a separate button on the lower left side. Are you referring to the “New health facility” button ?

For context, this is the structure I am trying to replicate

My thinking.

  1. By default I have the “New health facility” button, I click that and create MOH.

  2. Next step, I want to create a district “area” under MOH. First I click MOH tab on the left side, then click the blue circular icon, and I have the option to create a new area.

  3. I create the District “Area” and now this is what I have

  4. Next I want to create a health facility inside the District Area. But when I click the district area, inside it I only have the option to create a person or a household.

I thought that by having these settings, somewhere on the app I would have the option to create a health facility

 "contact_types": [
    {
      "id": "district_hospital",
      "name_key": "contact.type.district_hospital",
      "group_key": "contact.type.district_hospital.plural",
      "create_key": "contact.type.district_hospital.new",
      "edit_key": "contact.type.place.edit",
      "icon": "medic-district-hospital",
      "create_form": "form:contact:district_hospital:create",
      "edit_form": "form:contact:district_hospital:edit"
    },
    {
      "id": "health_center",
      "name_key": "contact.type.health_center",
      "group_key": "contact.type.health_center.plural",
      "create_key": "contact.type.health_center.new",
      "edit_key": "contact.type.place.edit",
      "parents": ["district_hospital"],
      "icon": "medic-health-center",
      "create_form": "form:contact:health_center:create",
      "edit_form": "form:contact:health_center:edit"
    }]

Thoughts ?

@Ben_Kiarie I believe the behavior that you are seeing is expected.
Tagging @michael and @Nicole_Orlowski for design questions.

@Ben_Kiarie I think your issue is with your configuration… you need to first configure your contact_types to align with the hierarchy you are trying to replicate.

Here’s what you currently have:

District Hospital -> Health Center

But what you want is:

MoH -> District -> Health Facility -> Community -> Household

…so you first have to set up this hierarchy in your contact_type configuration.

Hi @michael , thanks for your response.

Background context: I have been able to create district_hospitals via csv-to-docs as described in the docs and when I reload I see the Health Facility on the Left-side Pane

But I have an issue seeing the top most moh place on the left pane. Maybe my understanding is missing something

This is where I am at now.

  1. I added moh as a contact_type in base_settings.json
{
      "id": "moh",
      "name_key": "contact.type.moh",
      "group_key": "contact.type.moh.plural",
      "create_key": "contact.type.moh.new",
      "edit_key": "contact.type.place.edit",
      "icon": "medic-facility",
      "create_form": "form:contact:moh:create",
      "edit_form": "form:contact:moh:edit"
    }
  1. I compiled and uploaded the app settings with compile-app-settings upload-app-settings

I have checked app_settings.json and I see moh has been added as a contact_type.

  1. I created a place.moh.csv file, ran the cht csv-to-docs command. Which runs correctly and creates this json
{
  "type": "moh",
  "name": "Uganda MOH",
  "_id": "57d9f33c-6690-5d10-944b-9e70ab3f5307"
}
  1. when I run the compile-app-settings upload-app-settings command, I get back the confirmation INFO upload-docs complete. and when I check the log, this is what I get
{
  "ok": [
    "57d9f33c-6690-5d10-944b-9e70ab3f5307"
  ],
  "failed": {}
}

However, when I reload the Contacts tab, I don’t see the created MOH Uganda on the left pane I just see the district_hospitals. What step am I missing ? cc @diana if you happen to see this

@Ben_Kiarie can you copy your complete contact_types property here?

Sure, here it is from app_services.json

"contact_types": [
    {
      "id": "district_hospital",
      "name_key": "contact.type.district_hospital",
      "group_key": "contact.type.district_hospital.plural",
      "create_key": "contact.type.district_hospital.new",
      "edit_key": "contact.type.place.edit",
      "icon": "medic-district-hospital",
      "create_form": "form:contact:district_hospital:create",
      "edit_form": "form:contact:district_hospital:edit"
    },
    {
      "id": "health_center",
      "name_key": "contact.type.health_center",
      "group_key": "contact.type.health_center.plural",
      "create_key": "contact.type.health_center.new",
      "edit_key": "contact.type.place.edit",
      "parents": [
        "district_hospital"
      ],
      "icon": "medic-health-center",
      "create_form": "form:contact:health_center:create",
      "edit_form": "form:contact:health_center:edit"
    },
    {
      "id": "clinic",
      "name_key": "contact.type.clinic",
      "group_key": "contact.type.clinic.plural",
      "create_key": "contact.type.clinic.new",
      "edit_key": "contact.type.place.edit",
      "parents": [
        "health_center"
      ],
      "icon": "medic-clinic",
      "create_form": "form:contact:clinic:create",
      "edit_form": "form:contact:clinic:edit",
      "count_visits": true
    },
    {
      "id": "person",
      "name_key": "contact.type.person",
      "group_key": "contact.type.person.plural",
      "create_key": "contact.type.person.new",
      "edit_key": "contact.type.person.edit",
      "primary_contact_key": "clinic.field.contact",
      "parents": [
        "district_hospital",
        "health_center",
        "clinic"
      ],
      "icon": "medic-person",
      "create_form": "form:contact:person:create",
      "edit_form": "form:contact:person:edit",
      "person": true
    },
    {
      "id": "moh",
      "name_key": "contact.type.moh",
      "group_key": "contact.type.moh.plural",
      "create_key": "contact.type.moh.new",
      "edit_key": "contact.type.place.edit",
      "icon": "medic-facility",
      "create_form": "form:contact:moh:create",
      "edit_form": "form:contact:moh:edit"
    }
  ]

Thanks @Ben_Kiarie … so your moh contact type doesn’t have a parent specified and itself is not a parent to any other contact types so I think it’s kind of in a parallel universe :ringer_planet: (see diagram below).

Even if you were to just update district_hospital to have moh as a parent, existing data documents would need to be updated because all contacts and reports have the ID’s of ancestors in their hierarchy.

Here’s what your hierarchy currently represents but I’m not really sure if the CHT supports multiple distinct hierarchies. (I imagine this is why you aren’t seeing the “Uganda MOH” record you created)

1 Like

Thanks @michael that explanation makes sense. Here is what I did to give it another try.

  1. I changed the database location for couchdb to avoid the dealing with moving contacts. I preferred to start with a new hierarchy.

  2. After changing the database location and logging in as the default medic user I did not have any users in my application.

  3. I updated my contact types to the following and ran the command
    cht --url=https://medic:password@localhost:8444 --accept-self-signed-certs compile-app-settings upload-app-settings

"contact_types": [
    {
      "id": "moh",
      "name_key": "contact.type.moh",
      "group_key": "contact.type.moh.plural",
      "create_key": "contact.type.moh.new",
      "edit_key": "contact.type.place.edit",
      "icon": "medic-facility",
      "create_form": "form:contact:moh:create",
      "edit_form": "form:contact:moh:edit"
    },
    {
      "id": "district_hospital",
      "name_key": "contact.type.district_hospital",
      "group_key": "contact.type.district_hospital.plural",
      "create_key": "contact.type.district_hospital.new",
      "edit_key": "contact.type.place.edit",
      "parents": [
        "moh"
      ],
      "icon": "medic-district-hospital",
      "create_form": "form:contact:district_hospital:create",
      "edit_form": "form:contact:district_hospital:edit"
    },
    {
      "id": "health_center",
      "name_key": "contact.type.health_center",
      "group_key": "contact.type.health_center.plural",
      "create_key": "contact.type.health_center.new",
      "edit_key": "contact.type.place.edit",
      "parents": [
        "district_hospital"
      ],
      "icon": "medic-health-center",
      "create_form": "form:contact:health_center:create",
      "edit_form": "form:contact:health_center:edit"
    },
    {
      "id": "clinic",
      "name_key": "contact.type.clinic",
      "group_key": "contact.type.clinic.plural",
      "create_key": "contact.type.clinic.new",
      "edit_key": "contact.type.place.edit",
      "parents": [
        "health_center"
      ],
      "icon": "medic-clinic",
      "create_form": "form:contact:clinic:create",
      "edit_form": "form:contact:clinic:edit",
      "count_visits": true
    },
    {
      "id": "person",
      "name_key": "contact.type.person",
      "group_key": "contact.type.person.plural",
      "create_key": "contact.type.person.new",
      "edit_key": "contact.type.person.edit",
      "primary_contact_key": "clinic.field.contact",
      "parents": [
        "district_hospital",
        "health_center",
        "clinic"
      ],
      "icon": "medic-person",
      "create_form": "form:contact:person:create",
      "edit_form": "form:contact:person:edit",
      "person": true
    }
  ]
  1. After that I created a csv file named place.moh with a name key and value
    Screenshot 2023-10-03 at 11.39.07

  2. I ran the command cht csv-to-docs which generated the correct json

{
  "type": "moh",
  "name": "Uganda MOH",
  "_id": "57d9f33c-6690-5d10-944b-9e70ab3f5307"
}
  1. Next, I ran the command
    cht --url=https://medic:password@localhost:8444 --accept-self-signed-certs upload-docs
    And got back the following json
{
  "ok": [
    "57d9f33c-6690-5d10-944b-9e70ab3f5307"
  ],
  "failed": {}
}

At this point, should I be seeing moh in the contacts tab ? Currently, its blank.

1 Like

An update on this, I followed the instructions to create Contact Forms : Used for creating and editing people and places hoping that would allow me to create the above hierarchy including

  • Ministry of health
  • A District Hospital

Here is are the contact forms I have in my project so far

With those contact forms, I ran repeated the steps to create MOH again

  • cht --url=https://medic:password@localhost:8444 --accept-self-signed-certs compile-app-settings upload-app-settings

  • cht csv-to-docs which correctly generated the json for creating Uganda MOH of type moh

  • cht --url=https://medic:password@localhost:8444 --accept-self-signed-certs upload-docs I got back an ok status of the upload

Despite these efforts, I still don’t have Uganda MOH as a contact in my application.

1 Like