Form submission altering the patient enrollment date

I think probably the most helpful next step would be to review your integration scripts and/or any other kind of RapidPro scripting that you have. I have spoken about this behavior with some other colleagues here at Medic and confirmed that there is no CHT functionality that should be updating the reported_date on an existing contact. So, this change has to be getting pushed into Couch from some external integration. From the functionality and timing of the update it does appear that the integration is triggered in the same flow as the RapidPro.

Unfortunately I am not familiar with the specifics of your integration scripts, so I cannot say if perhaps this is coming from a parallel workflow (perhaps one also triggered by a different outbound script) or if somehow RapidPro can be configured to push updated phone numbers back into the CHT…

If all else fails, the HA Proxy container is logging info on all the traffic flowing through it. The logs for that container should be able to capture some info about a PUT request to the medic/{{contact_uuid}}. But, at best, that will probably only get us the IP Address of the service doing the update… There is some more info about grabbing logs in these docs.

2 Likes

thanks @jkuester i noticed another flow that is doing the contact update though in the webhook it still PUTs to https://<domain>/api/v2/contacts.json?uuid=@contact.uuid

@jkuester there is an update contact flow in rapidpro doing with a PUT ie @(default(trigger.params.couchdb,globals.couchdb))/medic/@results.medic_id

@jkuester my suspicion is that this body PUT in the webhook is causing the change

json(
  object(
    "_id", if(webhook.json._id, webhook.json._id, ""),
    "_rev", if(webhook.json._rev, webhook.json._rev, ""),
    "parent", if(webhook.json.parent, webhook.json.parent, ""),
    "type", if(webhook.json.type, webhook.json.type, ""),
    "role", if(webhook.json.role, webhook.json.role, ""),
    "rapidpro", if(webhook.json.rapidpro, webhook.json.rapidpro, ""),
    "first_name", if(webhook.json.first_name, webhook.json.first_name, ""),
    "surname", if(webhook.json.surname, webhook.json.surname, ""),
    "name", if(webhook.json.name, webhook.json.name, ""),
    "national_id", if(webhook.json.national_id, webhook.json.national_id, ""),
    "consent", if(webhook.json.consent, webhook.json.consent, ""),
    "phone", if(webhook.json.phone, webhook.json.phone, ""),
    "alt_phone", if(webhook.json.alt_phone, webhook.json.alt_phone, ""),
    "language_preference", if(webhook.json.language_preference, webhook.json.language_preference, ""),
    "language_code", if(webhook.json.language_code, webhook.json.language_code, ""),
    "reported_date", if(webhook.json.reported_date, webhook.json.reported_date, ""),
    "geolocation", if(webhook.json.geolocation, webhook.json.geolocation, ""),
    "geolocation_log", if(webhook.json.geolocation_log, webhook.json.geolocation_log, ""),
    "patient_id", if(webhook.json.patient_id, webhook.json.patient_id, ""),
    "rapidpro_uuid", contact.uuid
  )
)

particularly on "reported_date", if(webhook.json.reported_date, webhook.json.reported_date, ""),

hello @jkuester any thoughts on this ?

I agree with your assessment above that it seems likely your RabidPro webhook call is what is resetting the reported_date on the contact. I don’t have the full context for the workflows involved here or what this code is trying to achieve, but I can say that generally speaking the reported_date on a contact should never be updated (even if other data on the contact changes).

Can you tell from the rest of the RapidPro webhook config if the reported_date value is just getting passed through, or is it getting manipulated/updated?

thanks @jkuester , so i guess then we could try to remove "reported_date", if(webhook.json.reported_date, webhook.json.reported_date, "") ?

I am afraid that just removing that code will end up causing the contact doc to be updated to have _no reported_date value at all. Unless RapidPro does not magical JSON data merging behind the scenes, when you PUT an updated version of a document in Couch, it will entirely replace all the data for that doc with the JSON data you sent in your PUT body. So, if you do not include the reported_date field in the PUT, it will not be included in the contact body.

1 Like

thanks @jkuester ,will sharing more feedback on this

1 Like