Lutaaya Huzaifah Idris
Lutaaya Huzaifah Idris

Reputation: 4020

Adding Data in Firebase Database

I am migrating to Firebase to help me retrieve my data. My question is how can I format my Firebase Database data like the JSON below. How can I specify objects like the JSON below?

[
  {
    "DoctorsName": "DR.LUTAAYA HUZAIFAH IDRIS",
    "HealthCentreName": "Mulago",
    "Specialisation": "Dentist",
    "Information": "am genious",
    "photo": "huzaifah.jpg",
    "WorkingHours": "8:00am - 3:00pm",
    "PhoneNumber": "0704594180",
    "Email": "[email protected]"
  },
  {
    "DoctorsName": "DR. G. WABULEMBO",
    "HealthCentreName": "Kibuli",
    "Specialisation": "Opthalmologist",
    "Information": " is a consultant Opthalmologist with over 25 years experience in Canada and Uganda.",
    "photo": "wabulembo.jpg",
    "WorkingHours": "8:00am - 12:00pm",
    "PhoneNumber": "0756478923",
    "Email": "[email protected]"
  },
  {
    "DoctorsName": "DR. BUKIRWA JAUHARAH",
    "HealthCentreName": "Kibuli",
    "Specialisation": "Urologist",
    "Information": "Shes a Urologist , she has an experience of 7 years in Kibuli Hospital , and she studied in the United States Of America University",
    "photo": "jauharah.jpg",
    "WorkingHours": "10:00am - 4:00pm",
    "PhoneNumber": "0706081457",
    "Email": "[email protected]"
  },
  {
    "DoctorsName": "DR. R. SEKITOLEKO",
    "HealthCentreName": "Nakasero Hospital",
    "Specialisation": "General Physician",
    "Information": " is consultant physician with over 33 years of experience in Berlin and Hamburg (Germany) and Mulago Hospital (Uganda). He also practised as a consultant with WHO (2001-2003).",
    "photo": "sekitoleko.jpg",
    "WorkingHours": "12:00am - 7:00pm",
    "PhoneNumber": "0765633667",
    "Email": "[email protected]"
  },
  {
    "DoctorsName": "DR. A. MAKHOBA ",
    "HealthCentreName": "Nakasero Hospital",
    "Specialisation": "Cardiologist",
    "Information": "is a consultant cardiologist,. He has practised for more than 20 years in Illinois and Wisconsin (USA) and for over two years in Uganda, at the Uganda Heart Institute and Nakasero Hospital.",
    "photo": "makhoba.jpg",
    "WorkingHours": "8:00am- 4:00pm",
    "PhoneNumber": "0765453636",
    "Email": "[email protected]"
  },
  {
    "DoctorsName": "DR.Sako Banabus",
    "HealthCentreName": "Nakasero Hospital",
    "Specialisation": "Dentist",
    "Information": null,
    "photo": "kamanzi.jpg",
    "WorkingHours": "7:00pm - 3:00am",
    "PhoneNumber": "0754369696",
    "Email": "[email protected]"
  },
  {
    "DoctorsName": "DR. KAMANZI ABUBAKAR",
    "HealthCentreName": "Mengo Hosiptal",
    "Specialisation": "Neurosurgeon",
    "Information": "Hes a Neurosurgeon, he has an experience of 20 years in Mengo Hospital , he studied in the Carlifornia University",
    "photo": "kamanzi.jpg",
    "WorkingHours": "7:00pm - 3:00am",
    "PhoneNumber": "07003014850",
    "Email": "[email protected]"
  }
]

Upvotes: 1

Views: 258

Answers (1)

Alan K.
Alan K.

Reputation: 227

You can write pretty much any JSON you'd like directly to Firebase. For ease of retrieval though, you'd need to figure out some sort of schema. I'd recommend something like the following:

doctors
  <docotrId>
    - doctorId
    - doctorName
    - specialisation
    - information
    - photo
    - phone
    - email
    - @healthCenter
healthCenters
  <healthCenterId>
    - centerId
    - name
    - @doctors[]
specialisationDoctors
  <specialisationName>
    <doctorId>

The first thing you need to do is map your data to this schema. You can create POJO classes, Maps, or even JSON formatted strings.

Then push your mapped data using setValue() on the appropriate nodes. Make sure to read the documentation for more information.

You might also want to check out a Firebase object mapper I'm working on called Firebomb (shameless plug). The Android version will be coming soon.

Finally retrieve data by using the appropriate Firebase event listeners.

Upvotes: 1

Related Questions