Recommended Firebase data structure for my react native app - firebase

I'm creating a medical booking app in react native I almost done my UI and now I stuck in data structure in firebase. so the way app works is simple: user register/sign in select the doctor or the therapist and that therapist has some dates and times which user should choose from to set an appointment.
so the way I consider to structure my data is the following:
but I need a simpler approach so I can get all my dates as an array and feed my calendar with it (so user could see the available dates)
and also get all the timings for specific day so when a user select a time other users can't select that too.
how can I structure this data in firebase? sorry I'm new to this concepts if you feel this question is dumb and I'm thankful for any help.
if you need any extra information just let me know in comment section.

You might want to consider extractimg meetings to its own collection and using the dates as the id of each document.. So whenever someone wants to book a meeting, you check if there is a document with the ID of the date, and if not, create the meeting

Related

How to make Create/Join group with Firebase in Flutter

I want to make a Create/Join group feature in the app where anyone can Create the group
and share group ID and let others people to join(By using firebase as backend). How can I achieve something like that. I need some explanation. What do I need to do or to implement?
Just to keep in mind I don’t want to create chat group. This is more like a group that let users do things together like puzzle. Or like quizzes in Kahoot.
Example
I haven’t start to write yet so there won't be any code
Something i'm actually doing myself though my scenario is a little different as it's more focused on financial groups.
I can point you to a resource that's working for me though i'm still figuring it out myself,maybe it'll be of some help to you too(Note:it only shows how to create and join but doesn't go into how to make invites,but i think its a good start)
Source: this video

Making a leaderboard with Firebase Realtime database and Unity

I am making a leaderboard by using firebase realtime database, unity and facebook ( for profile pic and name )
But I am struggling, I am not sure about the way of doing that. I want to display multiple leaderboards -> All time WORLD / REGION / FRIENDS score, monthly WORLD / REGION / FRIENDS and weekly one.
I know I can use cloud functions to reset weekly and monthly leaderboards.
But how can I store world and region scores ?
Now I just have this ->
https://cdn.discordapp.com/attachments/440873502535450627/821361474353889320/ld.JPG
Thanks to that, I can easily get region leaderboards getref.getchild users . getchild france and then orderbyvalue . limittolast ! this is good !
The problem is how could I get world leaderboard ? ( I have other countries ) I am so lost...Do I need to make another structure for my leaderboard ?
There are a number of considerations that you might put into this including pricing, how much you trust the client, &c. Generally, with a NoSQL database like Realtime Database, you might have a lot of redundant data to make up for the fact that your ability to query is limited. It's also really easy to pull in a lot of data by mistake, so you'll see a number of best practices around keeping your database shallow.
With that said, I think I might recommend reorganizing your data a little bit. For example:
Have one node named "users" with all of your users in there. Each "user" in users should be placed in a node that's simply the userid (which makes security rules easier to write), and here you can place the all time score, monthly score, and weekly score. I'd also recommend storing the time you got that score (using ServerValue.Timestamp) so you don't have to worry about going through your users and deleting all the old scores. If your weekly timestamp isn't this week, you know to ignore/overwrite it (obviously, time is hard, so you'll have to work out what a "week" means to players of your game wrt time zones &c).
I'd also put an array of all a user's "friends" under this user node by their user id. That way, when you go to look up friends, you just just ask for "users/" explicitly there.
Now for regional and world leaderboards on monthly and weekly cadences, I'd just copy everything you want to display into that leaderboard node (say username and score) and add the uid if you need to attribute it back to a user (say if you want to click on that score and see their all time record). So if a user lives in France and they get a weekly high score for them, I'd first write that user's "users/" node with the weekly score and timestamp, then I'd go out to the weekly leaderboard for France and add the new score if it qualifies (ie: don't add it if you're only tracking the top 10), then go out to the world leaderboard and add it there.
How you do this copying is up to you. You could make it the client's responsibility with security rules just making sure they're well behaved - which would probably be fast and cheap but might get weird if they go offline partway through updating. You could use a Firebase trigger that would listen for a user updating their node and copy the data out to the respective leaderboards (this would be more expensive since you're paying for Cloud Functions time and a bit slower but will always work once the user node is updated).
A final note is that for, say, weekly leaderboards. I'd have a node that says "this is France's weekly leaderboard right now" and have all clients read that first before figuring out where to write. That way, at a time you decide for when the week turns over, you can change that node and just have people start writing somewhere else. You can then keep the old leaderboard up for some time (ex: maybe you want to see who changed between this week and last), and you can delete it at your leisure after you're sure that all players have their score in (ex: over slow internets, disconnects, &c).

Firestore goal tracker database modeling

I want to model my flutter firebase app, that will consist of tracking users goal/habits (kind of a todo app) and users can share their own goals and others can add them to become their goals and we can see for example where everyone is progressing on a specific goal for example :
John : 5/7 days checked
William : 3/7 days checked
This is an example of the modal I came with for now, I don't know if I should add a list of "members" for example for adding users that add this goal to their or duplicating the goal itself, the main thing is to watch the progress of all users who added that goal
As per I understood what you can do is create an user collection and goals collection separately.
Register each user under user collection using there auth uid {document} and relevant data.
So if you want to fetch user data all you can do is :
FirebaseFirestore.instance.collection('users').doc(auth.uid).get() and further logic
While in other hand while registering / tracking goals of the users keep all the goals under single collection with a name you prefer {I prefered it as goals} and as you defined additional parameter as owner of the goal pass the user UID as you described.
For the part how are you gonna access the data -
Lets consider I am a user and I have some goals I set, as you can see I am keeping the goals of all users under the same collection. So to fetch the goals for specific user I can do
FirebaseFirestore.instance.collection('goals').where('owner', isEqual: auth.uid)
and get this stream as my user specific goals.
Now second scenario lets suppose I am a user and I want to share the goals to all of the users who are using the app simply I can add one more field to my goals collection as visibility : public/private. So while on a screen where I am fetching goals all over the world (basically goals which are made public to all of the app users) I can write query as
irebaseFirestore.instance.collection('goals').where('visibility', isEqual:'public')
In third scenario lets say you want to send your goals to specific user you can maintain an array of uids you have added in your goals field as access so you can see shared goals by
FirebaseFirestore.instance.collection('goals').where('access', arrayContains: auth.uid)
And last suggestion is time stamping the goals this will help you to fetch the newer goals in order using queries.
I hope it is so much easy than I explained

Firebase database modeling in a appointment app

This is my first question ever on SO and I just want you to know that this community have been helping me for quite some time, and I really got this far thanks to all of you. So thank you. 😀
Now, let me tell you a bit about the question:
I have been scratching my head for days trying to figure this database model for a quite complex (for me, at least) appointment app.
Patients choose a day and it's respective hour slot (15 hourly slots - from 7AM to 9PM) to finish booking a appointment with a therapist. The problem is:
I don't want to show unavailable slots so I must do some real-time querying everytime a date is picked.
I found a way to do this by performing a isEqual query to check if the picked date existed on the therapists agenda collection. If false, the date is available.
The thing is: each therapist has their own subcollection called Agenda but I also need to check if the same date is available in a root collection called Appointments, which is also used by other therapists. This Appointments collection is related to the rooms available for booking. There are 3 rooms available and any room can be automatically booked if it's available. It's a quite complex operation so this is driving me nuts.
Root collection
what I got so far
The therapist agenda
I'm pretty sure I lack a few logical skills to solve this and the answer is probably right in front of my face but I'm failing to see it.
Could anyone please shed me a light into solving this puzzle? Is it possible to achieve all of this in one query function (or performing multiple queries in the same function)? Is there a better way or database structure to do this?
Thanks again!
I would suggest that you store the documents with a random ID and store inside of them a new field called appointment_date which will hold the date, after that, you can query the whole appointment collection with a query like whereEqualTo("appointment_date", yourDate), that query will just fetch the appointments of any specialist.
Also you can store an aditional field inside the appointments documents called specialist_id in which will help you also to get all the appointments for each specialist with a query like
FirebaseFirestore.getInstance().collection("appointments").whereEqualTo("appointment_date",your_date).whereEqualTo("speciallist_id",your_speccialist_id)
This is a kotlin code example, but, with this structure you have more flexibility to query for dates in the agenda, and also query for any speciallist dates
Then, you don't need a subcollection inside your specialist called Agenda, you can just do the query above and you can get each specialist appointment
Check: https://firebase.google.com/docs/firestore/query-data/queries

Add Multiple Time Values to A UserForm

I need assistance with displaying multiple time values on a userform. They will be listed in a list box and will need to remain static should a record require editing.. The user will not have access to the excel worksheet. I need to didplay: time in: time seen; time out on the userform and on a hidden worksheet. I can use the NOW function to record the current time when the customer fills out the form and submits their record(time in). How would I go about writing code that will record the time when the clerk retrieves the customer for service(time seen) and when the customer leaves the office(time out)?
Our clerks have to bring walkin customers in for service within 30 mins of arrival. They also have to issue badges to customers with appointments within 30mins of arrival. Hope that explanation helps. Thanks.
If you are talking about frontend technology then i will suggest Angular with Reactive forms where you can generate the form fields without writing multiple times by using form builder feature. follow below link to know more.
Angular Reactive form guide

Resources