Skip to content

Commit

Permalink
Merge branch 'main' into release
Browse files Browse the repository at this point in the history
  • Loading branch information
ashleybot committed Feb 10, 2024
2 parents bc2b090 + e722188 commit 09d3d6d
Show file tree
Hide file tree
Showing 30 changed files with 2,440 additions and 81 deletions.
84 changes: 41 additions & 43 deletions src/UDS.Net.Forms/DataAnnotations/DiagnosisAttribute.cs
Original file line number Diff line number Diff line change
@@ -1,64 +1,62 @@
using System;
using Microsoft.AspNetCore.Mvc.ModelBinding.Validation;
using System.ComponentModel.DataAnnotations;
using Microsoft.AspNetCore.Mvc.ModelBinding.Validation;
using UDS.Net.Forms.Models;
using UDS.Net.Forms.Models.UDS3;
using UDS.Net.Services.Enums;

namespace UDS.Net.Forms.DataAnnotations
[AttributeUsage(AttributeTargets.Property, AllowMultiple = false)]
public class DiagnosisAttribute : ValidationAttribute, IClientModelValidator
{
[AttributeUsage(AttributeTargets.Property, AllowMultiple = false)]
public class DiagnosisAttribute : ValidationAttribute, IClientModelValidator
{
private static string ERRORMESSAGE = "Diagnosis code invalid. Please see reference.";
private static int[] CODES = new int[] { 40, 41, 42, 43, 44, 45, 50, 70, 80, 100, 110, 120, 130, 131, 132, 133, 140, 150, 160, 170, 180, 190, 200, 210, 220, 230, 240, 250, 260, 270, 280, 310, 320, 400, 410, 420, 421, 430, 431, 432, 433, 434, 435, 436, 439, 440, 450, 490, 999 };
private static string ERRORMESSAGE = "Diagnosis code invalid. Please see reference.";
private static int[] CODES = new int[] { 40, 41, 42, 43, 44, 45, 50, 70, 80, 100, 110, 120, 130, 131, 132, 133, 140, 150, 160, 170, 180, 190, 200, 210, 220, 230, 240, 250, 260, 270, 280, 310, 320, 400, 410, 420, 421, 430, 431, 432, 433, 434, 435, 436, 439, 440, 450, 490, 999 };

protected override ValidationResult? IsValid(object? value, ValidationContext validationContext)
{
if (validationContext.ObjectType.IsSubclassOf(typeof(FormModel)))
{
var form = (FormModel)validationContext.ObjectInstance;
public bool AllowUnknown { get; set; } = false;

protected override ValidationResult? IsValid(object? value, ValidationContext validationContext)
{
if (validationContext.ObjectType.IsSubclassOf(typeof(FormModel)))
{
var form = (FormModel)validationContext.ObjectInstance;

// only validate if the form is attempting to be completed
if (form.Status == FormStatus.Complete)
// Only validate if the form is attempting to be completed
if (form.Status == FormStatus.Complete)
{
if (value is int)
{
if (value is int)
int code = (int)value;
if (CODES.Contains(code))
{
int code = (int)value;

if (CODES.Contains(code))
{
return ValidationResult.Success;
}

return ValidationResult.Success;
}
}

return new ValidationResult(ERRORMESSAGE);
if (AllowUnknown && value == null)
{
return ValidationResult.Success;
}
}

return ValidationResult.Success;
return new ValidationResult(ERRORMESSAGE);
}
}
return ValidationResult.Success;
}
public void AddValidation(ClientModelValidationContext context)
{
MergeAttribute(context.Attributes, "data-val", "true");
MergeAttribute(context.Attributes, "data-val-diagnosis", ERRORMESSAGE);
}

public void AddValidation(ClientModelValidationContext context)
/// <summary>
/// See https://learn.microsoft.com/en-us/aspnet/core/mvc/models/validation?view=aspnetcore-7.0#iclientmodelvalidator-for-client-side-validation
/// </summary>
private static bool MergeAttribute(IDictionary<string, string> attributes, string key, string value)
{
if (attributes.ContainsKey(key))
{
MergeAttribute(context.Attributes, "data-val", "true");
MergeAttribute(context.Attributes, "data-val-diagnosis", ERRORMESSAGE);
return false;
}

/// <summary>
/// See https://learn.microsoft.com/en-us/aspnet/core/mvc/models/validation?view=aspnetcore-7.0#iclientmodelvalidator-for-client-side-validation
/// </summary>
private static bool MergeAttribute(IDictionary<string, string> attributes, string key, string value)
{
if (attributes.ContainsKey(key))
{
return false;
}

attributes.Add(key, value);
return true;
}
attributes.Add(key, value);
return true;
}
}

48 changes: 48 additions & 0 deletions src/UDS.Net.Forms/Extensions/DomainToViewModelMapper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,54 @@ public static VisitModel ToVM(this Visit visit)
};
}

public static MilestoneModel ToVM(this Milestone milestone)
{
return new MilestoneModel()
{
Id = milestone.Id,
FormId = milestone.FormId,
ParticipationId = milestone.ParticipationId,
Status = milestone.Status,
CHANGEMO = milestone.CHANGEMO,
CHANGEDY = milestone.CHANGEDY,
CHANGEYR = milestone.CHANGEYR,
PROTOCOL = milestone.PROTOCOL,
ACONSENT = milestone.ACONSENT,
RECOGIM = milestone.RECOGIM.HasValue ? true : false,
REPHYILL = milestone.REPHYILL.HasValue ? true : false,
REREFUSE = milestone.REREFUSE.HasValue ? true : false,
RENAVAIL = milestone.RENAVAIL.HasValue ? true : false,
RENURSE = milestone.RENURSE.HasValue ? true : false,
NURSEMO = milestone.NURSEMO,
NURSEDY = milestone.NURSEDY,
NURSEYR = milestone.NURSEYR,
REJOIN = milestone.REJOIN.HasValue ? true : false,
FTLDDISC = milestone.FTLDDISC.HasValue ? true : false,
FTLDREAS = milestone.FTLDREAS,
FTLDREAX = milestone.FTLDREAX,
DECEASED = milestone.DECEASED.HasValue ? true : false,
DISCONT = milestone.DISCONT.HasValue ? true : false,
DEATHMO = milestone.DEATHMO,
DEATHDY = milestone.DEATHDY,
DEATHYR = milestone.DEATHYR,
AUTOPSY = milestone.AUTOPSY,
DISCMO = milestone.DISCMO,
DISCDAY = milestone.DISCDAY,
DISCYR = milestone.DISCYR,
DROPREAS = milestone.DROPREAS,
CreatedAt = milestone.CreatedAt,
CreatedBy = milestone.CreatedBy,
ModifiedBy = milestone.ModifiedBy,
DeletedBy = milestone.DeletedBy,
IsDeleted = milestone.IsDeleted,
};
}

public static IEnumerable<MilestoneModel> ToVM(this IEnumerable<Milestone> milestones)
{
return milestones.Select(m => m.ToVM()).ToList();
}

public static List<FormModel> ToVM(this IList<Form> forms)
{
List<FormModel> vm = new List<FormModel>();
Expand Down
43 changes: 43 additions & 0 deletions src/UDS.Net.Forms/Extensions/ViewModelToDomainMapper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,49 @@ public static Participation ToEntity(this ParticipationModel vm)
};
}

public static Milestone ToEntity(this MilestoneModel vm)
{
return new Milestone
{
Id = vm.Id,
FormId = vm.FormId,
ParticipationId = vm.ParticipationId,
Status = vm.Status,
CHANGEMO = vm.CHANGEMO,
CHANGEDY = vm.CHANGEDY,
CHANGEYR = vm.CHANGEYR,
PROTOCOL = vm.PROTOCOL,
ACONSENT = vm.ACONSENT,
RECOGIM = vm.RECOGIM == true ? 1 : null,
REPHYILL = vm.REPHYILL == true ? 1 : null,
REREFUSE = vm.REREFUSE == true ? 1 : null,
RENAVAIL = vm.RENAVAIL == true ? 1 : null,
RENURSE = vm.RENURSE == true ? 1 : null,
NURSEMO = vm.NURSEMO,
NURSEDY = vm.NURSEDY,
NURSEYR = vm.NURSEYR,
REJOIN = vm.REJOIN == true ? 1 : null,
FTLDDISC = vm.FTLDDISC == true ? 1 : null,
FTLDREAS = vm.FTLDREAS,
FTLDREAX = vm.FTLDREAX,
DECEASED = vm.DECEASED == true ? 1 : null,
DISCONT = vm.DISCONT == true ? 1 : null,
DEATHMO = vm.DEATHMO,
DEATHDY = vm.DEATHDY,
DEATHYR = vm.DEATHYR,
AUTOPSY = vm.AUTOPSY,
DISCMO = vm.DISCMO,
DISCDAY = vm.DISCDAY,
DISCYR = vm.DISCYR,
DROPREAS = vm.DROPREAS,
CreatedAt = vm.CreatedAt,
CreatedBy = vm.CreatedBy,
ModifiedBy = vm.ModifiedBy,
DeletedBy = vm.DeletedBy,
IsDeleted = vm.IsDeleted,
};
}

public static Visit ToEntity(this VisitModel vm)
{
return new Visit(vm.Id, vm.Number, vm.ParticipationId, vm.Version, vm.Kind, vm.StartDateTime, vm.CreatedAt, vm.CreatedBy, vm.ModifiedBy, vm.DeletedBy, vm.IsDeleted, vm.Forms.ToEntity());
Expand Down
73 changes: 73 additions & 0 deletions src/UDS.Net.Forms/Models/MilestoneModel.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
using System;
using System.ComponentModel.DataAnnotations;
using Microsoft.AspNetCore.Mvc.ModelBinding.Validation;
using UDS.Net.Forms.DataAnnotations;
using UDS.Net.Services.Enums;

namespace UDS.Net.Forms.Models
{
public class MilestoneModel
{
public int Id { get; set; }
public int FormId { get; set; }
public int ParticipationId { get; set; }
[Display(Name = "Status")]
public string Status { get; set; } = "Complete";
[Display(Name = "Month")]
public int? CHANGEMO { get; set; }
[Display(Name = "Day")]
public int? CHANGEDY { get; set; }
[Display(Name = "Year")]
public int? CHANGEYR { get; set; }
[Display(Name = "UDS data collection status changed; participant's new status is")]
public int? PROTOCOL { get; set; }
[Display(Name = "Autopsy consent on file?")]
public int? ACONSENT { get; set; }
[Display(Name = "Participant is too cognitively impaired.")]
public bool? RECOGIM { get; set; }
[Display(Name = "Participant is too ill or physically impaired.")]
public bool? REPHYILL { get; set; }
[Display(Name = "Participant refuses neuropsychological testing or clinical exam.")]
public bool? REREFUSE { get; set; }
[Display(Name = "Participant or co-participant unreachable, not available, or moved away.")]
public bool? RENAVAIL { get; set; }
[Display(Name = "Participant has permanently entered nursing home.")]
public bool? RENURSE { get; set; }
public int? NURSEMO { get; set; }
public int? NURSEDY { get; set; }
public int? NURSEYR { get; set; }
[Display(Name = "Participant is REJOINING ADC.")]
public bool? REJOIN { get; set; }
[Display(Name = "Participant will no longer receive FTLD Module follow-up, but annual in-person UDS visits will continue")]
public bool? FTLDDISC { get; set; }
public int? FTLDREAS { get; set; }
public string? FTLDREAX { get; set; }
[Display(Name = "Participant has died")]
public bool? DECEASED { get; set; }
[Display(Name = "Participant has been dropped from ADC")]
public bool? DISCONT { get; set; }
public int? DEATHMO { get; set; }
public int? DEATHDY { get; set; }
public int? DEATHYR { get; set; }
[Display(Name = "ADC autopsy")]
public int? AUTOPSY { get; set; }
public int? DISCMO { get; set; }
public int? DISCDAY { get; set; }
public int? DISCYR { get; set; }
[Display(Name = "Main reason for being dropped from ADC")]
public int? DROPREAS { get; set; }
public DateTime CreatedAt { get; set; }
public string? CreatedBy { get; set; }
public string? ModifiedBy { get; set; }
public string? DeletedBy { get; set; }
public bool IsDeleted { get; set; }
//Temporary properties only used in the view and NOT sent to the API
[Required]
[Display(Name = "Which milestone type are you reporting?")]
[Range(0, 1)]
//MilestoneType plays a role in client-side validation, must be answered but not stored
public int MilestoneType { get; set; }
//validation properties used as targets for validation messages in the manual validation
public int ProtocolReasonValidation { get; set; }
}
}
Loading

0 comments on commit 09d3d6d

Please sign in to comment.