53
Views
8
Comments
Solved
Doctor Name Should Not Appear in Dropdown if Already Assigned to a Patient
Question
Application Type
Reactive

Hi everyone,

I’m currently learning OutSystems and working on a Doctor-Patient Dashboard screen. I’ve come across a requirement and would appreciate some guidance.

In the patient assignment screen, I have a dropdown to select a doctor for a patient. The issue I’m facing is:

If a doctor is already assigned to a patient, their name should not appear again in the dropdown list when assigning a doctor to another patient.

Can someone help me understand how I can filter the dropdown list to exclude already assigned doctors?

Thanks in advance for your help!

2025-04-14 11-22-14
Aditi Saraswat
Solution

Hi @Deebha Shree Ravichandran,

You can achieve this by adding a new boolean attribute, HasAppointment, to your HasAppointment entity. Whenever a doctor is assigned to a patient from the patient page, set this attribute to true.

Then, when retrieving doctor data for the dropdown, simply apply a filter in the aggregate to include only those records where HasAppointment is false. This will ensure that only doctors without existing appointments appear in the list.

Attaching the OML for reference. 

Hope this helps.

Thanks 


DoctorPatientExample.oml
2026-01-28 16-57-48
Mihai Melencu
Champion

Hi @Deebha Shree Ravichandran ,

Could you share more details about how the Doctor and Patient entities are related in your data model? It would also be really helpful if you could provide a sample OML for reference so we can tailor a solution for your use case.

It sounds like you want each doctor to be assigned to only one patient. 

2024-10-09 04-44-30
Bhanu Pratap

Hi @Deebha Shree Ravichandran,

You can use ListFilter for your use case, Add filter condition if the doctor already assigned then show other doctors name in list. For example - Doctor Entity, Doctor Mapping entity (Doctor Id and PatientId) and have IsAssigned Attribute in mapping entity then check this condition like - DoctorMapping.IsAssigned = False

2022-07-12 09-55-09
Philip Paolo De Castro

Hi @Deebha Shree Ravichandran ,

You can check this very helpful article by Dorine Boudry OutSystems Reactive— Mutually exclusive Dropdowns

UserImage.jpg
Long Truong Hoang

Hello sir
With me, the easiest way is that in your Database, if you have a Boolean attribute that turn to true when a doctor already has an appointment and goes to false when free, you could use that with a filter to only display doctor whose is free, like this
Doctor.IsFree = false
Hope this help
*Pretty much a dropdown use data from a source list(aggregate) that you have defined before, just put a filter inside the aggregate that you are using to populate data for the dropdown, and you are done

2026-02-16 05-51-10
Sahana K

Hi @Deebha Shree Ravichandran ,
You can achieve this by using a Join between the Doctor and DoctorAssignment entities and filtering out doctors who already have an assignment. In the filter, check if the Doctor.Assigned = False. This will ensure that only doctors who are not assigned to any patient are displayed in the dropdown list.


Thanks,
Sahana

UserImage.jpg
Fazari

Hi @Deebha Shree Ravichandran,

You can achieve this easily by adding a boolean attribute HasAppointment to the Doctor table. Then, filter the aggregate used to display the list of doctors using the condition: not Doctor.HasAppointment.


If adding an attribute isn't possible, but you have a joining table for appointments, you can accomplish this using a Data Action. Here’s how:

  1. Create a Data Action that fetches data from both the Doctors and Appointments tables.

  2. Append all doctors to the Data Action output list.

  3. Iterate over the Appointments table.

  4. For each appointment, use the ListIndexOf action to find the corresponding doctor in the output list.

  5. Use the ListRemove action to remove doctors who already have appointments from the output list.

This way, you'll end up with a list of only those doctors who do not have any appointments.

Let me know if you need help implementing it!

Thanks,
Fazari

2025-04-14 11-22-14
Aditi Saraswat
Solution

Hi @Deebha Shree Ravichandran,

You can achieve this by adding a new boolean attribute, HasAppointment, to your HasAppointment entity. Whenever a doctor is assigned to a patient from the patient page, set this attribute to true.

Then, when retrieving doctor data for the dropdown, simply apply a filter in the aggregate to include only those records where HasAppointment is false. This will ensure that only doctors without existing appointments appear in the list.

Attaching the OML for reference. 

Hope this helps.

Thanks 


DoctorPatientExample.oml
2020-09-15 13-07-23
Kilian Hekhuis
 
MVP

Everyone here suggesting using a boolean in the data model, or suggesting ListFilter, I've downvoted you, because these sollutions are bad. Why? I'll explain:

  1. Using a boolean: that boolean would be so called redundant data. Redundancy in a data model means that more than one attribute contains the same, or derived, information. Redundancy in and of itself isn't bad per se, and it is often used for optimalization, but it comes with a catch, and should therefore be avoided if possible, especially in data that's volatile (i.e. changes often, like whether a doctor has an appointment): it can easily lead to data inconsistency. Say a doctor's appointment is cancelled, and the appointment is removed from the database, but the developer forgets there's also an "HasAppointment" boolean to set to False, the boolean stays True while there's no appointment;
  2. Using ListFilter: post-processing of data returned from the database is sometimes necessary, but it takes extra time and memory. If at all possible (and in this case it's certainly possible) avoid post-processing and solve your problem in the database. In this specific case, left-joining the appointment Entity and checking there's no acttive appointment (Id = NullIdentifier()) should be sufficient (though in practice, a doctor probably can have multiple appointments and the check is more complex, using Group By and possibly a calculated field or a sum).

Feel free to delete your bad answer.

As for Deebha's question, in general, when you want to solve things like this, you need to think in steps (until you're so experienced that all the steps appear to you immediately :)):

  1. You need a list of doctors. This needs a query on the database (Aggregate or SQL);
  2. You want to display only a subset of docters, in this case doctors that aren't assigned to patients. This means you have to remove thos doctors from the query output. Removing something from the output is done by adding the right Filter;
  3. So now the question is how to Filter out doctors that have an appointment. You didn't show your data model, so I'll assume there's an Entity that holds the appointment, with a DoctorId and a PatientId. You want all doctors that do not have such a record;
  4. To specify there is no record, the general trick is: left join the entity (i.e. a With or Without join in an Aggregate) and on the Filter tab, specify that the Entity's Id must be NullIdentifier(). That will leave you with all doctors that do not have an appointment.

A note of warning: when saving the new appointment, always check whether someone else didn't make an appointment for this doctor. When the screen starts you run the above query, but while the user is busy entering appointment details, some other user may already have created an appointment for the same doctor. So in the save Action, again check whether the doctor is available. Since theoretically, two or more users can press Save at the same time, and both conclude it's safe to save, you need some way to prevent this. In general, the best way is to use an Entity's Get...ForUpdate Action. In this case, a GetDoctorForUpdate, since it's the doctor's availability that's going to be checked.

Community GuidelinesBe kind and respectful, give credit to the original source of content, and search for duplicates before posting.