πŸ“„ IrbyImaging.DomainClasses/CovidTestData.cs Documentation


πŸ“‘ Table of Contents

  1. Overview & Purpose
  2. Dependencies & Technologies
  3. Domain Model: CovidTestData
  4. UML Class Diagram
  5. Usage Examples
  6. Best Practices & Notes
  7. 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 the irby.CovidTestData table.
  • [Key]
    Declares CovidTestDataId as the primary key.
  • [DatabaseGenerated(DatabaseGeneratedOption.None)]
    Indicates that the Guid must 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
    Because DatabaseGeneratedOption.None is set, you must supply your own Guid (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 the string Result with an enum 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!” πŸš€