public string AddPatientAppointment(int patientId, int patientMasterVisitId, DateTime appointmentDate, string description, int reasonId, int serviceAreaId, int statusId, int differentiatedCareId, int userId) { PatientAppointment patientAppointment = new PatientAppointment() { PatientId = patientId, PatientMasterVisitId = patientMasterVisitId, AppointmentDate = appointmentDate, Description = description, DifferentiatedCareId = differentiatedCareId, ReasonId = reasonId, ServiceAreaId = serviceAreaId, StatusId = statusId, CreatedBy = userId, CreateDate = DateTime.Now }; try { var appointment = new PatientAppointmentManager(); Result = appointment.AddPatientAppointments(patientAppointment); if (Result > 0) { Msg = "Patient appointment Added Successfully!"; } } catch (Exception e) { Msg = e.Message; } return(Msg); }
public static string Update(PatientAppointSchedulingDTO appointmentScheduling) { try { //todo: fetch assigning facility from the message string assigning_Facility = ""; PatientAppointmentManager manager = new PatientAppointmentManager(); PatientLookupManager patientLookup = new PatientLookupManager(); LookupLogic lookupLogic = new LookupLogic(); PatientMasterVisitManager masterVisitManager = new PatientMasterVisitManager(); var personIdentifierManager = new PersonIdentifierManager(); var interopPlacerValuesManager = new InteropPlacerValuesManager(); PatientLookup patient = new PatientLookup(); string cccNumber = String.Empty; string appointmentReason = String.Empty; string appointmentStatus = String.Empty; string appointmentType = String.Empty; int interopUserId = InteropUser.UserId; foreach (var item in appointmentScheduling.PATIENT_IDENTIFICATION.INTERNAL_PATIENT_ID) { if (item.IDENTIFIER_TYPE == "CCC_NUMBER" && item.ASSIGNING_AUTHORITY == "CCC") { cccNumber = item.ID; } } string godsNumber = appointmentScheduling.PATIENT_IDENTIFICATION.EXTERNAL_PATIENT_ID.ID; if (!String.IsNullOrWhiteSpace(cccNumber)) { patient = patientLookup.GetPatientByCccNumber(cccNumber); if (patient != null) { if (!string.IsNullOrWhiteSpace(godsNumber)) { IdentifierManager identifierManager = new IdentifierManager(); Identifier identifier = identifierManager.GetIdentifierByCode("GODS_NUMBER"); var personIdentifiers = personIdentifierManager.GetPersonIdentifiers(patient.PersonId, identifier.Id); if (personIdentifiers.Count == 0) { personIdentifierManager.AddPersonIdentifier(patient.PersonId, identifier.Id, godsNumber, interopUserId, assigning_Facility); } } int patientMasterVisitId = masterVisitManager.GetLastPatientVisit(patient.Id).Id; int serviceAreaId = lookupLogic.GetItemIdByGroupAndItemName("ServiceArea", "MoH 257 GREENCARD")[0].ItemId; foreach (var appointment in appointmentScheduling.APPOINTMENT_INFORMATION) { switch (appointment.APPOINTMENT_REASON) { case "PHARMACY_REFILL": appointmentReason = "Pharmacy Refill"; break; case "TREATMENT_PREP": appointmentReason = "Treatment Preparation"; break; case "LAB_TEST": appointmentReason = "Lab Tests"; break; case "FOLLOWUP": appointmentReason = "Follow Up"; break; default: appointmentReason = "Follow Up"; break; } switch (appointment.APPOINTMENT_STATUS) { case "HONORED": appointmentStatus = "Met"; break; case "MISSED": appointmentStatus = "Missed"; break; case "PENDING": appointmentStatus = "Pending"; break; case "CANCELLED": appointmentStatus = "CareEnded"; break; default: appointmentStatus = "Pending"; break; } switch (appointment.APPOINTMENT_TYPE) { case "CLINICAL": appointmentType = "Standard Care"; break; case "PHARMACY": appointmentType = "Express Care"; break; case "INVESTIGATION": appointmentType = "Express Care"; break; default: appointmentType = "Standard Care"; break; } var reasons = lookupLogic.GetItemIdByGroupAndItemName("AppointmentReason", appointmentReason); int reasonId = 0; if (reasons == null || reasons.Count > 0) { throw new Exception($"No matching reasons in the databases {appointmentReason}"); } reasonId = reasons[0].ItemId; int statusId = 0; var status = lookupLogic.GetItemIdByGroupAndItemName("AppointmentStatus", appointmentStatus); if (status == null || status.Count > 0) { throw new Exception($"No matching appointmentstatus in the databases {appointmentStatus}"); } statusId = status[0].ItemId; int differentiatedCareId = 0; var diffCare = lookupLogic.GetItemIdByGroupAndItemName("DifferentiatedCare", appointmentType); if (diffCare == null || diffCare.Count > 0) { throw new Exception($"No matching differentiated care option in the databases {appointmentType}"); } differentiatedCareId = diffCare[0].ItemId; InteropPlacerTypeManager interopPlacerTypeManager = new InteropPlacerTypeManager(); int interopPlacerTypeId = interopPlacerTypeManager.GetInteropPlacerTypeByName(appointment.PLACER_APPOINTMENT_NUMBER.ENTITY).Id; var interopPlacerValues = interopPlacerValuesManager.GetInteropPlacerValues(interopPlacerTypeId, 3, Convert.ToInt32(appointment.PLACER_APPOINTMENT_NUMBER.NUMBER)); if (interopPlacerValues != null) { PatientAppointment patientAppointment = manager.GetPatientAppointment(interopPlacerValues.EntityId); patientAppointment.AppointmentDate = DateTime.ParseExact(appointment.APPOINTMENT_DATE, "yyyyMMdd", null); patientAppointment.Description = appointment.APPOINTMENT_NOTE; patientAppointment.DifferentiatedCareId = differentiatedCareId; patientAppointment.ReasonId = reasonId; patientAppointment.ServiceAreaId = serviceAreaId; patientAppointment.StatusId = statusId; manager.UpdatePatientAppointments(patientAppointment); } else { PatientAppointment patientAppointment = new PatientAppointment() { PatientId = patient.Id, PatientMasterVisitId = patientMasterVisitId, AppointmentDate = DateTime.ParseExact(appointment.APPOINTMENT_DATE, "yyyyMMdd", null), Description = appointment.APPOINTMENT_NOTE, DifferentiatedCareId = differentiatedCareId, ReasonId = reasonId, ServiceAreaId = serviceAreaId, StatusId = statusId, CreatedBy = interopUserId, CreateDate = DateTime.Now }; int appointmentId = manager.AddPatientAppointments(patientAppointment); InteropPlacerValues placerValues = new InteropPlacerValues() { IdentifierType = 3, EntityId = appointmentId, InteropPlacerTypeId = interopPlacerTypeId, PlacerValue = Convert.ToInt32(appointment.PLACER_APPOINTMENT_NUMBER.NUMBER) }; interopPlacerValuesManager.AddInteropPlacerValue(placerValues); } } } } } catch (Exception e) { throw new Exception(e.Message); } return(String.Empty); }