Skip to content

Instantly share code, notes, and snippets.

@brandones
Last active December 16, 2020 21:21
Show Gist options
  • Save brandones/9a220f4236553c3aae984ec011245781 to your computer and use it in GitHub Desktop.
Save brandones/9a220f4236553c3aae984ec011245781 to your computer and use it in GitHub Desktop.
Config schema for esm-patient-registration
import { Type, validator, validators } from '@openmrs/esm-module-config';
const builtInFields = ['name', 'gender', 'dob', 'address', 'id', 'death']
export const schema = {
sections: {
_type: Type.Array,
_default: ['demographics', 'contact', 'ids', 'death'],
_description: "An array of strings which are the keys from 'sectionDefinitions'",
_elements: {
_type: Type.String
}
},
sectionDefinitions: {
_type: Type.Object,
_elements: {
name: {
_type: Type.String,
_default: "",
_description: "The title to display at the top of the section."
},
fields: {
_type: Type.Array,
_default: [],
_description: `The parts to include in the section. Can be any of the following built-in fields: ${builtInFields.join(', ')}. Can also be any of the keys from the fieldDefinitions object, which you can use to define custom fields.`,
_elements: { _type: Type.String } // another validator at top level
}
},
_default: {
demographics: { name: "Demographics", fields: ["name", "gender", "dob"] },
contact: { name: "Contact Info", fields: ["address"] },
ids: { name: "Identifiers", fields: ["id"] },
death: { name: "Death Info", fields: ["death"] }
}
},
fieldDefinitions: {
_type: Type.Object,
_elements: {
// Right now only patientAttributes are supported. We'll have to elaborate on this in order to support concepts.
label: { _type: Type.String, description: 'The label of the input' },
uuid: {
_type: Type.UUID
_description: 'Person attributetype uuid used to save the attribute',
},
placeholder: {
_type: Type.String,
_default: "",
_description: 'Placeholder that will appear in the input.'
},
validation: {
required: { _type: Type.Boolean, _default: false },
matches: { _type: Type.String, _default: null, _description: 'Optional RegEx for testing the validity of the input.' },
},
},
_default: {},
_description: "Definitions for custom fields that can be used in sectionDefinitions. Can also be used to override built-in fields."
}
}
@brandones
Copy link
Author

brandones commented Sep 18, 2020

So the config that would be needed in order to add a telephone number field to "Contact Info" would be

{
  sectionDefinitions: {
    contact: {
      questions: ["address", "phone"]
    },
  },
  fieldDefinitions: {
    phone: {
      label: "Telephone number",
      uuid: "14d4f066-15f5-102d-96e4-000c29c2a5d7",
      validation: { required: true, matches: "^[0-9]*$" }
    }
  }
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment