Changeset d23bf72 for FarmatikoServices


Ignore:
Timestamp:
11/05/20 06:57:35 (3 years ago)
Author:
DimitarSlezenkovski <dslezenkovski@…>
Branches:
master
Children:
afc9a9a
Parents:
1f4846d
Message:

Add SystemService, Auth, fix a lil bugs :)

Location:
FarmatikoServices
Files:
7 added
9 edited

Legend:

Unmodified
Added
Removed
  • FarmatikoServices/FarmatikoServiceInterfaces/IAdminService.cs

    r1f4846d rd23bf72  
    1212        Task<IEnumerable<PharmacyHead>> GetPharmacyHeads();
    1313        Task<IEnumerable<RequestPharmacyHead>> GetClaimingRequests();
    14         bool RejectRequest(RequestPharmacyHead req);
     14        bool RejectRequest(int Id);
    1515    }
    1616}
  • FarmatikoServices/FarmatikoServiceInterfaces/IPHService.cs

    r1f4846d rd23bf72  
    1010    public interface IPHService
    1111    {
    12         Task<IEnumerable<PharmacyHead>> GetPharmacyHeadInfo(string Token);
     12        Task<IEnumerable<PharmacyHead>> GetPharmacyHeadInfo();
    1313        Task UpdatePharmacyHead(PharmacyHead pharmacyHead);
    1414        Task<int> Login(PharmacyHead pharmacyHead);
     
    1818        Task<bool> Remove(int id);
    1919        Task<bool> RemoveClaimingRequest(int id);
     20        PharmacyHead GetPharmacyHead(string userName);
    2021    }
    2122}
  • FarmatikoServices/FarmatikoServiceInterfaces/IProcessJSONService.cs

    r1f4846d rd23bf72  
    99    public interface IProcessJSONService
    1010    {
    11         Task<HealthFacility> GetProcessedHealthFacilitiesFromJSON();
    12         Task<Pandemic> GetProcessedPandemicsFromJSONApi();
    13         Task<HealthcareWorker> GetProcessedHealthcareWorkersFromJSON();
    14         Task<Medicine> GetProcessedMedicinesFromJSON();
    15         Task<Medicine> ReadPharmaciesFromExcel();
     11        void GetProcessedHealthFacilitiesFromJSON();
     12        void GetProcessedPandemicsFromJSONApi();
     13        void GetProcessedHealthcareWorkersFromJSON();
     14        void GetProcessedMedicinesFromJSON();
     15        void DownloadPharmaciesExcel();
    1616    }
    1717}
  • FarmatikoServices/FarmatikoServiceInterfaces/IService.cs

    r1f4846d rd23bf72  
    1515        Task<IEnumerable<HealthFacility>> SearchFacilities(string query);
    1616        Task<HealthFacility> GetFacility(int id);
    17         Task<HealthFacility> GetFacilityJSON(string healthFacility);
     17        HealthFacility GetFacilityJSON(string healthFacility);
    1818        Task<Medicine> GetMedicine(int id);
    1919        Task<IEnumerable<Medicine>> SearchMedicines(string query);
  • FarmatikoServices/FarmatikoServices.csproj

    r1f4846d rd23bf72  
    66
    77  <ItemGroup>
     8    <PackageReference Include="AngleSharp" Version="0.14.0" />
    89    <PackageReference Include="EPPlus" Version="5.4.0" />
     10    <PackageReference Include="Microsoft.AspNetCore.Mvc.Core" Version="2.2.5" />
    911    <PackageReference Include="Newtonsoft.Json" Version="12.0.3" />
    10     <PackageReference Include="RestSharp" Version="106.11.4" />
     12    <PackageReference Include="RestSharp" Version="106.11.7" />
     13    <PackageReference Include="System.IdentityModel.Tokens.Jwt" Version="6.8.0" />
    1114  </ItemGroup>
    1215
     
    1518  </ItemGroup>
    1619
     20  <ItemGroup>
     21    <Folder Include="Services\ExcellDocs\" />
     22  </ItemGroup>
     23
    1724</Project>
  • FarmatikoServices/Services/AdminService.cs

    r1f4846d rd23bf72  
    3636        }
    3737
    38         public bool RejectRequest(RequestPharmacyHead req)
     38        public bool RejectRequest(int Id)
    3939        {
    40             if (req != null)
     40            if (Id >= 0)
    4141            {
    42                 _adminRepo.RemoveClaimRequest(req);
     42                _adminRepo.RemoveClaimRequest(Id);
    4343                return true;
    4444            }
  • FarmatikoServices/Services/PHService.cs

    r1f4846d rd23bf72  
    3838        }
    3939
    40         public async Task<IEnumerable<PharmacyHead>> GetPharmacyHeadInfo(string Token)
     40        public async Task<IEnumerable<PharmacyHead>> GetPharmacyHeadInfo()
    4141        {
    4242            var PHeads = await _iPHRepo.GetPharmacyHeadInfo();
     
    9292            return false;
    9393        }
     94
     95        public PharmacyHead GetPharmacyHead(string userName)
     96        {
     97            if (userName != null)
     98            {
     99                return _iPHRepo.GetPharmacyHeadByUserName(userName);
     100            }
     101            return default;
     102        }
    94103    }
    95104}
  • FarmatikoServices/Services/ProcessJSONService.cs

    r1f4846d rd23bf72  
    1313using OfficeOpenXml;
    1414using System.IO;
     15using Microsoft.VisualBasic;
    1516
    1617namespace FarmatikoServices.Services
     
    2627            _service = service;
    2728        }
    28 
    29         public async Task<Medicine> ReadPharmaciesFromExcel()
    30         {
    31             try
    32             {
    33                 var client = new WebClient();
    34                 string Path = client.DownloadString(@"C:\Users\dslez\Desktop\apteki-fzo.xlsx");
    35                 using (var package = new ExcelPackage(new FileInfo(Path)))
    36                 {
    37                     var Sheet = package.Workbook.Worksheets[1];
    38                     for (int i = 2; i < Sheet.Dimension.End.Row; ++i)
     29        //Excel reader
     30        private async Task<bool> ReadPharmaciesFromExcel(string Path)
     31        {
     32            using (var package = new ExcelPackage(new FileInfo(Path)))
     33            {
     34                var Sheet = package.Workbook.Worksheets[1];
     35                for (int i = 2; i < Sheet.Dimension.End.Row; ++i)
     36                {
     37                    Pharmacy pharmacy = new Pharmacy()
    3938                    {
    40                         Pharmacy pharmacy = new Pharmacy()
    41                         {
    42                             Name = Sheet.Cells[i, 2].Value.ToString(),
    43                             Address = Sheet.Cells[i, 3].Value.ToString(),
    44                             Location = Sheet.Cells[i, 4].Value.ToString(),
    45                             WorkAllTime = false
    46                         };
    47                         await _service.AddPharmacy(pharmacy);
    48                     }
    49                 }
    50 
    51             }
    52             catch(Exception e)
     39                        Name = Sheet.Cells[i, 2].Value.ToString(),
     40                        Address = Sheet.Cells[i, 3].Value.ToString(),
     41                        Location = Sheet.Cells[i, 4].Value.ToString(),
     42                        WorkAllTime = false
     43                    };
     44                    await _service.AddPharmacy(pharmacy);
     45                    return true;
     46                }
     47            }
     48            return false;
     49        }
     50        public async void DownloadPharmaciesExcel()
     51        {
     52            try
     53            {
     54                string pathToSave1 = Directory.GetCurrentDirectory() + @"\ExcellDocs\1.xlsx";
     55
     56                string pathToSave2 = Directory.GetCurrentDirectory() + @"\ExcellDocs\2.xlsx";
     57                var client = new WebClient();
     58                string url1 = "http://data.gov.mk/dataset/d84c31d9-e749-4b17-9faf-a5b4db3e7a70/resource/ce446f5c-e541-46f6-9e8c-67568059cbc6/download/registar-na-apteki-vnatre-vo-mreza-na-fzo-12.08.2020.xlsx";
     59                string url2 = "http://data.gov.mk/dataset/d84c31d9-e749-4b17-9faf-a5b4db3e7a70/resource/a16379b4-ec81-4de7-994d-0ee503d71b55/download/registar-na-apteki-nadvor-od-mreza-na-fzo-12.08.2020.xlsx";
     60                int count = 0;
     61                Uri uri1 = new Uri(url1);
     62                Uri uri2 = new Uri(url2);
     63                client.DownloadFile(uri1, @pathToSave1);
     64                client.DownloadFile(uri2, @pathToSave2);
     65
     66
     67                bool Success = await ReadPharmaciesFromExcel(pathToSave1);
     68                _logger.LogInformation(Success.ToString() + "1");
     69                Success = await ReadPharmaciesFromExcel(pathToSave2);
     70                _logger.LogInformation(Success.ToString() + "2");
     71            }
     72            catch (Exception e)
    5373            {
    5474                _logger.LogInformation(e.Message);
    5575                throw new Exception("Cannot process Medicines from Excel.");
    5676            }
    57             return null;
    58         }
    59 
    60 
    61         public async Task<HealthFacility> GetProcessedHealthFacilitiesFromJSON()
    62         {
    63             try
    64             {
    65                 var client = new WebClient();
    66                 var json = client.DownloadString(@"C:\Users\dslez\Desktop\ustanovi.json");
     77        }
     78
     79        //Healthfacilities
     80        public async void GetProcessedHealthFacilitiesFromJSON()
     81        {
     82            try
     83            {
     84                var client = new WebClient();
     85                var json = client.DownloadString(@"http://www.otvorenipodatoci.gov.mk/datastore/dump/505db453-4de2-4761-8a81-2800f7820b06?format=json");
    6786
    6887                var jsonResponse = JObject.Parse(json);
     
    7897                    var Phone = obj[11];
    7998                    var Type = obj[5];
    80                     HealthFacility healthFacility = new HealthFacility(Name, Municipality, Address, Type, Email, Phone);
    81                     await Task.Run(() => _service.AddFacility(healthFacility));
    82 
    83                 }
    84 
    85             }
    86             catch (Exception e)
    87             {
    88                 _logger.LogInformation(e.Message);
    89                 throw new Exception("Cannot process health facilities from JSON.");
    90             }
    91             return null;
    92         }
    93 
    94         public async Task<Pandemic> GetProcessedPandemicsFromJSONApi()
    95         {
    96             try
    97             {
    98                 var client = new RestClient("https://api.covid19api.com/summary");
     99                    HealthFacility healthFacility = new HealthFacility();
     100                    //Name, Municipality, Address, Type, Email, Phone
     101                    healthFacility.Name = Convert.ToString(Name);
     102                    healthFacility.Municipality = Convert.ToString(Municipality);
     103                    healthFacility.Address = Convert.ToString(Address);
     104                    healthFacility.Type = Convert.ToString(Type);
     105                    healthFacility.Email = Convert.ToString(Email);
     106                    healthFacility.Phone = Convert.ToString(Phone);
     107                    await _service.AddFacility(healthFacility);
     108
     109                }
     110
     111            }
     112            catch (Exception e)
     113            {
     114                _logger.LogInformation(e.Message);
     115                throw new Exception("Cannot process health facilities from JSON." + e.Message);
     116            }
     117        }
     118        //Pandemics
     119        public async void GetProcessedPandemicsFromJSONApi()
     120        {
     121            try
     122            {
     123                var Date = DateTime.UtcNow.ToString("yyyy-MM-dd");
     124                var client = new RestClient($"https://api.covid19tracking.narrativa.com/api/{Date}/country/north_macedonia");
    99125                var response = client.Execute(new RestRequest());
    100126                string original = response.Content;
    101127                var jsonResponsePandemic = JObject.Parse(original);
    102                 var global = JObject.Parse(jsonResponsePandemic.GetValue("Global").ToString());
    103                 var TotalConfirmed = long.Parse(global.GetValue("TotalConfirmed").ToString());
    104                 var TotalDeaths = long.Parse(global.GetValue("TotalDeaths").ToString());
    105                 var TotalRecovered = long.Parse(global.GetValue("TotalRecovered").ToString());
    106 
    107                 var mk = JArray.Parse(jsonResponsePandemic.GetValue("Countries").ToString());
    108                 dynamic objP = mk[100];
    109                 var TotalMk = Int32.Parse(objP.GetValue("TotalConfirmed").ToString());
    110                 var TotalDeathsMK = Int32.Parse(objP.GetValue("TotalDeaths").ToString());
    111                 var TotalRecoveredMK = Int32.Parse(objP.GetValue("TotalRecovered").ToString());
    112                 var NewMK = Int32.Parse(objP.GetValue("NewConfirmed").ToString());
     128                var global = JObject.Parse(jsonResponsePandemic.GetValue("total").ToString());
     129                var TotalConfirmed = long.Parse(global.GetValue("today_confirmed").ToString());
     130                var TotalDeaths = long.Parse(global.GetValue("today_deaths").ToString());
     131                var TotalRecovered = long.Parse(global.GetValue("today_new_recovered").ToString());
     132
     133                var mk = JObject.Parse(jsonResponsePandemic.GetValue("dates").ToString());
     134
     135                var date = JObject.Parse(mk.GetValue(Date).ToString());
     136                var country = JObject.Parse(date.GetValue("countries").ToString());
     137                var mkd = JObject.Parse(country.GetValue("North Macedonia").ToString());
     138                dynamic objP = mkd;
     139                var TotalMk = Int32.Parse(objP.GetValue("today_confirmed").ToString());
     140                var TotalDeathsMK = Int32.Parse(objP.GetValue("today_deaths").ToString());
     141                var TotalRecoveredMK = Int32.Parse(objP.GetValue("today_recovered").ToString());
     142                var NewMK = Int32.Parse(objP.GetValue("today_new_confirmed").ToString());
    113143
    114144                var Name = "Coronavirus";
     
    117147
    118148                Pandemic pandemic = new Pandemic(Name, TotalMk, ActiveMk, TotalDeathsMK, NewMK, TotalConfirmed, TotalDeaths, ActiveGlobal);
    119                 await Task.Run(() => _service.AddPandemic(pandemic));
    120             }
    121             catch (Exception e)
    122             {
    123                 _logger.LogInformation(e.Message);
    124             }
    125             return null;
    126         }
    127 
    128         public async Task<HealthcareWorker> GetProcessedHealthcareWorkersFromJSON()
    129         {
    130             try
    131             {
    132                 var client = new WebClient();
    133                 var jsonW = client.DownloadString(@"C:\Users\dslez\Desktop\rabotnici.json");
     149                await _service.AddPandemic(pandemic);
     150            }
     151            catch (Exception e)
     152            {
     153                _logger.LogInformation(e.Message);
     154            }
     155        }
     156        //Healthcare workers
     157        public async void GetProcessedHealthcareWorkersFromJSON()
     158        {
     159            try
     160            {
     161                var client = new WebClient();
     162                var jsonW = client.DownloadString(@"http://www.otvorenipodatoci.gov.mk/datastore/dump/5b661887-685b-4189-b6bb-9b52eb8ace16?format=json");
    134163
    135164                var jsonResponseW = JObject.Parse(jsonW);
     
    139168                {
    140169                    dynamic obj = JsonConvert.DeserializeObject(rec.ToString());
    141                     var Name = obj[4];
    142                     var Branch = obj[2];
    143                     var FacilityName = obj[1];
    144                     var Title = obj[3];
    145                     HealthFacility facility = await _service.GetFacilityJSON(FacilityName);
    146                     HealthFacility Facility = new HealthFacility(facility.Name, facility.Municipality, facility.Address,
    147                                                                         facility.Type, facility.Email, facility.Phone);
    148                     HealthcareWorker healthcareWorker = new HealthcareWorker(Name, Branch, Facility, Title);
    149                     /*Facility.Name = obj[1];
    150                     Facility.Municipality = "WorkerFacilityMunicipality";
    151                     Facility.Address = "WorkerFacilityAddress";*/
    152                     /*healthcareWorker.Name = Name;
    153                     healthcareWorker.Branch = Branch;
    154                     healthcareWorker.Facility = Facility;
    155                     healthcareWorker.Title = Title;*/
    156                     await Task.Run(() => _service.AddWorker(healthcareWorker));
    157                 }
    158             }
    159             catch (Exception e)
    160             {
    161                 _logger.LogInformation(e.Message);
    162             }
    163             return null;
    164         }
    165 
    166         public async Task<Medicine> GetProcessedMedicinesFromJSON()
    167         {
    168             try
    169             {
    170                 var client = new WebClient();
    171                 var jsonM = client.DownloadString(@"C:\Users\dslez\Desktop\lekovi.json");
     170                    var Name = Convert.ToString(obj[4]);
     171                    var Branch = Convert.ToString(obj[2]);
     172                    var FacilityName = Convert.ToString(obj[1]);
     173                    var Title = Convert.ToString(obj[3]);
     174
     175                    HealthFacility facility = _service.GetFacilityJSON(Convert.ToString(FacilityName));
     176
     177                    if (facility != null)
     178                    {
     179                        HealthFacility Facility = new HealthFacility(
     180                           facility.Name,
     181                           facility.Municipality,
     182                           facility.Address,
     183                           facility.Type,
     184                           facility.Email,
     185                           facility.Phone
     186                           );
     187                        HealthcareWorker healthcareWorker = new HealthcareWorker(Name, Branch, Facility, Title);
     188                        await _service.AddWorker(healthcareWorker);
     189                    }
     190                    else
     191                    {
     192                        HealthFacility Facility = new HealthFacility(
     193                           Convert.ToString(FacilityName),
     194                           "",
     195                           "",
     196                           Convert.ToString(Branch),
     197                           "",
     198                           ""
     199                           );
     200                        HealthcareWorker healthcareWorker = new HealthcareWorker(Name, Branch, Facility, Title);
     201                        await _service.AddWorker(healthcareWorker);
     202                    }
     203                   
     204
     205                }
     206            }
     207            catch (Exception e)
     208            {
     209                _logger.LogInformation(e.Message);
     210            }
     211        }
     212        //Medicines
     213        public async void GetProcessedMedicinesFromJSON()
     214        {
     215            try
     216            {
     217                var client = new WebClient();
     218                var jsonM = client.DownloadString(@"http://www.otvorenipodatoci.gov.mk/datastore/dump/ecff2aef-9c8e-4efd-a557-96df4fff9adb?format=json");
    172219
    173220                var jsonResponseM = JObject.Parse(jsonM);
     
    182229                    var WayOfIssuing = obj[9];
    183230                    var Manufacturer = obj[11];
    184                     var Price = float.Parse(obj[17]);
     231                    var Price = float.Parse(Convert.ToString(obj[17]));
    185232                    var Packaging = obj[8];
    186                     Medicine medicine = new Medicine(Name, Strength, Form, WayOfIssuing, Manufacturer, Price, Packaging);
    187                     /*medicine.Name = Name;
    188                     medicine.Strength = Strength;
    189                     medicine.Form = Form;
    190                     medicine.WayOfIssuing = WayOfIssuing;
    191                     medicine.Manufacturer = Manufacturer;
    192                     medicine.Price = Price;
    193                     medicine.Packaging = Packaging;*/
    194                     await Task.Run(() => _service.AddMedicines(medicine));
    195                 }
    196             }
    197             catch (Exception e)
    198             {
    199                 _logger.LogInformation(e.Message);
    200             }
    201             return null;
     233                    string price = Convert.ToString(Price);
     234                    Medicine medicine = new Medicine(Convert.ToString(Name), Convert.ToString(Strength), Convert.ToString(Form), Convert.ToString(WayOfIssuing), Convert.ToString(Manufacturer), Price, Convert.ToString(Packaging));
     235
     236                    await _service.AddMedicines(medicine);
     237                }
     238            }
     239            catch (Exception e)
     240            {
     241                _logger.LogInformation(e.Message);
     242                throw new Exception("medicine");
     243            }
    202244        }
    203245    }
  • FarmatikoServices/Services/Service.cs

    r1f4846d rd23bf72  
    103103            if (healthFacilities != null)
    104104                await _repository.AddFacility(healthFacilities);
    105             throw new Exception("Facility is null");
     105            else throw new Exception("Facility is null");
    106106        }
    107107        //za json(Sys updateer)
     
    110110            if (medicine != null)
    111111                await _repository.AddMedicines(medicine);
    112             throw new Exception("Medicine is null");
     112            else throw new Exception("Medicine is null");
    113113        }
    114114        //za json(Sys updateer)
     
    117117            if (pandemic != null)
    118118                await _repository.AddPandemic(pandemic);
    119             throw new Exception("Pandemic is null");
     119            else throw new Exception("Pandemic is null");
    120120        }
    121121        // Samo PharmacyHead i Admin imaat pristap
     
    124124            if (pharmacy != null)
    125125                await _repository.AddPharmacy(pharmacy);
    126             throw new Exception("Pharmacy is null");
     126            else throw new Exception("Pharmacy is null");
    127127        }
    128128        // Ovaa kontrola ja ima samo admin
     
    150150            if (worker != null)
    151151                await _repository.AddWorker(worker);
    152             throw new Exception("Worker is null");
     152            else throw new Exception("Worker is null");
    153153        }
    154154
     
    158158            if (healthFacilities != null)
    159159                await _repository.UpdateFacility(healthFacilities);
    160             throw new Exception("Facility is null");
     160            else throw new Exception("Facility is null");
    161161        }
    162162        //PharmacyHead
     
    165165            if (medicine != null)
    166166                await _repository.RemoveMedicine(medicine);
    167             throw new Exception("Medicine is null");
     167            else throw new Exception("Medicine is null");
    168168        }
    169169        //PharmacyHead
     
    172172            if (medicine != null)
    173173                await _repository.UpdateMedicine(medicine);
    174             throw new Exception("Medicine is null");
     174            else throw new Exception("Medicine is null");
    175175        }
    176176        //za json(Sys updateer)
     
    179179            if (pandemic != null)
    180180                await _repository.UpdatePandemic(pandemic);
    181             throw new Exception("Pandemic is null");
     181            else throw new Exception("Pandemic is null");
    182182        }
    183183        //PharmacyHead
     
    186186            if (pharmacy != null)
    187187                await _repository.RemovePharmacy(pharmacy);
    188             throw new Exception("Pharmacy is null");
     188            else throw new Exception("Pharmacy is null");
    189189        }
    190190        //PharamcyHead
     
    193193            if (pharmacy != null)
    194194                await _repository.UpadatePharmacy(pharmacy);
    195             throw new Exception("Pharmacy is null");
     195            else throw new Exception("Pharmacy is null");
    196196        }
    197197        //za json(Sys updateer)
     
    200200            if (worker != null)
    201201                await _repository.UpdateWorker(worker);
    202             throw new Exception("Worker is null");
     202            else throw new Exception("Worker is null");
    203203        }
    204204
     
    209209                await _repository.RemovePharmacyHead(Id);
    210210            }
    211             throw new Exception("Index out of bounds.");
    212         }
    213 
    214         public async Task<HealthFacility> GetFacilityJSON(string healthFacility)
     211            else throw new Exception("Index out of bounds.");
     212        }
     213
     214        public HealthFacility GetFacilityJSON(string healthFacility)
    215215        {
    216216            if (healthFacility != null)
    217                 return await _repository.GetFacilityJSON(healthFacility);
     217                return _repository.GetFacilityJSON(healthFacility);
    218218            return null;
    219219        }
Note: See TracChangeset for help on using the changeset viewer.