Ignore:
Timestamp:
08/07/20 11:01:25 (4 years ago)
Author:
Mile Jankuloski <mile.jankuloski@…>
Branches:
master
Children:
5d02859
Parents:
ee137aa (diff), c406ae5 (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent.
Message:

Merge branch 'master' of https://develop.finki.ukim.mk/git/farmatiko

File:
1 edited

Legend:

Unmodified
Added
Removed
  • FarmatikoServices/Services/ProcessJSONService.cs

    ree137aa r63d885e  
    1010using FarmatikoServices.FarmatikoServiceInterfaces;
    1111using RestSharp;
     12using System.Threading.Tasks;
    1213
    1314namespace FarmatikoServices.Services
     
    1516    public class ProcessJSONService : IProcessJSONService
    1617    {
    17         //private IHealthFacilityRepository _healthFacilityRepository;
     18        private IHealthFacilityRepository _healthFacilityRepository;
    1819        private IPandemicRepository _pandemicRepository;
    19         //private IHealthcareWorkerRepository _healthcareWorkerRepository;
    20         //private IMedicineRepository _medicineRepository;
    21         //private readonly ILogger _logger;
    22         public ProcessJSONService(/*IHealthFacilityRepository healthFacilityRepository, */IPandemicRepository pandemicRepository/*,
    23             IHealthcareWorkerRepository healthcareWorkerRepository, IMedicineRepository medicineRepository*/)
     20        private IHealthcareWorkerRepository _healthcareWorkerRepository;
     21        private IMedicineRepository _medicineRepository;
     22        private readonly ILogger _logger;
     23        public ProcessJSONService(IHealthFacilityRepository healthFacilityRepository, IPandemicRepository pandemicRepository,
     24            IHealthcareWorkerRepository healthcareWorkerRepository, IMedicineRepository medicineRepository, ILogger logger)
    2425        {
    25             //_logger = logger;
    26             //_healthFacilityRepository = healthFacilityRepository;
     26            _logger = logger;
     27            _healthFacilityRepository = healthFacilityRepository;
    2728            _pandemicRepository = pandemicRepository;
    28             //_healthcareWorkerRepository = healthcareWorkerRepository;
    29             //_medicineRepository = medicineRepository;
     29            _healthcareWorkerRepository = healthcareWorkerRepository;
     30            _medicineRepository = medicineRepository;
    3031        }
    31        
    32         public List<HealthFacilities> GetProcessedHealthFacilitiesFromJSON()
     32
     33        public async Task<HashSet<HealthFacilities>> GetProcessedHealthFacilitiesFromJSON()
    3334        {
    3435            try
    3536            {
    36                 /*var client = new WebClient();
    37                 var json = client.DownloadString(@"C:\Users\Miki\Desktop\ustanovi.json");
     37                HashSet<HealthFacilities> hashSet = new HashSet<HealthFacilities>();
     38                var client = new WebClient();
     39                var json = client.DownloadString(@"C:\Users\dslez\Desktop\ustanovi.json");
    3840
    3941                var jsonResponse = JObject.Parse(json);
    4042                var records = JArray.Parse(jsonResponse.GetValue("records").ToString());
    4143
    42                 foreach(var rec in records)
     44                foreach (var rec in records)
    4345                {
    4446                    dynamic obj = JsonConvert.DeserializeObject(rec.ToString());
     
    4951                    var Phone = obj[11];
    5052                    var Type = obj[5];
    51                     HealthFacilities healthFacility = new HealthFacilities();
    52                     healthFacility.Name = Name;
     53                    HealthFacilities healthFacility = new HealthFacilities(Name, Municipality, Address, Type, Email, Phone);
     54                    /*healthFacility.Name = Name;
    5355                    healthFacility.Municipality = Municipality;
    5456                    healthFacility.Address = Address;
    5557                    healthFacility.Email = Email;
    5658                    healthFacility.Phone = Phone;
    57                     healthFacility.Type = Type;
    58                     _healthFacilityRepository.Add(healthFacility);
    59                    
    60                 }*/
     59                    healthFacility.Type = Type;*/
     60                    //hashSet.Add(healthFacility);
     61                    await Task.Run(() => _healthFacilityRepository.Add(healthFacility));
    6162
     63                }
    6264
     65            }
     66            catch (Exception e)
     67            {
     68                _logger.LogInformation(e.Message);
     69                throw new Exception("Cannot process health facilities from JSON.");
     70            }
     71            return null;
     72        }
    6373
    64                 var client1 = new RestClient("https://api.covid19api.com/summary");
    65                 var response = client1.Execute(new RestRequest());
     74        public async Task<HashSet<Pandemic>> GetProcessedPandemicsFromJSONApi()
     75        {
     76            try
     77            {
     78                var client = new RestClient("https://api.covid19api.com/summary");
     79                var response = client.Execute(new RestRequest());
    6680                string original = response.Content;
    6781                var jsonResponsePandemic = JObject.Parse(original);
     
    7892                var NewMK = Int32.Parse(objP.GetValue("NewConfirmed").ToString());
    7993
    80                 Pandemic pandemic = new Pandemic();
    81                 pandemic.TotalGlobal = TotalConfirmed;
     94                var Name = "Coronavirus";
     95                var ActiveMk = TotalMk - (TotalRecoveredMK + TotalDeathsMK);
     96                var ActiveGlobal = TotalConfirmed - (TotalRecovered + TotalDeaths);
     97
     98                Pandemic pandemic = new Pandemic(Name, TotalMk, ActiveMk, TotalDeathsMK, NewMK, TotalConfirmed, TotalDeaths, ActiveGlobal);
     99                /*pandemic.TotalGlobal = TotalConfirmed;
    82100                pandemic.ActiveGlobal = TotalConfirmed - (TotalRecovered + TotalDeaths);
    83101                pandemic.DeathsGlobal = TotalDeaths;
     
    86104                pandemic.DeathsMK = TotalDeathsMK;
    87105                pandemic.NewMK = NewMK;
    88                 pandemic.Name = "Coronavirus";
    89                 _pandemicRepository.Add(pandemic);
     106                pandemic.Name = "Coronavirus";*/
     107                await Task.Run(() => _pandemicRepository.Add(pandemic));
     108            }
     109            catch (Exception e)
     110            {
     111                _logger.LogInformation(e.Message);
     112            }
     113            return null;
     114        }
    90115
    91 
    92 
    93                 /*var jsonW = client.DownloadString(@"C:\Users\Miki\Desktop\rabotnici.json");
     116        public async Task<HashSet<HealthcareWorkers>> GetProcessedHealthcareWorkersFromJSON()
     117        {
     118            try
     119            {
     120                var client = new WebClient();
     121                var jsonW = client.DownloadString(@"C:\Users\dslez\Desktop\rabotnici.json");
    94122
    95123                var jsonResponseW = JObject.Parse(jsonW);
     
    101129                    var Name = obj[4];
    102130                    var Branch = obj[2];
    103                     HealthFacilities facility = new HealthFacilities();
    104                     facility.Name = obj[1];
    105                     facility.Municipality = "WorkerFacilityMunicipality";
    106                     facility.Address = "WorkerFacilityAddress";
     131                    var FacilityName = obj[1];
    107132                    var Title = obj[3];
    108                     HealthcareWorkers healthcareWorker = new HealthcareWorkers();
    109                     healthcareWorker.Name = Name;
     133                    HealthFacilities facility = _healthFacilityRepository.GetByName(FacilityName);
     134                    HealthFacilities Facility = new HealthFacilities(facility.Name, facility.Municipality, facility.Address,
     135                                                                        facility.Type, facility.Email, facility.Phone);
     136                    HealthcareWorkers healthcareWorker = new HealthcareWorkers(Name, Branch, Facility, Title);
     137                    /*Facility.Name = obj[1];
     138                    Facility.Municipality = "WorkerFacilityMunicipality";
     139                    Facility.Address = "WorkerFacilityAddress";*/
     140                    /*healthcareWorker.Name = Name;
    110141                    healthcareWorker.Branch = Branch;
    111                     healthcareWorker.Facility = facility;
    112                     healthcareWorker.Title = Title;
    113                     _healthcareWorkerRepository.Add(healthcareWorker);
     142                    healthcareWorker.Facility = Facility;
     143                    healthcareWorker.Title = Title;*/
     144                    await Task.Run(() => _healthcareWorkerRepository.Add(healthcareWorker));
    114145                }
     146            }
     147            catch (Exception e)
     148            {
     149                _logger.LogInformation(e.Message);
     150            }
     151            return null;
     152        }
    115153
    116 
    117 
    118                 var jsonM = client.DownloadString(@"C:\Users\Miki\Desktop\lekovi.json");
     154        public async Task<HashSet<Medicine>> GetProcessedMedicinesFromJSON()
     155        {
     156            try
     157            {
     158                var client = new WebClient();
     159                var jsonM = client.DownloadString(@"C:\Users\dslez\Desktop\lekovi.json");
    119160
    120161                var jsonResponseM = JObject.Parse(jsonM);
     
    131172                    var Price = float.Parse(obj[17]);
    132173                    var Packaging = obj[8];
    133                     Medicine medicine = new Medicine();
    134                     medicine.Name = Name;
     174                    Medicine medicine = new Medicine(Name, Strength, Form, WayOfIssuing, Manufacturer, Price, Packaging);
     175                    /*medicine.Name = Name;
    135176                    medicine.Strength = Strength;
    136177                    medicine.Form = Form;
     
    138179                    medicine.Manufacturer = Manufacturer;
    139180                    medicine.Price = Price;
    140                     medicine.Packaging = Packaging;
    141                     _medicineRepository.Add(medicine);
    142                 }*/
    143 
    144 
     181                    medicine.Packaging = Packaging;*/
     182                    await Task.Run(() => _medicineRepository.Add(medicine));
     183                }
    145184            }
    146185            catch (Exception e)
    147186            {
    148                 //_logger.LogError(e.Message);
    149                 Console.WriteLine(e.Message);
    150                 throw e;
    151                 return null;
     187                _logger.LogInformation(e.Message);
    152188            }
    153189            return null;
    154190        }
    155 
    156191    }
    157192}
Note: See TracChangeset for help on using the changeset viewer.