def test_extension(self): from fhirtordf.rdfsupport.fhirgraphutils import extension g = Graph() g.load(os.path.join(self.base_dir, "patient-example.ttl"), format="turtle") s = FHIR['Patient/example'] birthdate = g.value(s, FHIR.Patient.birthDate) birthtime = extension( g, birthdate, URIRef( "http://hl7.org/fhir/StructureDefinition/patient-birthTime")) self.assertEqual( datetime(1974, 12, 25, 14, 35, 45, 0, FixedOffset(-5)), birthtime) self.assertTrue( isinstance( extension( g, birthdate, URIRef( "http://hl7.org/fhir/StructureDefinition/patient-birthTime" ), True), Literal))
# test precision ('15:33:42.123456', time(15, 33, 42, 123456), None), ('15:33:42.1234564', time(15, 33, 42, 123456), None), ('15:33:42.1234557', time(15, 33, 42, 123456), None), ('2320,8', time(23, 20, 48), None), ('23:20,8', time(23, 20, 48), None), ('23,3', time(23, 18), None), ('232030Z', time(23, 20, 30, tzinfo=UTC), TIME_BAS_COMPLETE + TZ_BAS), ('2320Z', time(23, 20, tzinfo=UTC), TIME_BAS_MINUTE + TZ_BAS), ('23Z', time(23, tzinfo=UTC), TIME_HOUR + TZ_BAS), ('23:20:30Z', time(23, 20, 30, tzinfo=UTC), TIME_EXT_COMPLETE + TZ_EXT), ('23:20Z', time(23, 20, tzinfo=UTC), TIME_EXT_MINUTE + TZ_EXT), ('152746+0100', time(15, 27, 46, tzinfo=FixedOffset(1, 0, '+0100')), TIME_BAS_COMPLETE + TZ_BAS), ('152746-0500', time(15, 27, 46, tzinfo=FixedOffset(-5, 0, '-0500')), TIME_BAS_COMPLETE + TZ_BAS), ('152746+01', time(15, 27, 46, tzinfo=FixedOffset(1, 0, '+01:00')), TIME_BAS_COMPLETE + TZ_HOUR), ('152746-05', time(15, 27, 46, tzinfo=FixedOffset(-5, -0, '-05:00')), TIME_BAS_COMPLETE + TZ_HOUR), ('15:27:46+01:00', time(15, 27, 46, tzinfo=FixedOffset(1, 0, '+01:00')), TIME_EXT_COMPLETE + TZ_EXT), ('15:27:46-05:00', time(15, 27, 46, tzinfo=FixedOffset(-5, -0, '-05:00')), TIME_EXT_COMPLETE + TZ_EXT),
# the following list contains tuples of ISO datetime strings and the expected # result from the parse_datetime method. A result of None means an ISO8601Error # is expected. TEST_CASES = [ ('19850412T1015', datetime(1985, 4, 12, 10, 15), DATE_BAS_COMPLETE + 'T' + TIME_BAS_MINUTE, '19850412T1015'), ('1985-04-12T10:15', datetime(1985, 4, 12, 10, 15), DATE_EXT_COMPLETE + 'T' + TIME_EXT_MINUTE, '1985-04-12T10:15'), ('1985102T1015Z', datetime(1985, 4, 12, 10, 15, tzinfo=UTC), DATE_BAS_ORD_COMPLETE + 'T' + TIME_BAS_MINUTE + TZ_BAS, '1985102T1015Z'), ('1985-102T10:15Z', datetime(1985, 4, 12, 10, 15, tzinfo=UTC), DATE_EXT_ORD_COMPLETE + 'T' + TIME_EXT_MINUTE + TZ_EXT, '1985-102T10:15Z'), ('1985W155T1015+0400', datetime(1985, 4, 12, 10, 15, tzinfo=FixedOffset(4, 0, '+0400')), DATE_BAS_WEEK_COMPLETE + 'T' + TIME_BAS_MINUTE + TZ_BAS, '1985W155T1015+0400'), ('1985-W15-5T10:15+04', datetime( 1985, 4, 12, 10, 15, tzinfo=FixedOffset(4, 0, '+0400'), ), DATE_EXT_WEEK_COMPLETE + 'T' + TIME_EXT_MINUTE + TZ_HOUR, '1985-W15-5T10:15+04'), ('20110410T101225.123000Z', datetime(2011, 4, 10, 10, 12, 25, 123000, tzinfo=UTC), DATE_BAS_COMPLETE + 'T' + TIME_BAS_COMPLETE + ".%f" + TZ_BAS,
('+001985-102', date(1985, 4, 12), DATE_EXT_ORD_COMPLETE), ('+001985W155', date(1985, 4, 12), DATE_BAS_WEEK_COMPLETE), ('+001985-W15-5', date(1985, 4, 12), DATE_EXT_WEEK_COMPLETE), ('+001985W15', date(1985, 4, 8), DATE_BAS_WEEK), ('+001985-W15', date(1985, 4, 8), DATE_EXT_WEEK)] DATETIME_TEST_CASES = [ ('19850412T1015', datetime(1985, 4, 12, 10, 15), DATE_BAS_COMPLETE + 'T' + TIME_BAS_MINUTE), ('1985-04-12T10:15', datetime(1985, 4, 12, 10, 15), DATE_EXT_COMPLETE + 'T' + TIME_EXT_MINUTE), ('1985102T1015Z', datetime(1985, 4, 12, 10, 15, tzinfo=UTC), DATE_BAS_ORD_COMPLETE + 'T' + TIME_BAS_MINUTE + TZ_BAS), ('1985-102T10:15Z', datetime(1985, 4, 12, 10, 15, tzinfo=UTC), DATE_EXT_ORD_COMPLETE + 'T' + TIME_EXT_MINUTE + TZ_EXT), ('1985W155T1015+0400', datetime(1985, 4, 12, 10, 15, tzinfo=FixedOffset(4, 0, '+0400')), DATE_BAS_WEEK_COMPLETE + 'T' + TIME_BAS_MINUTE + TZ_BAS), ('1985-W15-5T10:15+04', datetime(1985, 4, 12, 10, 15, tzinfo=FixedOffset(4, 0, '+0400')), DATE_EXT_WEEK_COMPLETE + 'T' + TIME_EXT_MINUTE + TZ_HOUR)] TIME_TEST_CASES = [ ('232050', time(23, 20, 50), TIME_BAS_COMPLETE + TZ_BAS), ('23:20:50', time(23, 20, 50), TIME_EXT_COMPLETE + TZ_EXT), ('2320', time(23, 20), TIME_BAS_MINUTE), ('23:20', time(23, 20), TIME_EXT_MINUTE), ('23', time(23), TIME_HOUR), ('232050,5', time(23, 20, 50, 500000), None), ('23:20:50.5', time(23, 20, 50, 500000), None), ('2320,8', time(23, 20, 48), None), ('23:20,8', time(23, 20, 48), None), ('23,3', time(23, 18), None),
('+001985-W15-5', date(1985, 4, 12), DATE_EXT_WEEK_COMPLETE), ('+001985W15', date(1985, 4, 8), DATE_BAS_WEEK), ('+001985-W15', date(1985, 4, 8), DATE_EXT_WEEK)] DATETIME_TEST_CASES = [ ('19850412T1015', datetime(1985, 4, 12, 10, 15), DATE_BAS_COMPLETE + 'T' + TIME_BAS_MINUTE), ('1985-04-12T10:15', datetime(1985, 4, 12, 10, 15), DATE_EXT_COMPLETE + 'T' + TIME_EXT_MINUTE), ('1985102T1015Z', datetime(1985, 4, 12, 10, 15, tzinfo=UTC), DATE_BAS_ORD_COMPLETE + 'T' + TIME_BAS_MINUTE + TZ_BAS), ('1985-102T10:15Z', datetime(1985, 4, 12, 10, 15, tzinfo=UTC), DATE_EXT_ORD_COMPLETE + 'T' + TIME_EXT_MINUTE + TZ_EXT), ('1985W155T1015+0400', datetime(1985, 4, 12, 10, 15, tzinfo=FixedOffset(4, 0, '+0400')), DATE_BAS_WEEK_COMPLETE + 'T' + TIME_BAS_MINUTE + TZ_BAS), ('1985-W15-5T10:15+04', datetime(1985, 4, 12, 10, 15, tzinfo=FixedOffset(4, 0, '+0400')), DATE_EXT_WEEK_COMPLETE + 'T' + TIME_EXT_MINUTE + TZ_HOUR) ] TIME_TEST_CASES = [ ('232050', time(23, 20, 50), TIME_BAS_COMPLETE + TZ_BAS), ('23:20:50', time(23, 20, 50), TIME_EXT_COMPLETE + TZ_EXT), ('2320', time(23, 20), TIME_BAS_MINUTE), ('23:20', time(23, 20), TIME_EXT_MINUTE), ('23', time(23), TIME_HOUR), ('232050,5', time(23, 20, 50, 500000), None), ('23:20:50.5', time(23, 20, 50, 500000), None), ('2320,8', time(23, 20, 48), None), ('23:20,8', time(23, 20, 48), None), ('23,3', time(23, 18), None),
('23', time(23), TIME_HOUR), ('232050,5', time(23, 20, 50, 500000), None), ('23:20:50.5', time(23, 20, 50, 500000), None), # test precision ('15:33:42.123456', time(15, 33, 42, 123456), None), ('15:33:42.1234564', time(15, 33, 42, 123456), None), ('15:33:42.1234557', time(15, 33, 42, 123456), None), ('2320,8', time(23, 20, 48), None), ('23:20,8', time(23, 20, 48), None), ('23,3', time(23, 18), None), ('232030Z', time(23, 20, 30, tzinfo=UTC), TIME_BAS_COMPLETE + TZ_BAS), ('2320Z', time(23, 20, tzinfo=UTC), TIME_BAS_MINUTE + TZ_BAS), ('23Z', time(23, tzinfo=UTC), TIME_HOUR + TZ_BAS), ('23:20:30Z', time(23, 20, 30, tzinfo=UTC), TIME_EXT_COMPLETE + TZ_EXT), ('23:20Z', time(23, 20, tzinfo=UTC), TIME_EXT_MINUTE + TZ_EXT), ('152746+0100', time(15, 27, 46, tzinfo=FixedOffset(1, 0, '+0100')), TIME_BAS_COMPLETE + TZ_BAS), ('152746-0500', time(15, 27, 46, tzinfo=FixedOffset(-5, 0, '-0500')), TIME_BAS_COMPLETE + TZ_BAS), ('152746+01', time(15, 27, 46, tzinfo=FixedOffset(1, 0, '+01:00')), TIME_BAS_COMPLETE + TZ_HOUR), ('152746-05', time(15, 27, 46, tzinfo=FixedOffset(-5, -0, '-05:00')), TIME_BAS_COMPLETE + TZ_HOUR), ('15:27:46+01:00', time(15, 27, 46, tzinfo=FixedOffset(1, 0, '+01:00')), TIME_EXT_COMPLETE + TZ_EXT), ('15:27:46-05:00', time(15, 27, 46, tzinfo=FixedOffset(-5, -0, '-05:00')), TIME_EXT_COMPLETE + TZ_EXT), ('15:27:46+01', time(15, 27, 46, tzinfo=FixedOffset(1, 0, '+01:00')), TIME_EXT_COMPLETE + TZ_HOUR), ('15:27:46-05', time(15, 27, 46, tzinfo=FixedOffset(-5, -0, '-05:00')), TIME_EXT_COMPLETE + TZ_HOUR),
# result from the parse_datetime method. A result of None means an ISO8601Error # is expected. TEST_CASES = [('19850412T1015', datetime(1985, 4, 12, 10, 15), DATE_BAS_COMPLETE + 'T' + TIME_BAS_MINUTE, '19850412T1015'), ('1985-04-12T10:15', datetime(1985, 4, 12, 10, 15), DATE_EXT_COMPLETE + 'T' + TIME_EXT_MINUTE, '1985-04-12T10:15'), ('1985102T1015Z', datetime(1985, 4, 12, 10, 15, tzinfo=UTC), DATE_BAS_ORD_COMPLETE + 'T' + TIME_BAS_MINUTE + TZ_BAS, '1985102T1015Z'), ('1985-102T10:15Z', datetime(1985, 4, 12, 10, 15, tzinfo=UTC), DATE_EXT_ORD_COMPLETE + 'T' + TIME_EXT_MINUTE + TZ_EXT, '1985-102T10:15Z'), ('1985W155T1015+0400', datetime(1985, 4, 12, 10, 15, tzinfo=FixedOffset(4, 0, '+0400')), DATE_BAS_WEEK_COMPLETE + 'T' + TIME_BAS_MINUTE + TZ_BAS, '1985W155T1015+0400'), ('1985-W15-5T10:15+04', datetime(1985, 4, 12, 10, 15, tzinfo=FixedOffset(4, 0, '+0400'),), DATE_EXT_WEEK_COMPLETE + 'T' + TIME_EXT_MINUTE + TZ_HOUR, '1985-W15-5T10:15+04'), ('20110410T101225.123000Z', datetime(2011, 4, 10, 10, 12, 25, 123000, tzinfo=UTC), DATE_BAS_COMPLETE + 'T' + TIME_BAS_COMPLETE + ".%f" + TZ_BAS, '20110410T101225.123000Z'), ('2012-10-12T08:29:46.069178Z', datetime(2012, 10, 12, 8, 29, 46, 69178, tzinfo=UTC), DATE_EXT_COMPLETE + 'T' + TIME_EXT_COMPLETE + '.%f' + TZ_BAS, '2012-10-12T08:29:46.069178Z'),
), ( "1985102T1015Z", datetime(1985, 4, 12, 10, 15, tzinfo=UTC), DATE_BAS_ORD_COMPLETE + "T" + TIME_BAS_MINUTE + TZ_BAS, "1985102T1015Z", ), ( "1985-102T10:15Z", datetime(1985, 4, 12, 10, 15, tzinfo=UTC), DATE_EXT_ORD_COMPLETE + "T" + TIME_EXT_MINUTE + TZ_EXT, "1985-102T10:15Z", ), ( "1985W155T1015+0400", datetime(1985, 4, 12, 10, 15, tzinfo=FixedOffset(4, 0, "+0400")), DATE_BAS_WEEK_COMPLETE + "T" + TIME_BAS_MINUTE + TZ_BAS, "1985W155T1015+0400", ), ( "1985-W15-5T10:15+04", datetime( 1985, 4, 12, 10, 15, tzinfo=FixedOffset(4, 0, "+0400"), ), DATE_EXT_WEEK_COMPLETE + "T" + TIME_EXT_MINUTE + TZ_HOUR, "1985-W15-5T10:15+04",
( "10:59:59.9999999Z", time(10, 59, 59, 999999, tzinfo=UTC), None, ), # TIME_EXT_COMPLETE + TZ_EXT), ("2320,8", time(23, 20, 48), None), ("23:20,8", time(23, 20, 48), None), ("23,3", time(23, 18), None), ("232030Z", time(23, 20, 30, tzinfo=UTC), TIME_BAS_COMPLETE + TZ_BAS), ("2320Z", time(23, 20, tzinfo=UTC), TIME_BAS_MINUTE + TZ_BAS), ("23Z", time(23, tzinfo=UTC), TIME_HOUR + TZ_BAS), ("23:20:30Z", time(23, 20, 30, tzinfo=UTC), TIME_EXT_COMPLETE + TZ_EXT), ("23:20Z", time(23, 20, tzinfo=UTC), TIME_EXT_MINUTE + TZ_EXT), ( "152746+0100", time(15, 27, 46, tzinfo=FixedOffset(1, 0, "+0100")), TIME_BAS_COMPLETE + TZ_BAS, ), ( "152746-0500", time(15, 27, 46, tzinfo=FixedOffset(-5, 0, "-0500")), TIME_BAS_COMPLETE + TZ_BAS, ), ( "152746+01", time(15, 27, 46, tzinfo=FixedOffset(1, 0, "+01:00")), TIME_BAS_COMPLETE + TZ_HOUR, ), ( "152746-05", time(15, 27, 46, tzinfo=FixedOffset(-5, -0, "-05:00")),
# the following list contains tuples of ISO datetime strings and the expected # result from the parse_datetime method. A result of None means an ISO8601Error # is expected. TEST_CASES = [ ('19850412T1015', datetime(1985, 4, 12, 10, 15), DATE_BAS_COMPLETE + 'T' + TIME_BAS_MINUTE, '19850412T1015'), ('1985-04-12T10:15', datetime(1985, 4, 12, 10, 15), DATE_EXT_COMPLETE + 'T' + TIME_EXT_MINUTE, '1985-04-12T10:15'), ('1985102T1015Z', datetime(1985, 4, 12, 10, 15, tzinfo=UTC), DATE_BAS_ORD_COMPLETE + 'T' + TIME_BAS_MINUTE + TZ_BAS, '1985102T1015Z'), ('1985-102T10:15Z', datetime(1985, 4, 12, 10, 15, tzinfo=UTC), DATE_EXT_ORD_COMPLETE + 'T' + TIME_EXT_MINUTE + TZ_EXT, '1985-102T10:15Z'), ('1985W155T1015+0400', datetime(1985, 4, 12, 10, 15, tzinfo=FixedOffset(4, 0, '+0400')), DATE_BAS_WEEK_COMPLETE + 'T' + TIME_BAS_MINUTE + TZ_BAS, '1985W155T1015+0400'), ('1985-W15-5T10:15+04', datetime( 1985, 4, 12, 10, 15, tzinfo=FixedOffset(4, 0, '+0400'), ), DATE_EXT_WEEK_COMPLETE + 'T' + TIME_EXT_MINUTE + TZ_HOUR, '1985-W15-5T10:15+04'), ('1985-W15-5T10:15-0430', datetime( 1985,