Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Investigate why blood screening tasks are in Ready status yet there are corresponding events for the same #1478

Closed
Rkareko opened this issue Jul 14, 2021 · 1 comment

Comments

@Rkareko
Copy link
Contributor

Rkareko commented Jul 14, 2021

Related to onaio/reveal-frontend#1624

@LZRS
Copy link
Contributor

LZRS commented Jul 23, 2021

Tasks affected were updated using query

WITH tasksToUpdate AS (SELECT DISTINCT task_metadata.identifier, 
	  				 				  nextVal('core.task_server_version_seq') as new_server_version
	  				  FROM core.task_metadata
	  				  INNER JOIN core.event ON event.json->'details'->>'taskIdentifier' = task_metadata.identifier
	  				  INNER JOIN core.task ON (task_metadata.task_id = task.id 
											   AND task.json->>'status' = 'Ready'
											   AND task.json->>'businessStatus' = 'Not Visited')
					  WHERE task_metadata.code = 'Blood Screening'),
	updatedTasks AS (UPDATE core.task SET server_version = tasksToUpdate.new_server_version, 
						json = (json 
							 || '{ "status": "Completed", "businessStatus": "Complete" }'::jsonb
							 || json_build_object('serverVersion', tasksToUpdate.new_server_version)::jsonb)
					 FROM tasksToUpdate
					 WHERE tasksToUpdate.identifier = task.json->>'identifier'
					 RETURNING task.* )
UPDATE core.task_metadata
SET server_version = updatedTasks.server_version
FROM updatedTasks
WHERE updatedTasks.id = task_metadata.task_id
RETURNING *;

@samkanga samkanga closed this as completed Oct 5, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants