예제 #1
0
        public static async Task <IActionResult> Run(
            [HttpTrigger(AuthorizationLevel.Function, "post", Route = null)] HttpRequest req,
            [ServiceBus("sbq-medicialsupplyorders-in", Connection = "ServiceBusConnection",
                        EntityType = EntityType.Queue)] IAsyncCollector <MedicineOrder> medicialSuppyOrders,
            ILogger log)
        {
            log.LogInformation("C# HTTP trigger function request received for medical order.");

            string requestBody = await new StreamReader(req.Body).ReadToEndAsync();
            MedicineOrderApproval medicineOrderApproval = JsonConvert.DeserializeObject <MedicineOrderApproval>(requestBody);

            SettingsData settingsData = new SettingsData();

            MedicineOrder medicineOrder = MedicalSupplyOrderRepository.RetrieveMedicalSupplyOrder(settingsData.SqlServerConnectionString, medicineOrderApproval.Id);

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

            medicineOrder.TimeofApproval     = medicineOrderApproval.TimeofApproval = DateTime.Now;
            medicineOrder.OrderStatus        = medicineOrderApproval.OrderStatus;
            medicineOrder.AdditionalComments = medicineOrderApproval.AdditionalComments;

            MedicalSupplyOrderRepository.ApproveMedicalSupplyOrder(settingsData.SqlServerConnectionString, medicineOrderApproval);

            if (medicineOrderApproval.OrderStatus == "Approved")
            {
                await medicialSuppyOrders.AddAsync(medicineOrder);
            }

            log.LogInformation("C# HTTP trigger function placed the medical order.");

            return(new NoContentResult());
        }
예제 #2
0
        public async Task<IActionResult> Run(
            [HttpTrigger(AuthorizationLevel.Function, "post",
            Route = "UpdatePharmacyOrder/{partitionKey}/{id}")] HttpRequest req,
            [CosmosDB(databaseName: "MedsRUsDataStore", collectionName: "MedOrders", ConnectionStringSetting = "CosmosDBConnection"
            , Id = "{id}", PartitionKey = "{partitionKey}")] MedicineOrder medicineOrder,
            [ServiceBus("sbq-medicialsupplyorders-out", Connection = "ServiceBusConnection",
            EntityType = EntityType.Queue)] IAsyncCollector<MedicineOrder> medicialSuppyOrders,
            ILogger log)
        {
            log.LogInformation("C# HTTP trigger function request received for updating pharmacy medical order.");

            log.LogInformation($"Medicine Order from Cosmos Db: {medicineOrder}");

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

            string requestBody = await new StreamReader(req.Body).ReadToEndAsync();
            MedicineOrderApproval medicineOrderApproval = JsonConvert.DeserializeObject<MedicineOrderApproval>(requestBody);

            medicineOrder.LotNumber = medicineOrderApproval.LotNumber;
            medicineOrder.PharmacyTimeofApproval = DateTime.Now;
            medicineOrder.PharmacyOrderStatus = medicineOrderApproval.PharmacyOrderStatus;
            medicineOrder.PharmacyAdditionalComments = medicineOrderApproval.PharmacyAdditionalComments;

            await medicialSuppyOrders.AddAsync(medicineOrder);

            return new OkObjectResult(medicineOrder);
        }
예제 #3
0
        public async Task <bool> ApproveMedicalSupplyOrder(string connectionString, MedicineOrderApproval medicineOrderApproval)
        {
            using (SqlConnection connection = new SqlConnection(connectionString))
            {
                SqlCommand command = new SqlCommand()
                {
                    CommandText = "[dbo].[usp_update_med_order_by_id]",
                    Connection  = connection,
                    CommandType = CommandType.StoredProcedure
                };

                command.Parameters.AddWithValue("@Id",
                                                medicineOrderApproval.Id).SqlDbType = SqlDbType.UniqueIdentifier;

                command.Parameters.AddWithValue("@OrderStatus",
                                                medicineOrderApproval.OrderStatus).SqlDbType = SqlDbType.VarChar;

                command.Parameters.AddWithValue("@TimeofApproval",
                                                medicineOrderApproval.TimeofApproval).SqlDbType = SqlDbType.DateTime2;

                command.Parameters.AddWithValue("@AdditionalComments",
                                                medicineOrderApproval.AdditionalComments).SqlDbType = SqlDbType.VarChar;

                connection.Open();
                await command.ExecuteNonQueryAsync().ConfigureAwait(false);
            }

            return(true);
        }