-2

I am working on a project that consists of a medical patient record system that stores a large amount of patient information within it. When a doctor/nurse adds a new patient, they must go through a big list of medical history conditions etc such as if the patient has cancer, if they are a smoker, if they are obese etc. Each of the variables is booleans and are declared as yes or no with a value of 1 or 0.

All the variables on the patient input form are needed since they are part of a larger risk-assessment calculator. Each of those conditions has specific values, for example, if a patient has cancer then yes is selected. That would then be +1 point to the scoring system that's added overall for each patient. Some variables such as obesity would have more than 1 answer so they'd get either 0/1/2 points.

All these variables are placed within a patient.cs class and so are features such as BMI calculators. Where and how would I be able to assign a score for each of my variables? (There are well over 15 different variables so it would have to be a big if-else statement)

Any assistance would be appreciated.

-----------------------[EDIT]-------------------------------------

The code below is my patient.cs class as of now

 public class Patient
    {
        //The patients ID
        [Key]
        [DatabaseGenerated(DatabaseGeneratedOption.Identity)]
        public int patientId { get; set; }

        [ForeignKey("ApplicationUser")]
        public string Id { get; set; }
        public virtual ApplicationUser ApplicationUser { get; set; }

        public string firstName { get; set; }

        public string middleName { get; set; }

        public string lastName { get; set; }

        public string gender { get; set; }

        public DateTime birthdate { get; set; }

        public decimal weight { get; set; }

        public decimal height { get; set; }


        /*  ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
            Pre-existing risk factors
            ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~          
         */

        //Parity is the amount of pregnancies had
        public int parity { get; set; }
        // single, married, seperated or divorced
        public string civilStatus { get; set; }
        //  yes = 4 | no = 0
        public bool previousVTE { get; set; }
        // Provoked by major surgery?  yes = 3 | no = 0
        public bool surgeryVTE { get; set; }
        //  yes = 3 | no = 0
        public bool highRiskThrombophilia { get; set; }
        //  yes =  | no = 
        public bool cancer { get; set; }
        //  yes = 3 | no = 0
        public bool heartFailure { get; set; }
        //  yes = 3 | no = 0
        public bool activeSystemicLupusErythematosus { get; set; }
        //  yes = 3 | no = 0
        public bool inflammatoryPolyarthropathy { get; set; }
        //  yes = 3 | no = 0
        public bool inflammatoryBowelDisease { get; set; }
        //  yes = 3 | no = 0
        public bool nephroticSyndrome { get; set; }
        //  yes = 3 | no = 0
        public bool typeIDiabetesMellitusWithNephropathy { get; set; }
        //  yes = 3 | no = 0
        public bool sickleCellDisease { get; set; }
        //  yes = 3 | no = 0
        public bool currentInratvenousDrugUser { get; set; }
        // Family history of unprovoked / estrogen-related VTE in first-degree relative? yes = 1 | no = 0
        public bool familyHistoryVTEFirstDegreeRelative { get; set; }
        //  yes = 1 | no = 0
        public bool lowRiskThrombophilia { get; set; }
        //  yes = 1 | no = 0
        public bool smoker { get; set; }
        //  yes = 1 | no = 0
        public bool grossVaricoseVeins { get; set; }

        //  0 = no, 1=>30 2=>40
        public string obesity { get; set; }


        /*  ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
            Obstetric risk factors
            ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~     
         */

        //  yes = 1 | no = 0
        public bool preEclampsiaInCurrentPregnancy { get; set; }
        // ART/IVF (antenatal only) yes = 1 | no = 0
        public bool ARTorIVF { get; set; }
        //  yes = 1 | no = 0
        public bool multiplePregnancy { get; set; }
        //  yes = 2 | no = 0
        public bool caesareanSectionInLabour { get; set; }
        //  yes = 1 | no = 0
        public bool electiveCaesareanSection { get; set; }
        // Mid-cavity or rotational operative delivery yes = 1 | no = 0
        public bool operativeDelivery { get; set; }
        // Prolonged labour (> 24 hours) yes = 1 | no = 0
        public bool prolongedLabour { get; set; }
        // PPH (> 1 litre or transfusion) yes = 1 | no = 0
        public bool PPH { get; set; }
        // Preterm birth < 37+0 weeks in current pregnancy yes = 1 | no = 0
        public bool pretermBirth { get; set; }
        // Stillbirth in current pregnancy yes = 1 | no = 0
        public bool stillBirth { get; set; }

        /*  ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
            Transient risk factors
            ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~     
         */

        // Any surgical procedure in pregnancy or puerperium except immediate repair of the
        // perineum, e.g.appendicectomy, postpartum sterilisation yes = 3 | no = 0
        public bool surgicalProcedure { get; set; }
        // yes = 3 | no = 0
        public bool Hyperemesis { get; set; }
        // yes OHSS(first trimester only = 4 | no = 0
        public bool OHSS { get; set; }
        //  yes = 1 | no = 0
        public bool currentSystemicInfection { get; set; }
        //  yes = 1 | no = 0
        public bool immobilityOrDehydration { get; set; }


        //public string middleName { get; set; }

        private ApplicationDbContext _dbContext;

        public Patient()
        {
            this._dbContext = new ApplicationDbContext();
        }


        public void AddToDatabase()
        {
            _dbContext.Patients.Add(this);
            _dbContext.SaveChanges();

        }
zadders
  • 428
  • 1
  • 8
  • 30
  • 1
    If each yes gives a +1 just iterate all of your properties and see if they are set to true and add 1 to the count. Perhaps this will help (https://stackoverflow.com/questions/8151888/c-sharp-iterate-through-class-properties) – Ryan Wilson Mar 18 '19 at 13:43
  • 2
    1. create `class Risk { string name; int value; bool checked; }` 2. build List of them ... 3. sum all value in list where checked is true `int sumOfRisks = list.Where(x=>x.checked).Sum(x=>x.value);` – Selvin Mar 18 '19 at 13:44
  • 2
    I would highly recommend taking the extra time to break that massive class down. If you are unfamiliar with it, look into the Single Responsibility Principle (SRP) and the Don't Repeat Yourself (DRY) principle. – Lews Therin Mar 18 '19 at 13:45
  • @LewsTherin I've added what my class looks like, I still haven't made the if-else statement part, because I was unsure if that was the right approach. I'm not familiar with the terms you mentioned so i'll research them – zadders Mar 18 '19 at 13:48
  • @Selvin I don't really get how I'd apply that, I'm not too experienced with c# since i'm still learning – zadders Mar 18 '19 at 13:49
  • @RyanWilson They're not all +1, some of them vary between 2,3 and 4 points. – zadders Mar 18 '19 at 14:08
  • @zadders I would go with Selvin's suggestion and make these into class objects containing the name, integer value for points total, and a boolean of selected (checked). Then you can just sum the list of objects based on if they are selected or not. – Ryan Wilson Mar 18 '19 at 14:33
  • @Selvin hey, I apologies for the late reply, but I ended up going with the method you recommended and it seemed to be the most straight forward and logical in my opinion. You should reply as an official answer so I can select it as a correct one :) – zadders Apr 03 '19 at 21:10

1 Answers1

1

Write a series of expressions representing the amount of score per risk factor, and put them in an array.

var riskFactors = new Func<Patient,float>[]
{
    p => p.cancer  ? 3.0F : 0F,
    p => p.multiplePregnancy ? 2.0F : 0F
    p => p.caesareanSectionInLabour ? 1.0F : 0.F,
    //One expression per item in the questionnaire
};

Then you just need to sum them to get a patient's total score:

public float GetScoreForPatient(Patient patient)
{
    return riskFactors.Select
    ( 
        factor => factor(patient)
    )
    .Sum();
}
John Wu
  • 50,556
  • 8
  • 44
  • 80