A Python-based tool to generate OpenMRS 3.x form schemas from Excel metadata files. Designed for rapid, robust, and flexible form creation, supporting advanced skip logic, translations, and a wide range of question types.
π Now with a modern Streamlit web interface for easy form generation!
- Supports various ID formats:
"1 - type"β"1type""Type - 1"β"Type - 1""Type 1 - Gynaecology"β"Type 1 - Gynaecology""1. Question"β"question"
- Ensures uniqueness by appending numbers for duplicates (e.g.,
question_1,question_2). - IDs are compatible with skip logic and custom expressions.
- Numeric sorting by
Ordercolumn in OptionSets (e.g., 1, 2, 3, 10, 20). - Supports decimal numbers (e.g., 1.5).
- Handles duplicate column names gracefully.
- Supports external IDs and answer translations.
- Supports single value, comma-separated, and set notation conditions:
[Question] !== 'Value'[Question] !== '1', '2', '3'[Question] !== {'A', 'B'}
- Multi-select skip logic:
For questions withmultiCheckboxorinlineMultiCheckboxrendering, skip logic usesincludes/!includes:- Example:
!includes(preoperativeDiagnosis, 'uuid')
- Example:
- Logical operators:
- Uses
&&for multiple conditions. - Automatically updates skip logic to use modified question IDs.
- Uses
- Maintains compatibility with generated question IDs, even if IDs are changed for uniqueness.
- Numeric and decimal sorting by
Ordercolumn. - Non-numeric values are placed at the end.
- Maintains sorted order in generated JSON.
- Handles duplicate columns and missing option sets with clear warnings.
- Supports a wide range of rendering types:
radio,multiCheckbox,inlineMultiCheckbox,boolean,numeric,number,text,textarea,markdown,workspace-launcher
- Decimal number handling:
decimalnumberrendering: allows decimals ("disallowDecimals": false)numberrendering: disallows decimals ("disallowDecimals": true), setsmin,max(from metadata), andstep: 1
- Custom min/max/step for numeric fields, using metadata columns.
- Generates translation files for form labels, sections, tooltips, and answers.
- Maintains alphabetical order in translation files.
- Streamlit-based web application for easy form generation
- Drag-and-drop Excel file upload
- Interactive sheet selection with configurable filtering
- Real-time form preview with JSON formatting
- Column mapping configuration interface
- Download generated forms and translations
- Progress tracking and error handling
- Columns:
QuestionLabel if differentQuestion IDExternal IDDatatypeRenderingOptionSet namePageSectionSkip logic- Translation columns (for questions, tooltips, answers)
- Columns:
#(for ordering)OptionSet nameAnswersExternal ID
{
"name": "Form Name",
"pages": [{
"label": "Page Name",
"sections": [{
"label": "Section Name",
"questions": [{
"id": "questionId",
"label": "Question Label",
"questionOptions": {
"rendering": "multiCheckbox",
"answers": [{
"label": "Answer Label",
"concept": "answer-uuid"
}]
}
}]
}]
}]
}{
"form": "Form Name",
"language": "ar",
"translations": {
"Answer Label": "Translated Answer",
"Question Label": "Translated Question",
"Section Name": "Translated Section"
}
}- Start the Streamlit app:
streamlit run src/app.py
- Open your browser and navigate to the provided URL
- Upload your Excel metadata file
- Configure column mappings if needed in the Configuration tab
- Select sheets to generate forms from
- Generate forms and download the JSON files
- Prepare your Excel metadata file following the required format.
- Configure column mappings in
config.jsonif needed. - Run the form generator:
from form_generator import generate_form, generate_translation_file, initialize_option_sets # Initialize option sets initialize_option_sets('metadata.xlsx') # Generate form form_data, _, _, _, _ = generate_form('F01', translations_data) # Generate translations translations = generate_translation_file('F01', 'ar', translations_data)
Run the test suite:
python -m unittest tests/test_form_generator.py -vTest coverage includes:
- Question ID generation and uniqueness
- Skip logic (including multi-select logic)
- Option set ordering and handling
- Decimal and numeric field handling
- Translation generation
The web interface provides an intuitive way to configure:
- Column mappings for Excel file compatibility
- Sheet filter patterns using regex (default:
F\d{2}for F01, F02, etc.) - Import/export of configuration files
Customize via config.json:
- Column mappings
- Sheet filter prefix (regex)
- Default values
- Translation settings
Example:
{
"columns": {
"QUESTION_COLUMN": "Question",
"LABEL_COLUMN": "Label if different",
"OPTION_SET_COLUMN": "OptionSet name"
},
"settings": {
"SHEET_FILTER_PREFIX": "F\\d{2}"
}
}- Python 3.7+
- pip package manager
pip install -r requirements.txtstreamlit- Web interface frameworkpandas- Data manipulationopenpyxl- Excel file handlingpython-dotenv- Environment variable management
- File Upload: Drag-and-drop Excel file upload
- Sheet Selection: Interactive checkbox selection with filtering
- Form Generation: One-click form generation with progress tracking
- Results Display: Comprehensive form statistics and previews
- Download: Direct download of generated JSON files
- Column Mapping: Customize Excel column names
- Sheet Filtering: Configure regex patterns for sheet identification
- Import/Export: Save and restore configuration settings
- Validation: Real-time validation of configuration changes
- Unique, robust question ID generation
- Numeric and decimal option set sorting
- Multi-select skip logic with
includes/!includes - Single, comma, and set notation skip logic
- All major OpenMRS 3.x rendering types
- Custom min/max/step for numeric fields
- Full translation support (questions, answers, tooltips, sections)
- Handles duplicate columns and missing option sets
- Comprehensive test suite
- Modern Streamlit web interface
- Interactive configuration management
- Real-time form preview and validation
-
Clone the repository:
git clone <repository-url> cd formgen
-
Install dependencies:
pip install -r requirements.txt
-
Launch the web interface:
streamlit run src/app.py
-
Open your browser and start generating forms!
Contributions are welcome! Please feel free to submit a Pull Request.
If you have questions or need help with advanced features, please open an issue or contact the maintainers.
This project is licensed under the terms specified in the LICENSE file.