Example #1
0
        public ManufacturedMaterial UpdateManufacturedMaterial([RestMessage(RestMessageFormat.SimpleJson)] ManufacturedMaterial manufacturedMaterial)
        {
            var query = NameValueCollection.ParseQueryString(MiniImsServer.CurrentContext.Request.Url.Query);

            Guid manufacturedMaterialKey        = Guid.Empty;
            Guid manufacturedMaterialVersionKey = Guid.Empty;

            if (query.ContainsKey("_id") && Guid.TryParse(query["_id"][0], out manufacturedMaterialKey) && query.ContainsKey("_versionId") && Guid.TryParse(query["_versionId"][0], out manufacturedMaterialVersionKey))
            {
                if (manufacturedMaterial.Key == manufacturedMaterialKey && manufacturedMaterial.VersionKey == manufacturedMaterialVersionKey)
                {
                    var manufacturedMaterialRepositoryService = ApplicationContext.Current.GetService <IMaterialRepositoryService>();

                    return(manufacturedMaterialRepositoryService.Save(manufacturedMaterial));
                }
                else
                {
                    throw new ArgumentException("Manufactured Material not found");
                }
            }
            else
            {
                throw new ArgumentException("Manufactured Material not found");
            }
        }
Example #2
0
 /// <summary>
 /// Insert manufactured material
 /// </summary>
 public ManufacturedMaterial Insert(ManufacturedMaterial material)
 {
     return(base.Insert(material));
 }
Example #3
0
 /// <summary>
 /// Save the specified manufactured material
 /// </summary>
 public ManufacturedMaterial Save(ManufacturedMaterial material)
 {
     return(base.Save(material));
 }
 /// <summary>
 /// Gets the balance for the material.
 /// </summary>
 /// <param name="place">The facility for which to get the balance of stock.</param>
 /// <param name="manufacturedMaterial">The manufactured material for which to retrieve the balance.</param>
 /// <returns>System.Int32.</returns>
 /// <exception cref="System.NotImplementedException"></exception>
 public int GetBalance(Place place, ManufacturedMaterial manufacturedMaterial)
 {
     throw new NotImplementedException(this.m_localizationService.GetString("error.type.NotImplementedException"));
 }
 /// <summary>
 /// Performs a stock adjustment for the specified facility and material.
 /// </summary>
 /// <param name="manufacturedMaterial">The manufactured material to be adjusted.</param>
 /// <param name="place">The facility for which the stock is to be adjusted.</param>
 /// <param name="quantity">The quantity to be adjusted.</param>
 /// <param name="reason">The reason for the stock to be adjusted.</param>
 /// <returns>Act.</returns>
 /// <exception cref="System.NotImplementedException"></exception>
 public Act Adjust(ManufacturedMaterial manufacturedMaterial, Place place, int quantity, Concept reason)
 {
     throw new NotImplementedException(this.m_localizationService.GetString("error.type.NotImplementedException"));
 }
Example #6
0
        /// <summary>
        /// Gets the manufactured material from the specified trade item
        /// </summary>
        public ManufacturedMaterial GetManufacturedMaterial(TransactionalTradeItemType tradeItem, bool createIfNotFound = false)
        {
            if (tradeItem == null)
            {
                throw new ArgumentNullException("tradeItem", "Trade item must have a value");
            }
            else if (String.IsNullOrEmpty(tradeItem.gtin))
            {
                throw new ArgumentException("Trade item is missing GTIN", "tradeItem");
            }


            var oidService = ApplicationContext.Current.GetService <IOidRegistrarService>();
            var gtin       = oidService.GetOid("GTIN");

            // Lookup material by lot number / gtin
            int tr = 0;
            var lotNumberString         = tradeItem.transactionalItemData[0].lotNumber;
            ManufacturedMaterial retVal = this.m_materialRepository.FindManufacturedMaterial(m => m.Identifiers.Any(o => o.Value == tradeItem.gtin && o.Authority.DomainName == "GTIN") && m.LotNumber == lotNumberString, 0, 1, out tr).FirstOrDefault();

            if (retVal == null && createIfNotFound)
            {
                var additionalData = tradeItem.transactionalItemData[0];
                if (!additionalData.itemExpirationDateSpecified)
                {
                    throw new InvalidOperationException("Cannot auto-create material, expiration date is missing");
                }

                // Material
                retVal = new ManufacturedMaterial()
                {
                    Key         = Guid.NewGuid(),
                    LotNumber   = additionalData.lotNumber,
                    Identifiers = new List <EntityIdentifier>()
                    {
                        new EntityIdentifier(new AssigningAuthority(gtin.Mnemonic, gtin.Name, gtin.Oid), tradeItem.gtin)
                    },
                    ExpiryDate = additionalData.itemExpirationDate,
                    Names      = new List <EntityName>()
                    {
                        new EntityName(NameUseKeys.Assigned, tradeItem.tradeItemDescription.Value)
                    },
                    StatusConceptKey   = StatusKeys.Active,
                    QuantityConceptKey = Guid.Parse("a4fc5c93-31c2-4f87-990e-c5a4e5ea2e76"),
                    Quantity           = 1
                };

                // Store additional identifiers
                if (tradeItem.additionalTradeItemIdentification != null)
                {
                    foreach (var id in tradeItem.additionalTradeItemIdentification)
                    {
                        var oid = oidService.GetOid(id.additionalTradeItemIdentificationTypeCode);
                        if (oid == null)
                        {
                            continue;
                        }
                        retVal.Identifiers.Add(new EntityIdentifier(new AssigningAuthority(oid.Mnemonic, oid.Name, oid.Oid), id.Value));
                    }
                }

                if (String.IsNullOrEmpty(tradeItem.itemTypeCode?.Value))
                {
                    throw new InvalidOperationException("Cannot auto-create material, type code must be specified");
                }
                else // lookup type code
                {
                    var concept = ApplicationContext.Current.GetService <IConceptRepositoryService>().FindConceptsByReferenceTerm(tradeItem.itemTypeCode.Value, tradeItem.itemTypeCode.codeListVersion).FirstOrDefault();
                    if (concept == null && tradeItem.itemTypeCode.codeListVersion == "OpenIZ-MaterialType")
                    {
                        concept = ApplicationContext.Current.GetService <IConceptRepositoryService>().GetConcept(tradeItem.itemTypeCode.Value);
                    }

                    // Type code not found
                    if (concept == null)
                    {
                        throw new InvalidOperationException($"Material type {tradeItem.itemTypeCode.Value} is not a valid concept");
                    }

                    // Get the material and set the type
                    retVal.TypeConceptKey = concept.Key;
                }

                // Find the type of material
                Material materialReference = null;
                if (tradeItem.tradeItemClassification != null)
                {
                    foreach (var id in tradeItem.tradeItemClassification.additionalTradeItemClassificationCode)
                    {
                        materialReference = this.m_materialRepository.FindMaterial(o => o.Identifiers.Any(i => i.Value == id.Value && i.Authority.DomainName == id.codeListVersion) && o.ClassConceptKey == EntityClassKeys.Material && o.StatusConceptKey != StatusKeys.Obsolete, 0, 1, out tr).SingleOrDefault();
                        if (materialReference != null)
                        {
                            break;
                        }
                    }
                }
                if (materialReference == null)
                {
                    materialReference = this.m_materialRepository.FindMaterial(o => o.TypeConceptKey == retVal.TypeConceptKey && o.ClassConceptKey == EntityClassKeys.Material && o.StatusConceptKey != StatusKeys.Obsolete, 0, 1, out tr).SingleOrDefault();
                }
                if (materialReference == null)
                {
                    throw new InvalidOperationException("Cannot find the base Material from trade item type code");
                }

                // Material relationship
                EntityRelationship materialRelationship = new EntityRelationship()
                {
                    RelationshipTypeKey        = EntityRelationshipTypeKeys.Instance,
                    Quantity                   = (int)(additionalData.tradeItemQuantity?.Value ?? 1),
                    SourceEntityKey            = materialReference.Key,
                    TargetEntityKey            = retVal.Key,
                    EffectiveVersionSequenceId = materialReference.VersionSequence
                };

                // TODO: Manufacturer won't be known

                // Insert the material && relationship
                ApplicationContext.Current.GetService <IBatchRepositoryService>().Insert(new Bundle()
                {
                    Item = new List <IdentifiedData>()
                    {
                        retVal,
                        materialRelationship
                    }
                });
            }
            else if (tradeItem.additionalTradeItemIdentification != null) // We may want to keep track of other identifiers this software knows as
            {
                bool shouldSave = false;
                foreach (var id in tradeItem.additionalTradeItemIdentification)
                {
                    var oid = oidService.GetOid(id.additionalTradeItemIdentificationTypeCode);
                    if (oid == null)
                    {
                        continue;
                    }
                    if (!retVal.Identifiers.Any(o => o.LoadProperty <AssigningAuthority>("Authority").DomainName == oid.Mnemonic))
                    {
                        retVal.Identifiers.Add(new EntityIdentifier(new AssigningAuthority(oid.Mnemonic, oid.Name, oid.Oid), id.Value));
                        shouldSave = true;
                    }
                }

                if (shouldSave)
                {
                    this.m_materialRepository.Save(retVal);
                }
            }

            return(retVal);
        }
 /// <summary>
 /// Initializes a new instance of the <see cref="ManufacturedMaterialViewModel"/> class
 /// with a specific <see cref="ManufacturedMaterial"/> instance.
 /// </summary>
 /// <param name="manufacturedMaterial">The <see cref="ManufacturedMaterial"/> instance.</param>
 public ManufacturedMaterialViewModel(ManufacturedMaterial manufacturedMaterial) : base(manufacturedMaterial)
 {
     this.LotNumber = manufacturedMaterial.LotNumber;
 }
 /// <summary>
 /// Gets the balance for the material.
 /// </summary>
 /// <param name="place">The facility for which to get the balance of stock.</param>
 /// <param name="manufacturedMaterial">The manufactured material for which to retrieve the balance.</param>
 /// <returns>System.Int32.</returns>
 /// <exception cref="System.NotImplementedException"></exception>
 public int GetBalance(Place place, ManufacturedMaterial manufacturedMaterial)
 {
     throw new NotImplementedException();
 }
 /// <summary>
 /// Performs a stock adjustment for the specified facility and material.
 /// </summary>
 /// <param name="manufacturedMaterial">The manufactured material to be adjusted.</param>
 /// <param name="place">The facility for which the stock is to be adjusted.</param>
 /// <param name="quantity">The quantity to be adjusted.</param>
 /// <param name="reason">The reason for the stock to be adjusted.</param>
 /// <returns>Act.</returns>
 /// <exception cref="System.NotImplementedException"></exception>
 public Act Adjust(ManufacturedMaterial manufacturedMaterial, Place place, int quantity, Concept reason)
 {
     throw new NotImplementedException();
 }
Example #10
0
        /// <summary>
        /// Map a facility
        /// </summary>
        static OpenIZ.Core.Model.Entities.ManufacturedMaterial MapMaterial(ItemLot item, DatasetInstall context)
        {
            Guid id = Guid.NewGuid();

            manufacturedMaterialMap.Add(item.Id, id);
            EntitySource.Current = new EntitySource(new DummyEntitySource());

            Guid materialId = Guid.Empty;

            if (!materialMap.TryGetValue(item.ItemId, out materialId))
            {
                materialId = Guid.NewGuid();
                Material material = new Material()
                {
                    Key                  = materialId,
                    ExpiryDate           = item.ItemObject.ExitDate,
                    FormConceptKey       = Guid.Parse(item.ItemObject.Name == "OPV" ? "66CBCE3A-2E77-401D-95D8-EE0361F4F076" : "9902267C-8F77-4233-BFD3-E6B068AB326A"),
                    DeterminerConceptKey = DeterminerKeys.Described,
                    Identifiers          = new List <EntityIdentifier>()
                    {
                        new EntityIdentifier(new AssigningAuthority("TIIS_ITEM", "TIIS Item Identifiers", "1.3.6.1.4.1.33349.3.1.5.102.3.5.12"), item.ItemId.ToString())
                    },
                    Names = new List <EntityName>()
                    {
                        new EntityName(NameUseKeys.OfficialRecord, item.ItemObject.Name)
                    },
                    StatusConceptKey = item.ItemObject.IsActive ? StatusKeys.Active : StatusKeys.Obsolete
                };
                context.Action.Add(new DataUpdate()
                {
                    InsertIfNotExists = true, Element = material
                });
                materialMap.Add(item.ItemId, materialId);
            }

            // Organization map?
            Guid organizationId = Guid.Empty;
            var  gtinObject     = ItemManufacturer.GetItemManufacturerByGtin(item.Gtin);

            if (gtinObject != null && !manufacturerMap.TryGetValue(gtinObject.ManufacturerId, out organizationId))
            {
                organizationId = Guid.NewGuid();
                Organization organization = new Organization()
                {
                    Key         = organizationId,
                    Identifiers = new List <EntityIdentifier>()
                    {
                        new EntityIdentifier(new AssigningAuthority("MANUFACTURER_CODE", "Manufacturer Codes", "1.3.6.1.4.1.33349.3.1.5.102.3.5.14"), gtinObject.ManufacturerObject.Code),
                        new EntityIdentifier(new AssigningAuthority("TIIS_MANUFACTURER", "TIIS Manufacturer Identifiers", "1.3.6.1.4.1.33349.3.1.5.102.3.5.13"), gtinObject.ManufacturerId.ToString())
                    },
                    Names = new List <EntityName>()
                    {
                        new EntityName(NameUseKeys.OfficialRecord, gtinObject.ManufacturerObject.Name)
                    },
                    StatusConceptKey   = gtinObject.ManufacturerObject.IsActive ? StatusKeys.Active : StatusKeys.Obsolete,
                    IndustryConceptKey = industryManufacturer
                };
                context.Action.Add(new DataUpdate()
                {
                    InsertIfNotExists = true, Element = organization
                });
                manufacturerMap.Add(gtinObject.ManufacturerId, organizationId);
            }

            Guid typeConceptKey = Guid.Empty;

            materialTypeMap.TryGetValue(item.ItemId, out typeConceptKey);

            // TODO: Migrate over kit items
            // TODO: Link boxes/vials/doses
            // Core construction of place
            ManufacturedMaterial retVal = new ManufacturedMaterial()
            {
                Key            = id,
                TypeConceptKey = typeConceptKey == Guid.Empty ? (Guid?)null : typeConceptKey,
                Relationships  = new List <EntityRelationship>()
                {
                    new EntityRelationship(EntityRelationshipTypeKeys.ManufacturedProduct, id)
                    {
                        SourceEntityKey = materialId
                    },
                },
                Names = new List <EntityName>()
                {
                    new EntityName(NameUseKeys.Assigned, String.Format("{0} ({1})", item.ItemObject.Name, gtinObject?.ManufacturerObject.Name))
                },
                ExpiryDate  = item.ExpireDate,
                LotNumber   = item.LotNumber,
                Identifiers = new List <EntityIdentifier>()
                {
                    new EntityIdentifier(new AssigningAuthority("GTIN", "GS1 Global Trade Identification Number (GTIN)", "1.3.160"), item.Gtin),
                    new EntityIdentifier(new AssigningAuthority("GIIS_ITEM_ID", "GIIS Item Identifiers", "1.3.6.1.4.1.33349.3.1.5.102.3.5.15"), item.Id.ToString())
                },
                IsAdministrative = false,
                StatusConceptKey = StatusKeys.Active
            };

            if (organizationId != Guid.Empty)
            {
                retVal.Relationships.Add(new EntityRelationship(EntityRelationshipTypeKeys.WarrantedProduct, id)
                {
                    SourceEntityKey = organizationId
                });
            }

            return(retVal);
        }