Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

(feat) O3-3367 Add support for person attributes #423

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

CynthiaKamau
Copy link
Contributor

@CynthiaKamau CynthiaKamau commented Nov 19, 2024

Requirements

  • This PR has a title that briefly describes the work done including the ticket number. If there is a ticket, make sure your PR title includes a conventional commit label. See existing PR titles for inspiration.
  • My work conforms to the OpenMRS 3.0 Styleguide and design documentation.
  • My work includes tests or is validated by existing tests.

Summary

Add support for person attributes

Schema :

{
  "name": "New person attributes  form ",
  "pages": [
    {
      "label": "newPage ",
      "sections": [
        {
          "label": "New section",
          "isExpanded": "true",
          "questions": [
            {
              "label": "Person attribute (String)",
              "type": "personAttribute",
              "required": false,
              "id": "bloodTyping",
              "questionOptions": {
                "rendering": "text",
                "attributeType": "8d871d18-c2cc-11de-8d13-0010c6dffd0f"
              }
            },
            {
              "label": "Person attribute (location drop down)",
              "type": "personAttribute",
              "required": false,
              "id": "bloodTyping1",
              "questionOptions": {
                "rendering": "ui-select-extended",
                "attributeType": "8d87236c-c2cc-11de-8d13-0010c6dffd0f"
              },
              "validators": []
            },
            {
              "label": "Person attribute (concept select drop down)",
              "type": "personAttribute",
              "required": false,
              "id": "bloodTyping2",
              "questionOptions": {
                "rendering": "ui-select-extended",
                "concept": "5272AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA",
                "attributeType": "8d871f2a-c2cc-11de-8d13-0010c6dffd0f"
              },
              "validators": []
            }
          ]
        }
      ]
    }
  ],
  "processor": "EncounterFormProcessor",
  "encounterType": "dd528487-82a5-4082-9c72-ed246bd49591",
  "referencedForms": [],
  "description": "Form that keeps HIV patient data",
  "version": "2.0",
  "uuid": "9478f8b6-0875-4127-b557-f8d844d1bd69"
}

Screenshots

Screen.Recording.2024-11-21.at.13.54.06.mov

Related Issue

Other

@CynthiaKamau CynthiaKamau marked this pull request as draft November 19, 2024 10:41
Copy link

github-actions bot commented Nov 19, 2024

Size Change: -263 kB (-17.3%) 👏

Total Size: 1.26 MB

Filename Size Change
dist/539.js 0 B -263 kB (removed) 🏆
ℹ️ View Unchanged
Filename Size Change
dist/122.js 265 kB 0 B
dist/151.js 379 kB 0 B
dist/225.js 2.57 kB 0 B
dist/254.js 88.7 kB 0 B
dist/277.js 1.85 kB 0 B
dist/300.js 642 B 0 B
dist/335.js 968 B 0 B
dist/353.js 3.02 kB 0 B
dist/41.js 3.37 kB 0 B
dist/540.js 2.63 kB 0 B
dist/55.js 758 B 0 B
dist/585.js 112 kB 0 B
dist/635.js 14.4 kB 0 B
dist/690.js 11.5 kB 0 B
dist/70.js 483 B 0 B
dist/979.js 6.87 kB 0 B
dist/99.js 691 B 0 B
dist/993.js 3.09 kB 0 B
dist/main.js 355 kB +359 B (+0.1%)
dist/openmrs-esm-form-engine-lib.js 3.8 kB -1 B (-0.03%)

compressed-size-action

@CynthiaKamau CynthiaKamau marked this pull request as ready for review November 21, 2024 11:25
@CynthiaKamau CynthiaKamau marked this pull request as draft November 21, 2024 11:48
@CynthiaKamau CynthiaKamau marked this pull request as ready for review November 22, 2024 07:43
@ibacher
Copy link
Member

ibacher commented Nov 22, 2024

So the immediate thing I see here is that we're embedding "format" in the form. I don't really love when we duplicate metadata like this in forms. Just load the format from the backend definition of the attribute type, so we don't face weird issues where changing an attribute type causes forms to break.

@@ -102,7 +102,7 @@ export interface FormSchemaTransformer {
/**
* Transforms the raw schema to be compatible with the React Form Engine.
*/
transform: (form: FormSchema) => FormSchema;
transform: (form: FormSchema) => Promise<FormSchema> | FormSchema;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need the Promise here? i believe the form is resolved before we get here

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We need it

Comment on lines 187 to 189
attribute?: {
type?: string;
};
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looking at the ampath schema docs for personAtttribute, we could eliminate the need for this being an object for backwards compatibility as well have a single format unless you have reasons for going this route

Screenshot 2024-11-29 at 07 10 58

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let me work on this

}
field.meta.submission.newValue = {
value: value,
attributeType: field.questionOptions?.attribute?.type,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The suggested changes in the schema will trickle down

formJson: any,
schemaTransformers: FormSchemaTransformer[] = [],
formSessionIntent?: string,
): FormSchema {
): Promise<FormSchema> {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have reservations to the Promise additions to this file because this affects the way the forms load. Maybe you can share why we need this

Copy link
Contributor Author

@CynthiaKamau CynthiaKamau Nov 29, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This adjustment is needed because the format of a person attribute uuid can be a text, location or concept and those details are fetched from the getPersonAttributeTypeFormat endpoint. Based on the response, we transform the question to the right datasource. @ibacher recommended that we get the backend definitions incase they change, we will still always get the right one. You can add suggestions on how to better handle it incase there is a better way to do it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants