public async Task <IHttpActionResult> PostOrderMedis(OrderMedisRequest orderMedisRequest)
        {
            try
            {
                if (!ModelState.IsValid)
                {
                    return(BadRequest("Data yang dikirim tidak lengkap"));
                }

                var orderMedis = new ORDER_MEDIS();
                var kasus      = db.KASUS.Where(x => x.ID_PEMERIKSAAN == orderMedisRequest.IdPemeriksaan).FirstOrDefault();
                var tKasus     = db.T_KASUS.Where(x => x.ID_KASUS == kasus.ID_KASUS).FirstOrDefault();

                while (true)
                {
                    orderMedis.ID_ORDER = _random.Next(1, 999999999);
                    var count = db.ORDER_MEDIS.Where(k => k.ID_ORDER == orderMedis.ID_ORDER).Count();

                    if (count == 0)
                    {
                        break;
                    }
                }

                orderMedis.ID_PEMERIKSAAN    = orderMedisRequest.IdPemeriksaan;
                orderMedis.ID_OBAT           = orderMedisRequest.IdObat;
                orderMedis.ID_LABORAT        = orderMedisRequest.IdLaborat;
                orderMedis.ID_PASIEN         = tKasus.ID_PASIEN;
                orderMedis.JUMLAH            = orderMedisRequest.Jumlah;
                orderMedis.JENIS_ORDER_MEDIS = orderMedisRequest.JenisOrderMedis;
                orderMedisRequest.IdOrder    = orderMedis.ID_ORDER;
                orderMedisRequest.IdPasien   = orderMedis.ID_PASIEN.GetValueOrDefault();

                db.ORDER_MEDIS.Add(orderMedis);

                await db.SaveChangesAsync();

                return(Ok(orderMedisRequest));
            }
            catch (Exception e)
            {
                return(BadRequest(e.Message));
            }
        }
        public IHttpActionResult GetOrderMedisById(int idOrder)
        {
            var result     = new OrderMedisRequest();
            var orderMedis = db.ORDER_MEDIS.Where(x => x.ID_ORDER == idOrder).FirstOrDefault();

            if (orderMedis == null)
            {
                return(Ok());
            }

            result.IdPemeriksaan   = orderMedis.ID_PEMERIKSAAN.GetValueOrDefault();
            result.IdOrder         = orderMedis.ID_ORDER;
            result.IdPasien        = orderMedis.ID_PASIEN.GetValueOrDefault();
            result.IdObat          = orderMedis.ID_OBAT.GetValueOrDefault();
            result.IdLaborat       = orderMedis.ID_LABORAT.GetValueOrDefault();
            result.JenisOrderMedis = orderMedis.JENIS_ORDER_MEDIS.GetValueOrDefault();
            result.Jumlah          = orderMedis.JUMLAH.GetValueOrDefault();

            return(Ok(result));
        }
        public async Task <IHttpActionResult> PutOrderMedis(int idOrder, OrderMedisRequest orderMedisRequest)
        {
            try
            {
                if (!ModelState.IsValid)
                {
                    return(BadRequest("Data yang dikirim tidak lengkap"));
                }

                var orderMedisInDB = db.ORDER_MEDIS.Where(x => x.ID_ORDER == idOrder).FirstOrDefault();
                orderMedisInDB.ID_OBAT           = orderMedisRequest.IdObat;
                orderMedisInDB.ID_LABORAT        = orderMedisRequest.IdLaborat;
                orderMedisInDB.JUMLAH            = orderMedisRequest.Jumlah;
                orderMedisInDB.JENIS_ORDER_MEDIS = orderMedisRequest.JenisOrderMedis;

                await db.SaveChangesAsync();

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