sdfsdfsdf

This commit is contained in:
2021-01-20 12:32:51 +03:00
parent d4a7dc4aba
commit 0c4a9638fe
5 changed files with 207 additions and 5 deletions
+83 -3
View File
@@ -1,15 +1,25 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Net;
using System.Text;
using Covid_Record.ObjectModel;
using Covid_Record.ObjectModel.recordInfo;
using Newtonsoft.Json;
using DoctorInfo = Covid_Record.ObjectModel.doctorinfo.DoctorInfo;
namespace Covid_Record
{
public class CovidAvailability
{
//2009 - Антитела
//2010 - ПЦР
//2011 - Вакцинация
//2004 - Пост - для теста
const string specialityCode = "2009"; //"2009";
private readonly TelegramBot _telegram;
private Record _currentRecord;
public CovidAvailability(TelegramBot telegram)
{
@@ -33,11 +43,13 @@ namespace Covid_Record
return data?.result?.FirstOrDefault()?.id;
}
public void GetCurrentAppointments(int patientId, string session)
{
_currentRecord = GetAppointments(patientId, session, specialityCode)?.FirstOrDefault();
}
public bool IsAvailable(string session, int patientId)
{
//2010 - covid
//2004 - Пост - для теста
var specialityCode = "2010";
var json =
"{ \"patient_id\":\"" + patientId + "\",\"speciality_code\":\"" + specialityCode + "\",\"auth\":{ \"session_id\":\"" + session + "\"} }";
@@ -61,6 +73,58 @@ namespace Covid_Record
}
}
var enableAppointmentAutoCreation = true;
var nearestDate = responseJson.result.clinics.FirstOrDefault()?.doctors_info?.FirstOrDefault();
// ReSharper disable once ConditionIsAlwaysTrueOrFalse
if (enableAppointmentAutoCreation && nearestDate != null)
{
var createAppointment = new CreateRecord()
{
availableResourceId = nearestDate.availableResourceId,
complexResourceId = nearestDate.complexResourceId,
auth = new Auth {session_id = session},
code = nearestDate.code,
date = DateTime.Parse(nearestDate.availability_date).Date.ToString("dd.MM.yyyy"),
doctorInfo = new ObjectModel.DoctorInfo
{
availability_date = DateTime.Parse(nearestDate.availability_date),
code = nearestDate.code,
availableResourceId = nearestDate.availableResourceId,
complexResourceId = nearestDate.complexResourceId,
clinic = nearestDate.clinic,
first_name = nearestDate.first_name,
last_name = nearestDate.last_name,
room = nearestDate.room,
second_name = nearestDate.second_name
},
patient_id = patientId.ToString(),
specialityCode = specialityCode,
specialityName = "",
startTime = DateTime.Parse(nearestDate.availability_date).ToString("dd.MM.yyyy HH:mm"),
endTime = DateTime.Parse(nearestDate.availability_date).AddMinutes(5).ToString("dd.MM.yyyy HH:mm"),
ticket = _currentRecord?.ticket
};
string responseCreateAppointmentJson;
if (!string.IsNullOrEmpty(createAppointment.ticket))
{
if (DateTime.Parse(_currentRecord?.dateBegin ?? "") > DateTime.Parse(nearestDate.availability_date))
{
responseCreateAppointmentJson = Post(
"https://emp.mos.ru/v1.1/doctor/shiftAppointment?token=887033d0649e62a84f80433e823526a1",
JsonConvert.SerializeObject(createAppointment));
GetCurrentAppointments(patientId, session);
}
}
else
{
responseCreateAppointmentJson = Post(
"https://emp.mos.ru/v1.1/doctor/createAppointment?token=887033d0649e62a84f80433e823526a1",
JsonConvert.SerializeObject(createAppointment));
GetCurrentAppointments(patientId, session);
}
}
Console.WriteLine(sb.ToString());
_telegram.SendMessage(sb.ToString());
}
@@ -68,6 +132,22 @@ namespace Covid_Record
return true;
}
public List<Record> GetAppointments(int patientId, string session, string specialityCode = null)
{
var json =
"{ \"patient_id\":\"" + patientId + "\",\"auth\":{ \"session_id\":\"" + session + "\"} }";
var response = Post("https://emp.mos.ru/v1.1/doctor/getList?token=887033d0649e62a84f80433e823526a1", json);
var responseDecoded = JsonConvert.DeserializeObject<RecordListResponse>(response);
var records = responseDecoded.result.records;
if (!string.IsNullOrEmpty(specialityCode))
{
records = records.Where(f => f.doctor.speciality_code == specialityCode).ToList();
}
return records;
}
public string Post(string url, string content, string contentType = "application/json")
{
var httpRequest = (HttpWebRequest)WebRequest.Create(url);
+41
View File
@@ -0,0 +1,41 @@
using System;
using System.Collections.Generic;
using System.Text;
namespace Covid_Record.ObjectModel
{
// Root myDeserializedClass = JsonConvert.DeserializeObject<Root>(myJsonResponse);
public class DoctorInfo
{
public string first_name { get; set; }
public string second_name { get; set; }
public string last_name { get; set; }
public DateTime availability_date { get; set; }
public string room { get; set; }
public string code { get; set; }
public string clinic { get; set; }
public string availableResourceId { get; set; }
public string complexResourceId { get; set; }
}
public class Auth
{
public string session_id { get; set; }
}
public class CreateRecord
{
public string patient_id { get; set; }
public string availableResourceId { get; set; }
public string complexResourceId { get; set; }
public string date { get; set; }
public DoctorInfo doctorInfo { get; set; }
public string code { get; set; }
public string startTime { get; set; }
public string endTime { get; set; }
public string specialityCode { get; set; }
public string specialityName { get; set; }
public Auth auth { get; set; }
public string ticket { get; set; }
}
}
@@ -0,0 +1,36 @@
using System;
using System.Collections.Generic;
using System.Text;
namespace Covid_Record.ObjectModel.doctorinfo
{
// Root myDeserializedClass = JsonConvert.DeserializeObject<Root>(myJsonResponse);
public class TimePeriod
{
public string startTime { get; set; }
public string endTime { get; set; }
}
public class Shedule
{
public string date { get; set; }
public List<TimePeriod> time_periods { get; set; }
}
public class Result
{
public List<Shedule> shedules { get; set; }
}
public class DoctorInfo
{
public int errorCode { get; set; }
public Result result { get; set; }
public string errorMessage { get; set; }
public double execTime { get; set; }
public string request_id { get; set; }
public string session_id { get; set; }
}
}
@@ -0,0 +1,43 @@
using System;
using System.Collections.Generic;
using System.Text;
namespace Covid_Record.ObjectModel.recordInfo
{
// Root myDeserializedClass = JsonConvert.DeserializeObject<Root>(myJsonResponse);
public class Doctor
{
public string doctor_specialty { get; set; }
public string speciality_code { get; set; }
public string doctor_fio { get; set; }
public string code { get; set; }
}
public class Record
{
public string ticket { get; set; }
public string clinic { get; set; }
public string dateBegin { get; set; }
public string visit_time { get; set; }
public Doctor doctor { get; set; }
}
public class Result
{
public string oms_number { get; set; }
public string fio { get; set; }
public List<Record> records { get; set; }
}
public class RecordListResponse
{
public int errorCode { get; set; }
public Result result { get; set; }
public string errorMessage { get; set; }
public double execTime { get; set; }
public string request_id { get; set; }
public string session_id { get; set; }
}
}
+4 -2
View File
@@ -10,8 +10,8 @@ namespace Covid_Record
var telegram = new TelegramBot();
var arr = new CovidAvailability(telegram);
var phone = "79160000000";
var password = "testpwd";
var phone = "7xxxxxxx";
var password = "xxxx";
var session = arr.GetSession(phone, password);
@@ -23,6 +23,8 @@ namespace Covid_Record
return;
}
arr.GetCurrentAppointments(patient ?? -1, session);
while (true)
{
arr.IsAvailable(session, patient.Value);