コード例 #1
0
        static EntityAddress MapAddress(GIIS.DataLayer.Place place)
        {
            var retVal = new EntityAddress();

            retVal.AddressUseKey = AddressUseKeys.Direct;
            if (!String.IsNullOrEmpty(place.Code))
            {
                retVal.Component.Add(new EntityAddressComponent(AddressComponentKeys.CensusTract, place.Code));
            }

            Queue <Guid> addressParts = new Queue <Guid>(new Guid[] {
                AddressComponentKeys.AdditionalLocator,
                AddressComponentKeys.StreetAddressLine,
                AddressComponentKeys.City,
                AddressComponentKeys.County,
                AddressComponentKeys.State,
                AddressComponentKeys.Country
            });

            // Queue places
            Queue <GIIS.DataLayer.Place> domicileParts = new Queue <GIIS.DataLayer.Place>();

            GIIS.DataLayer.Place current = place;
            while (current != null)
            {
                domicileParts.Enqueue(current);
                current = current.Parent;
            }

            // Now trim
            while (addressParts.Count > domicileParts.Count)
            {
                addressParts.Dequeue();
            }

            // Now map
            while (domicileParts.Count > 0)
            {
                retVal.Component.Add(new EntityAddressComponent(addressParts.Dequeue(), domicileParts.Dequeue().Name));
            }
            return(retVal);
        }
コード例 #2
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);
        }
コード例 #3
0
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!this.Page.IsPostBack)
        {
            List <string> actionList        = null;
            string        sessionNameAction = "";
            if (CurrentEnvironment.LoggedUser != null)
            {
                sessionNameAction = "__GIS_actionList_" + CurrentEnvironment.LoggedUser.Id;
                actionList        = (List <string>)Session[sessionNameAction];
            }

            if ((actionList != null) && actionList.Contains("ViewPlace") && (CurrentEnvironment.LoggedUser != null))
            {
                int    userId     = CurrentEnvironment.LoggedUser.Id;
                string language   = CurrentEnvironment.Language;
                int    languageId = int.Parse(language);
                Dictionary <string, string> wtList = (Dictionary <string, string>)HttpContext.Current.Cache["Place-dictionary" + language];
                if (wtList == null)
                {
                    List <WordTranslate> wordTranslateList = WordTranslate.GetWordByLanguage(languageId, "Place");
                    wtList = new Dictionary <string, string>();
                    foreach (WordTranslate vwt in wordTranslateList)
                    {
                        wtList.Add(vwt.Code, vwt.Name);
                    }
                    HttpContext.Current.Cache.Insert("Place-dictionary" + language, wtList);
                }

                //controls
                this.lblName.Text              = wtList["PlaceName"];
                this.lblParentId.Text          = wtList["PlaceParent"];
                this.lblLeaf.Text              = wtList["PlaceLeaf"];
                this.lblNotes.Text             = wtList["PlaceNotes"];
                this.lblIsActive.Text          = wtList["PlaceIsActive"];
                this.rblIsActive.Items[0].Text = wtList["PlaceYes"];
                this.rblIsActive.Items[1].Text = wtList["PlaceNo"];
                this.rblLeaf.Items[0].Text     = wtList["PlaceYes"];
                this.rblLeaf.Items[1].Text     = wtList["PlaceNo"];
                this.lblHealthFacility.Text    = wtList["PlaceHealthFacility"];

                //grid header text
                gvPlace.Columns[1].HeaderText = wtList["PlaceName"];
                gvPlace.Columns[3].HeaderText = wtList["PlaceParent"];
                gvPlace.Columns[4].HeaderText = wtList["PlaceLeaf"];
                gvPlace.Columns[5].HeaderText = wtList["PlaceNotes"];
                gvPlace.Columns[6].HeaderText = wtList["PlaceIsActive"];

                //actions
                this.btnAdd.Visible    = actionList.Contains("AddPlace");
                this.btnEdit.Visible   = actionList.Contains("EditPlace");
                this.btnRemove.Visible = actionList.Contains("RemovePlace");

                //buttons
                this.btnAdd.Text    = wtList["PlaceAddButton"];
                this.btnEdit.Text   = wtList["PlaceEditButton"];
                this.btnRemove.Text = wtList["PlaceRemoveButton"];

                //Page Title
                this.lblTitle.Text = wtList["PlacePageTitle"];

                //message
                this.lblSuccess.Text = wtList["PlaceSuccessText"];
                this.lblWarning.Text = wtList["PlaceWarningText"];
                this.lblError.Text   = wtList["PlaceErrorText"];
                if ((String)HttpContext.Current.Session["_successPlace"] == "1")
                {
                    lblSuccess.Visible = true;
                }
                else
                {
                    lblSuccess.Visible = false;
                }

                HttpContext.Current.Session["_successPlace"] = "0";

                //validators

                revPlace.Text        = wtList["PlaceParentValidator"];
                cvPlace.ErrorMessage = wtList["PlaceMandatory"];
                revName.Text         = wtList["PlaceNameValidator"];

                //selected object
                int    id  = -1;
                string _id = Request.QueryString["id"];
                if (!String.IsNullOrEmpty(_id))
                {
                    int.TryParse(_id, out id);
                    GIIS.DataLayer.Place o = GIIS.DataLayer.Place.GetPlaceById(id);
                    txtName.Text = o.Name;
                    txtCode.Text = o.Code;
                    if (o.Parent != null)
                    {
                        txtParentId.SelectedItemText = o.Parent.Name.ToString();
                    }
                    rblLeaf.SelectedValue = o.Leaf.ToString();
                    if (o.Leaf)
                    {
                        lblHealthFacility.Visible = true;
                        ddlHealthFacility.Visible = true;
                        string where = string.Empty;
                        if (!(CurrentEnvironment.LoggedUser.HealthFacilityId == 1))
                        {
                            string s = HealthFacility.GetAllChildsForOneHealthFacility(CurrentEnvironment.LoggedUser.HealthFacilityId); //true
                            where = string.Format(@"AND ""ID"" = {1} OR ""ID"" in ( {0})", s, CurrentEnvironment.LoggedUser.HealthFacilityId);
                        }
                        odsHealthF.SelectParameters.Clear();
                        odsHealthF.SelectParameters.Add("ids", where);
                        odsHealthF.DataBind();
                        ddlHealthFacility.SelectedValue = o.HealthFacilityId.ToString();
                        //txtHealthcenterId.SelectedItemText = o.HealthFacility.Name.ToString();
                    }
                    txtNotes.Text             = o.Notes;
                    rblIsActive.SelectedValue = o.IsActive.ToString();
                    gridview_Databind(id);
                    placeId        = o.ParentId.ToString();
                    btnAdd.Visible = false;
                }
                else
                {
                    //string s = HealthFacility.GetAllChildsForOneHealthFacility(CurrentEnvironment.LoggedUser.HealthFacilityId);
                    //odsHealthF.SelectParameters.Clear();
                    //odsHealthF.SelectParameters.Add("ids", s);
                    //odsHealthF.DataBind();
                    btnEdit.Visible     = false;
                    btnRemove.Visible   = false;
                    lblIsActive.Visible = false;
                    rblIsActive.Visible = false;
                }
                int i = 0;
                if (HttpContext.Current.Session["_lastPlace"] != null)
                {
                    i = (int)HttpContext.Current.Session["_lastPlace"];
                    gridview_Databind(i);
                    HttpContext.Current.Session["_lastPlace"] = null;
                }
            }
            else
            {
                Response.Redirect("Default.aspx");
            }
        }
    }