public async Task AddHealthMeasurementAsync(Guid patientId, HealthMeasurement <Guid, Guid> healthMeasurement, string token = null) { var patient = await _db.PatientRepository.RetrieveAsync(patientId); if (patient != null && healthMeasurement != null) { var lastMeasurementDatetime = await _db.PatientRepository.GetTimeOfLastPatientHealthMeasurementAsync(patientId); await _db.PatientRepository.AddHealthMeasurementAsync(patientId, healthMeasurement); if (lastMeasurementDatetime.Equals(DateTime.MinValue) || healthMeasurement.MeasurementTime > lastMeasurementDatetime) { patient.IgnorableSignPair = new List <PatientSign <Guid, ushort> >(await _db.RetrieveIgnorableSignsAsync(patientId)); _analyzer.Analyze(healthMeasurement, patient); var analysisResult = _analyzer.AnalysisResult; if (analysisResult.Threats.Any() && patient.CurrentHealthState.GetType() != typeof(ThreateningHealthState)) { patient.CurrentHealthState = ThreateningHealthState.GetInstance(); } else if (patient.CurrentHealthState.GetType() != typeof(NormalHealthState)) { patient.CurrentHealthState = NormalHealthState.GetInstance(); } } await _db.SaveAsync(); } else if (patient == null) { throw new ArgumentException($"Didn't find patient with id {patientId}"); } else { throw new ArgumentException("Health measurement can't be null"); } }
public PatientProfile() { CurrentActivityState = CasualActivityState.GetInstance(); CurrentHealthState = NormalHealthState.GetInstance(); }