To achieve your requirement, you can use LINQ to filter the Excel data for patients who visited twice on the same appointment date, and whose treatment includes “Knee.” Here’s how you can implement it in UiPath:
Solution using LINQ :
Read Excel Data:
Use the Read Range activity to load your Excel data into a DataTable (let’s call it dtPatients).
Add an Input for Treatment Type:
Use an Input Dialog or Assign activity to specify the treatment type (e.g., treatmentType = "Knee").
Use LINQ to Filter Data:
vb
Copy code
Dim treatmentType As String = "Knee" ' Replace this with your dynamic input if needed
Dim result = (From row In dtPatients.AsEnumerable()
Group row By Patient = row.Field(Of String)("Patient"), AppointmentDate = row.Field(Of Date)("Appointment Date") Into grp = Group
Where grp.Count() > 1 AndAlso grp.Any(Function(r) r.Field(Of String)("Treatment").ToLower() = treatmentType.ToLower())
From item In grp
Where item.Field(Of String)("Treatment").ToLower() = treatmentType.ToLower()
Select item).CopyToDataTable()
Explanation:
Treatment Type as a Variable: The treatment type (treatmentType) can be set dynamically.
ToLower(): Ensures case-insensitive comparison.
Group By: Groups by “Patient” and “Appointment Date”.
Count: Checks for multiple visits on the same date.
Any: Looks for any row with the specified treatment type.
CopyToDataTable: Converts the result back to a DataTable.
Write Data Back to Excel (Optional):
Use the Write Range activity to write result to a new Excel sheet.
Additional Notes:
Ensure your column names in the LINQ query match exactly as in your Excel file.
If dtPatients has inconsistent data types, you might need to adjust the .Field(Of String) or .Field(Of Date) methods.
This solution is flexible and allows you to specify any treatment type without changing the code. If you have more questions, feel free to ask!