Referencing Locations in Applications
CommTrack makes location data available through a fixture. For more details on how to work with fixtures, see: https://help.commcarehq.org/display/commcarepublic/Creating+and+Updating+Fixtures
Configuring Locations: In CommTrack, there is no need to create a fixture for locations. This is done automatically once the user has configured products through Setup -> Manage Locations.
Accessing Locations: When building a mobile application, fixture data can be accessed through the auto-created location fixture on the phone.
Referencing Location Hierarchies in Case List and Details Page
When making a module against supply-point cases, you can reference any location property available in the fixture, as well as any properties of any parents all the way up the chain. To reference a property, you must type a four part code into the case list or details configuration. You need to type this formula in the property box under Display Properties. The format is as follows:
location:[my type]:[reference type]/[property name]
Everything in brackets is something that you replace according to the following table. The colons and slash are mandatory.
location: Just the word "location". This never changes.
my type: The type of the location you expect to be in the case list. This is typically the lowest-level location type, e.g. "outlet". See the "type code" field under Locations (Advanced) in setup to see what to put for each type.
reference type: The type of the location you want to reference. This could be the same as "my type".
property name: The property you want to reference.
The following examples are for a simple hierarchy containing a state, district, block and outlet.
I am a... | referencing my... | Syntax to use |
---|---|---|
outlet | own type | location:outlet:outlet/location_type |
outlet | block name | location:outlet:block/name |
outlet | state name | location:outlet:state/name |
district | own type | location:district:district/location_type |
district | state name | location:district:state/name |
Example Location Fixture
This is the corresponding fixture that would be used. Advanced queries can be done if you understand this structure.
<?xml version="1.0" encoding="UTF-8"?>
<fixture id="commtrack:locations" user_id="217ce8d8e4cb726ca11c418dd00280d2">
<states>
<state id="217ce8d8e4cb726ca11c418dd06071ca">
<name>Mass</name>
<site_code />
<external_id />
<latitude />
<longitude />
<location_type>state</location_type>
<districts>
<district id="217ce8d8e4cb726ca11c418dd0606c8e">
<name>Suffolk</name>
<site_code />
<external_id />
<latitude />
<longitude />
<location_type>district</location_type>
<blocks>
<block id="217ce8d8e4cb726ca11c418dd0606643">
<name>Boston</name>
<site_code />
<external_id />
<latitude />
<longitude />
<location_type>block</location_type>
<outlets>
<outlet id="3b7bc6e458c49c6382c9220d7432a1ae">
<name>Boston medical</name>
<site_code>bmc</site_code>
<external_id />
<latitude />
<longitude />
<location_type>outlet</location_type>
</outlet>
</outlets>
</block>
</blocks>
</district>
</districts>
</state>
</states>
</fixture>