-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
30 changed files
with
2,440 additions
and
81 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; } | ||
} | ||
} |
Oops, something went wrong.