def NeonatalSWC_without_incidence(cause): with_condition_data_functions = {'birth_prevalence': lambda cause, builder: builder.data.load(f"cause.{cause}.birth_prevalence")} healthy = SusceptibleState(cause) with_condition = DiseaseState(cause, get_data_functions=with_condition_data_functions) healthy.allow_self_transitions() with_condition.allow_self_transitions() return DiseaseModel(cause, states=[healthy, with_condition])
def IschemicStroke(): susceptible = SusceptibleState('ischemic_stroke') data_funcs = {'dwell_time': lambda *args: pd.Timedelta(days=28)} acute_stroke = DiseaseState('acute_ischemic_stroke', cause_type='sequela', get_data_functions=data_funcs) post_stroke = DiseaseState( 'post_ischemic_stroke', cause_type='sequela', ) susceptible.allow_self_transitions() data_funcs = { 'incidence_rate': lambda _, builder: builder.data.load( 'cause.ischemic_stroke.incidence_rate') } susceptible.add_transition(acute_stroke, source_data_type='rate', get_data_functions=data_funcs) acute_stroke.allow_self_transitions() acute_stroke.add_transition(post_stroke) post_stroke.allow_self_transitions() data_funcs = { 'transition_rate': lambda builder, *_: builder.data.load( 'cause.ischemic_stroke.incidence_rate') } post_stroke.add_transition(acute_stroke, source_data_type='rate', get_data_functions=data_funcs) return DiseaseModel('ischemic_stroke', states=[susceptible, acute_stroke, post_stroke])
def IschemicHeartDisease(): susceptible = SusceptibleState('ischemic_heart_disease') data_funcs = {'dwell_time': lambda *args: pd.Timedelta(days=28)} acute_mi = DiseaseState('acute_myocardial_infarction', cause_type='sequela', get_data_functions=data_funcs) post_mi = DiseaseState( 'post_myocardial_infarction', cause_type='sequela', ) susceptible.allow_self_transitions() data_funcs = { 'incidence_rate': lambda _, builder: builder.data.load( 'cause.ischemic_heart_disease.incidence_rate') } susceptible.add_transition(acute_mi, source_data_type='rate', get_data_functions=data_funcs) acute_mi.allow_self_transitions() acute_mi.add_transition(post_mi) post_mi.allow_self_transitions() data_funcs = { 'transition_rate': lambda builder, *_: builder.data.load( 'cause.ischemic_heart_disease.incidence_rate') } post_mi.add_transition(acute_mi, source_data_type='rate', get_data_functions=data_funcs) return DiseaseModel('ischemic_heart_disease', states=[susceptible, acute_mi, post_mi])
def SI(cause: str) -> DiseaseModel: healthy = SusceptibleState(cause) infected = DiseaseState(cause) healthy.allow_self_transitions() healthy.add_transition(infected, source_data_type='rate') infected.allow_self_transitions() return DiseaseModel(cause, states=[healthy, infected])
def setup(self, builder): healthy = SusceptibleState(self.cause) infected = DementiaExcessMortalityState() healthy.allow_self_transitions() healthy.add_transition(infected, source_data_type='rate') infected.allow_self_transitions() builder.components.add_components([DiseaseModel(self.cause, states=[healthy, infected])])
def DiabetesMellitus(): susceptible = SusceptibleState(project_globals.DIABETES_MELLITUS.name) transient = TransientDiseaseState(project_globals.DIABETES_MELLITUS.name) moderate = DiseaseState( f'moderate_{project_globals.DIABETES_MELLITUS.name}', cause_type='sequela', ) severe = DiseaseState( f'severe_{project_globals.DIABETES_MELLITUS.name}', cause_type='sequela', ) # Self transitions susceptible.allow_self_transitions() moderate.allow_self_transitions() severe.allow_self_transitions() # Transitions from Susceptible susceptible.add_transition(transient, source_data_type='rate') # Transitions from Transient data_funcs = { 'proportion': lambda _, builder: builder.data.load(project_globals.DIABETES_MELLITUS. MODERATE_DIABETES_PROPORTION) } transient.add_transition(moderate, source_data_type='proportion', get_data_functions=data_funcs) data_funcs = { 'proportion': lambda _, builder: builder.data.load(project_globals.DIABETES_MELLITUS. SEVERE_DIABETES_PROPORTION) } transient.add_transition(severe, source_data_type='proportion', get_data_functions=data_funcs) # Remission transitions data_funcs = { 'transition_rate': lambda builder, *_: builder.data.load(project_globals.DIABETES_MELLITUS .REMISSION_RATE) } moderate.add_transition(susceptible, source_data_type='rate', get_data_functions=data_funcs) severe.add_transition(susceptible, source_data_type='rate', get_data_functions=data_funcs) return DiabetesDiseaseModel( project_globals.DIABETES_MELLITUS.name, states=[susceptible, transient, moderate, severe])
def SIS_fixed_duration(cause: str, duration: str) -> DiseaseModel: duration = pd.Timedelta(days=float(duration) // 1, hours=(float(duration) % 1) * 24.0) healthy = SusceptibleState(cause) infected = DiseaseState(cause, get_data_functions={'dwell_time': lambda _, __: duration}) healthy.allow_self_transitions() healthy.add_transition(infected, source_data_type='rate') infected.add_transition(healthy) infected.allow_self_transitions() return DiseaseModel(cause, states=[healthy, infected])
def NeonatalSIS(cause): with_condition_data_functions = {'birth_prevalence': lambda cause, builder: builder.data.load(f"cause.{cause}.birth_prevalence")} healthy = SusceptibleState(cause) with_condition = DiseaseState(cause, get_data_functions=with_condition_data_functions) healthy.allow_self_transitions() healthy.add_transition(with_condition, source_data_type='rate') with_condition.allow_self_transitions() with_condition.add_transition(healthy, source_data_type='rate') return DiseaseModel(cause, states=[healthy, with_condition])
def Stroke(stroke_name): stroke_types = [ 'ischemic_stroke', 'subarachnoid_hemorrhage', 'intracerebral_hemorrhage' ] if stroke_name not in stroke_types: raise ValueError( f'Stroke name must be one of {stroke_types}. You supplied {stroke_name}' ) susceptible = SusceptibleState(stroke_name) data_funcs = {'dwell_time': lambda *args: pd.Timedelta(days=28)} acute = DiseaseState(f'acute_{stroke_name}', cause_type='sequela', get_data_functions=data_funcs) #data_funcs = {'dwell_time': lambda *args: pd.Timedelta(days=365.25)} post = RelapseState(f'post_{stroke_name}', cause_type='sequela') susceptible.allow_self_transitions() data_funcs = { 'incidence_rate': lambda _, builder: builder.data.load( f'cause.{stroke_name}.incidence_rate') } susceptible.add_transition(acute, source_data_type='rate', get_data_functions=data_funcs) acute.allow_self_transitions() acute.add_transition(post) post.allow_self_transitions() data_funcs = { 'relapse_rate': lambda _, builder: builder.data.load( f'cause.{stroke_name}.incidence_rate') } post.add_transition(acute, source_data_type='rate', get_data_functions=data_funcs) #post.add_transition(susceptible, source_data_type='time') return DiseaseModel(stroke_name, states=[susceptible, acute, post])