Этап 3. Загрузка данных другого варианта из ХML-файлов
This commit is contained in:
parent
78ff9d797e
commit
ee7b714fc6
@ -2,7 +2,7 @@
|
|||||||
{
|
{
|
||||||
public interface IPatientModel : IId
|
public interface IPatientModel : IId
|
||||||
{
|
{
|
||||||
string? Surname { get; }
|
string Surname { get; }
|
||||||
string Name { get; }
|
string Name { get; }
|
||||||
string? Patronymic { get; }
|
string? Patronymic { get; }
|
||||||
DateTime BirthDate { get; }
|
DateTime BirthDate { get; }
|
||||||
|
@ -6,6 +6,24 @@
|
|||||||
<Nullable>enable</Nullable>
|
<Nullable>enable</Nullable>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<None Remove="XMLData\Patient.xml" />
|
||||||
|
<None Remove="XMLData\Procedure.xml" />
|
||||||
|
<None Remove="XMLData\Treatment.xml" />
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<EmbeddedResource Include="XMLData\Patient.xml">
|
||||||
|
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
||||||
|
</EmbeddedResource>
|
||||||
|
<EmbeddedResource Include="XMLData\Procedure.xml">
|
||||||
|
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
||||||
|
</EmbeddedResource>
|
||||||
|
<EmbeddedResource Include="XMLData\Treatment.xml">
|
||||||
|
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
||||||
|
</EmbeddedResource>
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="7.0.4" />
|
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="7.0.4" />
|
||||||
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="7.0.4" />
|
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="7.0.4" />
|
||||||
@ -20,4 +38,19 @@
|
|||||||
<ProjectReference Include="..\HospitalDataModels\HospitalDataModels.csproj" />
|
<ProjectReference Include="..\HospitalDataModels\HospitalDataModels.csproj" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<Compile Update="Properties\Resources.Designer.cs">
|
||||||
|
<DesignTime>True</DesignTime>
|
||||||
|
<AutoGen>True</AutoGen>
|
||||||
|
<DependentUpon>Resources.resx</DependentUpon>
|
||||||
|
</Compile>
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<EmbeddedResource Update="Properties\Resources.resx">
|
||||||
|
<Generator>ResXFileCodeGenerator</Generator>
|
||||||
|
<LastGenOutput>Resources.Designer.cs</LastGenOutput>
|
||||||
|
</EmbeddedResource>
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
</Project>
|
</Project>
|
||||||
|
62
Hospital/HospitalDatabaseImplement/LoaderFromXML.cs
Normal file
62
Hospital/HospitalDatabaseImplement/LoaderFromXML.cs
Normal file
@ -0,0 +1,62 @@
|
|||||||
|
using HospitalDatabaseImplement.Models;
|
||||||
|
using System.Xml.Linq;
|
||||||
|
|
||||||
|
namespace HospitalDatabaseImplement
|
||||||
|
{
|
||||||
|
public class LoaderFromXML
|
||||||
|
{
|
||||||
|
private static readonly string PatientFileName = "XMLData\\Patient.xml";
|
||||||
|
private static readonly string TreatmentFileName = "XMLData\\Treatment.xml";
|
||||||
|
private static readonly string ProcedureFileName = "XMLData\\Procedure.xml";
|
||||||
|
|
||||||
|
private static List<T>? LoadData<T>(string filename, string xmlNodeName, Func<XElement, T> selectFunction)
|
||||||
|
{
|
||||||
|
if (File.Exists(filename))
|
||||||
|
{
|
||||||
|
return XDocument.Load(filename)?.Root?.Elements(xmlNodeName)?.Select(selectFunction)?.ToList();
|
||||||
|
}
|
||||||
|
return new List<T>();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void LoadPatients()
|
||||||
|
{
|
||||||
|
// TODO return LoadData(PatientFileName, "Patient", x => Patient.Create(x)!)!;
|
||||||
|
using var context = new HospitalDatabase();
|
||||||
|
var list = LoadData(PatientFileName, "Patient", x => Patient.Create(x)!)!;
|
||||||
|
list.ForEach(x =>
|
||||||
|
{
|
||||||
|
context.Patients.Add(x);
|
||||||
|
context.SaveChanges();
|
||||||
|
});
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void LoadTreatments()
|
||||||
|
{
|
||||||
|
using var context = new HospitalDatabase();
|
||||||
|
if (context.Treatments.ToList().Count > 0)
|
||||||
|
return;
|
||||||
|
var list = LoadData(TreatmentFileName, "Treatment", x => Treatment.Create(context, x)!)!;
|
||||||
|
list.ForEach(x =>
|
||||||
|
{
|
||||||
|
context.Treatments.Add(x);
|
||||||
|
});
|
||||||
|
context.SaveChanges();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void LoadProcedures()
|
||||||
|
{
|
||||||
|
using var context = new HospitalDatabase();
|
||||||
|
if (context.Procedures.ToList().Count > 0)
|
||||||
|
return;
|
||||||
|
// TODO return LoadData(ProcedureFileName, "Procedure", x => Procedure.Create(context, x)!)!;
|
||||||
|
var list = LoadData(ProcedureFileName, "Procedure", x => Procedure.Create(context, x)!)!;
|
||||||
|
list.ForEach(x =>
|
||||||
|
{
|
||||||
|
context.Procedures.Add(x);
|
||||||
|
context.SaveChanges();
|
||||||
|
});
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -22,7 +22,7 @@ namespace HospitalDatabaseImplement.Models
|
|||||||
public string Dose { get; private set; } = string.Empty;
|
public string Dose { get; private set; } = string.Empty;
|
||||||
|
|
||||||
[Required]
|
[Required]
|
||||||
public int ApothecaryId { get; private set; }
|
public int ApothecaryId { get; private set; } = -1;
|
||||||
|
|
||||||
public virtual Apothecary Apothecary { get; set; }
|
public virtual Apothecary Apothecary { get; set; }
|
||||||
|
|
||||||
|
@ -7,6 +7,7 @@ using System.ComponentModel.DataAnnotations;
|
|||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
|
using System.Xml.Linq;
|
||||||
|
|
||||||
namespace HospitalDatabaseImplement.Models
|
namespace HospitalDatabaseImplement.Models
|
||||||
{
|
{
|
||||||
@ -14,7 +15,7 @@ namespace HospitalDatabaseImplement.Models
|
|||||||
{
|
{
|
||||||
public int Id { get; private set; }
|
public int Id { get; private set; }
|
||||||
|
|
||||||
public string? Surname { get; private set; } = string.Empty;
|
public string Surname { get; private set; } = string.Empty;
|
||||||
[Required]
|
[Required]
|
||||||
public string Name { get; private set; } = string.Empty;
|
public string Name { get; private set; } = string.Empty;
|
||||||
|
|
||||||
@ -42,16 +43,19 @@ namespace HospitalDatabaseImplement.Models
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Patient Create(PatientViewModel model)
|
public static Patient? Create(XElement element)
|
||||||
{
|
{
|
||||||
return new Patient
|
if (element == null)
|
||||||
{
|
{
|
||||||
Id = model.Id,
|
return null;
|
||||||
Surname = model.Surname,
|
}
|
||||||
Name = model.Name,
|
return new Patient()
|
||||||
Patronymic = model.Patronymic,
|
{
|
||||||
BirthDate = model.BirthDate,
|
Surname = element.Element("Surname")!.Value,
|
||||||
TreatmentId = model.TreatmentId
|
Name = element.Element("Name")!.Value,
|
||||||
|
Patronymic = element.Element("Patronymic")?.Value,
|
||||||
|
BirthDate = DateTime.ParseExact(element.Element("BirthDate")!.Value, "dd.mm.yyyy", null),
|
||||||
|
TreatmentId = Convert.ToInt32(element.Element("TreatmentId")!.Value)
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -8,6 +8,7 @@ using System.ComponentModel.DataAnnotations.Schema;
|
|||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
|
using System.Xml.Linq;
|
||||||
|
|
||||||
namespace HospitalDatabaseImplement.Models
|
namespace HospitalDatabaseImplement.Models
|
||||||
{
|
{
|
||||||
@ -52,6 +53,22 @@ namespace HospitalDatabaseImplement.Models
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static Procedure? Create(HospitalDatabase context, XElement element)
|
||||||
|
{
|
||||||
|
if (element == null)
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
return new Procedure()
|
||||||
|
{
|
||||||
|
Name = element.Element("Name")!.Value,
|
||||||
|
/* Medicines = element.Element("Medicines")!.Elements("MedicineId").Select(x => new ProcedureMedicine
|
||||||
|
{
|
||||||
|
Medicine = context.Medicines?.First(y => y.Id == Convert.ToInt32(x.Value))
|
||||||
|
}).ToList()*/
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
public void Update(ProcedureBindingModel model)
|
public void Update(ProcedureBindingModel model)
|
||||||
{
|
{
|
||||||
Name = model.Name;
|
Name = model.Name;
|
||||||
|
@ -8,6 +8,7 @@ using System.ComponentModel.DataAnnotations.Schema;
|
|||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
|
using System.Xml.Linq;
|
||||||
|
|
||||||
namespace HospitalDatabaseImplement.Models
|
namespace HospitalDatabaseImplement.Models
|
||||||
{
|
{
|
||||||
@ -54,6 +55,22 @@ namespace HospitalDatabaseImplement.Models
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static Treatment? Create(HospitalDatabase context, XElement element)
|
||||||
|
{
|
||||||
|
if (element == null)
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
return new Treatment()
|
||||||
|
{
|
||||||
|
Name = element.Element("Name")!.Value,
|
||||||
|
Procedures = element.Element("Procedures")!.Elements("ProcedureId").Select( x => new TreatmentProcedure
|
||||||
|
{
|
||||||
|
Procedure = context.Procedures.First(y => y.Id == Convert.ToInt32(x.Value))
|
||||||
|
}).ToList()
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
public void Update(TreatmentBindingModel model)
|
public void Update(TreatmentBindingModel model)
|
||||||
{
|
{
|
||||||
Name = model.Name;
|
Name = model.Name;
|
||||||
|
17
Hospital/HospitalDatabaseImplement/XMLData/Patient.xml
Normal file
17
Hospital/HospitalDatabaseImplement/XMLData/Patient.xml
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<Patients>
|
||||||
|
<Patient Id="1">
|
||||||
|
<Surname>Фамилия 1</Surname>
|
||||||
|
<Name>Имя 1</Name>
|
||||||
|
<Patronymic>Отчество 1</Patronymic>
|
||||||
|
<BirthDate>10.01.2021</BirthDate>
|
||||||
|
<TreatmentId>1</TreatmentId>
|
||||||
|
</Patient>
|
||||||
|
<Patient Id="2">
|
||||||
|
<Surname>Фамилия 2</Surname>
|
||||||
|
<Name>Имя 2</Name>
|
||||||
|
<Patronymic>Отчество 1</Patronymic>
|
||||||
|
<BirthDate>15.04.2001</BirthDate>
|
||||||
|
<TreatmentId>2</TreatmentId>
|
||||||
|
</Patient>
|
||||||
|
</Patients>
|
30
Hospital/HospitalDatabaseImplement/XMLData/Procedure.xml
Normal file
30
Hospital/HospitalDatabaseImplement/XMLData/Procedure.xml
Normal file
@ -0,0 +1,30 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<Procedures>
|
||||||
|
<Procedure Id="1">
|
||||||
|
<Name>Процедура 1</Name>
|
||||||
|
<Medicines>
|
||||||
|
<MedicineId >1</MedicineId>
|
||||||
|
<MedicineId >2</MedicineId>
|
||||||
|
<MedicineId >3</MedicineId>
|
||||||
|
</Medicines>
|
||||||
|
</Procedure>
|
||||||
|
<Procedure Id="2">
|
||||||
|
<Name>Процедура 2</Name>
|
||||||
|
<Medicines>
|
||||||
|
<MedicineId >1</MedicineId>
|
||||||
|
</Medicines>
|
||||||
|
</Procedure>
|
||||||
|
<Procedure Id="3">
|
||||||
|
<Name>Процедура 3</Name>
|
||||||
|
<Medicines>
|
||||||
|
<MedicineId >2</MedicineId>
|
||||||
|
<MedicineId >3</MedicineId>
|
||||||
|
</Medicines>
|
||||||
|
</Procedure>
|
||||||
|
<Procedure Id="4">
|
||||||
|
<Name>Процедура 4</Name>
|
||||||
|
</Procedure>
|
||||||
|
<Procedure Id="5">
|
||||||
|
<Name>Процедура 5</Name>
|
||||||
|
</Procedure>
|
||||||
|
</Procedures>
|
34
Hospital/HospitalDatabaseImplement/XMLData/Treatment.xml
Normal file
34
Hospital/HospitalDatabaseImplement/XMLData/Treatment.xml
Normal file
@ -0,0 +1,34 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<Treatments>
|
||||||
|
<Treatment Id="1">
|
||||||
|
<Name>Лечение 1</Name>
|
||||||
|
<Procedures>
|
||||||
|
<ProcedureId >1</ProcedureId>
|
||||||
|
<ProcedureId >2</ProcedureId>
|
||||||
|
<ProcedureId >3</ProcedureId>
|
||||||
|
</Procedures>
|
||||||
|
</Treatment>
|
||||||
|
<Treatment Id="2">
|
||||||
|
<Name>Лечение 2</Name>
|
||||||
|
<Procedures>
|
||||||
|
<ProcedureId >1</ProcedureId>
|
||||||
|
</Procedures>
|
||||||
|
</Treatment>
|
||||||
|
<Treatment Id="3">
|
||||||
|
<Name>Лечение 3</Name>
|
||||||
|
<Procedures>
|
||||||
|
<ProcedureId >2</ProcedureId>
|
||||||
|
<ProcedureId >3</ProcedureId>
|
||||||
|
</Procedures>
|
||||||
|
</Treatment>
|
||||||
|
<Treatment Id="4">
|
||||||
|
<Name>Лечение 4</Name>
|
||||||
|
<Procedures>
|
||||||
|
</Procedures>
|
||||||
|
</Treatment>
|
||||||
|
<Treatment Id="5">
|
||||||
|
<Name>Лечение 5</Name>
|
||||||
|
<Procedures>
|
||||||
|
</Procedures>
|
||||||
|
</Treatment>
|
||||||
|
</Treatments>
|
Loading…
x
Reference in New Issue
Block a user