Esempio n. 1
0
        /// <summary>
        /// Map a facility
        /// </summary>
        static OpenIZ.Core.Model.Entities.Place MapPlace(GIIS.DataLayer.Place plc)
        {
            Guid id = Guid.NewGuid();

            placeEntityMap.Add(plc.Id, id);
            EntitySource.Current = new EntitySource(new DummyEntitySource());

            Guid classCode = EntityClassKeys.Place, typeCode = PT_VILLAGE;

            switch (plc.Code.Length)
            {
            case 2:     // EX: "TZ"
                classCode = EntityClassKeys.Country;
                typeCode  = EntityClassKeys.Country;
                break;

            case 5:     // EX: TZ.NT
                classCode = EntityClassKeys.Place;
                typeCode  = PT_TERRITORY;
                break;

            case 8:     // EX: TZ.NT.AS
                classCode = EntityClassKeys.State;
                typeCode  = PT_REGION;
                break;

            case 11:     // EX: TZ.NT.AS.AM
                classCode = EntityClassKeys.CountyOrParish;
                typeCode  = PT_DISTRICT;
                break;

            default:
                if (plc.Code.Length <= 14)
                {
                    classCode = EntityClassKeys.CityOrTown;
                    typeCode  = PT_DISTRICT_COUNCIL;
                }
                else
                {
                    classCode = EntityClassKeys.Place;
                    typeCode  = PT_VILLAGE;
                }
                break;
            }


            // Core construction of place
            var retVal = new OpenIZ.Core.Model.Entities.Place()
            {
                Key             = id,
                ClassConceptKey = classCode,
                TypeConceptKey  = typeCode,
                Names           = new List <EntityName>()
                {
                    new EntityName(NameUseKeys.OfficialRecord, plc.Name)
                },
                Identifiers = new List <OpenIZ.Core.Model.DataTypes.EntityIdentifier>()
                {
                    new OpenIZ.Core.Model.DataTypes.EntityIdentifier(new AssigningAuthority("TIIS_PLCID", "TIIS Place Identifiers", "1.3.6.1.4.1.45219.1.3.5.12"), plc.Id.ToString()),
                    new OpenIZ.Core.Model.DataTypes.EntityIdentifier(new AssigningAuthority("TZ_FRID", "Facility Register Codes", "1.3.6.1.4.1.45219.1.3.5.11"), plc.Code)
                },
                StatusConceptKey = plc.IsActive ? StatusKeys.Active : StatusKeys.Nullfied,
                Extensions       = new List <EntityExtension>()
                {
                    new EntityExtension()
                    {
                        ExtensionType  = new ExtensionType("http://openiz.org/extensions/contrib/tiis/isleaf", typeof(BooleanExtensionHandler)),
                        ExtensionValue = plc.Leaf
                    }
                },
                Addresses = new List <EntityAddress>()
                {
                    MapAddress(plc)
                },
                Tags = new List <EntityTag>()
                {
                    new EntityTag("http://openiz.org/tags/contrib/importedData", "true")
                }
            };

            if (plc.ParentId != 0)
            {
                retVal.Relationships = new List <EntityRelationship>()
                {
                    new EntityRelationship(EntityRelationshipTypeKeys.Parent, new Entity()
                    {
                        Key = placeEntityMap[plc.ParentId]
                    })
                }
            }
            ;
            if (plc.HealthFacilityId != null && plc.HealthFacilityId != 0)
            {
                retVal.Relationships = new List <EntityRelationship>()
                {
                    new EntityRelationship(EntityRelationshipTypeKeys.DedicatedServiceDeliveryLocation, new Entity()
                    {
                        Key = facilityMap[plc.HealthFacilityId.Value]
                    })
                }
            }
            ;
            // TODO: Fix author key needing to be present in DB

            /*
             * if (!String.IsNullOrEmpty(hf.Notes))
             * {
             *  if(!userEntityMap.ContainsKey(hf.ModifiedBy))
             *      userEntityMap.Add(hf.ModifiedBy, Guid.NewGuid());
             *  retVal.Notes.Add(new EntityNote()
             *  {
             *      AuthorKey = userEntityMap[hf.ModifiedBy],
             *      Text = hf.Notes
             *  });
             * }*/
            return(retVal);
        }
Esempio n. 2
0
        /// <summary>
        /// Map a facility
        /// </summary>
        static OpenIZ.Core.Model.Entities.Place MapFacility(HealthFacility hf)
        {
            Guid id = Guid.NewGuid();

            Console.WriteLine("Adding health facility id");
            facilityMap.Add(hf.Id, id);
            Console.WriteLine("Adding health facility id successful");
            EntitySource.Current = new EntitySource(new DummyEntitySource());

            // Core construction of place
            Console.WriteLine("Creating core constructions of place");
            Console.WriteLine("cold storage capacity value is = " + hf.ColdStorageCapacity);

            var retVal = new OpenIZ.Core.Model.Entities.Place()
            {
                Key             = id,
                ClassConceptKey = EntityClassKeys.ServiceDeliveryLocation,
                TypeConceptKey  = facilityTypeId[hf.TypeId],
                Names           = new List <EntityName>()
                {
                    new EntityName(NameUseKeys.OfficialRecord, hf.Name)
                },
                Identifiers = new List <OpenIZ.Core.Model.DataTypes.EntityIdentifier>()
                {
                    new OpenIZ.Core.Model.DataTypes.EntityIdentifier(new AssigningAuthority("TIIS_FACID", "TIIS Facility Identifiers", "1.3.6.1.4.1.45219.1.3.5.5"), hf.Id.ToString()),
                    new OpenIZ.Core.Model.DataTypes.EntityIdentifier(new AssigningAuthority("TZ_FRID", "Facility Register Identifiers", "1.3.6.1.4.1.45219.1.3.5.10"), hf.Code)
                },
                StatusConceptKey = hf.IsActive ? StatusKeys.Active : StatusKeys.Nullfied,
                Extensions       = new List <EntityExtension>()
                {
                    new EntityExtension()
                    {
                        ExtensionType  = new ExtensionType("http://openiz.org/extensions/contrib/tiis/isleaf", typeof(BooleanExtensionHandler)),
                        ExtensionValue = hf.Leaf
                    },
                    new EntityExtension()
                    {
                        ExtensionType  = new ExtensionType("http://openiz.org/extensions/contrib/tiis/isVaccinationPoint", typeof(BooleanExtensionHandler)),
                        ExtensionValue = hf.VaccinationPoint
                    },
                    new EntityExtension()
                    {
                        ExtensionType  = new ExtensionType("http://openiz.org/extensions/contrib/tiis/vaccineStore", typeof(BooleanExtensionHandler)),
                        ExtensionValue = hf.VaccineStore
                    },
                    new EntityExtension()
                    {
                        ExtensionType  = new ExtensionType("http://openiz.org/extensions/contrib/tiis/coldStorageCapacity", typeof(DecimalExtensionHandler)),
                        ExtensionValue = Decimal.Parse(hf.ColdStorageCapacity.ToString())
                    }
                },
                Tags = new List <EntityTag>()
                {
                    new EntityTag("http://openiz.org/tags/contrib/importedData", "true")
                }
            };

            Console.WriteLine("Completed successful");
            if (hf.ParentId != 0)
            {
                retVal.Relationships = new List <EntityRelationship>()
                {
                    new EntityRelationship(EntityRelationshipTypeKeys.Parent, new Entity()
                    {
                        Key = facilityMap[hf.ParentId]
                    })
                }
            }
            ;

            // TODO: Fix author key needing to be present in DB

            /*
             * if (!String.IsNullOrEmpty(hf.Notes))
             * {
             *  if(!userEntityMap.ContainsKey(hf.ModifiedBy))
             *      userEntityMap.Add(hf.ModifiedBy, Guid.NewGuid());
             *  retVal.Notes.Add(new EntityNote()
             *  {
             *      AuthorKey = userEntityMap[hf.ModifiedBy],
             *      Text = hf.Notes
             *  });
             * }*/
            return(retVal);
        }