from django.db import models
from simple_history.models import HistoricalRecords
from django.contrib.postgres.fields import JSONField
#from django.contrib.auth import get_user_model
from django.contrib.auth.models import User
from treebeard.mp_tree import MP_Node

class Location(MP_Node):
    # Locations are set up as a tree structure, allowing a regions and sub-regions along with the
    # ability to constrain access control by region; we use django-treabeard's materialized path
    # implementation for efficiency of tree operations
    name = models.TextField()
    location_type = models.TextField()
    node_order_by = ['name']

    # A user can have their access scoped by one or more locations
    #users = models.ManyToManyField(get_user_model(), related_name='locations')

    # Automatically set timestamps
    created = models.DateTimeField(auto_now_add=True)
    updated = models.DateTimeField(auto_now=True)

    def __str__(self):
        return self.name

    def descendant_ids(self):
        return [descendant.id for descendant in self.get_descendants()]

    def parent_id(self):
        return self.get_parent().id

class VerbalAutopsy(models.Model):
    # Each VerbalAutopsy is associated with a facility, which is the leaf node location
    location = models.ForeignKey(Location, related_name='verbalautopsies', on_delete=models.CASCADE)

    # The VA fields collected as part of the WHO VA form or local versions
    # TODO: Need an approach that supports different variants in different countries
    deviceid = models.TextField(blank=True)
    phonenumber = models.TextField(blank=True)
    simserial = models.TextField(blank=True)
    username = models.TextField(blank=True)
    bid = models.TextField(blank=True)
    bid2 = models.TextField(blank=True)
    bid_check = models.TextField(blank=True)
    bid_image = models.TextField(blank=True)
    province = models.TextField(blank=True)
    area = models.TextField(blank=True)
    hospital = models.TextField(blank=True)
    Id10002 = models.TextField(blank=True)
    Id10003 = models.TextField(blank=True)
    Id10004 = models.TextField(blank=True)
    Id10007 = models.TextField(blank=True)
    Id10008 = models.TextField(blank=True)
    Id10009 = models.TextField(blank=True)
    Id10010 = models.TextField(blank=True)
    Id10012 = models.TextField(blank=True)
    Id10013 = models.TextField(blank=True)
    Id10011 = models.TextField(blank=True)
    Id10017 = models.TextField(blank=True)
    Id10018 = models.TextField(blank=True)
    Id10019 = models.TextField(blank=True)
    Id10020 = models.TextField(blank=True)
    Id10021 = models.TextField(blank=True)
    Id10022 = models.TextField(blank=True)
    Id10023_a = models.TextField(blank=True)
    Id10023_b = models.TextField(blank=True)
    Id10023 = models.TextField(blank=True)
    Id10024 = models.TextField(blank=True)
    ageInDays = models.TextField(blank=True)
    ageInDays2 = models.TextField(blank=True)
    ageInYears = models.TextField(blank=True)
    ageInYearsRemain = models.TextField(blank=True)
    ageInMonths = models.TextField(blank=True)
    ageInMonthsRemain = models.TextField(blank=True)
    isNeonatal1 = models.TextField(blank=True)
    isChild1 = models.TextField(blank=True)
    isAdult1 = models.TextField(blank=True)
    displayAgeNeonate = models.TextField(blank=True)
    displayAgeChild = models.TextField(blank=True)
    displayAgeAdult = models.TextField(blank=True)
    age_group = models.TextField(blank=True)
    age_neonate_days = models.TextField(blank=True)
    age_child_unit = models.TextField(blank=True)
    age_child_days = models.TextField(blank=True)
    age_child_months = models.TextField(blank=True)
    age_child_years = models.TextField(blank=True)
    age_adult = models.TextField(blank=True)
    ageInMonthsByYear = models.TextField(blank=True)
    ageInYears2 = models.TextField(blank=True)
    isNeonatal2 = models.TextField(blank=True)
    isChild2 = models.TextField(blank=True)
    isAdult2 = models.TextField(blank=True)
    isNeonatal = models.TextField(blank=True)
    isChild = models.TextField(blank=True)
    isAdult = models.TextField(blank=True)
    ageInDaysNeonate = models.TextField(blank=True)
    Id10008_check = models.TextField(blank=True)
    Id10058 = models.TextField(blank=True)
    Id10051 = models.TextField(blank=True)
    Id10052 = models.TextField(blank=True)
    Id10053 = models.TextField(blank=True)
    Id10054 = models.TextField(blank=True)
    Id10055 = models.TextField(blank=True)
    Id10057 = models.TextField(blank=True)
    Id10059 = models.TextField(blank=True)
    Id10060_check = models.TextField(blank=True)
    Id10060 = models.TextField(blank=True)
    Id10061 = models.TextField(blank=True)
    Id10062 = models.TextField(blank=True)
    Id10063 = models.TextField(blank=True)
    Id10064 = models.TextField(blank=True)
    Id10065 = models.TextField(blank=True)
    Id10066 = models.TextField(blank=True)
    Id10069 = models.TextField(blank=True)
    Id10069_a = models.TextField(blank=True)
    Id10070 = models.TextField(blank=True)
    Id10071_check = models.TextField(blank=True)
    Id10071 = models.TextField(blank=True)
    Id10072 = models.TextField(blank=True)
    Id10073 = models.TextField(blank=True)
    Id10476 = models.TextField(blank=True)
    narrat_image = models.TextField(blank=True)
    Id10477 = models.TextField(blank=True)
    Id10478 = models.TextField(blank=True)
    Id10479 = models.TextField(blank=True)
    id10477_check = models.TextField(blank=True)
    id10478_check = models.TextField(blank=True)
    id10479_check = models.TextField(blank=True)
    Id10104 = models.TextField(blank=True)
    Id10105 = models.TextField(blank=True)
    Id10106 = models.TextField(blank=True)
    Id10107 = models.TextField(blank=True)
    Id10108 = models.TextField(blank=True)
    Id10109 = models.TextField(blank=True)
    Id10110 = models.TextField(blank=True)
    Id10111 = models.TextField(blank=True)
    Id10112 = models.TextField(blank=True)
    Id10113 = models.TextField(blank=True)
    Id10114 = models.TextField(blank=True)
    Id10115 = models.TextField(blank=True)
    Id10116 = models.TextField(blank=True)
    Id10077 = models.TextField(blank=True)
    Id10079 = models.TextField(blank=True)
    Id10080 = models.TextField(blank=True)
    Id10081 = models.TextField(blank=True)
    Id10082 = models.TextField(blank=True)
    Id10083 = models.TextField(blank=True)
    Id10084 = models.TextField(blank=True)
    Id10085 = models.TextField(blank=True)
    Id10086 = models.TextField(blank=True)
    Id10087 = models.TextField(blank=True)
    Id10088 = models.TextField(blank=True)
    Id10089 = models.TextField(blank=True)
    Id10090 = models.TextField(blank=True)
    Id10091 = models.TextField(blank=True)
    Id10092 = models.TextField(blank=True)
    Id10093 = models.TextField(blank=True)
    Id10094 = models.TextField(blank=True)
    Id10095 = models.TextField(blank=True)
    Id10096 = models.TextField(blank=True)
    Id10097 = models.TextField(blank=True)
    Id10098 = models.TextField(blank=True)
    Id10099 = models.TextField(blank=True)
    Id10100 = models.TextField(blank=True)
    Id10351 = models.TextField(blank=True)
    Id10408 = models.TextField(blank=True)
    Id10120_0 = models.TextField(blank=True)
    id10120_unit = models.TextField(blank=True)
    Id10121 = models.TextField(blank=True)
    Id10122 = models.TextField(blank=True)
    Id10120_1 = models.TextField(blank=True)
    Id10120 = models.TextField(blank=True)
    Id10123 = models.TextField(blank=True)
    Id10125 = models.TextField(blank=True)
    Id10126 = models.TextField(blank=True)
    Id10127 = models.TextField(blank=True)
    Id10128 = models.TextField(blank=True)
    Id10129 = models.TextField(blank=True)
    Id10130 = models.TextField(blank=True)
    Id10131 = models.TextField(blank=True)
    Id10132 = models.TextField(blank=True)
    Id10133 = models.TextField(blank=True)
    Id10134 = models.TextField(blank=True)
    Id10135 = models.TextField(blank=True)
    Id10136 = models.TextField(blank=True)
    Id10137 = models.TextField(blank=True)
    Id10138 = models.TextField(blank=True)
    Id10139 = models.TextField(blank=True)
    Id10140 = models.TextField(blank=True)
    Id10141 = models.TextField(blank=True)
    Id10142 = models.TextField(blank=True)
    Id10143 = models.TextField(blank=True)
    Id10144 = models.TextField(blank=True)
    Id10147 = models.TextField(blank=True)
    Id10148_a = models.TextField(blank=True)
    Id10148_units = models.TextField(blank=True)
    Id10148_b = models.TextField(blank=True)
    Id10148_c = models.TextField(blank=True)
    Id10148 = models.TextField(blank=True)
    Id10149 = models.TextField(blank=True)
    Id10150 = models.TextField(blank=True)
    Id10151 = models.TextField(blank=True)
    Id10152 = models.TextField(blank=True)
    Id10153 = models.TextField(blank=True)
    Id10154_units = models.TextField(blank=True)
    Id10154_a = models.TextField(blank=True)
    Id10154_b = models.TextField(blank=True)
    Id10154 = models.TextField(blank=True)
    Id10155 = models.TextField(blank=True)
    Id10156 = models.TextField(blank=True)
    Id10157 = models.TextField(blank=True)
    Id10158 = models.TextField(blank=True)
    Id10159 = models.TextField(blank=True)
    Id10161_0 = models.TextField(blank=True)
    id10161_unit = models.TextField(blank=True)
    Id10161_1 = models.TextField(blank=True)
    Id10162 = models.TextField(blank=True)
    Id10163 = models.TextField(blank=True)
    Id10161 = models.TextField(blank=True)
    Id10165 = models.TextField(blank=True)
    Id10166 = models.TextField(blank=True)
    Id10167_a = models.TextField(blank=True)
    Id10167_units = models.TextField(blank=True)
    Id10167_b = models.TextField(blank=True)
    Id10167_c = models.TextField(blank=True)
    Id10167 = models.TextField(blank=True)
    Id10168 = models.TextField(blank=True)
    Id10169_a = models.TextField(blank=True)
    Id10169_units = models.TextField(blank=True)
    Id10169_b = models.TextField(blank=True)
    Id10169_c = models.TextField(blank=True)
    Id10169 = models.TextField(blank=True)
    Id10170 = models.TextField(blank=True)
    Id10171 = models.TextField(blank=True)
    Id10172 = models.TextField(blank=True)
    Id10173_nc = models.TextField(blank=True)
    id10173_check = models.TextField(blank=True)
    Id10173_a = models.TextField(blank=True)
    Id10173 = models.TextField(blank=True)
    Id10174 = models.TextField(blank=True)
    Id10175 = models.TextField(blank=True)
    Id10176 = models.TextField(blank=True)
    Id10178_unit = models.TextField(blank=True)
    Id10178 = models.TextField(blank=True)
    Id10179 = models.TextField(blank=True)
    Id10179_1 = models.TextField(blank=True)
    Id10181 = models.TextField(blank=True)
    Id10182_units = models.TextField(blank=True)
    Id10182_a = models.TextField(blank=True)
    Id10182_b = models.TextField(blank=True)
    Id10182 = models.TextField(blank=True)
    Id10183 = models.TextField(blank=True)
    Id10184_a = models.TextField(blank=True)
    Id10184_units = models.TextField(blank=True)
    Id10184_b = models.TextField(blank=True)
    Id10184_c = models.TextField(blank=True)
    Id10185 = models.TextField(blank=True)
    Id10186 = models.TextField(blank=True)
    Id10187 = models.TextField(blank=True)
    Id10188 = models.TextField(blank=True)
    Id10189 = models.TextField(blank=True)
    Id10190_units = models.TextField(blank=True)
    Id10190_a = models.TextField(blank=True)
    Id10190_b = models.TextField(blank=True)
    Id10191 = models.TextField(blank=True)
    Id10192 = models.TextField(blank=True)
    Id10193 = models.TextField(blank=True)
    Id10194 = models.TextField(blank=True)
    Id10195 = models.TextField(blank=True)
    id10196_unit = models.TextField(blank=True)
    Id10196 = models.TextField(blank=True)
    Id10197_a = models.TextField(blank=True)
    Id10198 = models.TextField(blank=True)
    Id10197 = models.TextField(blank=True)
    Id10199 = models.TextField(blank=True)
    Id10200 = models.TextField(blank=True)
    Id10201_unit = models.TextField(blank=True)
    Id10201_a = models.TextField(blank=True)
    Id10202 = models.TextField(blank=True)
    Id10201 = models.TextField(blank=True)
    Id10203 = models.TextField(blank=True)
    Id10204 = models.TextField(blank=True)
    Id10205_unit = models.TextField(blank=True)
    Id10205_a = models.TextField(blank=True)
    Id10206 = models.TextField(blank=True)
    Id10205 = models.TextField(blank=True)
    Id10207 = models.TextField(blank=True)
    Id10208 = models.TextField(blank=True)
    Id10209_units = models.TextField(blank=True)
    Id10209_a = models.TextField(blank=True)
    Id10209_b = models.TextField(blank=True)
    Id10209 = models.TextField(blank=True)
    Id10210 = models.TextField(blank=True)
    Id10211_units = models.TextField(blank=True)
    Id10211_a = models.TextField(blank=True)
    Id10211_b = models.TextField(blank=True)
    Id10211 = models.TextField(blank=True)
    Id10212 = models.TextField(blank=True)
    Id10213_units = models.TextField(blank=True)
    Id10213_a = models.TextField(blank=True)
    Id10213_b = models.TextField(blank=True)
    Id10213 = models.TextField(blank=True)
    Id10214 = models.TextField(blank=True)
    Id10215 = models.TextField(blank=True)
    Id10216_units = models.TextField(blank=True)
    Id10216_a = models.TextField(blank=True)
    Id10216_b = models.TextField(blank=True)
    Id10216 = models.TextField(blank=True)
    Id10217 = models.TextField(blank=True)
    Id10218 = models.TextField(blank=True)
    Id10219 = models.TextField(blank=True)
    Id10220 = models.TextField(blank=True)
    Id10221 = models.TextField(blank=True)
    Id10222 = models.TextField(blank=True)
    Id10223 = models.TextField(blank=True)
    Id10225 = models.TextField(blank=True)
    Id10226 = models.TextField(blank=True)
    Id10224 = models.TextField(blank=True)
    Id10227 = models.TextField(blank=True)
    Id10228 = models.TextField(blank=True)
    Id10229 = models.TextField(blank=True)
    Id10230 = models.TextField(blank=True)
    Id10231 = models.TextField(blank=True)
    Id10232_units = models.TextField(blank=True)
    Id10232_a = models.TextField(blank=True)
    Id10232_b = models.TextField(blank=True)
    Id10232 = models.TextField(blank=True)
    Id10233 = models.TextField(blank=True)
    Id10234 = models.TextField(blank=True)
    Id10235 = models.TextField(blank=True)
    id10235_check = models.TextField(blank=True)
    Id10236 = models.TextField(blank=True)
    Id10237 = models.TextField(blank=True)
    Id10238 = models.TextField(blank=True)
    Id10239 = models.TextField(blank=True)
    Id10240 = models.TextField(blank=True)
    Id10241 = models.TextField(blank=True)
    Id10242 = models.TextField(blank=True)
    Id10243 = models.TextField(blank=True)
    Id10244 = models.TextField(blank=True)
    Id10245 = models.TextField(blank=True)
    Id10246 = models.TextField(blank=True)
    Id10247 = models.TextField(blank=True)
    Id10248_units = models.TextField(blank=True)
    Id10248_a = models.TextField(blank=True)
    Id10248_b = models.TextField(blank=True)
    Id10248 = models.TextField(blank=True)
    Id10249 = models.TextField(blank=True)
    Id10250_units = models.TextField(blank=True)
    Id10250_a = models.TextField(blank=True)
    Id10250_b = models.TextField(blank=True)
    Id10250 = models.TextField(blank=True)
    Id10251 = models.TextField(blank=True)
    Id10252 = models.TextField(blank=True)
    Id10253 = models.TextField(blank=True)
    Id10254 = models.TextField(blank=True)
    Id10255 = models.TextField(blank=True)
    Id10256 = models.TextField(blank=True)
    Id10257 = models.TextField(blank=True)
    Id10258 = models.TextField(blank=True)
    Id10259 = models.TextField(blank=True)
    Id10260 = models.TextField(blank=True)
    id10260_check = models.TextField(blank=True)
    id10260_check2 = models.TextField(blank=True)
    Id10261 = models.TextField(blank=True)
    Id10262_units = models.TextField(blank=True)
    Id10262_a = models.TextField(blank=True)
    Id10262_b = models.TextField(blank=True)
    Id10262 = models.TextField(blank=True)
    Id10263 = models.TextField(blank=True)
    Id10264 = models.TextField(blank=True)
    Id10265 = models.TextField(blank=True)
    Id10266_units = models.TextField(blank=True)
    Id10266_a = models.TextField(blank=True)
    Id10266_b = models.TextField(blank=True)
    Id10266 = models.TextField(blank=True)
    Id10267 = models.TextField(blank=True)
    Id10268 = models.TextField(blank=True)
    Id10269 = models.TextField(blank=True)
    Id10270 = models.TextField(blank=True)
    Id10271 = models.TextField(blank=True)
    Id10272 = models.TextField(blank=True)
    Id10273 = models.TextField(blank=True)
    Id10274_a = models.TextField(blank=True)
    Id10274_units = models.TextField(blank=True)
    Id10274_b = models.TextField(blank=True)
    Id10274_c = models.TextField(blank=True)
    Id10274 = models.TextField(blank=True)
    Id10275 = models.TextField(blank=True)
    Id10276 = models.TextField(blank=True)
    Id10277 = models.TextField(blank=True)
    Id10278 = models.TextField(blank=True)
    Id10279 = models.TextField(blank=True)
    Id10281 = models.TextField(blank=True)
    Id10282 = models.TextField(blank=True)
    Id10283 = models.TextField(blank=True)
    Id10284 = models.TextField(blank=True)
    Id10285 = models.TextField(blank=True)
    Id10286 = models.TextField(blank=True)
    Id10287 = models.TextField(blank=True)
    Id10288 = models.TextField(blank=True)
    Id10289 = models.TextField(blank=True)
    Id10290 = models.TextField(blank=True)
    Id10294 = models.TextField(blank=True)
    Id10295 = models.TextField(blank=True)
    Id10296 = models.TextField(blank=True)
    Id10297 = models.TextField(blank=True)
    Id10298 = models.TextField(blank=True)
    Id10301 = models.TextField(blank=True)
    Id10299 = models.TextField(blank=True)
    Id10302 = models.TextField(blank=True)
    Id10303 = models.TextField(blank=True)
    Id10300 = models.TextField(blank=True)
    Id10304 = models.TextField(blank=True)
    Id10305 = models.TextField(blank=True)
    Id10306 = models.TextField(blank=True)
    Id10307 = models.TextField(blank=True)
    Id10308 = models.TextField(blank=True)
    Id10309 = models.TextField(blank=True)
    Id10310 = models.TextField(blank=True)
    Id10310_check = models.TextField(blank=True)
    Id10312 = models.TextField(blank=True)
    Id10313 = models.TextField(blank=True)
    Id10314 = models.TextField(blank=True)
    Id10315_a = models.TextField(blank=True)
    Id10315 = models.TextField(blank=True)
    Id10316 = models.TextField(blank=True)
    Id10317 = models.TextField(blank=True)
    Id10318 = models.TextField(blank=True)
    Id10319 = models.TextField(blank=True)
    Id10320 = models.TextField(blank=True)
    Id10321 = models.TextField(blank=True)
    Id10322 = models.TextField(blank=True)
    Id10323 = models.TextField(blank=True)
    Id10324 = models.TextField(blank=True)
    Id10325 = models.TextField(blank=True)
    Id10326 = models.TextField(blank=True)
    Id10327 = models.TextField(blank=True)
    Id10328 = models.TextField(blank=True)
    Id10329 = models.TextField(blank=True)
    Id10330 = models.TextField(blank=True)
    Id10331 = models.TextField(blank=True)
    Id10332 = models.TextField(blank=True)
    Id10333 = models.TextField(blank=True)
    Id10334 = models.TextField(blank=True)
    Id10335 = models.TextField(blank=True)
    Id10336 = models.TextField(blank=True)
    Id10337 = models.TextField(blank=True)
    Id10338 = models.TextField(blank=True)
    Id10339 = models.TextField(blank=True)
    Id10342 = models.TextField(blank=True)
    Id10343 = models.TextField(blank=True)
    Id10344 = models.TextField(blank=True)
    Id10347 = models.TextField(blank=True)
    Id10340 = models.TextField(blank=True)
    Id10352_units = models.TextField(blank=True)
    Id10352_a = models.TextField(blank=True)
    Id10352_b = models.TextField(blank=True)
    Id10352 = models.TextField(blank=True)
    Id10354 = models.TextField(blank=True)
    Id10355 = models.TextField(blank=True)
    Id10356 = models.TextField(blank=True)
    Id10357 = models.TextField(blank=True)
    Id10358_units = models.TextField(blank=True)
    Id10358 = models.TextField(blank=True)
    Id10359 = models.TextField(blank=True)
    Id10359_a = models.TextField(blank=True)
    Id10360 = models.TextField(blank=True)
    Id10361 = models.TextField(blank=True)
    Id10362 = models.TextField(blank=True)
    Id10363 = models.TextField(blank=True)
    Id10364 = models.TextField(blank=True)
    Id10365 = models.TextField(blank=True)
    id1036X_check = models.TextField(blank=True)
    Id10366_unit = models.TextField(blank=True)
    Id10366_a = models.TextField(blank=True)
    Id10366_b = models.TextField(blank=True)
    Id10366 = models.TextField(blank=True)
    Id10367 = models.TextField(blank=True)
    Id10368 = models.TextField(blank=True)
    Id10369 = models.TextField(blank=True)
    Id10370 = models.TextField(blank=True)
    Id10371 = models.TextField(blank=True)
    Id10372 = models.TextField(blank=True)
    Id10373 = models.TextField(blank=True)
    Id10394 = models.TextField(blank=True)
    Id10376 = models.TextField(blank=True)
    Id10377 = models.TextField(blank=True)
    Id10379_unit = models.TextField(blank=True)
    Id10379 = models.TextField(blank=True)
    Id10380 = models.TextField(blank=True)
    Id10382 = models.TextField(blank=True)
    Id10383 = models.TextField(blank=True)
    Id10384 = models.TextField(blank=True)
    Id10385 = models.TextField(blank=True)
    Id10387 = models.TextField(blank=True)
    Id10388 = models.TextField(blank=True)
    Id10389 = models.TextField(blank=True)
    id10389_check = models.TextField(blank=True)
    Id10391 = models.TextField(blank=True)
    Id10392 = models.TextField(blank=True)
    Id10393 = models.TextField(blank=True)
    Id10395 = models.TextField(blank=True)
    Id10396 = models.TextField(blank=True)
    Id10397 = models.TextField(blank=True)
    Id10398 = models.TextField(blank=True)
    Id10399 = models.TextField(blank=True)
    Id10400 = models.TextField(blank=True)
    Id10401 = models.TextField(blank=True)
    Id10402 = models.TextField(blank=True)
    Id10403 = models.TextField(blank=True)
    Id10404 = models.TextField(blank=True)
    Id10405 = models.TextField(blank=True)
    Id10406 = models.TextField(blank=True)
    Id10411 = models.TextField(blank=True)
    Id10412 = models.TextField(blank=True)
    Id10413 = models.TextField(blank=True)
    Id10414 = models.TextField(blank=True)
    id10414_check = models.TextField(blank=True)
    Id10415 = models.TextField(blank=True)
    Id10416 = models.TextField(blank=True)
    Id10418 = models.TextField(blank=True)
    Id10419 = models.TextField(blank=True)
    Id10420 = models.TextField(blank=True)
    Id10421 = models.TextField(blank=True)
    Id10422 = models.TextField(blank=True)
    Id10423 = models.TextField(blank=True)
    Id10424 = models.TextField(blank=True)
    Id10425 = models.TextField(blank=True)
    Id10426 = models.TextField(blank=True)
    Id10427 = models.TextField(blank=True)
    Id10428 = models.TextField(blank=True)
    Id10429 = models.TextField(blank=True)
    Id10430 = models.TextField(blank=True)
    Id10431 = models.TextField(blank=True)
    id10431_check = models.TextField(blank=True)
    Id10432 = models.TextField(blank=True)
    Id10433 = models.TextField(blank=True)
    id10433_check = models.TextField(blank=True)
    Id10434 = models.TextField(blank=True)
    Id10435 = models.TextField(blank=True)
    Id10436 = models.TextField(blank=True)
    Id10437 = models.TextField(blank=True)
    Id10438 = models.TextField(blank=True)
    Id10439_check = models.TextField(blank=True)
    Id10439 = models.TextField(blank=True)
    Id10440_check = models.TextField(blank=True)
    Id10440 = models.TextField(blank=True)
    Id10441_check = models.TextField(blank=True)
    Id10441 = models.TextField(blank=True)
    Id10442 = models.TextField(blank=True)
    Id10443 = models.TextField(blank=True)
    Id10444 = models.TextField(blank=True)
    Id10445 = models.TextField(blank=True)
    Id10446 = models.TextField(blank=True)
    Id10450 = models.TextField(blank=True)
    Id10451 = models.TextField(blank=True)
    Id10452 = models.TextField(blank=True)
    Id10453 = models.TextField(blank=True)
    Id10454 = models.TextField(blank=True)
    Id10455 = models.TextField(blank=True)
    Id10456 = models.TextField(blank=True)
    Id10457 = models.TextField(blank=True)
    Id10458 = models.TextField(blank=True)
    Id10459 = models.TextField(blank=True)
    Id10462 = models.TextField(blank=True)
    Id10463 = models.TextField(blank=True)
    Id10464 = models.TextField(blank=True)
    Id10465 = models.TextField(blank=True)
    Id10466 = models.TextField(blank=True)
    Id10467 = models.TextField(blank=True)
    Id10468 = models.TextField(blank=True)
    Id10469 = models.TextField(blank=True)
    Id10470 = models.TextField(blank=True)
    Id10471 = models.TextField(blank=True)
    Id10472 = models.TextField(blank=True)
    Id10473 = models.TextField(blank=True)
    Id10481 = models.TextField(blank=True)
    geopoint = models.TextField(blank=True)
    comment = models.TextField(blank=True)
    # Track the history of changes to each verbal autopsy
    history = HistoricalRecords()
    # Automatically set timestamps
    created = models.DateTimeField(auto_now_add=True)
    updated = models.DateTimeField(auto_now=True)

class CauseOfDeath(models.Model):
    # One VerbalAutopsy can have multiple causes of death (through different algorithms)
    verbalautopsy = models.ForeignKey(VerbalAutopsy, related_name='causes', on_delete=models.CASCADE)
    # Track the cause and the algorithm that provided the cause
    cause = models.TextField()
    # TODO: do we want the algorithm as a string or by referring to an algorithm table?
    algorithm = models.TextField()
    # Store the settings used for this particular coding run
    # NOTE: by using JSONField we tie ourselves to postgres
    settings = JSONField()
    # Track the history of changes to each verbal autopsy cause of death coding
    # TODO: confirm that we need a history of this
    history = HistoricalRecords()
    # Automatically set timestamps
    created = models.DateTimeField(auto_now_add=True)
    updated = models.DateTimeField(auto_now=True)

    def __str__(self):
        return self.cause

class CauseCodingIssue(models.Model):
    # One VerbalAutopsy can have multiple coding issues
    verbalautopsy = models.ForeignKey(VerbalAutopsy, related_name='coding_issues', on_delete=models.CASCADE)
    text = models.TextField()
    SEVERITY_OPTIONS = ['error', 'warning']
    severity = models.CharField(max_length=7, choices=[(option, option) for option in SEVERITY_OPTIONS])
    # We track which algorithm and the settings for that algorithm
    # NOTE: this is a denormalized approach for convenience, which should still scale reasonably
    algorithm = models.TextField()
    # NOTE: by using JSONField we tie ourselves to postgres
    settings = JSONField()
    # Automatically set timestamps
    created = models.DateTimeField(auto_now_add=True)
    updated = models.DateTimeField(auto_now=True)

    def __str__(self):
        return self.text
