public Bed(Transfer transfer, Patient patient, Visit visit) { FromDate = transfer.FromDate; Pending = transfer.Pending; CampusId = transfer.CampusId; WardId = transfer.WardId; RoomId = transfer.RoomId; BedId = transfer.BedId; PriorCampusId = transfer.PriorCampusId; PriorWardId = transfer.PriorWardId; PriorRoomId = transfer.PriorRoomId; PriorBedId = transfer.PriorBedId; TemporaryLocation = transfer.TemporaryLocation; LocationStatus = transfer.LocationStatus; PriorLocationStatus = transfer.PriorLocationStatus; ConsultingDoctor = transfer.ConsultingDoctor; DepartmentId = transfer.DepartmentId; DepartmentType = transfer.DepartmentType; FinancialClass = transfer.FinancialClass; FinancialClassFromDate = transfer.FinancialClassFromDate; RoomAsked = transfer.RoomAsked; RoomAssigned = transfer.RoomAssigned; PatientId = patient.Id; PatientLastName = patient.LastName; PatientFirstName = patient.FirstName; PatientBirthDate = patient.BirthDate; PatientSex = patient.Sex; VisitId = visit.Id; PendingAdmission = visit.Pending; PatientClass = visit.PatientClass; AdmissionType = visit.AdmissionType; AdmissionDate = visit.AdmissionDate; DischargeDate = visit.DischargeDate; PendingDischarge = visit.PendingDischarge; }
async Task StoreVisit(Visit visit) { if (visit != null) { if (visit.Transfers != null && !visit.Transfers.Any()) visit.Transfers = null; else visit.Transfers = (from transfer in visit.Transfers orderby transfer.FromDate.GetValueOrDefault(DateTime.MaxValue) select transfer).ToList(); await httpClient.PutAsync(string.Format(visitUri, visit.Id), visit).ConfigureAwait(false); } }
async Task ProcessVisit() { int transferIndex; if (visit.Transfers == null) visit.Transfers = new List<Transfer>(); switch (eventType) { case "A01": //Admit a patient case "A04": //Register a patient case "A14": //Pending admit visit.Transfers = new List<Transfer>(); //clear all transfers visit.Transfers.Add(transfer); break; case "A02": //Transfer a patient transferIndex = visit.Transfers.FindIndex(x => x.FromDate == eventOccured); if (transferIndex != -1) visit.Transfers.RemoveAt(transferIndex); visit.Transfers.Add(transfer); break; case "A03": //Discharge a patient visit.PendingDischarge = null; visit.DischargeDate = eventOccured; transferIndex = visit.Transfers.FindIndex(x => x.FromDate == eventOccured); if (transferIndex != -1) visit.Transfers.RemoveAt(transferIndex); visit.Transfers.Add(transfer); break; case "A05": //Preadmit a patient break; case "A08": //Update patient information break; case "A11": //Cancel admit await httpClient.DeleteAsync(string.Format(visitUri, visit.Id)).ConfigureAwait(false); visit = null; break; case "A12": //Cancel transfer transferIndex = visit.Transfers.FindIndex(x => x.FromDate == eventOccured); if (transferIndex != -1) visit.Transfers.RemoveAt(transferIndex); break; case "A13": //Cancel discharge visit.DischargeDate = null; visit.PendingDischarge = null; transferIndex = visit.Transfers.FindIndex(x => x.FromDate == eventOccured); if (transferIndex != -1) visit.Transfers.RemoveAt(transferIndex); break; case "A15": //Pending transfer transferIndex = visit.Transfers.FindIndex(x => x.FromDate == eventOccured); if (transferIndex != -1) visit.Transfers.RemoveAt(transferIndex); visit.Transfers.Add(transfer); break; case "A16": //Pending discharge visit.PendingDischarge = true; transferIndex = visit.Transfers.FindIndex(x => x.FromDate == eventOccured); if (transferIndex != -1) visit.Transfers.RemoveAt(transferIndex); visit.Transfers.Add(transfer); break; case "A24": //Link Patient Information break; case "A25": //Cancel pending discharge visit.PendingDischarge = null; visit.DischargeDate = null; transferIndex = visit.Transfers.FindIndex(x => x.FromDate == eventOccured); if (transferIndex != -1) visit.Transfers.RemoveAt(transferIndex); break; case "A26": //Cancel pending transfer transferIndex = visit.Transfers.FindIndex(x => x.FromDate == eventOccured); if (transferIndex != -1) visit.Transfers.RemoveAt(transferIndex); break; case "A27": //Cancel pending admit await httpClient.DeleteAsync(string.Format(visitUri, visit.Id)).ConfigureAwait(false); visit = null; break; case "A28": //Add person information break; case "A31": //Update person information break; case "A37": //Unlink Patient Information break; case "A38": //Cancel preadmit break; case "A40": //Merge patient break; default: break; } if (visit != null) { await CheckDischargeTransferLocation().ConfigureAwait(false); await StoreVisit(visit).ConfigureAwait(false); } }
async Task ProcessPV1(string segment) { var fields = segment.Split(fieldSep); var visitNumber = GetValueFromField(fields.ElementAtOrDefault(19)); if (string.IsNullOrEmpty(visitNumber)) return; visit = await httpClient.GetAsync<Visit>(string.Format(visitUri, visitNumber)).ConfigureAwait(false); if (visit == null) { if ((new string[] { "A01", "A04", "A05", "A14" }).Contains(eventType)) visit = new Visit() { Id = visitNumber }; else { if (log.IsWarnEnabled) log.WarnFormat("No visit in DB with number {0} for HL7 with eventType {1} ", visitNumber, eventType); return; } } visit.PatientId = patient.Id; transfer = new Transfer(); visit.PatientClass = GetValueFromField(fields.ElementAtOrDefault(2)); transfer.WardId = GetValueFromField(fields.ElementAtOrDefault(3)); transfer.RoomId = GetValueFromField(fields.ElementAtOrDefault(3), componentIndex: 1); transfer.BedId = GetValueFromField(fields.ElementAtOrDefault(3), componentIndex: 2); transfer.CampusId = GetValueFromField(fields.ElementAtOrDefault(3), componentIndex: 3); transfer.LocationStatus = GetValueFromField(fields.ElementAtOrDefault(3), componentIndex: 4); visit.AdmissionType = GetValueFromField(fields.ElementAtOrDefault(4)); if ((new string[] { "A04", "A05" }).Contains(eventType)) visit.PreadmitNumber = GetValueFromField(fields.ElementAtOrDefault(5)); transfer.PriorWardId = GetValueFromField(fields.ElementAtOrDefault(6)); transfer.PriorRoomId = GetValueFromField(fields.ElementAtOrDefault(6), componentIndex: 1); transfer.PriorBedId = GetValueFromField(fields.ElementAtOrDefault(6), componentIndex: 2); transfer.PriorCampusId = GetValueFromField(fields.ElementAtOrDefault(6), componentIndex: 3); transfer.PriorLocationStatus = GetValueFromField(fields.ElementAtOrDefault(6), componentIndex: 4); visit.HomeDoctor = GetValueFromField(fields.ElementAtOrDefault(7)); visit.ReferringDoctor = GetValueFromField(fields.ElementAtOrDefault(8)); transfer.ConsultingDoctor = GetValueFromField(fields.ElementAtOrDefault(9)); consultingDoctorLastName = GetValueFromField(fields.ElementAtOrDefault(9), componentIndex: 1); consultingDoctorFirstName = GetValueFromField(fields.ElementAtOrDefault(9), componentIndex: 2); transfer.DepartmentId = GetValueFromField(fields.ElementAtOrDefault(10)); transfer.TemporaryLocation = GetValueFromField(fields.ElementAtOrDefault(11)); visit.AdmittingDoctor = GetValueFromField(fields.ElementAtOrDefault(17)); transfer.FinancialClass = GetValueFromField(fields.ElementAtOrDefault(20)); transfer.FinancialClassFromDate = GetValueFromField(fields.ElementAtOrDefault(20), componentIndex: 1).ToNullableDatetime("yyyyMMdd", "yyyyMMddHHmm", "dd/MM/yyyy"); visit.ChargePriceIndicator = GetValueFromField(fields.ElementAtOrDefault(21)); visit.HomeDoctorRecievesLetter = GetValueFromField(fields.ElementAtOrDefault(22)).Maybe(x => x == "N" ? (bool?)true : null); if ((new string[] { "A01", "A02", "A03", "A04", "A08" }).Contains(eventType)) visit.Internet = GetValueFromField(fields.ElementAtOrDefault(28)).Maybe(x => x == "1" ? (bool?)true : null); if ((new string[] { "A03", "A16" }).Contains(eventType)) { visit.DischargeDisposition = GetValueFromField(fields.ElementAtOrDefault(36)); visit.DischargeToLocation = GetValueFromField(fields.ElementAtOrDefault(37)); } transfer.DepartmentType = GetValueFromField(fields.ElementAtOrDefault(39)); visit.AdmissionDate = GetValueFromField(fields.ElementAtOrDefault(44)).ToNullableDatetime("yyyyMMdd", "yyyyMMddHHmm", "dd/MM/yyyy") ?? eventOccured; transfer.Pending = (new string[] { "A15", "A16" }).Contains(eventType) ? (bool?)true : null; transfer.FromDate = (new string[] { "A01", "A04", "A05", "A14" }).Contains(eventType) ? visit.AdmissionDate : eventOccured; visit.Pending = (new string[] { "A05", "A14" }).Contains(eventType) ? (bool?)true : null; if ((new string[] { "A03", "A16", "A08" }).Contains(eventType)) visit.DischargeDate = GetValueFromField(fields.ElementAtOrDefault(45)).ToNullableDatetime("yyyyMMdd", "yyyyMMddHHmm", "dd/MM/yyyy"); visit.ExternalId = GetValueFromField(fields.ElementAtOrDefault(50)); }