π IrbyImaging.DomainClasses/CovidTestData.cs Documentation
π Table of Contents
- Overview & Purpose
- Dependencies & Technologies
- Domain Model:
CovidTestData - UML Class Diagram
- Usage Examples
- Best Practices & Notes
- Conclusion
βοΈ Overview & Purpose
The CovidTestData class represents a domain entity within the IrbyImaging.DomainClasses assembly. It models all the information collected during a COVIDβ19 test, such as:
- π Test date
- π§ͺ Test kit details
- β Test results and supporting images
- π©ββοΈ Supervisor information
- π Audit fields (inserted by / date)
This entity is designed to be persisted using Entity Framework Core into the irby.CovidTestData table.
π§ Dependencies & Technologies
| Technology / Package | Purpose |
|---|---|
Microsoft.EntityFrameworkCore |
ORM for mapping the class to the database |
System.ComponentModel.DataAnnotations |
Attributes for key, mapping, and validation |
System.ComponentModel.DataAnnotations.Schema |
[Table], [Key], [DatabaseGenerated] |
| .NET 6+ / .NET Core 3.1+ | Target framework (C# 10+) |
ποΈ Domain Model: CovidTestData
namespace IrbyImaging.DomainClasses
{
[Table("CovidTestData", Schema = "irby")]
public class CovidTestData
{
[Key]
[DatabaseGenerated(DatabaseGeneratedOption.None)]
public Guid CovidTestDataId { get; set; }
public DateTime TestDate { get; set; }
public string TestKitName { get; set; }
public string TestKitNumber { get; set; }
public byte[] TestKitImage { get; set; }
public string Result { get; set; }
public string ResultNotes { get; set; }
public int SupervisorNumber { get; set; }
public string SupervisorName { get; set; }
public byte[] ResultImage { get; set; }
public string RowInsertedBy { get; set; }
public DateTime RowInsertedDate { get; set; }
}
}
π·οΈ 3.1 Entity Mapping Attributes
- [Table("CovidTestData", Schema = "irby")]
Maps the class to theirby.CovidTestDatatable. - [Key]
DeclaresCovidTestDataIdas the primary key. - [DatabaseGenerated(DatabaseGeneratedOption.None)]
Indicates that theGuidmust be provided by the application (no auto-generation by the database).
π 3.2 Properties Overview
| Property Name | Type | Description |
|---|---|---|
CovidTestDataId |
Guid |
βοΈ Primary key; unique identifier for the record. |
TestDate |
DateTime |
π Date and time when the test was performed. |
TestKitName |
string |
π·οΈ Name of the test kit used. |
TestKitNumber |
string |
π’ Serial or batch number of the kit. |
TestKitImage |
byte[] |
π· Raw image data of the test kit (e.g., barcode). |
Result |
string |
β Textual result (e.g., βPositiveβ, βNegativeβ). |
ResultNotes |
string |
π Additional notes or observations. |
SupervisorNumber |
int |
π’ Employee number of the supervising staff. |
SupervisorName |
string |
π€ Full name of the supervisor. |
ResultImage |
byte[] |
πΈ Image of test result (e.g., rapid-test strip). |
RowInsertedBy |
string |
ποΈ Username or system that inserted the row. |
RowInsertedDate |
DateTime |
β±οΈ Timestamp when the row was created. |
π UML Class Diagram
classDiagram
class CovidTestData {
<<Entity>>
+Guid CovidTestDataId
+DateTime TestDate
+string TestKitName
+string TestKitNumber
+byte[] TestKitImage
+string Result
+string ResultNotes
+int SupervisorNumber
+string SupervisorName
+byte[] ResultImage
+string RowInsertedBy
+DateTime RowInsertedDate
}
CovidTestData : <<Table("CovidTestData", Schema="irby")>>
CovidTestData : <<Key>> CovidTestDataId
π οΈ Usage Examples
5.1 Configuring the DbContext
public class ApplicationDbContext : DbContext
{
public DbSet<CovidTestData> CovidTests { get; set; }
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
// Optional: further Fluent API configurations
modelBuilder.Entity<CovidTestData>()
.ToTable("CovidTestData", schema: "irby");
}
}
5.2 Creating & Saving a Record
using (var context = new ApplicationDbContext())
{
var testData = new CovidTestData
{
CovidTestDataId = Guid.NewGuid(),
TestDate = DateTime.UtcNow,
TestKitName = "RapidCheck COVIDβ19",
TestKitNumber = "RC-2022-1234",
TestKitImage = File.ReadAllBytes("kit.jpg"),
Result = "Negative",
ResultNotes = "No symptoms observed.",
SupervisorNumber = 456,
SupervisorName = "Jane Doe",
ResultImage = File.ReadAllBytes("result.jpg"),
RowInsertedBy = "system",
RowInsertedDate = DateTime.UtcNow
};
context.CovidTests.Add(testData);
context.SaveChanges();
}
5.3 Querying Data
// Get all positive results
var positives = context.CovidTests
.Where(ct => ct.Result == "Positive")
.OrderByDescending(ct => ct.TestDate)
.ToList();
π‘ Best Practices & Notes
- ID Generation
BecauseDatabaseGeneratedOption.Noneis set, you must supply your ownGuid(e.g.,Guid.NewGuid()) before saving. - Byte Arrays
Storing images in SQL can bloat the database. Consider using an external storage (e.g., Azure Blob Storage) and save only the URI. - Result Enumeration
For stronger typing, replace thestring Resultwith anenum TestResult { Positive, Negative, Inconclusive }. - Validation
Add[Required],[MaxLength], or custom validation attributes to ensure data integrity.
β Conclusion
The CovidTestData entity provides a straightforward data model for storing and querying COVIDβ19 test results. π― It leverages EF Coreβs code-first approach with DataAnnotation attributes for seamless mapping.
By following the examples and best practices above, you can integrate this class into your ApplicationDbContext, perform CRUD operations, and ensure consistent, auditable test data management.
βWellβstructured domain models make building reliable dataβdriven applications a breeze!β π