Hi everyone,
How can I add an event to an existing TEI using the DHIS2 tracker API. I’m currently implementing this using python and my DHIS2 version is 2.40.3.
Below is a sample of the code where I want to put the code:
query_url = f"http://localhost:8081/dhis/api/33/trackedEntityInstances/query.json?program={program}&query={person_case_id}&ou={organisation_unit}"
response = requests.get(query_url, auth=(username, password))
data = response.json()
# print(data)
if data['rows']:
# Record exists, perform import update
instance_id = data['rows'][0][0]
# Create a new event for the existing TEI here
else:
# Send the POST request to import the tracker data
response = requests.post(url, auth=HTTPBasicAuth(username, password), json=json_data)
# Check the response status
if response.status_code == 200:
print('New Tracker record number ' +str(successful_insert_counter)+ ' imported successfully and Status is ' + str(status))
# print('Returned message:', response.text)
successful_insert_counter += 1
else:
print('Failed to import tracker data. Status code:', response.status_code)
print('Error message:', response.text)
failed_insert_counter += 1
so first where query to check if any TEI of the person to be imported into the DHIS2 exist. If it does, then that’s where I want to create a new event of that existing TEI else create a new TEI all together. note that this is sample and incomplete code. I neeed the end points to just create the new event in an existing TEI otherwise everthing else I can do