Changeset d23bf72 for FarmatikoServices/Services
- Timestamp:
- 11/05/20 06:57:35 (4 years ago)
- Branches:
- master
- Children:
- afc9a9a
- Parents:
- 1f4846d
- Location:
- FarmatikoServices/Services
- Files:
-
- 1 added
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
FarmatikoServices/Services/AdminService.cs
r1f4846d rd23bf72 36 36 } 37 37 38 public bool RejectRequest( RequestPharmacyHead req)38 public bool RejectRequest(int Id) 39 39 { 40 if ( req != null)40 if (Id >= 0) 41 41 { 42 _adminRepo.RemoveClaimRequest( req);42 _adminRepo.RemoveClaimRequest(Id); 43 43 return true; 44 44 } -
FarmatikoServices/Services/PHService.cs
r1f4846d rd23bf72 38 38 } 39 39 40 public async Task<IEnumerable<PharmacyHead>> GetPharmacyHeadInfo( string Token)40 public async Task<IEnumerable<PharmacyHead>> GetPharmacyHeadInfo() 41 41 { 42 42 var PHeads = await _iPHRepo.GetPharmacyHeadInfo(); … … 92 92 return false; 93 93 } 94 95 public PharmacyHead GetPharmacyHead(string userName) 96 { 97 if (userName != null) 98 { 99 return _iPHRepo.GetPharmacyHeadByUserName(userName); 100 } 101 return default; 102 } 94 103 } 95 104 } -
FarmatikoServices/Services/ProcessJSONService.cs
r1f4846d rd23bf72 13 13 using OfficeOpenXml; 14 14 using System.IO; 15 using Microsoft.VisualBasic; 15 16 16 17 namespace FarmatikoServices.Services … … 26 27 _service = service; 27 28 } 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() 39 38 { 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) 53 73 { 54 74 _logger.LogInformation(e.Message); 55 75 throw new Exception("Cannot process Medicines from Excel."); 56 76 } 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"); 67 86 68 87 var jsonResponse = JObject.Parse(json); … … 78 97 var Phone = obj[11]; 79 98 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"); 99 125 var response = client.Execute(new RestRequest()); 100 126 string original = response.Content; 101 127 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()); 113 143 114 144 var Name = "Coronavirus"; … … 117 147 118 148 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"); 134 163 135 164 var jsonResponseW = JObject.Parse(jsonW); … … 139 168 { 140 169 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"); 172 219 173 220 var jsonResponseM = JObject.Parse(jsonM); … … 182 229 var WayOfIssuing = obj[9]; 183 230 var Manufacturer = obj[11]; 184 var Price = float.Parse( obj[17]);231 var Price = float.Parse(Convert.ToString(obj[17])); 185 232 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 } 202 244 } 203 245 } -
FarmatikoServices/Services/Service.cs
r1f4846d rd23bf72 103 103 if (healthFacilities != null) 104 104 await _repository.AddFacility(healthFacilities); 105 throw new Exception("Facility is null");105 else throw new Exception("Facility is null"); 106 106 } 107 107 //za json(Sys updateer) … … 110 110 if (medicine != null) 111 111 await _repository.AddMedicines(medicine); 112 throw new Exception("Medicine is null");112 else throw new Exception("Medicine is null"); 113 113 } 114 114 //za json(Sys updateer) … … 117 117 if (pandemic != null) 118 118 await _repository.AddPandemic(pandemic); 119 throw new Exception("Pandemic is null");119 else throw new Exception("Pandemic is null"); 120 120 } 121 121 // Samo PharmacyHead i Admin imaat pristap … … 124 124 if (pharmacy != null) 125 125 await _repository.AddPharmacy(pharmacy); 126 throw new Exception("Pharmacy is null");126 else throw new Exception("Pharmacy is null"); 127 127 } 128 128 // Ovaa kontrola ja ima samo admin … … 150 150 if (worker != null) 151 151 await _repository.AddWorker(worker); 152 throw new Exception("Worker is null");152 else throw new Exception("Worker is null"); 153 153 } 154 154 … … 158 158 if (healthFacilities != null) 159 159 await _repository.UpdateFacility(healthFacilities); 160 throw new Exception("Facility is null");160 else throw new Exception("Facility is null"); 161 161 } 162 162 //PharmacyHead … … 165 165 if (medicine != null) 166 166 await _repository.RemoveMedicine(medicine); 167 throw new Exception("Medicine is null");167 else throw new Exception("Medicine is null"); 168 168 } 169 169 //PharmacyHead … … 172 172 if (medicine != null) 173 173 await _repository.UpdateMedicine(medicine); 174 throw new Exception("Medicine is null");174 else throw new Exception("Medicine is null"); 175 175 } 176 176 //za json(Sys updateer) … … 179 179 if (pandemic != null) 180 180 await _repository.UpdatePandemic(pandemic); 181 throw new Exception("Pandemic is null");181 else throw new Exception("Pandemic is null"); 182 182 } 183 183 //PharmacyHead … … 186 186 if (pharmacy != null) 187 187 await _repository.RemovePharmacy(pharmacy); 188 throw new Exception("Pharmacy is null");188 else throw new Exception("Pharmacy is null"); 189 189 } 190 190 //PharamcyHead … … 193 193 if (pharmacy != null) 194 194 await _repository.UpadatePharmacy(pharmacy); 195 throw new Exception("Pharmacy is null");195 else throw new Exception("Pharmacy is null"); 196 196 } 197 197 //za json(Sys updateer) … … 200 200 if (worker != null) 201 201 await _repository.UpdateWorker(worker); 202 throw new Exception("Worker is null");202 else throw new Exception("Worker is null"); 203 203 } 204 204 … … 209 209 await _repository.RemovePharmacyHead(Id); 210 210 } 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) 215 215 { 216 216 if (healthFacility != null) 217 return await_repository.GetFacilityJSON(healthFacility);217 return _repository.GetFacilityJSON(healthFacility); 218 218 return null; 219 219 }
Note:
See TracChangeset
for help on using the changeset viewer.