Exemple #1
0
        public async Task <ActionResult <HealthAuthority> > PostHealthAuthority(HealthAuthority healthAuthority)
        {
            _context.HealthAuthorities.Add(healthAuthority);
            await _context.SaveChangesAsync();

            return(CreatedAtAction(nameof(GetHealthAuthority), new { id = healthAuthority.Id }, healthAuthority));
        }
Exemple #2
0
        public async Task <IActionResult> PutHealthAuthority(int id, HealthAuthority healthAuthority)
        {
            if (id != healthAuthority.Id)
            {
                return(BadRequest());
            }

            _context.Entry(healthAuthority).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!HealthAuthorityExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
Exemple #3
0
        private void LoadSampleData()
        {
            if (_db.Cases.Count() > 0)
            {
                return;
            }

            string  file = System.IO.File.ReadAllText("RawData/case_details_210320.json");
            dynamic json = JsonConvert.DeserializeObject(file);


            List <Case> cases = new List <Case>();

            foreach (JObject record in json)
            {
                string reportedDate           = record["Reported_Date"].ToString();
                string HA                     = record["HA"].ToString();
                string sex                    = record["Sex"].ToString();
                string ageGroup               = record["Age_Group"].ToString();
                string classificationReported = record["Classification_Reported"].ToString();

                try
                {
                    // Find AgeGroup
                    AgeGroup ag = _db.AgeGroups.Single(a => a.Range == ageGroup);
                    // Find HealthAuthority
                    HealthAuthority ha = _db.HealthAuthorities.Where(h => h.Region.Name == HA).Single();

                    Case COVID_case = new Case();
                    COVID_case.ReportedDate           = DateTime.Parse(reportedDate);
                    COVID_case.HealthAuthority        = ha;
                    COVID_case.Sex                    = sex;
                    COVID_case.AgeGroup               = ag;
                    COVID_case.ClassificationReported = classificationReported;

                    cases.Add(COVID_case);
                }
                catch (Exception e)
                {
                    continue;
                }
            }

            _db.AddRange(cases);
            _db.SaveChanges();
        }
Exemple #4
0
        private void InitHealthAuthorities()
        {
            if (_db.HealthAuthorities.Count() > 0)
            {
                return;
            }

            string  file = System.IO.File.ReadAllText("RawData/regional_summary_210320.json");
            dynamic json = JsonConvert.DeserializeObject(file);

            List <Tuple <string, string> > HA_HSDA = new List <Tuple <string, string> >();

            foreach (JObject record in json)
            {
                string HA   = record["HA"].ToString();
                string HSDA = record["HSDA"].ToString();

                HA_HSDA.Add(Tuple.Create(HA, HSDA));
            }
            HA_HSDA = HA_HSDA.Distinct().ToList();

            List <HealthAuthority> healthAuthorities = new List <HealthAuthority>();

            foreach (Tuple <string, string> tuple in HA_HSDA)
            {
                HealthAuthority HA = healthAuthorities.Find(ha => ha.Region.Name == tuple.Item1);
                if (HA == null)
                {
                    var region = _db.Regions.Single(r => r.Name == tuple.Item1);
                    HA        = new HealthAuthority();
                    HA.Region = region;

                    healthAuthorities.Add(HA);
                }

                HealthServiceDeliveryArea HSDA = new HealthServiceDeliveryArea();
                HSDA.Area = tuple.Item2;
                HA.HealthServiceDeliveryAreas.Add(HSDA);
            }

            _db.AddRange(healthAuthorities);
            _db.SaveChanges();
        }