Source code for emodpy_tbhiv.interventions.cd4diag

from emod_api import schema_to_class as s2c
import emod_api.interventions.common as common
import emod_api.interventions.utils as utils
from emodpy_tbhiv.interventions import purge_campaign_event

def _get_thresh( name, low, high, camp ):
    thresh = {}
    thresh["Event"] = camp.get_send_trigger( name )
    thresh["Low"] = low
    thresh["High"] = high
    return thresh

def _get_threshes( group_names, camp ):
    threshes = list()
    threshes.append( _get_thresh( group_names[0], 0, 200, camp ) )
    threshes.append( _get_thresh( group_names[1], 200, 350, camp ) )
    threshes.append( _get_thresh( group_names[2], 350, 500, camp ) )
    threshes.append( _get_thresh( group_names[3], 500, 20000, camp ) )
    return threshes
 
[docs]def CD4Diag( camp, trigger_treatment_list, event_200='Below200', event_350='Below350', event_500='Below500', event_above_500='Above500', start_day=1, duration=-1, property_restrictions_list=[], nodeIDs=[], cost=0, black_period=0, black_trigger='Blackout', event_name='CD4 Diagnostic'): """ Create and return triggered campaign event that issues an CD4Diagnostic intervention. Args: camp: The :py:obj:`emod_api:emod_api.campaign` module instance which serves as the campaign accumulator. trigger_treatment_list: List of 1 or more triggers (or events or signals) which are listened to and trigger the distribution of the intervention. There is no default. event_200: ... event_350: ... event_500: ... event_above_500: ... start_day: The timestep when this campaign event takes effect. Defaults to 1. duration: How long the campaign event remains in effect. Defaults to forever. property_restrictions_list: Optiional list of Individual Properties to limit the intervention to. nodeIDs: Optiona list of node ids to target. Defaults to all. cost: Per unit 'price' of each intervention. black_period: Undocumented. black_trigger: Undocumented. event_name: Undocumented. Returns: New campaign event that can be added to the campaign. """ schema_path = camp.schema_path intervention = s2c.get_class_with_defaults( "CD4Diagnostic", schema_path ) intervention.CD4_Thresholds = _get_threshes( [ event_200, event_350, event_500, event_above_500 ], camp ) intervention.Cost_To_Consumer = cost event = common.TriggeredCampaignEvent( camp, start_day,event_name, trigger_treatment_list, [ intervention ], Node_Ids=nodeIDs, Duration=duration, Property_Restrictions=property_restrictions_list ) purge_campaign_event( event ) return event
[docs]def new_intervention_as_file( camp, filename="cd4.json" ): camp.add( CD4Diag( camp, trigger_treatment_list=[ "Births" ] ) ) camp.save( filename ) return filename