|
| 1 | +--- |
| 2 | +title: Input Definition Transformation |
| 3 | +description: Input Definition Transformation |
| 4 | +--- |
| 5 | + |
| 6 | +## EligibilityCheck InputDefinitions |
| 7 | + |
| 8 | +Each EligibilityCheck defines a JSON Schema for that data it takes as inputs. This JSON Schema is located at `EligibilityCheck.inputDefinition`, and when a Check is added to a Benefit this JSON Schema is copied to `CheckConfig.inputDefinition`. |
| 9 | + |
| 10 | +Example `EligibilityCheck.inputDefinition` JSON Schema for `Person-min-age` (as of 2026-02-25): |
| 11 | + |
| 12 | +``` |
| 13 | +{ |
| 14 | + "type": "object", |
| 15 | + "properties": { |
| 16 | + "people": { |
| 17 | + "type": "array", |
| 18 | + "items": { |
| 19 | + "type": "object", |
| 20 | + "properties": { |
| 21 | + "dateOfBirth": { |
| 22 | + "type": "string", |
| 23 | + "format": "date" |
| 24 | + }, |
| 25 | + "id": { |
| 26 | + "type": "string" |
| 27 | + } |
| 28 | + } |
| 29 | + } |
| 30 | + } |
| 31 | + } |
| 32 | +} |
| 33 | +``` |
| 34 | + |
| 35 | +Example Data that would be accepted by `EligibilityCheck.inputDefinition` JSON Schema (as of 2026-02-25): |
| 36 | + |
| 37 | +``` |
| 38 | +{ |
| 39 | + "people": [ |
| 40 | + { |
| 41 | + "id": "client", |
| 42 | + "dateOfBirth": "1960-01-01" |
| 43 | + }, |
| 44 | + { |
| 45 | + "id": "spouse", |
| 46 | + "dateOfBirth": "1984-01-01" |
| 47 | + } |
| 48 | + ] |
| 49 | +} |
| 50 | +``` |
| 51 | + |
| 52 | +## The reason for a transformation layer |
| 53 | + |
| 54 | +This JSON Schema existing makes it easy to validate the data being sent to an EligibilityCheck (library or custom). However, forcing the Screener Form to produce data that conforms to this Schema leads to a poor user experience. |
| 55 | + |
| 56 | +After some deliberation, the Tech team of BDT decided that the following format would be more suited to the user experience of building a form: |
| 57 | + |
| 58 | +``` |
| 59 | +{ |
| 60 | + "people": { |
| 61 | + "client": { |
| 62 | + "dateOfBirth": "1960-01-01" |
| 63 | + }, |
| 64 | + "spouse": { |
| 65 | + "dateOfBirth": "1984-01-01" |
| 66 | + } |
| 67 | + } |
| 68 | +} |
| 69 | +``` |
| 70 | + |
| 71 | +If this was the data the Screener Form was expected to produce, then we could have the user choose between the following options when building their form: `["people.client.dateOfBirth", "people.spouse.dateOfBirth"]` |
| 72 | + |
| 73 | +## The transformation Layer |
| 74 | + |
| 75 | +As of 2026-02-25, the Data Transformation Layer has two parts. |
| 76 | + |
| 77 | +- The endpoint `/screener/{screenerId}/form-paths` was made. |
| 78 | + - This endpoint loops over each Benefit in the selected Screener, then loops over each Check selected in those benefits, and transforms the InputDefinitions of those checks into JSON Schemas that match the desired data (`transformInputDefinitionSchema`). |
| 79 | + - Then once the JSON Schema has been created for a check, the "FormPaths" are extracted from that new JSON Schema (`extractJsonSchemaPaths`). |
| 80 | + - These "FormPath" objects are returned to the Frontend. |
| 81 | +- A step was added to Decision Endpoints to transform the Form Data into a state that matched what the EligibilityChecks expect (`FormDataTransformer.transformFormData`). |
| 82 | + |
| 83 | +## Potential weaknesses of this approach |
| 84 | + |
| 85 | +- `InputSchemaService` and `FormDataTransformer` are two different classes in the backend. They are related, but because one of these operates on JSON Schema definitions and the other operates on actual Form Data it is difficult to determine the boundaries of these services. |
| 86 | +- The preferred schema of the Form Data for user experience is known only by the devs and/or by looking at what the transformations do. Some definition of what this "preferred schema" actually is could be added to the codebase. |
| 87 | +- The old method of having the form output match what the EligibilityCheck expected made it simple for devs to know what the output of the form needed to be in order to satisfy the checks. This may also be solved by documenting this preferred form-data schema. |
0 commit comments