private async Task CheckSingleAppointment(double?latitude, double?longitude, DateTime startDate, string zipCode, string locationText) { AppointmentResponse result = new AppointmentResponse() { success = false }; try { var appointmentRequest = new AppointmentRequest(); appointmentRequest.Build("99", zipCode, startDate.ToString("yyyy-MM-dd"), 25); result = await _appointmentChecker.CheckForAppointmentAsync(appointmentRequest.ToString()); result = AddLatLongIfAvailable(result, latitude, longitude); result.stateName = locationText; } catch (Exception ex) { Console.WriteLine(ex.Message); } if (result.success == false || result.appointmentsAvailable == false) { _failedChecks.Add(result); Console.Write("."); } else { _successfulChecks.Add(result); Console.Write($"«{result.zipCode}/{result.stateCode}»"); } }
/// <summary> /// Deserialize JSON into a FHIR AppointmentResponse /// </summary> public static void DeserializeJson(this AppointmentResponse current, ref Utf8JsonReader reader, JsonSerializerOptions options) { string propertyName; while (reader.Read()) { if (reader.TokenType == JsonTokenType.EndObject) { return; } if (reader.TokenType == JsonTokenType.PropertyName) { propertyName = reader.GetString(); if (Hl7.Fhir.Serialization.FhirSerializerOptions.Debug) { Console.WriteLine($"AppointmentResponse >>> AppointmentResponse.{propertyName}, depth: {reader.CurrentDepth}, pos: {reader.BytesConsumed}"); } reader.Read(); current.DeserializeJsonProperty(ref reader, options, propertyName); } } throw new JsonException($"AppointmentResponse: invalid state! depth: {reader.CurrentDepth}, pos: {reader.BytesConsumed}"); }
public void ShouldReturnUserAppointmentListWhenUserIdIsValid() { var user = new User { Id = "1", Name = "name", Password = "******" }; List <Appointment> appointments = new List <Appointment>(); appointments.Add(new Appointment() { Id = 1, Hour = new TimeSpan(), Description = "description", HealthcareFacilityId = 1, Type = "userAppointment" }); user.Appointments = appointments; var userController = SetupUserController(user); var result = userController.GetUserAppointments(1); var objectResult = result as ObjectResult; var objectResultValue = objectResult?.Value as List <AppointmentResponse>; Assert.Equal(StatusCodes.Status200OK, objectResult?.StatusCode); Assert.NotNull(objectResultValue); Assert.NotEmpty(objectResultValue); Assert.Single(objectResultValue); AppointmentResponse appointment = objectResultValue.FirstOrDefault(); Assert.Equal(1, appointment?.Id); Assert.Equal("userAppointment", appointment?.Type); }
public AppointmentResponse Get(int id) { AppointmentResponse response = new AppointmentResponse() { Success = true }; try { var appointment = appointmentService.GetAppointment(id); if (appointment == null) { throw new RecordNotFoundException(string.Format("Appointment {0} not found", id)); } response.Appointment = appointment; } catch (RecordNotFoundException exc) { response.Success = false; response.ErrorCode = ((int)ErrorResponse.RecordNotFound).ToString(); response.ErrorMessage = exc.Message; } catch (Exception exc) { response.Success = false; response.ErrorCode = ((int)ErrorResponse.ServerError).ToString(); response.ErrorMessage = exc.Message; } return(response); }
public JsonResult CreateAppointment(string employeeID, string clinicId, string poliId, string doctorId, string necesity, string AppointmentDate, string MCUPackage) { var response = new AppointmentResponse(); var _model = new AppointmentModel { AppointmentDate = CommonUtils.ConvertStringDate2Datetime(AppointmentDate), ClinicID = Convert.ToInt64(clinicId), EmployeeID = Convert.ToInt64(employeeID), DoctorID = Convert.ToInt64(doctorId), PoliID = Convert.ToInt64(poliId), RequirementID = Convert.ToInt16(necesity), MCUPakageID = Convert.ToInt64(MCUPackage), }; if (Session["UserLogon"] != null) { _model.Account = (AccountModel)Session["UserLogon"]; } var request = new AppointmentRequest { Data = _model }; response = new AppointmentValidator(_unitOfWork).Validate(request); return(Json(new { Status = response.Status, Message = response.Message }, JsonRequestBehavior.AllowGet)); }
private async void CancelAppointment() { var answer = await Application.Current.MainPage.DisplayAlert( Languages.ConfirmMessage, Languages.CancelAppointmentConfirm, Languages.YesMessage, Languages.NoMessage); if (answer) { this.apiService = new ApiService(); var checkConnetion = await this.apiService.CheckConnection(); if (!checkConnetion.IsSuccess) { await Application.Current.MainPage.DisplayAlert( Languages.Error, checkConnetion.Message, Languages.Accept); return; } var mainViewModel = MainViewModel.GetInstance(); mainViewModel.Appointments.IsRefreshing = true; var appointment = new AppointmentResponse { UserId = mainViewModel.User.UserId, BarberId = this.BarberId, Date = this.Date.Date, Hour = this.Hour, StatusAppointmentId = 3, AppointmentId = this.AppointmentId }; var apiSecurity = Application.Current.Resources["APISecurity"].ToString(); var response = await this.apiService.Put( apiSecurity, "/api", "/Appointments", mainViewModel.Token.TokenType, mainViewModel.Token.AccessToken, appointment); if (!response.IsSuccess) { await Application.Current.MainPage.DisplayAlert( Languages.Error, response.Message, Languages.Accept); return; } mainViewModel.Appointments.IsRefreshing = false; await Application.Current.MainPage.DisplayAlert( Languages.ConfirmMessage, Languages.AppointmentCanceled, Languages.Accept); await App.Navigator.PopAsync(); } }
private static void AssertAppointments(AppointmentResponse expected, AppointmentResponse actual) { Assert.AreEqual(expected.AvailabilityBlockId, actual.AvailabilityBlockId); Assert.AreEqual(expected.AppointmentId, actual.AppointmentId); Assert.AreEqual(expected.AppointmentStatusCode, actual.AppointmentStatusCode); Assert.AreEqual(expected.AppointmentTypeCode, actual.AppointmentTypeCode); Assert.AreEqual(expected.StartTime, actual.StartTime); Assert.AreEqual(expected.EndTime, actual.EndTime); Assert.AreEqual(expected.PatientQueueId, actual.PatientQueueId); }
private AppointmentResponse AddLatLongIfAvailable(AppointmentResponse response, double?latitude, double?longitude) { if (latitude != null) { response.Latitude = latitude.Value; } if (longitude != null) { response.Longitude = longitude.Value; } return(response); }
private static void CheckForErrorsAndIncludeInAppointmentResponse(string rawResponse) { if (rawResponse.ToLowerInvariant().Contains("error")) { try { var appointmentErrors = JsonConvert.DeserializeObject <AppointmentErrors>(rawResponse); var appointmentResponseError = new AppointmentResponse { Error = appointmentErrors.Errors.FirstOrDefault() }; } catch (Exception ex) { log.Warn("Encountered an error parsing the Error Response."); Console.Write("x"); } } }
public AppointmentResponse GetDocSchedule(AppointmentRequest request) { AppointmentResponse response = new AppointmentResponse(); // Set correlation Id response.CorrelationId = request.RequestId; try { // Get customer list via Customer Facade. AppointmentFacade facade = new AppointmentFacade(); response.ds= facade.GetDocSchedule(request.date,request.docID); } catch (Exception ex) { response.Acknowledge = AcknowledgeType.Failure; response.Message = "Request cannot be handled at this time."+ex.Message; } return response; }
/// <summary> /// Serialize a FHIR AppointmentResponse into JSON /// </summary> public static void SerializeJson(this AppointmentResponse current, Utf8JsonWriter writer, JsonSerializerOptions options, bool includeStartObject = true) { if (includeStartObject) { writer.WriteStartObject(); } writer.WriteString("resourceType", "AppointmentResponse"); // Complex: AppointmentResponse, Export: AppointmentResponse, Base: DomainResource (DomainResource) ((Hl7.Fhir.Model.DomainResource)current).SerializeJson(writer, options, false); if ((current.Identifier != null) && (current.Identifier.Count != 0)) { writer.WritePropertyName("identifier"); writer.WriteStartArray(); foreach (Identifier val in current.Identifier) { val.SerializeJson(writer, options, true); } writer.WriteEndArray(); } writer.WritePropertyName("appointment"); current.Appointment.SerializeJson(writer, options); if (current.StartElement != null) { if (current.StartElement.Value != null) { writer.WriteString("start", ((DateTimeOffset)current.StartElement.Value).ToString("yyyy-MM-dd'T'HH:mm:ss.FFFFFFFK", System.Globalization.CultureInfo.InvariantCulture)); } if (current.StartElement.HasExtensions() || (!string.IsNullOrEmpty(current.StartElement.ElementId))) { JsonStreamUtilities.SerializeExtensionList(writer, options, "_start", false, current.StartElement.Extension, current.StartElement.ElementId); } } if (current.EndElement != null) { if (current.EndElement.Value != null) { writer.WriteString("end", ((DateTimeOffset)current.EndElement.Value).ToString("yyyy-MM-dd'T'HH:mm:ss.FFFFFFFK", System.Globalization.CultureInfo.InvariantCulture)); } if (current.EndElement.HasExtensions() || (!string.IsNullOrEmpty(current.EndElement.ElementId))) { JsonStreamUtilities.SerializeExtensionList(writer, options, "_end", false, current.EndElement.Extension, current.EndElement.ElementId); } } if ((current.ParticipantType != null) && (current.ParticipantType.Count != 0)) { writer.WritePropertyName("participantType"); writer.WriteStartArray(); foreach (CodeableConcept val in current.ParticipantType) { val.SerializeJson(writer, options, true); } writer.WriteEndArray(); } if (current.Actor != null) { writer.WritePropertyName("actor"); current.Actor.SerializeJson(writer, options); } writer.WriteString("participantStatus", Hl7.Fhir.Utility.EnumUtility.GetLiteral(current.ParticipantStatusElement.Value)); if (current.CommentElement != null) { if (!string.IsNullOrEmpty(current.CommentElement.Value)) { writer.WriteString("comment", current.CommentElement.Value); } if (current.CommentElement.HasExtensions() || (!string.IsNullOrEmpty(current.CommentElement.ElementId))) { JsonStreamUtilities.SerializeExtensionList(writer, options, "_comment", false, current.CommentElement.Extension, current.CommentElement.ElementId); } } if (includeStartObject) { writer.WriteEndObject(); } }
/// <summary> /// Deserialize JSON into a FHIR AppointmentResponse /// </summary> public static void DeserializeJsonProperty(this AppointmentResponse current, ref Utf8JsonReader reader, JsonSerializerOptions options, string propertyName) { switch (propertyName) { case "identifier": if ((reader.TokenType != JsonTokenType.StartArray) || (!reader.Read())) { throw new JsonException($"AppointmentResponse error reading 'identifier' expected StartArray, found {reader.TokenType}! depth: {reader.CurrentDepth}, pos: {reader.BytesConsumed}"); } current.Identifier = new List <Identifier>(); while (reader.TokenType != JsonTokenType.EndArray) { Hl7.Fhir.Model.Identifier v_Identifier = new Hl7.Fhir.Model.Identifier(); v_Identifier.DeserializeJson(ref reader, options); current.Identifier.Add(v_Identifier); if (!reader.Read()) { throw new JsonException($"AppointmentResponse error reading 'identifier' array, read failed! depth: {reader.CurrentDepth}, pos: {reader.BytesConsumed}"); } if (reader.TokenType == JsonTokenType.EndObject) { reader.Read(); } } if (current.Identifier.Count == 0) { current.Identifier = null; } break; case "appointment": current.Appointment = new Hl7.Fhir.Model.ResourceReference(); ((Hl7.Fhir.Model.ResourceReference)current.Appointment).DeserializeJson(ref reader, options); break; case "start": if (reader.TokenType == JsonTokenType.Null) { current.StartElement = new Instant(); reader.Skip(); } else { current.StartElement = new Instant(DateTimeOffset.Parse(reader.GetString())); } break; case "_start": if (current.StartElement == null) { current.StartElement = new Instant(); } ((Hl7.Fhir.Model.Element)current.StartElement).DeserializeJson(ref reader, options); break; case "end": if (reader.TokenType == JsonTokenType.Null) { current.EndElement = new Instant(); reader.Skip(); } else { current.EndElement = new Instant(DateTimeOffset.Parse(reader.GetString())); } break; case "_end": if (current.EndElement == null) { current.EndElement = new Instant(); } ((Hl7.Fhir.Model.Element)current.EndElement).DeserializeJson(ref reader, options); break; case "participantType": if ((reader.TokenType != JsonTokenType.StartArray) || (!reader.Read())) { throw new JsonException($"AppointmentResponse error reading 'participantType' expected StartArray, found {reader.TokenType}! depth: {reader.CurrentDepth}, pos: {reader.BytesConsumed}"); } current.ParticipantType = new List <CodeableConcept>(); while (reader.TokenType != JsonTokenType.EndArray) { Hl7.Fhir.Model.CodeableConcept v_ParticipantType = new Hl7.Fhir.Model.CodeableConcept(); v_ParticipantType.DeserializeJson(ref reader, options); current.ParticipantType.Add(v_ParticipantType); if (!reader.Read()) { throw new JsonException($"AppointmentResponse error reading 'participantType' array, read failed! depth: {reader.CurrentDepth}, pos: {reader.BytesConsumed}"); } if (reader.TokenType == JsonTokenType.EndObject) { reader.Read(); } } if (current.ParticipantType.Count == 0) { current.ParticipantType = null; } break; case "actor": current.Actor = new Hl7.Fhir.Model.ResourceReference(); ((Hl7.Fhir.Model.ResourceReference)current.Actor).DeserializeJson(ref reader, options); break; case "participantStatus": if (reader.TokenType == JsonTokenType.Null) { current.ParticipantStatusElement = new Code <Hl7.Fhir.Model.ParticipationStatus>(); reader.Skip(); } else { current.ParticipantStatusElement = new Code <Hl7.Fhir.Model.ParticipationStatus>(Hl7.Fhir.Utility.EnumUtility.ParseLiteral <Hl7.Fhir.Model.ParticipationStatus>(reader.GetString())); } break; case "_participantStatus": if (current.ParticipantStatusElement == null) { current.ParticipantStatusElement = new Code <Hl7.Fhir.Model.ParticipationStatus>(); } ((Hl7.Fhir.Model.Element)current.ParticipantStatusElement).DeserializeJson(ref reader, options); break; case "comment": if (reader.TokenType == JsonTokenType.Null) { current.CommentElement = new FhirString(); reader.Skip(); } else { current.CommentElement = new FhirString(reader.GetString()); } break; case "_comment": if (current.CommentElement == null) { current.CommentElement = new FhirString(); } ((Hl7.Fhir.Model.Element)current.CommentElement).DeserializeJson(ref reader, options); break; // Complex: AppointmentResponse, Export: AppointmentResponse, Base: DomainResource default: ((Hl7.Fhir.Model.DomainResource)current).DeserializeJsonProperty(ref reader, options, propertyName); break; } }
public Appointment(AppointmentResponse response) { //mTotal = response.serviceID; }
public async Task <AppointmentResponse> CheckForAppointmentAsync(string content) { if (!AppointmentEndpointIsSet()) { log.Info("Endpoint was not set."); throw new ApplicationException("Endpoint was not set"); } if (string.IsNullOrEmpty(content)) { log.Warn("Body not set for post."); return(new AppointmentResponse() { success = false }); } try { var stringContent = new StringContent(content, Encoding.UTF8, "application/json"); HttpResponseMessage responseBody; try { while (DateTime.Now - _timeOfLastRun < TimeSpan.FromSeconds(2)) { var delayInMs = Convert.ToInt32(Math.Round(100 * _rando.NextDouble(), 0)); await Task.Delay(delayInMs); } _timeOfLastRun = DateTime.Now; responseBody = await _reentrantClient.PostAsync(new Uri(appointmentEndpointUrl), stringContent); } catch (Exception ex) { Console.Write("X"); return(new AppointmentResponse() { Error = new AppointmentError() { Message = ex.Message } }); } string rawResponse = await InterpretReponse(responseBody); if (rawResponse.Contains("<H1>Access Denied</H1>")) { Console.Write("D"); return(new AppointmentResponse() { Error = new AppointmentError() { Message = "Access Denied" } }); } CheckForErrorsAndIncludeInAppointmentResponse(rawResponse); AppointmentResponse appointmentResponse = JsonConvert.DeserializeObject <AppointmentResponse>(rawResponse); appointmentResponse.success = true; return(appointmentResponse); } catch (HttpRequestException e) { Console.WriteLine(e); return(new AppointmentResponse() { success = false }); } }