Creates Continuous Inpatient (CIP) spells by combining one or more provider spells into a single uninterrupted period of inpatient care. CIP definitions follow the NHS Digital methodology: transfers between providers can be part of the same CIP spell where specific admission, discharge, and timing criteria are met. A CIP spell begins when a patient is admitted under consultant care and ends when they are discharged or die. http://content.digital.nhs.uk/media/11859/Provider-Spells-Methodology/pdf/Spells_Methodology.pdf
Where spells meet the CIP criteria, they are merged into a continuous spell. The output includes a CIP index and the derived start and end dates for the full CIP period.
Usage
cip_spells(
x,
group_vars,
spell_start_date,
admission_method,
admission_source,
spell_end_date,
discharge_destination,
patient_classification,
.forceCopy = FALSE
)Arguments
- x
A data.frame or data.table; will be converted to a data.table (usually HES/SUS data)
- group_vars
Character vector of variables used to group records (minimum: a patient identifier).
- spell_start_date
Quoted column name containing the provider spell admission date.
- admission_method
CDS admission method code.
- admission_source
CDS admission source code.
- spell_end_date
Quoted column name containing the provider spell discharge date.
- discharge_destination
CDS discharge destination code.
- patient_classification
CDS patient classification code.
- .forceCopy
Logical (default
FALSE). IfFALSE, the input is converted to adata.tableand modified by reference. IfTRUE, the input must already be adata.table, and the function will create an explicit copy to avoid modifying the original object.
Value
A data.table containing the original data and three new variables:
cip_indxUnique identifier for the derived CIP spell.
cip_spell_startStart date for the continuous inpatient spell.
cip_spell_endEnd date for the continuous inpatient spell.
Examples
cip_test <- data.frame(
id = c('465','465','465','465','8418','8418','8418',
'8418','8418','8418','8418','8418','26443',
'26443','26443','33299','33299','33299','33299',
'33299','33299','33299','33299','33299','33299',
'52635','52635','52635','52635','52635','52635',
'52635','52635','52635','52635','52635','52635',
'52635','52635','52635','52635','52635','52635',
'52635','52635','52635','52635','52635','52635',
'52635','52635','52635','78915','78915','78915'),
provider = c('X1T','X1T','X1T','X1T','KHA','KHA','KHA',
'KHA','KHA','KHA','KHA','KHA','BX2','BX2',
'BX2','PXH','PXH','PXH','PXH','PXH','PXH',
'PXH','PXH','PXH','PXH','9HA','9HA','9HA',
'9HA','9HA','9HA','9HA','9HA','9HA','9HA',
'9HA','9HA','9HA','9HA','9HA','9HA','YYT',
'YYT','YYT','YYT','YYT','YYT','YYT','YYT',
'YYT','YYT','YYT','ABX','ABX','ABX'),
spell_start = as.Date(c(
'2020-03-07','2020-03-07','2020-03-25','2020-04-03','2020-01-25',
'2020-01-26','2020-07-14','2020-08-02','2020-08-12','2020-08-19',
'2020-08-19','2020-11-19','2019-11-12','2020-04-17','2020-04-23',
'2020-07-03','2020-01-17','2020-02-07','2020-03-20','2020-04-27',
'2020-06-21','2020-07-02','2020-10-17','2020-11-27','2021-01-02',
'2019-12-31','2020-01-02','2020-01-14','2020-01-16','2020-02-07',
'2020-02-11','2020-02-14','2020-02-18','2020-02-21','2020-02-25',
'2020-02-28','2020-03-09','2020-03-11','2020-03-12','2020-03-13',
'2020-03-14','2020-02-04','2020-02-07','2020-02-11','2020-02-14',
'2020-02-18','2020-02-21','2020-02-25','2020-02-28','2020-03-09',
'2020-03-11','2020-03-12','2020-04-16','2020-04-24','2020-05-13')),
spell_end = as.Date(c(
'2020-03-07','2020-03-25','2020-04-02','2020-04-27','2020-01-25',
'2020-01-27','2020-07-17','2020-08-07','2020-08-14','2020-08-19',
'2020-08-22','2020-12-16','2020-04-17','2020-04-23','2020-05-20',
'2020-07-24','2020-01-28','2020-02-07','2020-03-23','2020-04-29',
'2020-06-21','2020-07-03','2020-11-27','2021-01-02','2021-01-10',
'2019-12-31','2020-01-11','2020-01-14','2020-02-04','2020-02-07',
'2020-02-11','2020-02-14','2020-02-18','2020-02-21','2020-02-25',
'2020-02-28','2020-03-09','2020-03-11','2020-03-12','2020-03-13',
'2020-03-30','2020-02-07','2020-02-11','2020-02-14','2020-02-18',
'2020-02-21','2020-02-25','2020-02-28','2020-03-09','2020-03-11',
'2020-03-12','2020-03-13','2020-04-24','2020-05-13','2020-06-11')),
adm_meth = c('21','81','21','81','21','21','11','21','21','21','21',
'21','21','81','21','81','21','21','21','21','21','21',
'21','13','13','12','22','12','2D','13','13','13','13',
'13','13','13','13','13','13','13','21','81','81','81',
'81','81','13','81','81','13','13','13','21','11','81'),
adm_src = c('19','51','19','51','19','51','19','51','19','19','19',
'51','19','51','19','51','19','19','19','19','19','19',
'19','51','19','19','19','19','19','19','19','19','19',
'19','19','19','51','51','51','51','19','51','51','51',
'51','51','51','51','51','51','51','51','19','51','51'),
dis_meth = c('1','1','1','1','1','1','1','1','1','1','1','4','1','1',
'4','1','1','1','1','1','1','1','8','1','4','1','1','1',
'1','1','1','1','1','1','1','1','1','1','1','1','1','1',
'1','1','1','1','1','1','1','1','1','1','1','1','2'),
dis_dest = c('51','51','51','54','51','19','19','19','19','51','19',
'79','51','51','79','65','19','19','19','19','19','29',
'98','51','79','19','19','19','51','19','19','19','51',
'51','51','19','19','51','51','19','51','51','51','51',
'51','51','51','51','51','51','51','51','29','54','19'),
patclass = c('1','1','1','1','1','1','1','1','1','1','1','1','1','1',
'1','1','1','1','1','1','1','1','1','1','1','2','1','2',
'1','2','2','2','2','2','2','2','2','2','2','2','1','1',
'1','1','1','1','1','1','1','1','1','1','1','1','1')
)
cip_spells(x=cip_test,
group_vars = c('id','provider'),
patient_classification = 'patclass',
spell_start_date = 'spell_start',
admission_method = 'adm_meth',
admission_source = 'adm_src',
spell_end_date = 'spell_end',
discharge_destination = 'dis_dest'
)[]
#> id provider spell_start spell_end adm_meth adm_src dis_meth dis_dest
#> <char> <char> <Date> <Date> <char> <char> <char> <char>
#> 1: 26443 BX2 2019-11-12 2020-04-17 21 19 1 51
#> 2: 26443 BX2 2020-04-17 2020-04-23 81 51 1 51
#> 3: 26443 BX2 2020-04-23 2020-05-20 21 19 4 79
#> 4: 33299 PXH 2020-01-17 2020-01-28 21 19 1 19
#> 5: 33299 PXH 2020-02-07 2020-02-07 21 19 1 19
#> 6: 33299 PXH 2020-03-20 2020-03-23 21 19 1 19
#> 7: 33299 PXH 2020-04-27 2020-04-29 21 19 1 19
#> 8: 33299 PXH 2020-06-21 2020-06-21 21 19 1 19
#> 9: 33299 PXH 2020-07-02 2020-07-03 21 19 1 29
#> 10: 33299 PXH 2020-07-03 2020-07-24 81 51 1 65
#> 11: 33299 PXH 2020-10-17 2020-11-27 21 19 8 98
#> 12: 33299 PXH 2020-11-27 2021-01-02 13 51 1 51
#> 13: 33299 PXH 2021-01-02 2021-01-10 13 19 4 79
#> 14: 465 X1T 2020-03-07 2020-03-07 21 19 1 51
#> 15: 465 X1T 2020-03-07 2020-03-25 81 51 1 51
#> 16: 465 X1T 2020-03-25 2020-04-02 21 19 1 51
#> 17: 465 X1T 2020-04-03 2020-04-27 81 51 1 54
#> 18: 52635 9HA 2019-12-31 2019-12-31 12 19 1 19
#> 19: 52635 9HA 2020-01-02 2020-01-11 22 19 1 19
#> 20: 52635 9HA 2020-01-14 2020-01-14 12 19 1 19
#> 21: 52635 9HA 2020-01-16 2020-02-04 2D 19 1 51
#> 22: 52635 9HA 2020-02-07 2020-02-07 13 19 1 19
#> 23: 52635 9HA 2020-02-11 2020-02-11 13 19 1 19
#> 24: 52635 9HA 2020-02-14 2020-02-14 13 19 1 19
#> 25: 52635 9HA 2020-02-18 2020-02-18 13 19 1 51
#> 26: 52635 9HA 2020-02-21 2020-02-21 13 19 1 51
#> 27: 52635 9HA 2020-02-25 2020-02-25 13 19 1 51
#> 28: 52635 9HA 2020-02-28 2020-02-28 13 19 1 19
#> 29: 52635 9HA 2020-03-09 2020-03-09 13 51 1 19
#> 30: 52635 9HA 2020-03-11 2020-03-11 13 51 1 51
#> 31: 52635 9HA 2020-03-12 2020-03-12 13 51 1 51
#> 32: 52635 9HA 2020-03-13 2020-03-13 13 51 1 19
#> 33: 52635 9HA 2020-03-14 2020-03-30 21 19 1 51
#> 34: 52635 YYT 2020-02-04 2020-02-07 81 51 1 51
#> 35: 52635 YYT 2020-02-07 2020-02-11 81 51 1 51
#> 36: 52635 YYT 2020-02-11 2020-02-14 81 51 1 51
#> 37: 52635 YYT 2020-02-14 2020-02-18 81 51 1 51
#> 38: 52635 YYT 2020-02-18 2020-02-21 81 51 1 51
#> 39: 52635 YYT 2020-02-21 2020-02-25 13 51 1 51
#> 40: 52635 YYT 2020-02-25 2020-02-28 81 51 1 51
#> 41: 52635 YYT 2020-02-28 2020-03-09 81 51 1 51
#> 42: 52635 YYT 2020-03-09 2020-03-11 13 51 1 51
#> 43: 52635 YYT 2020-03-11 2020-03-12 13 51 1 51
#> 44: 52635 YYT 2020-03-12 2020-03-13 13 51 1 51
#> 45: 78915 ABX 2020-04-16 2020-04-24 21 19 1 29
#> 46: 78915 ABX 2020-04-24 2020-05-13 11 51 1 54
#> 47: 78915 ABX 2020-05-13 2020-06-11 81 51 2 19
#> 48: 8418 KHA 2020-01-25 2020-01-25 21 19 1 51
#> 49: 8418 KHA 2020-01-26 2020-01-27 21 51 1 19
#> 50: 8418 KHA 2020-07-14 2020-07-17 11 19 1 19
#> 51: 8418 KHA 2020-08-02 2020-08-07 21 51 1 19
#> 52: 8418 KHA 2020-08-12 2020-08-14 21 19 1 19
#> 53: 8418 KHA 2020-08-19 2020-08-19 21 19 1 51
#> 54: 8418 KHA 2020-08-19 2020-08-22 21 19 1 19
#> 55: 8418 KHA 2020-11-19 2020-12-16 21 51 4 79
#> id provider spell_start spell_end adm_meth adm_src dis_meth dis_dest
#> <char> <char> <Date> <Date> <char> <char> <char> <char>
#> patclass proxy_missing cip_indx cip_spell_start cip_spell_end
#> <char> <num> <char> <Date> <Date>
#> 1: 1 0 1.3.0 2019-11-12 2020-05-20
#> 2: 1 0 1.3.0 2019-11-12 2020-05-20
#> 3: 1 0 1.3.0 2019-11-12 2020-05-20
#> 4: 1 0 2.10.0 2020-01-17 2020-01-28
#> 5: 1 0 2.10.1 2020-02-07 2020-02-07
#> 6: 1 0 2.10.2 2020-03-20 2020-03-23
#> 7: 1 0 2.10.3 2020-04-27 2020-04-29
#> 8: 1 0 2.10.4 2020-06-21 2020-06-21
#> 9: 1 0 2.10.5 2020-07-02 2020-07-24
#> 10: 1 0 2.10.5 2020-07-02 2020-07-24
#> 11: 1 0 2.10.6 2020-10-17 2021-01-10
#> 12: 1 0 2.10.6 2020-10-17 2021-01-10
#> 13: 1 0 2.10.6 2020-10-17 2021-01-10
#> 14: 1 0 3.4.0 2020-03-07 2020-04-02
#> 15: 1 0 3.4.0 2020-03-07 2020-04-02
#> 16: 1 0 3.4.0 2020-03-07 2020-04-02
#> 17: 1 0 3.4.1 2020-04-03 2020-04-27
#> 18: 2 0 4.16.0 2019-12-31 2019-12-31
#> 19: 1 0 4.16.1 2020-01-02 2020-01-11
#> 20: 2 0 4.16.2 2020-01-14 2020-01-14
#> 21: 1 0 4.16.3 2020-01-16 2020-02-04
#> 22: 2 0 4.16.4 2020-02-07 2020-02-07
#> 23: 2 0 4.16.5 2020-02-11 2020-02-11
#> 24: 2 0 4.16.6 2020-02-14 2020-02-14
#> 25: 2 0 4.16.7 2020-02-18 2020-02-18
#> 26: 2 0 4.16.8 2020-02-21 2020-02-21
#> 27: 2 0 4.16.9 2020-02-25 2020-02-25
#> 28: 2 0 4.16.10 2020-02-28 2020-02-28
#> 29: 2 0 4.16.11 2020-03-09 2020-03-09
#> 30: 2 0 4.16.12 2020-03-11 2020-03-11
#> 31: 2 0 4.16.13 2020-03-12 2020-03-12
#> 32: 2 0 4.16.14 2020-03-13 2020-03-13
#> 33: 1 0 4.16.16 2020-03-14 2020-03-30
#> 34: 1 0 5.11.0 2020-02-04 2020-03-13
#> 35: 1 0 5.11.0 2020-02-04 2020-03-13
#> 36: 1 0 5.11.0 2020-02-04 2020-03-13
#> 37: 1 0 5.11.0 2020-02-04 2020-03-13
#> 38: 1 0 5.11.0 2020-02-04 2020-03-13
#> 39: 1 0 5.11.0 2020-02-04 2020-03-13
#> 40: 1 0 5.11.0 2020-02-04 2020-03-13
#> 41: 1 0 5.11.0 2020-02-04 2020-03-13
#> 42: 1 0 5.11.0 2020-02-04 2020-03-13
#> 43: 1 0 5.11.0 2020-02-04 2020-03-13
#> 44: 1 0 5.11.0 2020-02-04 2020-03-13
#> 45: 1 0 6.3.0 2020-04-16 2020-06-11
#> 46: 1 0 6.3.0 2020-04-16 2020-06-11
#> 47: 1 0 6.3.0 2020-04-16 2020-06-11
#> 48: 1 0 7.8.0 2020-01-25 2020-01-25
#> 49: 1 0 7.8.1 2020-01-26 2020-01-27
#> 50: 1 0 7.8.2 2020-07-14 2020-07-17
#> 51: 1 0 7.8.3 2020-08-02 2020-08-07
#> 52: 1 0 7.8.4 2020-08-12 2020-08-14
#> 53: 1 0 7.8.5 2020-08-19 2020-08-22
#> 54: 1 0 7.8.5 2020-08-19 2020-08-22
#> 55: 1 0 7.8.7 2020-11-19 2020-12-16
#> patclass proxy_missing cip_indx cip_spell_start cip_spell_end
#> <char> <num> <char> <Date> <Date>
