Skip to content

Commit

Permalink
fix(#165): removing potentially ambiguous date format
Browse files Browse the repository at this point in the history
  • Loading branch information
witash committed Sep 24, 2024
1 parent e4f0906 commit 26f4da7
Show file tree
Hide file tree
Showing 2 changed files with 1 addition and 2 deletions.
1 change: 0 additions & 1 deletion models/contacts/person.sql
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ SELECT
CASE
WHEN NULLIF(couchdb.doc->>'date_of_birth', '') IS NULL THEN NULL
WHEN couchdb.doc->>'date_of_birth' ~ '^\d{4}-\d{2}-\d{2}$' THEN (couchdb.doc->>'date_of_birth')::date
WHEN couchdb.doc->>'date_of_birth' ~ '^\d{2}/\d{2}/\d{4}$' THEN TO_DATE(couchdb.doc->>'date_of_birth', 'DD/MM/YYYY')
ELSE NULL
END as date_of_birth,
couchdb.doc->>'sex' as sex,
Expand Down
2 changes: 1 addition & 1 deletion tests/init.sql
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ INSERT INTO v1.couchdb VALUES ('2024-06-18 09:59:23.582', '011982c2-3e43-5ec5-be
INSERT INTO v1.couchdb VALUES ('2024-06-18 09:59:23.582', '00084637-631b-5578-9a89-99809eca3b79', '0', '{"_id": "00084637-631b-5578-9a89-99809eca3b79", "_rev": "1-d0d1afe9dcf2ce0f4c4bccb11335882b", "form": "pregnancy", "from": "+16143331816", "type": "data_record", "fields": {"edd": "Feb 29, 2020", "inputs": {"source": "contact", "contact": {"_id": "e3040ffc-0a1e-5b3c-9dcf-f9d23ee16c343", "sex": "female", "name": "Person 524", "date_of_birth": "2000-10-19"}}, "chw_sms": "Hi , a pregnancy for Person 2 (46462) has been registered at the facility. You will receive ANC notifications for this patient. Please follow up to identify the patient. Thank you!", "edd_8601": "2019-06-13T00:00:00.000Z", "lmp_date": "May 25, 2019", "group_lmp": {"g_edd": "Feb 29, 2020", "g_edd_8601": "2019-06-13T00:00:00.000Z", "g_lmp_date": "May 25, 2019", "g_lmp_approx": "91", "g_lmp_method": "approx", "g_lmp_date_raw": "Thu Sep 06 2018 00:00:00 GMT-0400 (Eastern Daylight Time)", "g_lmp_date_8601": "2019-05-25"}, "group_note": {"is_sms_edited": "yes", "default_chw_sms": "default", "default_chw_sms_note": "", "default_chw_sms_text": "Hi , a pregnancy for Person 2 (46462) has been registered at the facility. You will receive ANC notifications for this patient. Please follow up to identify the patient. Thank you!"}, "lmp_method": "approx", "patient_name": "Person 524", "patient_uuid": "e3040ffc-0a1e-5b3c-9dcf-f9d23ee16c343", "lmp_date_8601": "2019-05-25", "days_since_lmp": "91.75", "weeks_since_lmp": "13.11", "patient_age_at_lmp": "18", "patient_age_in_years": "18"}, "contact": {"_id": "101f7c2e-698a-57cd-802b-32d7eb6f5143", "sex": "female", "name": "Person 524", "type": "person", "phone": "16145553296", "parent": {"_id": "64cc225a-10fe-5d9a-aa31-0c29df922d0a", "name": "Clinic_5", "type": "clinic", "parent": {"_id": "8606a91a-f454-56e3-a089-0b686af3c6b7", "name": "HC1", "type": "health_center", "parent": {"_id": "fc9928ae-9f48-5d2d-8a0f-222b2389f77f", "name": "Pregnancies", "type": "district_hospital", "notes": "", "parent": "", "external_id": "", "geolocation": "", "reported_date": 1544031155715, "is_name_generated": "false"}, "reported_date": 1544031155715, "is_name_generated": "FALSE"}, "reported_date": 1544031155715, "is_name_generated": "FALSE"}, "patient_id": "80524", "date_of_birth": "2001-07-04", "reported_date": "1530976675000"}, "patient_id": "80524", "content_type": "xml", "reported_date": 1710928470357}');
INSERT INTO v1.couchdb VALUES ('2024-06-18 09:59:23.582', '00c1f336-5e1e-5671-b6f4-661fa0a75263', '0', '{"_id": "00c1f336-5e1e-5671-b6f4-661fa0a75263", "_rev": "1-39a5ebf17e4974652845d80f48f9a64b", "form": "pregnancy", "from": "+16143331942", "type": "data_record", "fields": {"edd": "Jul 4, 2020", "inputs": {"source": "contact", "contact": {"_id": "e3040ffc-0a1e-5b3c-9dcf-f9d23ee16c469", "sex": "female", "name": "Person 776", "date_of_birth": "2001-02-22"}}, "chw_sms": "Hi , a pregnancy for Person 2 (46462) has been registered at the facility. You will receive ANC notifications for this patient. Please follow up to identify the patient. Thank you!", "edd_8601": "2019-06-13T00:00:00.000Z", "lmp_date": "Sep 28, 2019", "group_lmp": {"g_edd": "Jul 4, 2020", "g_edd_8601": "2019-06-13T00:00:00.000Z", "g_lmp_date": "Sep 28, 2019", "g_lmp_approx": "91", "g_lmp_method": "approx", "g_lmp_date_raw": "Thu Sep 06 2018 00:00:00 GMT-0400 (Eastern Daylight Time)", "g_lmp_date_8601": "2019-09-28"}, "group_note": {"is_sms_edited": "yes", "default_chw_sms": "default", "default_chw_sms_note": "", "default_chw_sms_text": "Hi , a pregnancy for Person 2 (46462) has been registered at the facility. You will receive ANC notifications for this patient. Please follow up to identify the patient. Thank you!"}, "lmp_method": "approx", "patient_name": "Person 776", "patient_uuid": "e3040ffc-0a1e-5b3c-9dcf-f9d23ee16c469", "lmp_date_8601": "2019-09-28", "days_since_lmp": "91.75", "weeks_since_lmp": "13.11", "patient_age_at_lmp": "18", "patient_age_in_years": "18"}, "contact": {"_id": "3afe9708-de92-5a1d-a9cc-2b356d049b6f", "sex": "female", "name": "Person 776", "type": "person", "phone": "16145553548", "parent": {"_id": "7ba7f250-d52b-52ee-becd-3495cb5c50e2", "name": "Clinic_6", "type": "clinic", "parent": {"_id": "8606a91a-f454-56e3-a089-0b686af3c6b7", "name": "HC1", "type": "health_center", "parent": {"_id": "fc9928ae-9f48-5d2d-8a0f-222b2389f77f", "name": "Pregnancies", "type": "district_hospital", "notes": "", "parent": "", "external_id": "", "geolocation": "", "reported_date": 1544031155715, "is_name_generated": "false"}, "reported_date": 1544031155715, "is_name_generated": "FALSE"}, "reported_date": 1544031155715, "is_name_generated": "FALSE"}, "patient_id": "80776", "date_of_birth": "2002-03-13", "reported_date": "1530976927000"}, "patient_id": "80776", "content_type": "xml", "reported_date": 1710928344357}');
INSERT INTO v1.couchdb VALUES ('2024-06-18 09:59:23.582', '025034d7-78d4-54ad-b2c3-a6c44aa3f400', '0', '{"_id": "025034d7-78d4-54ad-b2c3-a6c44aa3f400", "_rev": "1-5edcba45805f8fee016fe806919d7a37", "form": "pregnancy", "from": "+16143332113", "type": "data_record", "fields": {"edd": "Dec 22, 2020", "inputs": {"source": "contact", "contact": {"_id": "e3040ffc-0a1e-5b3c-9dcf-f9d23ee16c640", "sex": "female", "name": "Person 1118", "date_of_birth": "2001-08-12"}}, "chw_sms": "Hi , a pregnancy for Person 2 (46462) has been registered at the facility. You will receive ANC notifications for this patient. Please follow up to identify the patient. Thank you!", "edd_8601": "2019-06-13T00:00:00.000Z", "lmp_date": "Mar 17, 2020", "group_lmp": {"g_edd": "Dec 22, 2020", "g_edd_8601": "2019-06-13T00:00:00.000Z", "g_lmp_date": "Mar 17, 2020", "g_lmp_approx": "91", "g_lmp_method": "approx", "g_lmp_date_raw": "Thu Sep 06 2018 00:00:00 GMT-0400 (Eastern Daylight Time)", "g_lmp_date_8601": "2020-03-17"}, "group_note": {"is_sms_edited": "yes", "default_chw_sms": "default", "default_chw_sms_note": "", "default_chw_sms_text": "Hi , a pregnancy for Person 2 (46462) has been registered at the facility. You will receive ANC notifications for this patient. Please follow up to identify the patient. Thank you!"}, "lmp_method": "approx", "patient_name": "Person 1118", "patient_uuid": "e3040ffc-0a1e-5b3c-9dcf-f9d23ee16c640", "lmp_date_8601": "2020-03-17", "days_since_lmp": "91.75", "weeks_since_lmp": "13.11", "patient_age_at_lmp": "18", "patient_age_in_years": "18"}, "contact": {"_id": "8c93e1ea-030b-583f-bcaf-6da6f97b78c8", "sex": "female", "name": "Person 1118", "type": "person", "phone": "16145553890", "parent": {"_id": "e6182af7-31f3-56b4-8d7a-56b6b7266069", "name": "Clinic_7", "type": "clinic", "parent": {"_id": "7599762e-605f-5a8c-9801-3c7a4eb36f5f", "name": "HC2", "type": "health_center", "parent": {"_id": "fc9928ae-9f48-5d2d-8a0f-222b2389f77f", "name": "Pregnancies", "type": "district_hospital", "notes": "", "parent": "", "external_id": "", "geolocation": "", "reported_date": 1544031155715, "is_name_generated": "false"}, "reported_date": 1544031155715, "is_name_generated": "FALSE"}, "reported_date": 1544031155715, "is_name_generated": "FALSE"}, "patient_id": "81118", "date_of_birth": "2003-02-18", "reported_date": "1530977269000"}, "patient_id": "81118", "content_type": "xml", "reported_date": 1710928173357}');
INSERT INTO v1.couchdb VALUES ('2024-06-18 09:59:23.582', '01246507-9aa5-50b6-9c8f-6009c87f0fe9', '0', '{"_id": "01246507-9aa5-50b6-9c8f-6009c87f0fe9", "sex": "male", "_rev": "1-d0fa463f20ef8f45f37d1b63994e2de4", "name": "la personne 1675", "type": "person", "phone": "16145551675", "parent": {"_id": "3f137e96-f22c-56c0-868b-285a970807fb", "name": "Clinic_14", "type": "clinic", "parent": {"_id": "6c0911a0-d4b8-52c0-985a-e1b69becc6c1", "name": "HC4", "type": "health_center", "parent": {"_id": "fc9928ae-9f48-5d2d-8a0f-222b2389f77f", "name": "Pregnancies", "type": "district_hospital", "notes": "", "parent": "", "external_id": "", "geolocation": "", "reported_date": 1544031155715, "is_name_generated": "false"}, "reported_date": 1544031155715, "is_name_generated": "FALSE"}, "reported_date": 1544031155715, "is_name_generated": "FALSE"}, "patient_id": "51674", "date_of_birth": "2000-02-01", "reported_date": "1530977826000"}');
INSERT INTO v1.couchdb VALUES ('2024-06-18 09:59:23.582', '01246507-9aa5-50b6-9c8f-6009c87f0fe9', '0', '{"_id": "01246507-9aa5-50b6-9c8f-6009c87f0fe9", "sex": "male", "_rev": "1-d0fa463f20ef8f45f37d1b63994e2de4", "name": "la personne 1675", "type": "person", "phone": "16145551675", "parent": {"_id": "3f137e96-f22c-56c0-868b-285a970807fb", "name": "Clinic_14", "type": "clinic", "parent": {"_id": "6c0911a0-d4b8-52c0-985a-e1b69becc6c1", "name": "HC4", "type": "health_center", "parent": {"_id": "fc9928ae-9f48-5d2d-8a0f-222b2389f77f", "name": "Pregnancies", "type": "district_hospital", "notes": "", "parent": "", "external_id": "", "geolocation": "", "reported_date": 1544031155715, "is_name_generated": "false"}, "reported_date": 1544031155715, "is_name_generated": "FALSE"}, "reported_date": 1544031155715, "is_name_generated": "FALSE"}, "patient_id": "51674", "date_of_birth": "10/15/1998", "reported_date": "1530977826000"}');
INSERT INTO v1.couchdb VALUES ('2024-06-18 09:59:23.582', '00172650-a2d1-540b-b308-d53ff75f102c', '0', '{"_id": "00172650-a2d1-540b-b308-d53ff75f102c", "sex": "female", "_rev": "1-9201495f926a8e8a727a88fddab53337", "name": "la personne 1670", "type": "person", "phone": "16145551670", "parent": {"_id": "3f137e96-f22c-56c0-868b-285a970807fb", "name": "Clinic_14", "type": "clinic", "parent": {"_id": "6c0911a0-d4b8-52c0-985a-e1b69becc6c1", "name": "HC4", "type": "health_center", "parent": {"_id": "fc9928ae-9f48-5d2d-8a0f-222b2389f77f", "name": "Pregnancies", "type": "district_hospital", "notes": "", "parent": "", "external_id": "", "geolocation": "", "reported_date": 1544031155715, "is_name_generated": "false"}, "reported_date": 1544031155715, "is_name_generated": "FALSE"}, "reported_date": 1544031155715, "is_name_generated": "FALSE"}, "patient_id": "51669", "date_of_birth": "2000-02-01", "reported_date": "1530977821000"}');
INSERT INTO v1.couchdb VALUES ('2024-06-18 09:59:23.582', '01174a78-e44d-5730-b382-d95105ce35b9', '0', '{"_id": "01174a78-e44d-5730-b382-d95105ce35b9", "sex": "male", "_rev": "1-9032973eb94daac6d9ebf00b836fa8dd", "name": "Person 3926", "type": "person", "phone": "16145556698", "parent": {"_id": "c1f5db2f-0205-56ee-9433-dcc8a2f9b5c2", "name": "Clinic_9", "type": "clinic", "parent": {"_id": "7599762e-605f-5a8c-9801-3c7a4eb36f5f", "name": "HC2", "type": "health_center", "parent": {"_id": "fc9928ae-9f48-5d2d-8a0f-222b2389f77f", "name": "Pregnancies", "type": "district_hospital", "notes": "", "parent": "", "external_id": "", "geolocation": "", "reported_date": 1544031155715, "is_name_generated": "false"}, "reported_date": 1544031155715, "is_name_generated": "FALSE"}, "reported_date": 1544031155715, "is_name_generated": "FALSE"}, "patient_id": "83926", "date_of_birth": "2010-10-27", "reported_date": "1530980077000"}');
INSERT INTO v1.couchdb VALUES ('2024-06-18 09:59:23.582', '0059decb-11f0-5a66-bb76-902a5887a69e', '0', '{"_id": "0059decb-11f0-5a66-bb76-902a5887a69e", "sex": "female", "_rev": "1-1b91ed7890656ccd5829111d23f05071", "name": "la personne 1020", "type": "person", "phone": "16145551020", "parent": {"_id": "758ba93c-f202-5930-92c6-b94ec6d00d18", "name": "Clinic_13", "type": "clinic", "parent": {"_id": "5ecf4a0f-2ca9-5c97-a026-e90d93193577", "name": "HC3", "type": "health_center", "parent": {"_id": "fc9928ae-9f48-5d2d-8a0f-222b2389f77f", "name": "Pregnancies", "type": "district_hospital", "notes": "", "parent": "", "external_id": "", "geolocation": "", "reported_date": 1544031155715, "is_name_generated": "false"}, "reported_date": 1544031155715, "is_name_generated": "FALSE"}, "reported_date": 1544031155715, "is_name_generated": "FALSE"}, "patient_id": "51019", "date_of_birth": "2000-02-01", "reported_date": "1530977171000"}');
Expand Down

0 comments on commit 26f4da7

Please sign in to comment.