Help: Creating csv file from a text file that doesn't have the same data in each row

I have a file that is exported from an upstream system and data is not the same in each row.

But the main attributes in the file are below. Not all the rows might have all the attributes.

unitnumber
idnumber
mail
givenname
manager
department
city
title
mobile

Contents in the file are as below and can only have the above attributes.

i/p:
(‘uid=test.test51,ou=People,o=ic.com,o=xerox’, {‘city’: [‘Irving’], ‘title’: [‘Application Developer’], ‘mobile’: [‘2054444444’], ‘manager’: [‘test.test100’], ‘idnumber’: [‘44451’], ‘department’: [‘National Claims’], ‘mail’: [‘test.test51@infinityplus.com’], ‘givenname’: [‘Test1’], ‘unitnumber’: [‘551’]})
(‘uid=pinuser,ou=People,o=ic.com,o=xerox’, {‘givenname’: [‘Pin’]})
(‘uid=jim.gober,ou=People,o=ic.com,o=xerox’, {‘city’: [‘Birmingham’], ‘title’: [‘CEO’], ‘manager’: [‘jim.gober’], ‘idnumber’: [‘137741’], ‘department’: [‘Executive’], ‘givenname’: [‘James’], ‘unitnumber’: [‘887’]})
(‘uid=ServiceAdmin,ou=People,o=ic.com,o=xerox’, {})
(‘uid=joann.kerr,ou=People,o=ic.com,o=xerox’, {‘city’: [‘Alpharetta’], ‘title’: [‘Senior Software Architect’], ‘manager’: [‘Cynthia Berger’], ‘idnumber’: [‘0003677’], ‘department’: [‘Information Technology’], ‘givenname’: [‘Joann’], ‘unitnumber’: [‘SHD’]})

I need to create a csv file from this that has the data in the below format

required o/p:

1st line with header that can be static followed by the data from the above file.
unitnumber,idnumber,mail,givenname,manager,department,city,title,mobile
551,44451,test.test51@infinityplus.com,Test1,test.test100,National Claims,Irving,Application Developer,2054444444
,Pin,
887,137741,James,jim.gober,Executive,Birmingham,CEO,
,
SHD,0003677,Joann,Cynthia Berger,Information Technology,Alpharetta,Senior Software Architect,