Skip to content

Changes to data model

Vivek Singh edited this page Apr 18, 2022 · 5 revisions

You may want to make changes to forms in Avni or Bahmni, or add new forms there, or add new person attributes to Bahmni. This documentation explains the steps you should take when making these changes. In all the cases any form change requires change in both the systems and mapping to be created in integration database.

Follow the following when making any changes to the mappings

  • Stop integrator systemctl stop abi.service
  • From abi-host directory run sh start-with-sync-disabled.sh
  • Make changes to the mapping.
  • Start integrator systemctl start abi.service

Naming convention

  • For any new form in Bahmni the forms and encounter types in Avni are named with (Hospital) suffix in the name.
  • For any new form in Avni, the forms and encounter types in Bahmni are named with [Avni] suffix in the name.
  • For any concept in Bahmni, the corresponding concept in Avni is named with [H] suffix.
  • For any patient attribute in Bahmni, the corresponding concept in Avni is named with [HP] suffix.
  • For any concept in Avni, the corresponding concept in Bahmni is named with [Avni] suffix.

Addition of new program and its enrolment form in Avni

  • Create a form in Bahmni (using the concept set approach)
  • Create an encounter type in Bahmni

Create following mapping in integration system using the user interface.

  • Mapping Group=ProgramEnrolment, Mapping Type=CommunityEnrolment_EncounterType, Avni value=Name of program, Bahmni value=UUID of encounter type
  • Mapping Group=ProgramEnrolment, Mapping Type=CommunityEnrolment_BahmniForm, Avni value=Name of enrolment form, Bahmni value=UUID of form concept
  • (for each concept in the form, if not already mapped) Mapping Group=Observation, Mapping Type=Concept, Avni value=Name of the concept, Bahmni value=UUID of the concept, Select coded if it is a coded concept

Addition of new program encounter form in Avni

  • Create a form in Bahmni (using the concept set approach)
  • Create an encounter type in Bahmni

Create following mapping in integration system using the user interface.

  • Mapping Group=ProgramEncounter, Mapping Type=CommunityEncounter_EncounterType, Avni value=Name of encounter type, Bahmni value=UUID of encounter type
  • Mapping Group=ProgramEncounter, Mapping Type=CommunityEncounter_BahmniForm, Avni value=Name of encounter form, Bahmni value=UUID of form concept
  • (for each concept in the form, if not already mapped) Mapping Group=Observation, Mapping Type=Concept, Avni value=Name of the concept, Bahmni value=UUID of the concept, Select coded if it is a coded concept

Addition of new form in Bahmni outside any program

  • Create a form in Avni
  • Create an encounter type in Avni

Create following mapping in integration system using the user interface.

  • Mapping Group=GeneralEncounter, Mapping Type=EncounterType, Avni value=Name of encounter type, Bahmni value=UUID of encounter type
  • (for each concept in the form, if not already mapped) Mapping Group=Observation, Mapping Type=Concept, Avni value=Name of the concept, Bahmni value=UUID of the concept, Select coded if it is a coded concept

Modification to existing form in Avni

  • (for each concept in the form, if not already mapped) Mapping Group=Observation, Mapping Type=Concept, Avni value=Name of the concept, Bahmni value=UUID of the concept, Select coded if it is a coded concept

Modification to existing form in Bahmni

  • (for each concept in the form, if not already mapped) Mapping Group=Observation, Mapping Type=Concept, Avni value=Name of the concept, Bahmni value=UUID of the concept, Select coded if it is a coded concept

Supporting queries to get information from Bahmni

Get mapping details required for a concept

?1 = name of the concept

select c.uuid, cn.name, cdt.name, cn.concept_name_type from concept c join concept_name cn on cn.concept_id = c.concept_id join concept_datatype cdt on cdt.concept_datatype_id = c.datatype_id join concept_class cc on cc.concept_class_id = c.class_id where c.is_set = false and cdt.name not in ('Rule', 'Document', 'Complex') and cn.concept_name_type = 'FULLY_SPECIFIED' and cc.name not in ('Concept Attribute', 'Drug', 'Image', 'URL', 'Video') and cn.name not like '%[Avni]' and cn.name = ?1

Get mapping details of coded answers for a concept

?1 = uuid of the parent concept

select ac.uuid, acn.name, cd.name from concept c join concept_answer ca on c.concept_id = ca.concept_id join concept ac on ca.answer_concept = ac.concept_id join concept_name acn on acn.concept_id = ac.concept_id join concept_datatype cd on ac.datatype_id = cd.concept_datatype_id where c.uuid = ?1 and acn.concept_name_type = 'FULLY_SPECIFIED'

Getting all person attribute types

select COALESCE(pat.description, pat.name), pat.uuid from person_attribute_type pat where pat.format!='org.openmrs.Concept' and pat.retired=false and pat.name not in ('familyNameLocal', 'middleNameLocal', 'primaryContact')

Getting coded person attribute types

Get coded person attribute types.

select COALESCE(pat.description, pat.name), pat.uuid from person_attribute_type pat join concept question on pat.foreign_key=question.concept_id join concept_name question_name on question_name.concept_id = question.concept_id where pat.format='org.openmrs.Concept' and pat.retired=false and question_name.concept_name_type = 'FULLY_SPECIFIED'

Getting coded answers from a coded person attribute type

?1 = specific coded person attribute type name

select answer.uuid, answer_name.name, cd.name from concept_answer mapping join concept question on question.concept_id = mapping.concept_id join concept answer on answer.concept_id = mapping.answer_concept join concept_name answer_name on answer_name.concept_id = answer.concept_id join concept_name question_name on question_name.concept_id = question.concept_id join person_attribute_type pat on pat.foreign_key=question.concept_id join concept_datatype cd on answer.datatype_id = cd.concept_datatype_id where pat.format='org.openmrs.Concept' and pat.retired=false and answer_name.concept_name_type = 'FULLY_SPECIFIED' and question_name.concept_name_type = 'FULLY_SPECIFIED' and COALESCE(pat.description, pat.name) = ?

Supporting queries to get information from Avni (to be used from metabase in Avni)

Get details required for form mapping

?1 = Name of the form

select distinct form.id as form_id, form.name as form_name, form.form_type as form_type, st.name as st_name, p.name as p_name, et.name as et_name from form join form_mapping fm on form.id = fm.form_id left join subject_type st on fm.subject_type_id = st.id left join program p on fm.entity_id = p.id left join encounter_type et on fm.observations_type_entity_id = et.id where form.name = ?1

Get concepts in a form

?1 = name of the form

select form.name, form_element_group.name, form_element.name, concept.name, concept.uuid from form join form_element_group on form.id = form_element_group.form_id join form_element on form_element_group.id = form_element.form_element_group_id join concept on form_element.concept_id = concept.id where form.name = ?: order by form_element_group.display_order, form_element.display_order asc

Get all answers of a concept

?1 = name of the concept

select concept.name, concept.uuid, ac.name, ac.uuid from concept join concept_answer ca on concept.id = ca.concept_id join concept ac on ac.id = ca.answer_concept_id where concept.name = ?1 order by ca.answer_order asc

Clone this wiki locally