Skip to content

Commit

Permalink
Vulnerable Areas
Browse files Browse the repository at this point in the history
  • Loading branch information
ionwyn committed May 27, 2024
1 parent 93d34a3 commit 03e1ce6
Show file tree
Hide file tree
Showing 15 changed files with 628 additions and 33 deletions.
103 changes: 103 additions & 0 deletions api/Hmcr.Data/Database/Entities/AppDbContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ public AppDbContext(DbContextOptions<AppDbContext> options)
public virtual DbSet<HmrSaltReport> HmrSaltReports { get; set; }
public virtual DbSet<HmrSaltStockpile> HmrSaltStockpiles { get; set; }
public virtual DbSet<HmrSaltReportAppendix> HmrSaltReportAppendixes { get; set; }
public virtual DbSet<HmrSaltVulnArea> HmrSaltVulnAreas { get; set; }

protected override void OnModelCreating(ModelBuilder modelBuilder)
{
Expand Down Expand Up @@ -6816,6 +6817,11 @@ protected override void OnModelCreating(ModelBuilder modelBuilder)
.HasForeignKey(e => e.SaltReportId)
.OnDelete(DeleteBehavior.Cascade);

entity.HasMany(e => e.VulnerableAreas)
.WithOne(e => e.SaltReport)
.HasForeignKey(e => e.SaltReportId)
.OnDelete(DeleteBehavior.Cascade);

entity.HasOne(e => e.Appendix)
.WithOne(e => e.SaltReport)
.HasForeignKey<HmrSaltReportAppendix>(e => e.SaltReportId)
Expand Down Expand Up @@ -7108,6 +7114,103 @@ protected override void OnModelCreating(ModelBuilder modelBuilder)
.HasComment("Named database user who created record");
});

modelBuilder.Entity<HmrSaltVulnArea>(entity =>
{
entity.ToTable("HMR_SALT_VULNAREA");

entity.HasKey(e => e.VulnerableAreaId)
.HasName("HMR_SLTVUL_PK");

entity.Property(e => e.VulnerableAreaId)
.HasColumnName("VULNAREA_ID")
.HasColumnType("numeric(9, 0)")
.HasDefaultValueSql("(NEXT VALUE FOR [HMR_SLT_VULNAREA_ID_SEQ])")
.HasComment("A system generated unique identifier.");

entity.Property(e => e.SaltReportId)
.HasColumnName("SALT_REPORT_ID")
.HasColumnType("numeric(9, 0)");

entity.Property(e => e.AppCreateTimestamp)
.HasColumnName("APP_CREATE_TIMESTAMP")
.HasColumnType("datetime")
.HasComment("Date and time of record creation");

entity.Property(e => e.AppCreateUserDirectory)
.IsRequired()
.HasColumnName("APP_CREATE_USER_DIRECTORY")
.HasMaxLength(12)
.IsUnicode(false)
.HasComment("Active Directory which retains source of truth for user idenifiers.");

entity.Property(e => e.AppCreateUserGuid)
.HasColumnName("APP_CREATE_USER_GUID")
.HasComment("Unique idenifier of user who created record");

entity.Property(e => e.AppCreateUserid)
.IsRequired()
.HasColumnName("APP_CREATE_USERID")
.HasMaxLength(30)
.IsUnicode(false)
.HasComment("Unique idenifier of user who created record");

entity.Property(e => e.AppLastUpdateTimestamp)
.HasColumnName("APP_LAST_UPDATE_TIMESTAMP")
.HasColumnType("datetime")
.HasComment("Date and time of last record update");

entity.Property(e => e.AppLastUpdateUserDirectory)
.IsRequired()
.HasColumnName("APP_LAST_UPDATE_USER_DIRECTORY")
.HasMaxLength(12)
.IsUnicode(false)
.HasComment("Active Directory which retains source of truth for user idenifiers.");

entity.Property(e => e.AppLastUpdateUserGuid)
.HasColumnName("APP_LAST_UPDATE_USER_GUID")
.HasComment("Unique idenifier of user who last updated record");

entity.Property(e => e.AppLastUpdateUserid)
.IsRequired()
.HasColumnName("APP_LAST_UPDATE_USERID")
.HasMaxLength(30)
.IsUnicode(false)
.HasComment("Unique idenifier of user who last updated record");

entity.Property(e => e.ConcurrencyControlNumber)
.HasColumnName("CONCURRENCY_CONTROL_NUMBER")
.HasDefaultValueSql("((1))")
.HasComment("Record under edit indicator used for optomisitc record contention management. If number differs from start of edit, then user will be prompted to that record has been updated by someone else.");

entity.Property(e => e.DbAuditCreateTimestamp)
.HasColumnName("DB_AUDIT_CREATE_TIMESTAMP")
.HasColumnType("datetime")
.HasDefaultValueSql("(getutcdate())")
.HasComment("Date and time record created in the database");

entity.Property(e => e.DbAuditCreateUserid)
.IsRequired()
.HasColumnName("DB_AUDIT_CREATE_USERID")
.HasMaxLength(30)
.IsUnicode(false)
.HasDefaultValueSql("(user_name())")
.HasComment("Named database user who created record");

entity.Property(e => e.DbAuditLastUpdateTimestamp)
.HasColumnName("DB_AUDIT_LAST_UPDATE_TIMESTAMP")
.HasColumnType("datetime")
.HasDefaultValueSql("(getutcdate())")
.HasComment("Date and time record was last updated in the database.");

entity.Property(e => e.DbAuditLastUpdateUserid)
.IsRequired()
.HasColumnName("DB_AUDIT_LAST_UPDATE_USERID")
.HasMaxLength(30)
.IsUnicode(false)
.HasDefaultValueSql("(user_name())")
.HasComment("Named database user who created record");
});

modelBuilder.HasSequence("FDBK_MSG_ID_SEQ")
.HasMin(1)
.HasMax(999999999);
Expand Down
1 change: 1 addition & 0 deletions api/Hmcr.Data/Database/Entities/HmrSaltReport.cs
Original file line number Diff line number Diff line change
Expand Up @@ -391,6 +391,7 @@ public class HmrSaltReport
[Column("VAL_LANDS_CHLOR_ID")]
public int? ValuedLandsAreasWithChloride { get; set; }

public ICollection<HmrSaltVulnArea> VulnerableAreas { get; set; }

// Appendix
public HmrSaltReportAppendix Appendix { get; set; }
Expand Down
58 changes: 58 additions & 0 deletions api/Hmcr.Data/Database/Entities/HmrVulnArea.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
using System;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;

namespace Hmcr.Data.Database.Entities
{
[Table("HMR_SALT_VULNAREA", Schema = "dbo")]
public class HmrSaltVulnArea
{
public decimal VulnerableAreaId { get; set; }
public decimal SaltReportId { get; set; }
public HmrSaltReport SaltReport { get; set; } // Navigation property

[Column("HWY_NO")]
[StringLength(16)]
public string HighwayNumber { get; set; }

[Column("LAT")]
public decimal? Latitude { get; set; }

[Column("LONG")]
public decimal? Longitude { get; set; }

[Column("FEATURE")]
[StringLength(255)]
public string Feature { get; set; }

[Column("TYPE")]
[StringLength(255)]
public string Type { get; set; }

[Column("PROT_MEASURES")]
[StringLength(255)]
public string ProtectionMeasures { get; set; }

[Column("ENV_MONITORING")]
public bool? EnvironmentalMonitoring { get; set; }

[Column("COMMENTS")]
[StringLength(255)]
public string Comments { get; set; }

// Default
public long ConcurrencyControlNumber { get; set; }
public string AppCreateUserid { get; set; }
public DateTime AppCreateTimestamp { get; set; }
public Guid AppCreateUserGuid { get; set; }
public string AppCreateUserDirectory { get; set; }
public string AppLastUpdateUserid { get; set; }
public DateTime AppLastUpdateTimestamp { get; set; }
public Guid AppLastUpdateUserGuid { get; set; }
public string AppLastUpdateUserDirectory { get; set; }
public string DbAuditCreateUserid { get; set; }
public DateTime? DbAuditCreateTimestamp { get; set; }
public string DbAuditLastUpdateUserid { get; set; }
public DateTime? DbAuditLastUpdateTimestamp { get; set; }
}
}
13 changes: 13 additions & 0 deletions api/Hmcr.Data/Mappings/ModelToEntityProfile.cs
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,7 @@ public ModelToEntityProfile()
.ForMember(dest => dest.ValuedLandsAreasWithProtection, opt => opt.MapFrom(src => src.Sect7.TypesOfVulnerableAreas.ValuedLands.AreasWithProtection))
.ForMember(dest => dest.ValuedLandsAreasWithChloride, opt => opt.MapFrom(src => src.Sect7.TypesOfVulnerableAreas.ValuedLands.AreasWithChloride))
.ForMember(dest => dest.Appendix, opt => opt.Ignore())
.ForMember(dest => dest.VulnerableAreas, opt => opt.Ignore())
.ForMember(dest => dest.AppCreateTimestamp, opt => opt.MapFrom(src => src.AppCreateTimestamp))
.ReverseMap();

Expand Down Expand Up @@ -346,6 +347,18 @@ public ModelToEntityProfile()
.ForMember(dest => dest.OtherVulnerableAreasIdentified, opt => opt.MapFrom(src => src.VulnerableAreas.OtherVulnerableAreas.Identified))
.ForMember(dest => dest.OtherVulnerableAreasAchieved, opt => opt.MapFrom(src => src.VulnerableAreas.OtherVulnerableAreas.Achieved))
.ReverseMap();

CreateMap<VulnareaDto, HmrSaltVulnArea>()
.ForMember(dest => dest.VulnerableAreaId, opt => opt.MapFrom(src => src.VulnerableAreaId))
.ForMember(dest => dest.HighwayNumber, opt => opt.MapFrom(src => src.HighwayNumber))
.ForMember(dest => dest.Latitude, opt => opt.MapFrom(src => src.Latitude))
.ForMember(dest => dest.Longitude, opt => opt.MapFrom(src => src.Longitude))
.ForMember(dest => dest.Feature, opt => opt.MapFrom(src => src.Feature))
.ForMember(dest => dest.Type, opt => opt.MapFrom(src => src.Type))
.ForMember(dest => dest.ProtectionMeasures, opt => opt.MapFrom(src => src.ProtectionMeasures))
.ForMember(dest => dest.EnvironmentalMonitoring, opt => opt.MapFrom(src => src.EnvironmentalMonitoring))
.ForMember(dest => dest.Comments, opt => opt.MapFrom(src => src.Comments))
.ReverseMap();
}
}
}
46 changes: 36 additions & 10 deletions api/Hmcr.Domain/Services/SaltReportService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public async Task<HmrSaltReport> CreateReportAsync(SaltReportDto dto)
{
try
{
var saltReport = MapToEntity(dto);
var saltReport = MapToEntity(dto);

await _context.HmrSaltReports.AddAsync(saltReport);
_unitOfWork.Commit();
Expand All @@ -68,6 +68,17 @@ public async Task<HmrSaltReport> CreateReportAsync(SaltReportDto dto)
_unitOfWork.Commit(); // Commit stockpiles
}

if (dto.Sect7.VulnerableAreas != null && dto.Sect7.VulnerableAreas.Any())
{
var vulnareas = MapToVulnareas(dto.Sect7.VulnerableAreas); // Map vulnareas using AutoMapper
foreach (var vulnArea in vulnareas)
{
vulnArea.SaltReportId = saltReport.SaltReportId; // Set the foreign key
}
await _context.HmrSaltVulnAreas.AddRangeAsync(vulnareas);
_unitOfWork.Commit(); // Commit vulnerable areas
}

if (dto.Appendix != null)
{
var appendix = MapToAppendix(dto.Appendix, saltReport.SaltReportId); // Use the updated mapping method
Expand Down Expand Up @@ -110,6 +121,16 @@ public List<HmrSaltStockpile> MapToStockpiles(List<StockpileDto> stockpileDtos)
return stockpiles;
}

public List<HmrSaltVulnArea> MapToVulnareas(List<VulnareaDto> vulnareaDtos)
{
// Ensure the list is not null before attempting to map
if (vulnareaDtos == null) throw new ArgumentNullException(nameof(vulnareaDtos));

// Use AutoMapper to map the list of DTOs to the list of entities
var vulnAreas = _mapper.Map<List<HmrSaltVulnArea>>(vulnareaDtos);

return vulnAreas;
}

public void ValidateDto(SaltReportDto dto)
{
Expand Down Expand Up @@ -200,25 +221,30 @@ public async Task<SaltReportDto> GetSaltReportByIdAsync(int saltReportId)
public Stream ConvertToCsvStream(IEnumerable<HmrSaltReport> saltReportEntities)
{
var memoryStream = new MemoryStream();
using var writer = new StreamWriter(memoryStream, leaveOpen: true);
using var csv = new CsvWriter(writer, CultureInfo.InvariantCulture);
using (var writer = new StreamWriter(memoryStream, leaveOpen: true))
{
using (var csv = new CsvWriter(writer, CultureInfo.InvariantCulture))
{
WriteCsvHeaders(writer); // Ensure headers are written correctly
RegisterCsvConverters(csv); // Ensure any custom converters are registered

WriteCsvHeaders(writer);
RegisterCsvConverters(csv);
csv.WriteRecords(saltReportEntities);
csv.WriteRecords(saltReportEntities); // Write records

WriteTotals(writer, saltReportEntities);
writer.Flush(); // Ensure writer is flushed to write all data to the stream
}
// Ensure no additional writes here that could affect the output
WriteTotals(writer, saltReportEntities); // Write any totals or summaries if necessary
}

writer.Flush();
memoryStream.Position = 0;
memoryStream.Position = 0; // Reset stream position to beginning

return memoryStream;
}

private void WriteCsvHeaders(StreamWriter writer)
{
// Headers
writer.WriteLine("2022-23,,,,1. Salt Management Plan,,,,,,,,,,,,2. Winter Ops,,3. Materials Applied,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,4. Design & Operation at Road Salt Storage sites,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,5. Salt Application,,,,,,,,,,,,,,,,,,,,,,6. Snow Disposal,,,,7. Management of Salt Vulnerable Areas,,,,,,,,,,,,,,,,,,,");
writer.WriteLine(",,,,1. Salt Management Plan,,,,,,,,,,,,2. Winter Ops,,3. Materials Applied,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,4. Design & Operation at Road Salt Storage sites,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,5. Salt Application,,,,,,,,,,,,,,,,,,,,,,6. Snow Disposal,,,,7. Management of Salt Vulnerable Areas,,,,,,,,,,,,,,,,,,,");
writer.WriteLine(",,,,Salt Management Plan,,,1.4 Training offered to:,,,,,1.5 Objectives:,,,,(2.1 not used),,3.1 Quantity of materials used:,,,,,,,,,,,,,,,,,,,,,,,3.2 Multi-Chloride Liquids,,,,,,,,4.1,4.2 Stockpile Conditions,,,,,,,,4.3 Good Housekeeping Practices,,,,,,,,,,,,,,,,,,,,,,5.1 Management of Equipment,,,,,,,5.2 Weather Monitoring,,,,,,,5.3 Maintenance Decision Support,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,");
writer.WriteLine(",,,,1.1,1.2,1.3,Managers,Superv's,Operators,Mechanics,Patrollers,Storage Facilities,,Salt Application,,2.2 Total length,2.3 # of days that,SOLIDS:,,,,,,,,LIQUIDS:,wet sand/salt as it goes out,,,,stop the sand from freezing (goes on the stockpile),,,,,to anti-ice (prevent bond); de-ice (too late),,,,,,,,,,,,,Total # of,Road Salts,,,,Treated Abrasive,,,,Materials handled on imperm surface,,Truck overload prevention,,Truck wash-water collection system,,Control & diversion of external (non-salt) water,,Drainage inside with collection systems for runoff of salt contaminated waters:,,Discharged into:,,,,,,,,Ongoing cleanup and sweeping,,Risk mgmt & emerg meas plans in place,,# Vehicles used for salt application,,,,,,,Sources of information,,,,,,,Types of systems used to aid decision making,,,,,,,,6.1,,6.2,6.3,Salt Vulnerable Areas,,,,,,,,,,,,,,,,,,,");
writer.WriteLine(",,,,developed,reviewed,updated,,,,,,#,#,#,#,of roads that,salt was,De-icers,,,,Treated Abrasives,,,,Pre-wetting liquid,,,,,Pre-treatment liquid,,,,,Direct Liquid Application,,,,,Mix A,,,,Mix B,,,,Salt Storage,# salt,Impermeable Surface,Permanent Roof,Tarp Only,total #,Impermeable Surface,Permanent Roof,Tarp Only,,,,,,,,,,,Municipal sewer system,,Containment for removal,,Watercourse,,Other,,,,,,Total #,,conveyor & grnd,,direct,Regular Calibration?,,Infrared Thermometer,,Weather Srv,Fixed RWIS,,Mobile RWIS,,Auto Vehicle Locate,,Record Salt App rates,,Chart for app rates,,Testing of MDSS,,Perform snow disposal at desginated site?,,Use snow melters?,Meltwater discharged in storm sewer?,Inventory?,Vulnerable areas?,Action Plan?,Mitigation Measures,Monitoring?,Drinking Water # Identified,Drinking Water # with protection,Drinking Water # Chloride ,Aquatic Life # Identified,Aquatic Life # with protection,Aquatic Life # Chloride ,Wetlands & Associated aquatic life # Identified,Wetlands & Associated aquatic life # with protection,Wetlands & Associated aquatic life # Chloride ,Delimited Areas w/ terrestrial Fauna/flora # Identified,Delimited Areas w/ terrestrial Fauna/flora # with protection,Delimited Areas w/ terrestrial Fauna/flora # Chloride ,Valued Lands # Identified,Valued Lands # with protection,Valued Lands # Chloride ");
Expand Down
2 changes: 2 additions & 0 deletions api/Hmcr.Model/Dtos/SaltReport/SaltReportDto.cs
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,8 @@ public class AreaDto
public int? AreasWithChloride { get; set; }
}
}

public List<VulnareaDto> VulnerableAreas { get; set; }
}

}
16 changes: 16 additions & 0 deletions api/Hmcr.Model/Dtos/SaltReport/SaltReportVulnareaDto.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
namespace Hmcr.Model.Dtos.SaltReport
{
public class VulnareaDto
{
public decimal VulnerableAreaId { get; set; }
public decimal SaltReportId { get; set; }
public string HighwayNumber { get; set; }
public decimal? Latitude { get; set; }
public decimal? Longitude { get; set; }
public string Feature { get; set; }
public string Type { get; set; }
public string ProtectionMeasures { get; set; }
public bool? EnvironmentalMonitoring { get; set; }
public string Comments { get; set; }
}
}
2 changes: 1 addition & 1 deletion client/src/js/components/SaltReporting.js
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ const SaltReporting = ({ currentUser }) => {
disableClose={loading}
>
{!loading && saltReportCompleteMessage ? (
<Alert color="info">
<Alert color={saltReportSuccess ? 'success' : 'danger'}>
{saltReportCompleteMessage}
{saltReportSuccess && (
<>
Expand Down
Loading

0 comments on commit 03e1ce6

Please sign in to comment.