using System.Collections.Generic;
public class zephyrPatientDataList
public List<zephyrPatientData> patients { get; set; }
public zephyrPatientDataList CopyWithClaimedScripts() => new()
patients = patients.Select(p => p.CopyWithClaimedScripts()).ToList()
public class zephyrPatientData
public int CustomerID { get; set; }
public int ClaimID { get; set; }
public string ChemistID { get; set; }
public string FirstName { get; set; }
public string LastName { get; set; }
public List<zDispenseScriptData> scripts{get;set;}
public zephyrPatientData CopyWithClaimedScripts()
scripts = scripts.Where(s => s.claimItem).Select(s => s.Copy()).ToList()
public class zDispenseScriptData
public bool claimItem { get; set; }
public string id { get; set; }
public zDispenseScriptData Copy()
public static void Main()
zephyrPatientDataList list = new()
new() { claimItem = false, id = "ABC" },
new() { claimItem = false, id = "DEF" },
new() { claimItem = true, id = "GHI" },
new() { claimItem = false, id = "JKL" },
new() { claimItem = true, id = "MNO" },
new() { claimItem = false, id = "PQR" },
new() { claimItem = true, id = "ABC" },
new() { claimItem = false, id = "DEF" },
new() { claimItem = true, id = "GHI" },
new() { claimItem = true, id = "JKL" },
new() { claimItem = false, id = "MNO" },
new() { claimItem = true, id = "PQR" },
var newList = list.CopyWithClaimedScripts();
Console.WriteLine("Patient objects in original list:");
PrintPatients(list.patients);
Console.WriteLine("\n\nPatient objects in filtered list:");
PrintPatients(newList.patients);
public static void PrintPatients(IEnumerable<zephyrPatientData> patients)
foreach (var patient in patients)
Console.WriteLine("=======");
Console.WriteLine($"Patient {patient.FirstName} {patient.LastName} (ID: {patient.CustomerID}) (Chemist: {patient.ChemistID}) (Claim ID: {patient.ClaimID})");
foreach (var script in patient.scripts)
Console.WriteLine($"- Script ID {script.id} ({(script.claimItem ? "claimed" : "not claimed")})");