Changeset f554983
- Timestamp:
- 02/14/21 17:54:35 (4 years ago)
- Branches:
- master
- Children:
- 472dd7e
- Parents:
- 6e6f04b
- Files:
-
- 6 added
- 1 deleted
- 11 edited
Legend:
- Unmodified
- Added
- Removed
-
Farmatiko/Controllers/FarmatikoController.cs
r6e6f04b rf554983 26 26 //_JSONservice.DownloadPharmaciesExcel(); 27 27 //_JSONservice.GetProcessedHealthcareWorkersFromJSON(); 28 //_JSONservice.GetProcessedHealthFacilitiesFromJSON(); 29 //_JSONservice.GetProcessedMedicinesFromJSON(); 30 //_JSONservice.GetProcessedPandemicsFromJSONApi(); 28 //await _JSONservice.GetProcessedHealthFacilitiesFromJSON(); 29 //await _JSONservice.GetProcessedMedicinesFromJSON(); 31 30 } 32 31 [HttpGet] -
Farmatiko/Program.cs
r6e6f04b rf554983 3 3 using System.Linq; 4 4 using System.Threading.Tasks; 5 using FarmatikoServices.Services; 5 6 using Microsoft.AspNetCore.Hosting; 6 7 using Microsoft.Extensions.Configuration; 8 using Microsoft.Extensions.DependencyInjection; 7 9 using Microsoft.Extensions.Hosting; 8 10 using Microsoft.Extensions.Logging; … … 22 24 { 23 25 webBuilder.UseStartup<Startup>(); 26 24 27 }); 25 28 } -
Farmatiko/Startup.cs
r6e6f04b rf554983 18 18 using FarmatikoServices.Infrastructure; 19 19 using System; 20 using Quartz; 21 using Quartz.Impl; 22 using Quartz.Spi; 23 using FarmatikoServices.Services.JobDTO; 24 20 25 namespace Farmatiko 21 26 { … … 23 28 { 24 29 readonly string MyAllowSpecificOrigins = "_myAllowSpecificOrigins"; 25 26 30 public Startup(IConfiguration configuration) 27 31 { … … 53 57 services.AddEntityFrameworkNpgsql().AddDbContext<FarmatikoDataContext>(opt => opt.UseNpgsql(connectionString)); 54 58 59 60 55 61 services.AddScoped<IPHRepo, PHRepo>(); 56 62 services.AddScoped<IRepository, Repository>(); 57 63 services.AddScoped<IAdminRepo, AdminRepo>(); 64 services.AddTransient<IUpdateDataRepo, UpdateDataRepo>(); 58 65 59 services.Add Scoped<IPHService, PHService>();66 services.AddTransient<IPHService, PHService>(); 60 67 services.AddTransient<IAdminService, AdminService>(); 61 68 services.AddTransient<IService, Service>(); … … 64 71 65 72 services.AddTransient<ILogger, Logger<ProcessJSONService>>(); 66 67 // services.AddTransient<ISystemService, SystemService>();68 73 69 74 … … 116 121 o.MemoryBufferThreshold = int.MaxValue; 117 122 });*/ 123 124 services.AddSingleton<IJobFactory, SingletonUpdateDataJobFactory>(); 125 services.AddSingleton<ISchedulerFactory, StdSchedulerFactory>(); 126 127 services.AddTransient<UpdateDataJob>(); 128 services.AddSingleton(new JobSchedule( 129 jobType: typeof(UpdateDataJob), 130 cronExpression: "0/30 * * * * ?")); 131 132 133 // "0 0 12 */7 * ?" 134 135 136 services.AddHostedService<UpdateDataHostedService>(); 118 137 119 138 } -
Farmatiko/appsettings.json
r6e6f04b rf554983 24 24 }, 25 25 "SecretKey": "PEJcK2bD4E2BKdNmAlUl", 26 "TokenIssuer": "FARMATIKOISSUER" 26 "TokenIssuer": "FARMATIKOISSUER", 27 "ifStartup": "true" 27 28 } -
FarmatikoData/FarmatikoRepo/Repository.cs
r6e6f04b rf554983 274 274 var PHreqs = await _context.PHRequests.Where(x => x.Head.Id.Equals(PHead.Id)).FirstOrDefaultAsync(); 275 275 PHead.Pharmacies.Select(x => x.PheadId = null); 276 //PHead.Pharmacies.Select(x => x.PharmacyHead = null);276 PHead.Pharmacies.Select(x => x.PharmacyHead = null); 277 277 _context.PHRequests.Remove(PHreqs); 278 278 _context.PharmacyHeads.Remove(PHead); -
FarmatikoServices/FarmatikoServiceInterfaces/IProcessJSONService.cs
r6e6f04b rf554983 10 10 { 11 11 void GetProcessedHealthFacilitiesFromJSON(); 12 void GetProcessedPandemicsFromJSONApi();13 12 void GetProcessedHealthcareWorkersFromJSON(); 14 13 void GetProcessedMedicinesFromJSON(); -
FarmatikoServices/FarmatikoServiceInterfaces/IService.cs
r6e6f04b rf554983 2 2 using FarmatikoData.Models; 3 3 using System.Collections.Generic; 4 using System.Linq;5 4 using System.Threading.Tasks; 6 5 … … 9 8 public interface IService 10 9 { 11 //GET 10 Task AddFacility(HealthFacility healthFacility); 11 Task AddMedicines(Medicine medicine); 12 Task AddPandemic(Pandemic pandemic); 13 void AddPharmacy(Pharmacy pharmacy); 14 Task<bool> AddPharmacyHead(PharmacyHeadDto pharmacyHead); 15 Task AddWorker(HealthcareWorker worker); 12 16 Task<IEnumerable<HealthcareWorker>> GetAllWorkers(); 13 Task<IEnumerable<HealthcareWorker>> SearchWorkers(string query);14 Task<HealthcareWorker> GetWorker(int id);15 17 Task<IEnumerable<HealthFacility>> GetFacilities(); 16 Task<IEnumerable<HealthFacility>> SearchFacilities(string query);17 18 Task<HealthFacility> GetFacility(int id); 18 19 HealthFacility GetFacilityJSON(string healthFacility); 19 20 Task<Medicine> GetMedicine(int id); 20 Task<IEnumerable<MedicineDTO>> SearchMedicines(string query);21 21 Task<List<MedicineDTO>> GetMedicines(); 22 22 Pandemic GetPandemic(); 23 23 Task<List<PharmacyDTO>> GetPharmacies(); 24 Task<Pharmacy> GetPharmacy(int id); 25 Task<HealthcareWorker> GetWorker(int id); 26 Task RemoveMedicine(Medicine medicine); 27 Task RemovePharmacy(Pharmacy pharmacy); 28 Task RemovePharmacyHead(int Id); 29 Task<IEnumerable<HealthFacility>> SearchFacilities(string query); 30 Task<IEnumerable<MedicineDTO>> SearchMedicines(string query); 24 31 Task<IEnumerable<PharmacyDTO>> SearchPharmacies(string query); 25 Task<Pharmacy> GetPharmacy(int id); 26 //POST 27 Task AddWorker(HealthcareWorker worker); 28 Task AddFacility(HealthFacility healthFacilities); 29 void AddPharmacy(Pharmacy pharmacy); 30 Task<bool> AddPharmacyHead(PharmacyHeadDto pharmacyHead); 31 Task AddMedicines(Medicine medicine); 32 Task AddPandemic(Pandemic pandemic); 32 Task<IEnumerable<HealthcareWorker>> SearchWorkers(string query); 33 33 Task UpdateFacility(HealthFacility healthFacilities); 34 Task RemoveMedicine(Medicine medicine); 35 Task RemovePharmacyHead(int Id); 34 Task UpdateMedicine(Medicine medicine); 36 35 Task UpdatePandemic(Pandemic pandemic); 37 Task RemovePharmacy(Pharmacy pharmacy);36 Task UpdatePharmacy(Pharmacy pharmacy); 38 37 Task UpdateWorker(HealthcareWorker worker); 39 Task UpdatePharmacy(Pharmacy pharmacy);40 38 } 41 39 } -
FarmatikoServices/FarmatikoServices.csproj
r6e6f04b rf554983 11 11 <PackageReference Include="Microsoft.AspNetCore.Mvc.Core" Version="2.2.5" /> 12 12 <PackageReference Include="Newtonsoft.Json" Version="12.0.3" /> 13 <PackageReference Include="Quartz.AspNetCore" Version="3.2.4" /> 13 14 <PackageReference Include="RestSharp" Version="106.11.7" /> 14 15 <PackageReference Include="System.IdentityModel.Tokens.Jwt" Version="6.8.0" /> -
FarmatikoServices/Services/PHService.cs
r6e6f04b rf554983 83 83 PHMedicines.Add(medicine); 84 84 } 85 86 if (!pharmacyHead.Medicines.Equals(PHMedicines)) 87 { 88 /* 89 * USELESS 90 * if (pharmacyHead.Medicines.Count() == 0) 85 foreach(var phMed in PHMedicines) 86 { 87 if (!pharmacyHead.Medicines.Contains(phMed)) 91 88 { 92 phead.Medicines = null; 93 int PHMId = phead.Medicines.Select(x => x.Id).Single(); 94 int phId = phead.Medicines.Select(x => x.PheadId).Single(); 95 int medId = phead.Medicines.Select(x => x.MedicineId).Single(); 96 _iPHRepo.DeletePHMedicine(PHMId, phId, medId); 97 return; 98 }*/ 99 if (phead.Medicines != null && phead.Medicines.Count() > 0) 100 { 101 foreach (var med in pharmacyHead.Medicines) 102 { 103 Medicine medicine = new Medicine() 89 /* 90 * USELESS 91 * if (pharmacyHead.Medicines.Count() == 0) 92 { 93 phead.Medicines = null; 94 int PHMId = phead.Medicines.Select(x => x.Id).Single(); 95 int phId = phead.Medicines.Select(x => x.PheadId).Single(); 96 int medId = phead.Medicines.Select(x => x.MedicineId).Single(); 97 _iPHRepo.DeletePHMedicine(PHMId, phId, medId); 98 return; 99 }*/ 100 if (phead.Medicines != null && phead.Medicines.Count() > 0) 101 { 102 foreach (var med in pharmacyHead.Medicines) 104 103 { 105 Name = med.Name, 106 Form = med.Form, 107 Manufacturer = med.Manufacturer, 108 Medicines = med.Medicines, 109 Packaging = med.Packaging, 110 Price = med.Price, 111 Strength = med.Strength, 112 WayOfIssuing = med.WayOfIssuing 113 }; 114 115 PharmacyHeadMedicine phm = new PharmacyHeadMedicine() 104 Medicine medicine = new Medicine() 105 { 106 Name = med.Name, 107 Form = med.Form, 108 Manufacturer = med.Manufacturer, 109 Medicines = med.Medicines, 110 Packaging = med.Packaging, 111 Price = med.Price, 112 Strength = med.Strength, 113 WayOfIssuing = med.WayOfIssuing 114 }; 115 116 PharmacyHeadMedicine phm = new PharmacyHeadMedicine() 117 { 118 PheadId = phead.Id, 119 Head = phead, 120 MedicineId = med.Id, 121 Medicine = medicine 122 }; 123 124 bool ifExists = phead.Medicines.Contains(phm); 125 if (!ifExists) 126 list.Add(phm); 127 128 } 129 } 130 else 131 { 132 foreach (var med in pharmacyHead.Medicines) 116 133 { 117 PheadId = phead.Id, 118 Head = phead, 119 MedicineId = med.Id, 120 Medicine = medicine 121 }; 122 123 bool ifExists = phead.Medicines.Contains(phm); 124 if (!ifExists) 125 list.Add(phm); 126 134 PharmacyHead head1 = new PharmacyHead() 135 { 136 Id = pharmacyHead.Id, 137 Name = pharmacyHead.Name, 138 Email = pharmacyHead.Email, 139 Password = pharmacyHead.Password 140 }; 141 PharmacyHeadMedicine phmed = new PharmacyHeadMedicine() 142 { 143 Head = head1, 144 Medicine = med 145 }; 146 list.Add(phmed); 147 } 127 148 } 149 150 151 phead.Medicines = list; 152 153 await _iPHRepo.UpdatePharmacyHead(phead); 154 128 155 } 129 else130 {131 foreach (var med in pharmacyHead.Medicines)132 {133 PharmacyHead head1 = new PharmacyHead()134 {135 Id = pharmacyHead.Id,136 Name = pharmacyHead.Name,137 Email = pharmacyHead.Email,138 Password = pharmacyHead.Password139 };140 PharmacyHeadMedicine phMed = new PharmacyHeadMedicine()141 {142 Head = head1,143 Medicine = med144 };145 list.Add(phMed);146 }147 }148 149 150 phead.Medicines = list;151 152 await _iPHRepo.UpdatePharmacyHead(phead);153 154 156 } 157 155 158 } 156 159 PharmacyHead head = new PharmacyHead() -
FarmatikoServices/Services/ProcessJSONService.cs
r6e6f04b rf554983 13 13 using GemBox.Spreadsheet; 14 14 using System.Text; 15 using FarmatikoData.FarmatikoRepoInterfaces; 15 16 16 17 namespace FarmatikoServices.Services … … 20 21 21 22 private readonly ILogger _logger; 23 private readonly IUpdateDataRepo _repo; 22 24 private readonly IService _service; 23 public ProcessJSONService(ILogger logger, I Service service)25 public ProcessJSONService(ILogger logger, IUpdateDataRepo repo, IService service) 24 26 { 25 27 _logger = logger; 28 _repo = repo; 26 29 _service = service; 27 30 } … … 77 80 bool Success = ReadPharmaciesFromExcel(pathToSave1); 78 81 _logger.LogInformation(Success.ToString() + "1"); 79 /* Success = await ReadPharmaciesFromExcel(pathToSave2); 80 _logger.LogInformation(Success.ToString() + "2");*/82 83 81 84 } 82 85 catch (Exception e) … … 88 91 89 92 //Healthfacilities 90 public asyncvoid GetProcessedHealthFacilitiesFromJSON()93 public void GetProcessedHealthFacilitiesFromJSON() 91 94 { 92 95 try … … 115 118 healthFacility.Email = Convert.ToString(Email); 116 119 healthFacility.Phone = Convert.ToString(Phone); 117 await_service.AddFacility(healthFacility);118 119 } 120 120 _service.AddFacility(healthFacility); 121 122 } 123 121 124 } 122 125 catch (Exception e) … … 126 129 } 127 130 } 128 //Pandemics 129 public async void GetProcessedPandemicsFromJSONApi() 130 { 131 try 132 { 133 var Date = DateTime.UtcNow.ToString("yyyy-MM-dd"); 134 var client = new RestClient($"https://api.covid19tracking.narrativa.com/api/{Date}/country/north_macedonia"); 135 var response = client.Execute(new RestRequest()); 136 string original = response.Content; 137 var jsonResponsePandemic = JObject.Parse(original); 138 var global = JObject.Parse(jsonResponsePandemic.GetValue("total").ToString()); 139 var TotalConfirmed = long.Parse(global.GetValue("today_confirmed").ToString()); 140 var TotalDeaths = long.Parse(global.GetValue("today_deaths").ToString()); 141 var TotalRecovered = long.Parse(global.GetValue("today_new_recovered").ToString()); 142 143 var mk = JObject.Parse(jsonResponsePandemic.GetValue("dates").ToString()); 144 145 var date = JObject.Parse(mk.GetValue(Date).ToString()); 146 var country = JObject.Parse(date.GetValue("countries").ToString()); 147 var mkd = JObject.Parse(country.GetValue("North Macedonia").ToString()); 148 dynamic objP = mkd; 149 var TotalMk = Int32.Parse(objP.GetValue("today_confirmed").ToString()); 150 var TotalDeathsMK = Int32.Parse(objP.GetValue("today_deaths").ToString()); 151 var TotalRecoveredMK = Int32.Parse(objP.GetValue("today_recovered").ToString()); 152 var NewMK = Int32.Parse(objP.GetValue("today_new_confirmed").ToString()); 153 154 var Name = "Coronavirus"; 155 var ActiveMk = TotalMk - (TotalRecoveredMK + TotalDeathsMK); 156 var ActiveGlobal = TotalConfirmed - (TotalRecovered + TotalDeaths); 157 158 Pandemic pandemic = new Pandemic(Name, TotalMk, ActiveMk, TotalDeathsMK, NewMK, TotalConfirmed, TotalDeaths, ActiveGlobal); 159 await _service.AddPandemic(pandemic); 160 } 161 catch (Exception e) 162 { 163 _logger.LogInformation(e.Message); 164 } 165 } 131 166 132 //Healthcare workers 167 public asyncvoid GetProcessedHealthcareWorkersFromJSON()133 public void GetProcessedHealthcareWorkersFromJSON() 168 134 { 169 135 try … … 183 149 var Title = Convert.ToString(obj[3]); 184 150 185 HealthFacility facility = _ service.GetFacilityJSON(Convert.ToString(FacilityName));151 HealthFacility facility = _repo.GetFacilityJSON(Convert.ToString(FacilityName)); 186 152 187 153 if (facility != null && facility != default) … … 196 162 ); 197 163 HealthcareWorker healthcareWorker = new HealthcareWorker(Name, Branch, Facility, Title); 198 await_service.AddWorker(healthcareWorker);164 _service.AddWorker(healthcareWorker); 199 165 } 200 166 else … … 209 175 ); 210 176 HealthcareWorker healthcareWorker = new HealthcareWorker(Name, Branch, Facility, Title); 211 await_service.AddWorker(healthcareWorker);177 _service.AddWorker(healthcareWorker); 212 178 } 213 179 214 180 215 181 } 182 216 183 } 217 184 catch (Exception e) … … 221 188 } 222 189 //Medicines 223 public asyncvoid GetProcessedMedicinesFromJSON()190 public void GetProcessedMedicinesFromJSON() 224 191 { 225 192 try … … 244 211 Medicine medicine = new Medicine(Convert.ToString(Name), Convert.ToString(Strength), Convert.ToString(Form), Convert.ToString(WayOfIssuing), Convert.ToString(Manufacturer), Price, Convert.ToString(Packaging)); 245 212 246 await_service.AddMedicines(medicine);213 _service.AddMedicines(medicine); 247 214 } 248 215 } -
FarmatikoServices/Services/Service.cs
r6e6f04b rf554983 144 144 var Pharmacies = await _repository.GetPharmacies(); 145 145 List<PharmacyDTO> pharmacies = new List<PharmacyDTO>(); 146 147 foreach (var pharm in Pharmacies)146 147 foreach (var pharm in Pharmacies) 148 148 { 149 149 PharmacyDTO pharmacyDTO = new PharmacyDTO() … … 222 222 List<PharmacyDTO> pharmacies = new List<PharmacyDTO>(); 223 223 var heads = await _phrepo.GetPharmacyHeadInfo(); 224 224 225 225 foreach (var pharm in SearchQuery) 226 226 { … … 232 232 WorkAllTime = pharm.WorkAllTime 233 233 }; 234 235 foreach (var head in heads.ToList())234 235 foreach (var head in heads.ToList()) 236 236 { 237 237 if (head.Pharmacies.Contains(pharm)) … … 241 241 } 242 242 } 243 243 244 244 pharmacies.Add(pharmacyDTO); 245 245 } … … 256 256 //POST (ADD NEW OBJECTS) 257 257 //za json(Sys updateer) 258 public async Task AddFacility(HealthFacility healthFacilities) 259 { 260 if (healthFacilities != null) 261 await _repository.AddFacility(healthFacilities); 258 public async Task AddFacility(HealthFacility healthFacility) 259 { 260 if (healthFacility != null) 261 { 262 var facilities = await _repository.GetFacilities(); 263 if (!facilities.Contains(healthFacility)) 264 { 265 await _repository.AddFacility(healthFacility); 266 } 267 else throw new Exception("The facility already exists."); 268 } 262 269 else throw new Exception("Facility is null"); 263 270 } … … 266 273 { 267 274 if (medicine != null) 268 await _repository.AddMedicines(medicine); 275 { 276 var medicines = await _repository.GetMedicinesAsync(); 277 if (!medicines.Contains(medicine)) 278 await _repository.AddMedicines(medicine); 279 else throw new Exception("Medicine already exists."); 280 } 269 281 else throw new Exception("Medicine is null"); 270 282 } … … 277 289 } 278 290 // Samo PharmacyHead i Admin imaat pristap 279 public void AddPharmacy(Pharmacy pharmacy)291 public async void AddPharmacy(Pharmacy pharmacy) 280 292 { 281 293 if (pharmacy != null) 282 _repository.AddPharmacy(pharmacy); 294 { 295 var pharmacies = await _repository.GetPharmacies(); 296 if (!pharmacies.Contains(pharmacy)) 297 await _repository.AddPharmacy(pharmacy); 298 else throw new Exception("Pharmacy already exists."); 299 } 283 300 else throw new Exception("Pharmacy is null"); 284 301 } 285 302 286 303 // Ovaa kontrola ja ima samo admin 287 304 288 305 public async Task<bool> AddPharmacyHead(PharmacyHeadDto pharmacyHead) 289 306 { … … 324 341 { 325 342 if (worker != null) 326 await _repository.AddWorker(worker); 343 { 344 var workers = await _repository.GetAllWorkers(); 345 if (!workers.Contains(worker)) 346 await _repository.AddWorker(worker); 347 else throw new Exception("Worker already exists."); 348 } 327 349 else throw new Exception("Worker is null"); 328 350 }
Note:
See TracChangeset
for help on using the changeset viewer.