Пример #1
0
        /// <summary>
        /// To add system Formulary
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        public async Task <BusinessResult <SystemItemSetupRequest> > AddSystemItem(SystemItemSetupRequest request)
        {
            var existingItem = await _itemReository.GetItemByCode(request.ItemId);

            if (existingItem != null)
            {
                return(new BusinessResult <SystemItemSetupRequest>(null, CreateUpdateResultEnum.ErrorAlreadyExists));
            }

            var key = Guid.NewGuid();

            var itemEntity = new ItemEntity
            {
                ItemKey                = key,
                TenantKey              = Guid.NewGuid(),
                CreatedByActorKey      = Guid.NewGuid(),
                CreatedDateTime        = DateTimeOffset.Now,
                LastModifiedDateTime   = DateTime.UtcNow,
                LastModifiedByActorKey = Guid.NewGuid(),
                ItemID             = request.ItemId,
                AlternateItemID    = request.AlternateItemID,
                MedicationItemFlag = true
            };

            itemEntity.CreatedDateTime = DateTimeOffset.Now;

            var medEntity = new MedicationItemEntity
            {
                MedicationItemKey                   = key,
                TenantKey                           = Guid.NewGuid(),
                CreatedByActorKey                   = Guid.NewGuid(),
                CreatedDateTime                     = DateTimeOffset.Now,
                LastModifiedDateTime                = DateTime.UtcNow,
                LastModifiedByActorKey              = Guid.NewGuid(),
                MedicationClassKey                  = request.MedicationClassKey,
                Description                         = request.Description,
                GLAccountKey                        = request.GenralLedgerAccountKey,
                DispenseFormLookupKey               = request.DispensingFormKey,
                DispenseUnitLookupKey               = request.DispensingUnitKey,
                StrengthAmount                      = request.StrengthAmount,
                ConcentrationVolumeAmount           = request.ConcentrationVolumeAmount,
                TotalVolumeAmount                   = request.TotalVolumeAmount,
                TotalVolumeUnitOfMeasureKey         = request.TotalVolumeUnitOfMessureKey,
                StrengthUnitOfMeasureKey            = request.StrengthUnitOfMessureKey,
                ConcentrationVolumeUnitOfMeasureKey = request.ConcentrationVolumeUnitOfMessureKey,
                ChargeCode                          = request.ChargeCode,
                HighRiskFlag                        = request.HighRiskFlag,
                ChemotherapyFlag                    = request.ChemotherapyFlag,
                NonFormularyFlag                    = request.NonFormularyFlag,
                LASAFlag         = request.LASAFlag,
                RefrigeratedFlag = request.RefrigeratedFlag,
                DrugFlag         = request.DrugFlag,
                ChemoAgentFlag   = request.ChemoAgentFlag,
                BioHazFlag       = request.BioHazFlag,
                HazAerosolFlag   = request.HazAerosolFlag,
                HazBaseFlag      = request.HazBaseFlag,
                HazAcidFlag      = request.HazAcidFlag,
                HazChemicalFlag  = request.HazChemicalFlag,
                HazOxidizerFlag  = request.HazOxidizerFlag,
                HazToxicFlag     = request.HazToxicFlag,
                FreezerFlag      = request.FreezerFlag,
                ActiveFlag       = request.ActiveFlag
            };

            itemEntity.MedicationItem = medEntity;

            var systemFormulary = _mapper.Map <SystemFormulary>(request);

            systemFormulary.ItemKey           = itemEntity.ItemKey;
            systemFormulary.MedicationItemKey = itemEntity.MedicationItem.MedicationItemKey;


            if (await _itemReository.AddSystemItem(itemEntity) /*&& await _medicationItemRepository.AddMedicationItem(medEntity)*/)
            {
                return(new BusinessResult <SystemItemSetupRequest>(systemFormulary,
                                                                   CreateUpdateResultEnum.Success));
            }
            return(new BusinessResult <SystemItemSetupRequest>(null, CreateUpdateResultEnum.ValidationFailed));
        }