Ejemplo n.º 1
0
        public virtual ActionResult <WaitingListEntry> UpdateWaitingListEntry([FromBody] WaitingListEntry body, [FromRoute][Required] string ambulanceId, [FromRoute][Required] string entryId)
        {
            //TODO: Uncomment the next line to return response 200 or use other options such as return this.NotFound(), return this.BadRequest(..), ...
            // return StatusCode(200, default(WaitingListEntry));

            //TODO: Uncomment the next line to return response 403 or use other options such as return this.NotFound(), return this.BadRequest(..), ...
            // return StatusCode(403);

            //TODO: Uncomment the next line to return response 404 or use other options such as return this.NotFound(), return this.BadRequest(..), ...
            // return StatusCode(404);
            //CHANGE TO
            if (!entryId.Equals(body.Id))
            {
                return(new BadRequestResult());
            }

            var ambulance = this.repository.GetAmbulanceData(ambulanceId);
            var entry     = ambulance == null ? null
                : ambulance.WaitingList.FirstOrDefault(_ => _.Id.Equals(entryId));

            if (entry == null)
            {
                return(new NotFoundResult());
            }

            ambulance.WaitingList.Remove(entry);
            ambulance.WaitingList.Add(body);

            this.repository.UpsertAmbulanceData(ambulance);
            return(body);
        }
Ejemplo n.º 2
0
        public void FirstPatientLeavesAmbulance_NextPatientEntersJustAfterwards()
        {
            // given
            var ambulance = new Ambulance
            {
                OpeningTime = "08:00",
                WaitingList = new List <WaitingListEntry>
                {
                    new WaitingListEntry
                    {
                        Id        = "A",
                        PatientId = "test-patient-A",
                        Name      = "Patient Test A",
                        Since     = DateTime.Today + new TimeSpan(9, 40, 0),
                        Estimated = DateTime.Today + new TimeSpan(5, 0, 0)
                    },
                    new WaitingListEntry
                    {
                        Id        = "B",
                        PatientId = "test-patient",
                        Name      = "Patient Test",
                        Since     = DateTime.Today + new TimeSpan(7, 20, 0),
                        EstimatedDurationMinutes = 25
                    }
                }
            };

            // when
            ambulance.EstimateAndSortWaitingListEntries();
            var result = ambulance.WaitingList;

            // then
            WaitingListEntry previous = null;

            foreach (var next in result)
            {
                if (previous == null)
                {
                    previous = next;
                    continue;
                }
                Assert.IsTrue(
                    previous.Estimated
                    + TimeSpan.FromMinutes(previous.EstimatedDurationMinutes ?? 15)
                    <= next.Estimated);
            }
        }
Ejemplo n.º 3
0
        public virtual IActionResult UpdateWaitingListEntry([FromBody] WaitingListEntry body, [FromRoute][Required] string ambulanceId, [FromRoute][Required] string entryId)
        {
            //TODO: Uncomment the next line to return response 200 or use other options such as return this.NotFound(), return this.BadRequest(..), ...
            // return StatusCode(200, default(WaitingListEntry));

            //TODO: Uncomment the next line to return response 403 or use other options such as return this.NotFound(), return this.BadRequest(..), ...
            // return StatusCode(403);

            //TODO: Uncomment the next line to return response 404 or use other options such as return this.NotFound(), return this.BadRequest(..), ...
            // return StatusCode(404);
            string exampleJson = null;

            exampleJson = "{\n  \"condition\" : {\n    \"reference\" : \"https://zdravoteka.sk/priznaky/zvysena-telesna-teplota/\",\n    \"code\" : \"subfebrilia\",\n    \"typicalDurationMinutes\" : 20,\n    \"value\" : \"Teploty\"\n  },\n  \"patientId\" : \"460527-jozef-pucik\",\n  \"estimatedDurationMinutes\" : 15,\n  \"name\" : \"Jožko Púčik\",\n  \"estimated\" : \"2018-12-24T10:35:00Z\",\n  \"id\" : \"x321ab3\",\n  \"since\" : \"2018-12-24T10:05:00Z\"\n}";

            var example = exampleJson != null
                        ? JsonConvert.DeserializeObject <WaitingListEntry>(exampleJson)
                        : default(WaitingListEntry);            //TODO: Change the data returned

            return(new ObjectResult(example));
        }
Ejemplo n.º 4
0
        public virtual ActionResult <WaitingListEntry> StoreWaitingListEntry([FromBody] WaitingListEntry body, [FromRoute][Required] string ambulanceId)
        {
            //TODO: Uncomment the next line to return response 200 or use other options such as return this.NotFound(), return this.BadRequest(..), ...
            // return StatusCode(200, default(WaitingListEntry));

            //TODO: Uncomment the next line to return response 400 or use other options such as return this.NotFound(), return this.BadRequest(..), ...
            // return StatusCode(400);

            //TODO: Uncomment the next line to return response 404 or use other options such as return this.NotFound(), return this.BadRequest(..), ...
            // return StatusCode(404);
            var ambulance = this.repository.GetAmbulanceData(ambulanceId);

            if (ambulance == null)
            {
                return(new NotFoundResult());
            }

            body.Id = Guid.NewGuid().ToString();
            ambulance.WaitingList.Add(body);
            this.repository.UpsertAmbulanceData(ambulance);

            return(body);
        }
Ejemplo n.º 5
0
        private List<WaitingListEntry> LoadWaitingList(string waitingListFileName)
        {
            if(!File.Exists(waitingListFileName))
            {
                throw new FileNotFoundException("File does not exist: " + waitingListFileName);
            }
            List<WaitingListEntry> entries = new List<WaitingListEntry>();
            string[][] csvFileEntries;
            using (TextReader tr = new StreamReader(waitingListFileName))
            {
                csvFileEntries = CSVParser.Parse(tr);
            }

            for (int i = 0; i < csvFileEntries.Length; i++)
            {
                if (i == 0)
                {
                    if (string.Compare(csvFileEntries[0][0], "position", true) != 0)
                    {
                        throw new ArgumentException("Waiting list file line 1 does not have 'POSITION' in field 1");
                    }
                    if (string.Compare(csvFileEntries[0][1], "name", true) != 0)
                    {
                        throw new ArgumentException("Waiting list file line 1 does not have 'NAME' in field 2");
                    }
                    if (string.Compare(csvFileEntries[0][2], "date added", true) != 0)
                    {
                        throw new ArgumentException("Waiting list file line 1 does not have 'DATE ADDED' in field 3");
                    }
                }
                else if ((csvFileEntries[i].Length > 2) &&
                    // skip if all 3 are empty
                    !(string.IsNullOrEmpty(csvFileEntries[i][0]) &&
                      string.IsNullOrEmpty(csvFileEntries[i][1]) &&
                      string.IsNullOrEmpty(csvFileEntries[i][2])))
                {
                    WaitingListEntry wle = new WaitingListEntry();
                    wle.Name = csvFileEntries[i][1];

                    int position;
                    if (!int.TryParse(csvFileEntries[i][0], out position))
                    {
                        throw new ArgumentException(string.Format(
                            "Waiting list file error on line {0}: position field is not an integer: {1} ",
                            i + 1, csvFileEntries[i][0]));
                    }
                    wle.Position = position;

                    DateTime dt;
                    if (!DateTime.TryParse(csvFileEntries[i][2], out dt))
                    {
                        throw new ArgumentException(string.Format(
                            "Waiting list file error on line {0}: date added field is not a date: {1} ",
                            i + 1, csvFileEntries[i][2]));
                    }
                    wle.DateAdded = dt;

                    entries.Add(wle);
                }
            }

            return entries;
        }