Пример #1
0
        public PatientEpisodes GetPatientEpisodesByNhsNumber(NhsNumber nhsNumber)
        {
            Patient targetPatient = this.testPatientDatabase.SingleOrDefault(x => x.NhsNumber.Equals(nhsNumber));

            if (targetPatient == null)
            {
                return(null);
            }

            var episodes = this.testEpisodeDatabase.Where(x => x.PatientId.Equals(nhsNumber)).ToList();

            PatientEpisodes value = new PatientEpisodes(targetPatient)
            {
                Episodes = episodes
            };

            return(value);
        }
Пример #2
0
        internal static TheographChartViewModel GetPatientEpsiodesChart(PatientEpisodes patientEpisodes)
        {
            TheographChartViewModel output = new TheographChartViewModel();

            var episodeGroups = patientEpisodes.Episodes.GroupBy(x => x.EpisodeType.DisplayName);
            var xAxis         = new TheographAxisData
            {
                Type     = "datetime",
                Min      = DateTime.Today.AddYears(-1).ToHighchartsTime(),
                Max      = DateTime.Today.AddDays(1).ToHighchartsTime(),
                MinRange = 1000 * 60 * 60 * 24, // max zoom of 1 day,
            };

            xAxis.DateTimeLabelFormats = new TheographDataTimeLabelFormatData
            {
                Month = "%b %y",
                Week  = "%e %b",
                Day   = "%e %b"
            };

            var yAxis = new TheographAxisData();

            const int height = 100;

            yAxis.TickInterval = height;
            yAxis.Max          = episodeGroups.Count() * height;
            yAxis.MinRange     = episodeGroups.Count() * height;
            yAxis.Labels       = new TheographAxisLabelData();
            yAxis.Title        = new TheographTitleData();

            for (int i = 0; i < episodeGroups.Count(); i++)
            {
                var episodeGroup = episodeGroups.ElementAt(i);

                var series = new TheographChartSeries
                {
                    Name = episodeGroup.Key
                };

                var plotBand = new TheographPlotBandData
                {
                    From  = i * height,
                    To    = (i + 1) * height,
                    Color = (i % 2 == 0) ? "rgba(68, 170, 213, 0.1)" : null
                };

                plotBand.Label.Text = episodeGroup.Key;

                var orderedEpsiodes = episodeGroup.OrderBy(x => x.StartTime);

                foreach (var orderedEpsiode in orderedEpsiodes)
                {
                    int    yPoint       = ((i + 1) * height) - (height / 2);
                    string tooltipTitle = string.Format("{0}{1}",
                                                        episodeGroup.Key,
                                                        orderedEpsiode.TreatmentSite != null ? " at " + orderedEpsiode.TreatmentSite.Name : string.Empty);
                    StringBuilder sbToolTipText = new StringBuilder();
                    sbToolTipText.AppendFormat(
                        "Start: {0:ddd MMMM} <sup>{1}</sup> {0:yyyy HH:mm}",
                        orderedEpsiode.StartTime,
                        orderedEpsiode.StartTime.GetDayOrdinal());

                    if (orderedEpsiode.EndTime.HasValue)
                    {
                        sbToolTipText.AppendFormat(
                            "<br/>End: {0:ddd MMMM} <sup>{1}</sup> {0:yyyy HH:mm}",
                            orderedEpsiode.EndTime.Value,
                            orderedEpsiode.EndTime.Value.GetDayOrdinal());
                    }

                    // start point
                    var dataPoint = new TheographChartSeriesData
                    {
                        // * 1000 to conform with the Highcharts way of handling dates
                        EpisodeStartTimestamp = orderedEpsiode.StartTime.ToHighchartsTime(),
                        Y = yPoint
                    };

                    dataPoint.AddData("tooltipTitle", tooltipTitle);
                    dataPoint.AddData("tooltipText", sbToolTipText.ToString());
                    dataPoint.AddData("episodeId", orderedEpsiode.EpisodeId.Value);

                    series.Data.Add(dataPoint);

                    // end point
                    if (orderedEpsiode.EndTime.HasValue)
                    {
                        dataPoint = new TheographChartSeriesData
                        {
                            // * 1000 to conform with the Highcharts way of handling dates
                            EpisodeStartTimestamp = orderedEpsiode.EndTime.Value.ToHighchartsTime(),
                            Y = yPoint
                        };

                        dataPoint.AddData("tooltipTitle", tooltipTitle);
                        dataPoint.AddData("tooltipText", sbToolTipText.ToString());
                        dataPoint.AddData("episodeId", orderedEpsiode.EpisodeId.Value);

                        series.Data.Add(dataPoint);
                    }

                    // add null-value point to disconnect separate epsiodes
                    var dataNullPoint = new TheographChartSeriesData
                    {
                        EpisodeStartTimestamp = dataPoint.EpisodeStartTimestamp + 1,
                        Y = null
                    };

                    series.Data.Add(dataNullPoint);
                }

                output.Series.Add(series);
                yAxis.AddPlotBand(plotBand);
            }

            output.Axes.Add("x", xAxis);
            output.Axes.Add("y", yAxis);

            return(output);
        }