# Questions about form versioning introduced in cht-core 3.15 / cht-conf 3.10

**URL:** <https://forum.communityhealthtoolkit.org/t/questions-about-form-versioning-introduced-in-cht-core-3-15-cht-conf-3-10/2032>\
**Category:** Development\
**Tags:** forms, data, data-science\
**Created:** [July 22, 2022, 5:28pm UTC](https://forum.communityhealthtoolkit.org/t/questions-about-form-versioning-introduced-in-cht-core-3-15-cht-conf-3-10/2032 "2022-07-22T17:28:38Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![michael](https://communityhealthtoolkit.b-cdn.net/user_avatar/forum.communityhealthtoolkit.org/michael/32/319_2.png) [@michael](https://forum.communityhealthtoolkit.org/u/michael)\
**Post date:** [July 22, 2022, 5:28pm UTC](https://forum.communityhealthtoolkit.org/t/questions-about-form-versioning-introduced-in-cht-core-3-15-cht-conf-3-10/2032/1 "2022-07-22T17:28:38Z")

</div>

[cht-conf/395](https://github.com/medic/cht-conf/issues/395) added `xmlVersion` to forms. [cht-core/7561](https://github.com/medic/cht-core/issues/7561) writes that `xmlVersion` as the `form_version` on `data_records`.

A couple questions

1. There’s a [comment in 7561](https://github.com/medic/cht-core/issues/7561#issuecomment-1089550181) that says “_It should be completely backwards compatible so it works even if the form was generated with an older version of cht-conf._” **QUESTION** : if the form was generated with the older version of `cht-conf`, what can we expect on the `data_record`… will the CHT include the `form_version`, `time`, and `sha256` keys with no values or do we not even include the `form_version` key?
2. The name implies it, but just want to confirm this is only for reports… we do not store version of contact forms?
3. [This comment](https://github.com/medic/cht-conf/issues/395#issuecomment-922537633) mentions that forms uploaded via the GUI will “store the date the form was uploaded as the version”. I understand that means we’ll have the unix date/time in the `{xmlVersion,time}` field. Will the `sha256` key exist and be blank or will it not exist at all?
4. After upgrading the instance to cht-core 3.15 and cht-conf to 3.10, you would have to re-upload all your forms to the instance and then all users would have to download the updated forms to start seeing the `form_version` on your `data_records`, correct?

---

<div class="post-metadata">

**Author:** ![gareth](https://communityhealthtoolkit.b-cdn.net/user_avatar/forum.communityhealthtoolkit.org/gareth/32/62_2.png) [@gareth](https://forum.communityhealthtoolkit.org/u/gareth)\
**Post date:** [July 24, 2022, 7:26pm UTC](https://forum.communityhealthtoolkit.org/t/questions-about-form-versioning-introduced-in-cht-core-3-15-cht-conf-3-10/2032/2 "2022-07-24T19:26:28Z")

</div>

> [@michael](#):
>
> If the form was generated with the older version of `cht-conf`, what can we expect on the `data_record`… will the CHT include the `form_version`, `time`, and `sha256` keys with no values or do we not even include the `form_version` key?

In this case there will be no `forum_version` property at all. I think the “backwards compatible” comment was to indicate that cht-core v3.15.0 will behave the same as cht-core v3.14.0 if the form is not updated.

> [@michael](#):
>
> The name implies it, but just want to confirm this is only for reports… we do not store version of contact forms?

Contact forms are a subset of reports so I expected it to just work, but I’ve tested this out and while the contact form itself has the `xml_version` property, the contact created does not have the `form_version` property. I think this is an oversight and have [raised an issue](https://github.com/medic/cht-core/issues/7689) to fix this in a future version.

> [@michael](#):
>
> [This comment](https://github.com/medic/cht-conf/issues/395#issuecomment-922537633) mentions that forms uploaded via the GUI will “store the date the form was uploaded as the version”.

I’ve just tested and uploading using the App Management GUI did not update the `xmlVersion` property as expected so I don’t think this made it in to the release. I’ve raised [an issue](https://github.com/medic/cht-core/issues/7690) to fix this.

> [@michael](#):
>
> After upgrading the instance to cht-core 3.15 and cht-conf to 3.10, you would have to re-upload all your forms to the instance and then all users would have to download the updated forms to start seeing the `form_version` on your `data_records`, correct?

That’s right. Users who are offline won’t get the changes immediately so will still be creating reports based on the old form and/or the previous version of cht-core, so those will not have the `form_version` property. The property will only be generated on reports filed after they sync to get the updated form and cht-core code.

---

<div class="post-metadata">

**Author:** ![michael](https://communityhealthtoolkit.b-cdn.net/user_avatar/forum.communityhealthtoolkit.org/michael/32/319_2.png) [@michael](https://forum.communityhealthtoolkit.org/u/michael)\
**Post date:** [July 25, 2022, 3:22pm UTC](https://forum.communityhealthtoolkit.org/t/questions-about-form-versioning-introduced-in-cht-core-3-15-cht-conf-3-10/2032/3 "2022-07-25T15:22:55Z")

</div>

Tagging @Victor_ZUGADI as he was specifically asking about the versioning functionality.

---

<div class="post-metadata">

**Author:** ![mrjones](https://communityhealthtoolkit.b-cdn.net/user_avatar/forum.communityhealthtoolkit.org/mrjones/32/681_2.png) [@mrjones](https://forum.communityhealthtoolkit.org/u/mrjones)\
**Post date:** [July 29, 2022, 9:45pm UTC](https://forum.communityhealthtoolkit.org/t/questions-about-form-versioning-introduced-in-cht-core-3-15-cht-conf-3-10/2032/4 "2022-07-29T21:45:17Z")

</div>

I think @bamatic was interested in this topic too!

---

<div class="post-metadata">

**Author:** ![bamatic](https://communityhealthtoolkit.b-cdn.net/user_avatar/forum.communityhealthtoolkit.org/bamatic/32/1318_2.png) [@bamatic](https://forum.communityhealthtoolkit.org/u/bamatic)\
**Post date:** [August 1, 2022, 10:20am UTC](https://forum.communityhealthtoolkit.org/t/questions-about-form-versioning-introduced-in-cht-core-3-15-cht-conf-3-10/2032/5 "2022-08-01T10:20:50Z")

</div>

Yes victor zugadi is also bamatic.

---

<div class="post-metadata">

**Author:** ![bamatic](https://communityhealthtoolkit.b-cdn.net/user_avatar/forum.communityhealthtoolkit.org/bamatic/32/1318_2.png) [@bamatic](https://forum.communityhealthtoolkit.org/u/bamatic)\
**Post date:** [September 6, 2022, 8:32am UTC](https://forum.communityhealthtoolkit.org/t/questions-about-form-versioning-introduced-in-cht-core-3-15-cht-conf-3-10/2032/6 "2022-09-06T08:32:20Z")

</div>

Hi there,  
Another question, the couchdb doc with \_id form:xxxx has an attachement xml with the form definition  
if we have several versions of the same form:xxxx, will we have several attachements xml one by each version ?  
if not, will be able to access somewhere the form definition xml file for a given form version ?

it will be great to have an API something like GET /api/v1/forms/{{id}}.{{format}}/[{version}} and get the xml of this version and something like GET api/v1/forms/{{id}}/versions and get an array of form versions

```auto
[
{"time":xxx, "sha256":"xxx"}, {"time":xxxx, "sha256":"xxxx"}
]

```

---

<div class="post-metadata">

**Author:** ![bamatic](https://communityhealthtoolkit.b-cdn.net/user_avatar/forum.communityhealthtoolkit.org/bamatic/32/1318_2.png) [@bamatic](https://forum.communityhealthtoolkit.org/u/bamatic)\
**Post date:** [September 6, 2022, 11:01am UTC](https://forum.communityhealthtoolkit.org/t/questions-about-form-versioning-introduced-in-cht-core-3-15-cht-conf-3-10/2032/7 "2022-09-06T11:01:39Z")

</div>

as I see in cht-conf source code lib/upload-forms.js

```auto
if (changes) {
      await insertOrReplace(db, doc);
      log.info(`Form ${filePath} uploaded`);
    } else {
      log.info(`Form ${filePath} not uploaded, no changes`);
    }

```

So the new version overrides the old version form, I think that maybe we could create another doc type “type”:“old-form”, and before to overrite the form containing the old version, save it with type=“old-form” and “doc-id”:“form:formId” so it will persist in the database this could be used by the cht api to serve old form versions  
If this makes sense we could contribute to this

Here a PR where I try to implement the saving of the current form before to replacing it.  
This would be very helpful for data analyst, to have the exact definition of the form used to send a data record marked with the same form\_version key.  
[https://github.com/medic/cht-conf/pull/506](https://github.com/medic/cht-conf/pull/506)
