Doubt in adding custom fragments to Manage Account dashboard

Hello,

I´m playing with add new fields in account management, but I don´t understand how to do that. I have been reading this post: Adding Custom…. Sorry but when it says " 1. create a JSON into your omod → module → resources → app → customAddEditPersonInfoName.json"…I don´t know if I have to create this json in a new empty module, or in a custom branch for adminui module…¿?

For example, now I have created a personAttributeType (Email), and I have the UUID. If I have to create it in a new empty module…I have to create a new fragment inside with the email field? or it´s not neccesary.

I have this customAddEditPersonInfoName.json:

{ “id”: “${project.parent.groupId}.${project.parent.artifactId}.userAccount.personAttributeEditEmail”, “extensionPointId”: “userAccount.personAttributeEditFragment”, “extensionParams”: { “title” : “Email”, “type”: “personAttribute”, “label”: “Select Email”, “formFieldName”: “personEmail”, “uuid”: “3e4703e6-fabd-4641-99ba-3e6b37462021”, “provider”: “${project.parent.artifactId}”, “fragment”: “manageAccount/addEmail” } }

Thanks so much. Best regards.

Means your own module.

Yes, you need to have it in your custom module.

Yes, you have to need to have the fragment in resource/webapp/fragment/manageAccount/ inside this folder keep the addEmail.gsp to show the email option.

check this

Ok! Perfect! Thanks so much. I have done it, and I got the email field in the account page. It works.

Now, If I put a second field (Telephone Number)…I have a problem when I edit the person details. It just update the last custom field. If I put an email and a telephone number, and I edit person details (account page)…It just update the last field added (telephone number). I have been doing several test, and I think it can be a bug (I´m sorry if I´m wrong). I have been looking at AccountPageController.java (adminui-omod/src/main/java/org/openmrs/module/adminui/page/controller/systemadmin/accounts/AccountPageController.java) and I see that when it take the for customPersonAttributeEditFragments…always overwrite “personAttributeInfo” with the last customPersonAttribute…It´s like that?

ynUIOyrjcK

Ok! Solved! It was that. If you just modify the AdminUI module, and in “personAttributeInfo” add a number for each attribute, It works properly: …

> so = new SimpleObject();
> 		int i = 0;
> 		for(Extension ext : customPersonAttributeEditFragments) {
> 			Object type = ext.getExtensionParams().get("type");
> 			Object personAttributeTypeUuid = ext.getExtensionParams().get("uuid");
> 			Person person = account.getPerson();
> 			if (person != null && type != null && personAttributeTypeUuid != null &&
> 					type.toString().equals("personAttribute")) {
> 				String formFieldName = ext.getExtensionParams().get("formFieldName").toString();
> 				PersonAttribute personAttribute = person.getAttribute(Context.getPersonService()
> 						.getPersonAttributeTypeByUuid(personAttributeTypeUuid.toString()));
> 				if(personAttribute != null) {
> 					String personAttributeUuid = personAttribute.getUuid();
> 					SimpleObject personAttributeInfo = new SimpleObject();
> 					personAttributeInfo.put("formFieldName", formFieldName);
> 					personAttributeInfo.put("personAttributeUuid", personAttributeUuid);
> 					so.put("personAttributeInfo" + i++, personAttributeInfo);
> 				}
> 			}
> 		}
> 		model.addAttribute("customPersonAttributeJson", mapper.writeValueAsString(so));