void OnPatientAdmitted(AdmissionArgs admissionArgs)
        {
            using var serviceScope = _serviceProvider.CreateScope();
            using var ctx          = serviceScope.ServiceProvider.GetService <CoronaReporterContext>();

            var patient = ctx.Patients
                          .Include(p => p.Consultations)
                          .SingleOrDefault(p => p.Id == admissionArgs.PatientId);

            if (patient == null)
            {
                patient = new Patient();
                patient.PopulateFrom(admissionArgs);
                ctx.Patients.Add(patient);
                _logger.LogInformation($"New patient admission: {patient}");
            }
            else
            {
                patient.PopulateFrom(admissionArgs);
                _logger.LogInformation($"New admission for existing patient: {patient}");
            }

            // TODO: Two consultations open at the same time? Understand consultation logic
            // (is there an ID?)
            var consultation = new Consultation
            {
                Patient       = patient,
                AdmissionTime = admissionArgs.AdmissionTime
            };

            patient.Consultations.Add(consultation);

            ctx.SaveChanges();

            PatientAdmitted?.Invoke(consultation);
        }
Пример #2
0
 internal void PopulateFrom(AdmissionArgs admissionArgs)
 {
     Id          = admissionArgs.PatientId;
     Name        = admissionArgs.Name;
     DateOfBirth = admissionArgs.DateOfBirth;
 }