예제 #1
0
        public async Task <IHttpActionResult> PostPenjadwalan(JadwalRequest jadwalRequest)
        {
            try
            {
                if (!ModelState.IsValid)
                {
                    return(BadRequest("Data yang dikirim tidak lengkap"));
                }

                var jadwal = new JADWAL();
                jadwal.MULAI          = jadwalRequest.TglMulai;
                jadwal.SELESAI        = jadwalRequest.TglSelesai;
                jadwal.ID_PEMERIKSAAN = jadwalRequest.IdPemeriksaan;
                jadwal.KEPERLUAN      = jadwalRequest.Keperluan;
                jadwal.STATUS         = 1;

                while (true)
                {
                    jadwal.ID_JADWAL = _random.Next(1, 999999999);
                    var count = db.JADWALs.Where(k => k.ID_JADWAL == jadwal.ID_JADWAL).Count();

                    if (count == 0)
                    {
                        break;
                    }
                }
                jadwalRequest.IdJadwal = jadwal.ID_JADWAL;

                db.JADWALs.Add(jadwal);

                await db.SaveChangesAsync();

                return(Ok(jadwalRequest));
            }
            catch (Exception e)
            {
                return(BadRequest(e.Message));
            }
        }
예제 #2
0
        public async Task <IHttpActionResult> PostPenjadwalanRecent(JadwalRequest jadwalRequest)
        {
            try
            {
                if (!ModelState.IsValid)
                {
                    return(BadRequest("Data yang dikirim tidak lengkap"));
                }

                var historyMedis = new VW_HISTORY_MEDIS_PASIEN();
                var rekamMedis   = new REKAM_MEDIS();

                var identity = (ClaimsIdentity)User.Identity;
                var roles    = identity.Claims.Where(c => c.Type == ClaimTypes.Role).FirstOrDefault();
                if (roles.Value == "Pasien")
                {
                    var username = identity.Claims.Where(c => c.Type == ClaimTypes.Name).FirstOrDefault().Value;
                    var pasien   = db.PASIENs.Where(x => x.USER.USERNAME == username).FirstOrDefault();

                    historyMedis = db.VW_HISTORY_MEDIS_PASIEN.Where(x => x.ID_PASIEN == pasien.ID_PASIEN).OrderByDescending(x => x.TGL_MASUK).FirstOrDefault();
                    var tKasus = db.PEMERIKSAANs.Where(x => x.ID_PEMERIKSAAN == historyMedis.ID_PEMERIKSAAN).FirstOrDefault();
                    if (tKasus.ID_REKAM_MEDIS.HasValue)
                    {
                        rekamMedis = db.REKAM_MEDIS.Where(x => x.ID_REKAM_MEDIS == tKasus.ID_REKAM_MEDIS).FirstOrDefault();
                    }
                }
                else
                {
                    historyMedis = db.VW_HISTORY_MEDIS_PASIEN.OrderByDescending(x => x.TGL_MASUK).ThenBy(x => x.PASIEN).FirstOrDefault();
                    var tKasus = db.PEMERIKSAANs.Where(x => x.ID_PEMERIKSAAN == historyMedis.ID_PEMERIKSAAN).FirstOrDefault();
                    if (tKasus.ID_REKAM_MEDIS.HasValue)
                    {
                        rekamMedis = db.REKAM_MEDIS.Where(x => x.ID_REKAM_MEDIS == tKasus.ID_REKAM_MEDIS).FirstOrDefault();
                    }
                }

                var jadwal = new JADWAL();
                jadwal.MULAI          = jadwalRequest.TglMulai;
                jadwal.SELESAI        = jadwalRequest.TglSelesai;
                jadwal.ID_PEMERIKSAAN = historyMedis.ID_PEMERIKSAAN.GetValueOrDefault();
                jadwal.KEPERLUAN      = jadwalRequest.Keperluan;
                jadwal.STATUS         = 1;

                while (true)
                {
                    jadwal.ID_JADWAL = _random.Next(1, 999999999);
                    var count = db.JADWALs.Where(k => k.ID_JADWAL == jadwal.ID_JADWAL).Count();

                    if (count == 0)
                    {
                        break;
                    }
                }
                jadwalRequest.IdJadwal = jadwal.ID_JADWAL;

                db.JADWALs.Add(jadwal);

                await db.SaveChangesAsync();

                return(Ok(jadwalRequest));
            }
            catch (Exception e)
            {
                return(BadRequest(e.Message));
            }
        }