Example #1
0
        ///<summary>After taking a screening using a sheet, this method will import the sheet as a screen and insert it into the db.
        ///Returns null if the sheet passed in is not a Screening sheet type or if the sheet is missing the required ScreenGroupNum param.
        ///Optionally supply a screen if you want to preset some values.  E.g. ScreenGroupOrder is often preset before calling this method.</summary>
        public static Screen CreateScreenFromSheet(Sheet sheet, Screen screen = null)
        {
            //No need to check RemotingRole; no call to db.
            //Make sure that the sheet passed in is a screening and contains the required ScreenGroupNum parameter.
            if (sheet.SheetType != SheetTypeEnum.Screening || SheetParameter.GetParamByName(sheet.Parameters, "ScreenGroupNum") == null)
            {
                return(null);
            }
            if (screen == null)
            {
                screen = new Screen();
                screen.ScreenGroupNum = (long)SheetParameter.GetParamByName(sheet.Parameters, "ScreenGroupNum").ParamValue;
            }
            screen.SheetNum = sheet.SheetNum;
            foreach (SheetField field in sheet.SheetFields)
            {
                switch (field.FieldName)
                {
                case "Gender":
                    if (field.FieldValue.Trim().ToLower().StartsWith("m"))
                    {
                        screen.Gender = PatientGender.Male;
                    }
                    else if (field.FieldValue.Trim().ToLower().StartsWith("f"))
                    {
                        screen.Gender = PatientGender.Female;
                    }
                    else
                    {
                        screen.Gender = PatientGender.Unknown;
                    }
                    break;

                case "Race/Ethnicity":
                    PatientRaceOld patientRace = PatientRaceOld.Unknown;
                    Enum.TryParse <PatientRaceOld>(field.FieldValue.Split(';')[0], out patientRace);
                    screen.RaceOld = patientRace;
                    break;

                case "GradeLevel":
                    PatientGrade patientGrade = PatientGrade.Unknown;
                    Enum.TryParse <PatientGrade>(field.FieldValue.Split(';')[0], out patientGrade);
                    screen.GradeLevel = patientGrade;
                    break;

                case "Age":
                    if (screen.Age != 0)
                    {
                        break;                                //Already calculated via Birthdate.
                    }
                    byte age = 0;
                    byte.TryParse(field.FieldValue, out age);
                    screen.Age = age;
                    break;

                case "Urgency":
                    TreatmentUrgency treatmentUrgency = TreatmentUrgency.Unknown;
                    Enum.TryParse <TreatmentUrgency>(field.FieldValue.Split(';')[0], out treatmentUrgency);
                    screen.Urgency = treatmentUrgency;
                    break;

                case "ChartSealantTreatment":
                    //Only mark "carious" if TP chart has C marked for any tooth surface.
                    if (field.FieldValue.Contains("C"))
                    {
                        screen.HasCaries = YN.Yes;                              //Caries is present in TP'd chart.  Compl chart doesn't matter, it's only for sealant placement.
                    }
                    else
                    {
                        screen.HasCaries = YN.No;
                    }
                    //Only mark "needs sealants" if TP chart has S marked for any tooth surface.
                    if (field.FieldValue.Contains("S"))
                    {
                        screen.NeedsSealants = YN.Yes;
                    }
                    else
                    {
                        screen.NeedsSealants = YN.No;
                    }
                    break;

                case "CariesExperience":
                    screen.CariesExperience = field.FieldValue == "X" ? YN.Yes : YN.No;
                    break;

                case "EarlyChildCaries":
                    screen.EarlyChildCaries = field.FieldValue == "X" ? YN.Yes : YN.No;
                    break;

                case "ExistingSealants":
                    screen.ExistingSealants = field.FieldValue == "X" ? YN.Yes : YN.No;
                    break;

                case "MissingAllTeeth":
                    screen.MissingAllTeeth = field.FieldValue == "X" ? YN.Yes : YN.No;
                    break;

                case "Birthdate":
                    DateTime birthdate = new DateTime(1, 1, 1);
                    DateTime.TryParse(field.FieldValue, out birthdate);
                    screen.Birthdate = birthdate;
                    //Check to see if the sheet has Age manually filled out.
                    //If Age was not manually set, automatically calculate the age based on the birthdate entered.
                    //This matches screening functionality.
                    SheetField sheetFieldAge = sheet.SheetFields.FirstOrDefault(x => x.FieldName == "Age");
                    if (sheetFieldAge != null && string.IsNullOrEmpty(sheetFieldAge.FieldValue))
                    {
                        screen.Age = PIn.Byte(Patients.DateToAge(birthdate).ToString());
                    }
                    break;

                case "Comments":
                    screen.Comments = field.FieldValue;
                    break;
                }
            }
            if (screen.ScreenNum == 0)
            {
                Insert(screen);
            }
            else
            {
                Update(screen);
            }
            return(screen);
        }