示例#1
0
    bool HIVSimpleDiagnostic::AbortDueToCurrentCascadeState()
    {
        IHIVCascadeOfCare *ihcc = nullptr;
        if ( s_OK != parent->GetInterventionsContext()->QueryInterface(GET_IID(IHIVCascadeOfCare), (void **)&ihcc) )
        {
            throw QueryInterfaceException( __FILE__, __LINE__, __FUNCTION__,
                                           "parent->GetInterventionsContext()",
                                           "IHIVCascadeOfCare",
                                           "IIndividualHumanInterventionsContext" );
        }

        std::string currentState = ihcc->getCascadeState();

        if ( abortStates.find(currentState) != abortStates.end() )
        {

            // Duplicated from SimpleDiagnostic::positiveTestDistribute
            INodeTriggeredInterventionConsumer* broadcaster = nullptr;
            if (s_OK != parent->GetEventContext()->GetNodeEventContext()->QueryInterface(GET_IID(INodeTriggeredInterventionConsumer), (void**)&broadcaster))
            {
                throw QueryInterfaceException( __FILE__, __LINE__, __FUNCTION__, "parent->GetEventContext()->GetNodeEventContext()", "INodeTriggeredInterventionConsumer", "INodeEventContext" );
            }

            broadcaster->TriggerNodeEventObservers( parent->GetEventContext(), IndividualEventTriggerType::CascadeStateAborted );
            LOG_DEBUG_F("The current cascade state \"%s\" is one of the Abort_States.  Expiring the diagnostic for individual %d.\n", currentState.c_str(), parent->GetSuid().data );
            expired = true;

            return true;
        }
        return false;
    }
示例#2
0
    void IndividualHumanMalaria::setupMaternalAntibodies(IIndividualHumanContext* mother, INodeContext* node)
    {
        if ( mother )
        {
            IMalariaHumanContext* malaria_mother;
            if( s_OK != mother->QueryInterface(GET_IID(IMalariaHumanContext), (void**)&malaria_mother) )
            {
                throw QueryInterfaceException( __FILE__, __LINE__, __FUNCTION__, "mother", "IMalariaHumanContext", "IIndividualHumanContext" );
            }

            // If we are using individual pregnancies, initialize maternal antibodies dependent on mother's antibody history
            malaria_susceptibility->init_maternal_antibodies(malaria_mother->GetMalariaSusceptibilityContext()->get_fraction_of_variants_with_antibodies(MalariaAntibodyType::PfEMP1_major));
        }
        else
        {
            INodeMalaria* malaria_node;
            if( s_OK != node->QueryInterface(GET_IID(INodeMalaria), (void**)&malaria_node) )
            {
                throw QueryInterfaceException( __FILE__, __LINE__, __FUNCTION__, "node", "INodeMalaria", "INodeContext" );
            }

            // If we are doing births at population level, use the average antibody history of all possible mothers
            malaria_susceptibility->init_maternal_antibodies(malaria_node->GetMaternalAntibodyFraction());
        }
    }
示例#3
0
    void
    DiagnosticTreatNeg::onPatientDefault()
    {
        LOG_DEBUG_F( "Individual %d got the test but defaulted, receiving Defaulters intervention without waiting for days_to_diagnosis (actually means days_to_intervention) \n", parent->GetSuid().data );

        // Important: Use the instance method to obtain the intervention factory obj instead of static method to cross the DLL boundary
        IGlobalContext *pGC = nullptr;
        const IInterventionFactory* ifobj = nullptr;
        if (s_OK == parent->QueryInterface(GET_IID(IGlobalContext), (void**)&pGC))
        {
            ifobj = pGC->GetInterventionFactory();
        }
        if (!ifobj)
        {
            throw NullPointerException( __FILE__, __LINE__, __FUNCTION__, "parent->GetInterventionFactoryObj()" );
        }


        if( !defaulters_event.IsUninitialized() )
        {
            if( defaulters_event != NO_TRIGGER_STR )
            {
                INodeTriggeredInterventionConsumer* broadcaster = nullptr;

                if (s_OK != parent->GetEventContext()->GetNodeEventContext()->QueryInterface(GET_IID(INodeTriggeredInterventionConsumer), (void**)&broadcaster))

                {

                    throw QueryInterfaceException( __FILE__, __LINE__, __FUNCTION__, "parent->GetEventContext()->GetNodeEventContext()", "INodeTriggeredInterventionConsumer", "INodeEventContext" );
                }
                broadcaster->TriggerNodeEventObserversByString( parent->GetEventContext(), defaulters_event );
            }
        }
        else if( defaulters_config._json.Type() != ElementType::NULL_ELEMENT )
        {
            auto tmp_config = Configuration::CopyFromElement(defaulters_config._json);

            // Distribute the defaulters intervention, right away (do not use the days_to_diagnosis
            IDistributableIntervention *di = const_cast<IInterventionFactory*>(ifobj)->CreateIntervention( tmp_config );

            delete tmp_config;
            tmp_config = nullptr;

            ICampaignCostObserver* pICCO;
            // Now make sure cost of the test-positive intervention is reported back to node
            if (s_OK == parent->GetEventContext()->GetNodeEventContext()->QueryInterface(GET_IID(ICampaignCostObserver), (void**)&pICCO) )
            {
                di->Distribute( parent->GetInterventionsContext(), pICCO );
                pICCO->notifyCampaignEventOccurred( (IBaseIntervention*)di, (IBaseIntervention*)this, parent );
            }
            else
            {
                throw QueryInterfaceException( __FILE__, __LINE__, __FUNCTION__, "parent->GetEventContext()->GetNodeEventContext()", "ICampaignCostObserver", "INodeEventContext" );
            }
        }
        else
        {
            throw GeneralConfigurationException( __FILE__, __LINE__, __FUNCTION__, "neither event or config defined" );
        }
    }
示例#4
0
    void DiagnosticTreatNeg::negativeTestDistribute()
    {

        LOG_DEBUG_F( "Individual %d tested 'negative', receiving negative intervention.\n", parent->GetSuid().data );
        // Important: Use the instance method to obtain the intervention factory obj instead of static method to cross the DLL boundary
        IGlobalContext *pGC = nullptr;
        const IInterventionFactory* ifobj = nullptr;
        if (s_OK == parent->QueryInterface(GET_IID(IGlobalContext), (void**)&pGC))
        {
            ifobj = pGC->GetInterventionFactory();
        }
        if (!ifobj)
        {
            throw NullPointerException( __FILE__, __LINE__, __FUNCTION__, "parent->GetInterventionFactoryObj()" );
        }

        if( use_event_or_config == EventOrConfig::Event )
        {
            INodeTriggeredInterventionConsumer* broadcaster = nullptr;

            if (s_OK != parent->GetEventContext()->GetNodeEventContext()->QueryInterface(GET_IID(INodeTriggeredInterventionConsumer), (void**)&broadcaster))

            {

                throw QueryInterfaceException( __FILE__, __LINE__, __FUNCTION__, "parent->GetEventContext()->GetNodeEventContext()", "INodeTriggeredInterventionConsumer", "INodeEventContext" );
            }
            broadcaster->TriggerNodeEventObservers( parent->GetEventContext(), negative_diagnosis_event );
        }
        else if( negative_diagnosis_config._json.Type() != ElementType::NULL_ELEMENT )
        {
            auto tmp_config = Configuration::CopyFromElement( negative_diagnosis_config._json, "campaign" );

            // Distribute the test-negative intervention
            IDistributableIntervention *di = const_cast<IInterventionFactory*>(ifobj)->CreateIntervention( tmp_config );

            delete tmp_config;
            tmp_config = nullptr;

            ICampaignCostObserver* pICCO;
            // Now make sure cost of the test-positive intervention is reported back to node
            if (s_OK == parent->GetEventContext()->GetNodeEventContext()->QueryInterface(GET_IID(ICampaignCostObserver), (void**)&pICCO) )
            {
                di->Distribute( parent->GetInterventionsContext(), pICCO );
                pICCO->notifyCampaignEventOccurred( (IBaseIntervention*)di, (IBaseIntervention*)this, parent );
            }
            else
            {
                throw QueryInterfaceException( __FILE__, __LINE__, __FUNCTION__, "parent->GetEventContext()->GetNodeEventContext()", "ICampaignCostObserver", "INodeEventContext" );
            }
        }
        else
        {
            throw GeneralConfigurationException( __FILE__, __LINE__, __FUNCTION__, "neither event or config defined" );
        }
        expired = true;
    }
    bool
    NodeLevelHealthTriggeredIV::Distribute(
        INodeEventContext *pNodeEventContext,
        IEventCoordinator2 *pEC
    )
    {
        bool was_distributed = BaseNodeIntervention::Distribute(pNodeEventContext, pEC);
        if (was_distributed)
        {
            LOG_DEBUG_F("Distributed Nodelevel health-triggered intervention to NODE: %d\n", pNodeEventContext->GetId().data);

            // QI to register ourself as a NodeLevelHealthTriggeredIV observer
            INodeTriggeredInterventionConsumer * pNTIC = nullptr;
            if (s_OK != pNodeEventContext->QueryInterface(GET_IID(INodeTriggeredInterventionConsumer), (void**)&pNTIC))
            {
                throw QueryInterfaceException(__FILE__, __LINE__, __FUNCTION__, "pNodeEventContext", "INodeTriggeredInterventionConsumer", "INodeEventContext");
            }
            release_assert(pNTIC);
            for (auto &trigger : m_trigger_conditions)
            {
                pNTIC->RegisterNodeEventObserver((IIndividualEventObserver*)this, trigger);
            }
        }
        return was_distributed;
    }
示例#6
0
    bool DiagnosticTreatNeg::positiveTestResult()
    {
        LOG_DEBUG_F("Individual %d is taking the test \n", parent->GetSuid().data);
        
        //This test is the same as smear, but if you are smear neg you can get a different intervention

        // Apply diagnostic test with given specificity/sensitivity
        IIndividualHumanTB2* tb_ind = nullptr;
        if(parent->QueryInterface( GET_IID( IIndividualHumanTB2 ), (void**)&tb_ind ) != s_OK)
        {
            LOG_WARN("DiagnosticTreatNeg works with TB sims ONLY");
            throw QueryInterfaceException( __FILE__, __LINE__, __FUNCTION__, "parent", "IIndividualHumanTB2", "IIndividualHuman" );
        }

        bool activeinf = tb_ind->HasActiveInfection() && !tb_ind->HasActivePresymptomaticInfection();

        if (activeinf)
        {
            // True positive (sensitivity), or False positive (1-specificity)
            bool smearpos = tb_ind->IsSmearPositive();
            bool positiveTest = applySensitivityAndSpecificity( smearpos );
            LOG_DEBUG_F("Individual %d is active %d, smearpos %d, Test sensitivity is %f, result is %d \n", parent->GetSuid().data, activeinf, smearpos, (float) base_sensitivity, positiveTest);
            return positiveTest;
        }
        else
        { 
            LOG_DEBUG("Got a negative result \n");
            return false;
        }
    }
    void MultiEffectBoosterVaccine::ApplyPrimingAndBoostingEffects(IIndividualHumanInterventionsContext *context)
    {
        IDrugVaccineInterventionEffects* idvie = nullptr;
        if (s_OK != context->QueryInterface(GET_IID(IDrugVaccineInterventionEffects), (void**)&idvie) )
        {
            throw QueryInterfaceException( __FILE__, __LINE__, __FUNCTION__, "context", "IDrugVaccineInterventionEffects", "IIndividualHumanInterventionsContext" );
        }
        ISusceptibilityContext* isc = context->GetParent()->GetSusceptibilityContext();

        float acquisition_immunity =  idvie->GetInterventionReducedAcquire()*  isc->getModAcquire();
        float transmission_immunity = idvie->GetInterventionReducedTransmit()* isc->getModTransmit();
        float mortality_immunity =    idvie->GetInterventionReducedMortality()*isc->getModMortality();
        
        acquire_effect->SetInitial(prime_acquire);
        transmit_effect->SetInitial(prime_transmit);
        mortality_effect->SetInitial(prime_mortality);
        if (acquisition_immunity < (1.0f - boost_threshold_acquire) )
        {
            acquire_effect->SetInitial(boost_acquire);  
        }
        if (transmission_immunity < (1.0f - boost_threshold_transmit) ) 
        {
            transmit_effect->SetInitial(boost_transmit);   
        }
        if (mortality_immunity < (1.0f - boost_threshold_mortality) ) 
        {
            mortality_effect->SetInitial(boost_mortality);   
        }
    }
    void HIVInterventionsContainer::OnTestForHIV(bool test_result)
    {

        if( test_result && !ever_tested_HIV_positive)
        {
            INodeTriggeredInterventionConsumer* broadcaster = nullptr;
            if (s_OK != parent->GetEventContext()->GetNodeEventContext()->QueryInterface(GET_IID(INodeTriggeredInterventionConsumer), (void**)&broadcaster))
            {
                throw QueryInterfaceException( __FILE__, __LINE__, __FUNCTION__, 
                                               "parent->GetEventContext()->GetNodeEventContext()", 
                                               "INodeTriggeredInterventionConsumer", 
                                               "INodeEventContext" );
            }

            broadcaster->TriggerNodeEventObservers( parent->GetEventContext(), EventTrigger::HIVNewlyDiagnosed );
        }

        ever_tested = true;
        if (test_result)
        {
           ever_tested_HIV_positive = true;
        }
        float t = parent->GetEventContext()->GetNodeEventContext()->GetTime().time;
        time_of_most_recent_test = t;
        time_last_seen_by_healthcare = t;
    }
示例#9
0
    void HIVDelayedIntervention::Update(float dt)
    {
        if( !DelayedIntervention::UpdateIndividualsInterventionStatus() )
        {
            return;
        }

        days_remaining -= dt;
        if( days_remaining < 0 )
        {
            expired = true;

            INodeTriggeredInterventionConsumer* broadcaster = nullptr;
            if (s_OK != parent->GetEventContext()->GetNodeEventContext()->QueryInterface(GET_IID(INodeTriggeredInterventionConsumer), (void**)&broadcaster))
            {
                throw QueryInterfaceException( __FILE__, __LINE__, __FUNCTION__, "parent->GetEventContext()->GetNodeEventContext()", "INodeTriggeredInterventionConsumer", "INodeEventContext" );
            }
            if( !broadcast_on_expiration_event.IsUninitialized() )
            {
                broadcaster->TriggerNodeEventObservers( parent->GetEventContext(), broadcast_on_expiration_event );
            }
            LOG_DEBUG_F("broadcast on expiration event\n");

            LOG_DEBUG_F("expiring before delay-triggered intervention\n");
            return;
        }

        remaining_delay_days.Decrement( dt );
    }
示例#10
0
    IIndividualHuman*
    NodeSTI::processImmigratingIndividual(
        IIndividualHuman* movedind
    )
    {
        // -------------------------------------------------------------------------------
        // --- SetContextTo() is called in Node::processImmigratingIndividual() but
        // --- we need need to set context before onImmigrating().  onImmigrating() needs
        // --- the RelationshipManager which is part of the node.
        // -------------------------------------------------------------------------------
        movedind->SetContextTo(getContextPointer());

        IIndividualHumanSTI* sti_individual = nullptr;
        if (movedind->QueryInterface(GET_IID(IIndividualHumanSTI), (void**)&sti_individual) != s_OK)
        {
            throw QueryInterfaceException( __FILE__, __LINE__, __FUNCTION__, "retVal", "IIndividualSTI", "IndividualHuman" );
        }
        sti_individual->onImmigrating();

        auto retVal = Node::processImmigratingIndividual( movedind );

        event_context_host->TriggerNodeEventObservers( retVal->GetEventContext(), IndividualEventTriggerType::STIPostImmigrating );

        return retVal;
    }
    bool CommunityHealthWorkerEventCoordinator::Distribute( IIndividualHumanEventContext* pIHEC )
    {
        release_assert( m_pInterventionIndividual );

        IDistributableIntervention *di = m_pInterventionIndividual->Clone();
        release_assert(di);

        ICampaignCostObserver* p_icco = nullptr;
        if (s_OK != pIHEC->GetNodeEventContext()->QueryInterface(GET_IID(ICampaignCostObserver), (void**)&p_icco))
        {
            throw QueryInterfaceException( __FILE__, __LINE__, __FUNCTION__, "pIHEC->GetNodeEventContext()", "ICampaignCostObserver", "INodeEventContext" );
        }

        di->AddRef();

        bool distributed = di->Distribute( pIHEC->GetInterventionsContext(), p_icco );

        if( distributed )
        {
            LOG_DEBUG_F("Distributed '%s' intervention to individual %d\n", m_InterventionName.c_str(), pIHEC->GetSuid().data );
        }

        di->Release();

        return distributed;
    }
示例#12
0
    // todo: lift to HIVIntervention or helper function (repeated in HIVDelayedIntervention)
    bool HIVSimpleDiagnostic::UpdateCascade()
    {
        if( AbortDueToCurrentCascadeState() )
        {
            return false ;
        }

        // is this the first time through?  if so, update the cascade state.
        if (firstUpdate)
        {
            IHIVCascadeOfCare *ihcc = nullptr;
            if ( s_OK != parent->GetInterventionsContext()->QueryInterface(GET_IID(IHIVCascadeOfCare), (void **)&ihcc) )
            {
                throw QueryInterfaceException( __FILE__, __LINE__, __FUNCTION__,
                                               "parent->GetInterventionsContext()",
                                               "IHIVCascadeOfCare",
                                               "IIndividualHumanInterventionsContext" );
            }
            LOG_DEBUG_F( "Setting Cascade State to %s for individual %d.\n", cascadeState.c_str(), parent->GetSuid().data );
            ihcc->setCascadeState(cascadeState);

            original_days_to_diagnosis = days_to_diagnosis;
        }
        return true ;
    }
    void NodeLevelHealthTriggeredIVScaleUpSwitch::onDisqualifiedByCoverage(
                IIndividualHumanEventContext *pIndiv
    )
    {
        //if qualify by everything except demographic coverage, give the not_covered_individualintervention_config 
        // this intervention is the one phased out as the actual_individualintervention_config is phased in
        // if the not_covered_individualintervention_config is NULL, then there is no intervention to phase out
        LOG_DEBUG("The person qualified by everything except demographic coverage, give the not_covered_individualintervention_config \n");


        // Query for campaign cost observer interface from INodeEventContext *parent
        ICampaignCostObserver *iCCO;
        if (s_OK != parent->QueryInterface(GET_IID(ICampaignCostObserver), (void**)&iCCO))
        {
            throw QueryInterfaceException( __FILE__, __LINE__, __FUNCTION__, "parent", "ICampaignCostObserver", "INodeEventContext" );
        }

        // Important: Use the instance method to obtain the intervention factory obj instead of static method to cross the DLL boundary
        //const IInterventionFactory* ifobj = dynamic_cast<NodeEventContextHost *>(parent)->GetInterventionFactoryObj();
        IGlobalContext *pGC = nullptr;
        const IInterventionFactory* ifobj = nullptr;
        if (s_OK == parent->QueryInterface(GET_IID(IGlobalContext), (void**)&pGC))
        {
            ifobj = pGC->GetInterventionFactory();
        }
        if (!ifobj)
        {
            throw GeneralConfigurationException( __FILE__, __LINE__, __FUNCTION__, "The pointer to IInterventionFactory object is not valid (could be DLL specific)" );
        }

        const json::Array & interventions_array = json::QuickInterpreter(not_covered_intervention_configs._json).As<json::Array>();
        LOG_DEBUG_F("not_covered_intervention_configs array size = %d\n", interventions_array.Size());
       
        if (interventions_array.Size() == 0 )
        {
            LOG_DEBUG("nothing to phase out \n"); 
        }
        else
        {
            for( int idx=0; idx<interventions_array.Size(); idx++ )
            {
                const json::Object& notcoveredIntervention = json_cast<const json::Object&>(interventions_array[idx]);
                Configuration * tmpConfig = Configuration::CopyFromElement( notcoveredIntervention, "campaign" );
                assert( tmpConfig );
                LOG_DEBUG_F("NodeHTIScaleUpSwitch will distribute notcoveredintervention #%d\n", idx);

                IDistributableIntervention *di = const_cast<IInterventionFactory*>(ifobj)->CreateIntervention(tmpConfig); 
                delete tmpConfig;
                tmpConfig = nullptr;

                if( di )
                {
                    di->Distribute( pIndiv->GetInterventionsContext(), iCCO );
                    LOG_DEBUG("A Node level health-triggered intervention was successfully distributed, gave the not_covered_intervention_configs\n");
                    // It's not at all clear to me that we would incur cost at this point, but we could.
                    //iCCO->notifyCampaignExpenseIncurred( interventionCost, pIndiv );
                }
            }
         }       
    }
 IIndividualHumanHIV* HIVRelationshipStartReporter::GetIndividualHumanHIV( IIndividualHumanSTI* pPartner )
 {
     IIndividualHumanHIV* p_hiv_individual = nullptr;
     if( pPartner->QueryInterface(GET_IID(IIndividualHumanHIV), (void**)&p_hiv_individual) != s_OK )
     {
         throw QueryInterfaceException( __FILE__, __LINE__, __FUNCTION__, "pPartner", "IIndividualHumanHIV", "IIndividualHumanSTI*" );
     }
     return p_hiv_individual ;
 }
 IHIVMedicalHistory* HIVRelationshipStartReporter::GetMedicalHistory( IIndividualHumanHIV* pPartner )
 {
     IHIVMedicalHistory * p_med_history = nullptr;
     if( pPartner->GetHIVInterventionsContainer()->QueryInterface(GET_IID(IHIVMedicalHistory), (void**)&p_med_history) != s_OK)
     {
         throw QueryInterfaceException( __FILE__, __LINE__, __FUNCTION__, "pPartner->GetHIVInterventionsContainer()", "IHIVMedicalHistory", "IHIVInterventionsContainer" );
     }
     return p_med_history ;
 }
    bool ReferenceTrackingEventCoordinatorHIV::qualifiesDemographically( const IIndividualHumanEventContext * pIndividual )
    {
        bool qualifies = ReferenceTrackingEventCoordinator::qualifiesDemographically( pIndividual );
        if( qualifies )
        {
            IIndividualHumanHIV* p_hiv_individual = nullptr;
            if(const_cast<IIndividualHumanEventContext*>(pIndividual)->QueryInterface( GET_IID( IIndividualHumanHIV ), (void**)&p_hiv_individual ) != s_OK)
            {
                throw QueryInterfaceException( __FILE__, __LINE__, __FUNCTION__, "pIndividual", "IIndividualHumanHIV", "IIndividualHumanEventContext" );
            }

            IHIVInterventionsContainer* p_hiv_container = p_hiv_individual->GetHIVInterventionsContainer();
            IHIVMedicalHistory* p_med_history = nullptr;
            if( p_hiv_container->QueryInterface( GET_IID( IHIVMedicalHistory ), (void**)&p_med_history ) != s_OK)
            {
                throw QueryInterfaceException( __FILE__, __LINE__, __FUNCTION__, "p_hiv_container", "IHIVMedicalHistory", "IHIVInterventionsContainer" );
            }

            switch( target_disease_state )
            {
                case TargetDiseaseStateType::Everyone:
                    qualifies = true;
                    break;
                case TargetDiseaseStateType::HIV_Positive:
                    qualifies = p_hiv_individual->HasHIV();
                    break;
                case TargetDiseaseStateType::HIV_Negative:
                    qualifies = !p_hiv_individual->HasHIV();
                    break;
                case TargetDiseaseStateType::Tested_Positive:
                    qualifies = p_med_history->EverTestedHIVPositive();
                    break;
                case TargetDiseaseStateType::Tested_Negative:
                    qualifies = p_med_history->EverTested() && !p_med_history->EverTestedHIVPositive();
                    break;
                case TargetDiseaseStateType::Not_Tested_Or_Tested_Negative:
                    qualifies = !p_med_history->EverTested() || !p_med_history->EverTestedHIVPositive();
                    break;
                default:
                    throw BadEnumInSwitchStatementException( __FILE__, __LINE__, __FUNCTION__, "target_disease_state", target_disease_state );
            }
        }
        return qualifies;
    }
示例#17
0
    void NodeSTI::Update( float dt )
    {
        // Update relationships (dissolution only, at this point)
        list<IIndividualHuman*> population;  //not used by RelationshipManager
        relMan->Update( population, transmissionGroups, dt );

        society->BeginUpdate();

        for (auto& person : individualHumans)
        {
            IIndividualHumanSTI* sti_person = nullptr;
            if (person->QueryInterface(GET_IID(IIndividualHumanSTI), (void**)&sti_person) != s_OK)
            {
                throw QueryInterfaceException( __FILE__, __LINE__, __FUNCTION__, "person", "IIndividualHumanSTI", "IIndividualHuman" );
            }
            sti_person->UpdateEligibility();        // DJK: Could be slow to do this on every update.  Could check for relationship status changes. <ERAD-1869>
        }

        if (pfa_burnin_duration > 0)
        {
            pfa_burnin_duration -= dt;
            society->UpdatePairFormationRates( GetTime(), dt );
        }

        for (auto& person : individualHumans)
        {
            IIndividualHumanSTI* sti_person = nullptr;
            if (person->QueryInterface(GET_IID(IIndividualHumanSTI), (void**)&sti_person) != s_OK)
            {
                throw QueryInterfaceException( __FILE__, __LINE__, __FUNCTION__, "person", "IIndividualHumanSTI", "IIndividualHuman" );
            }
            sti_person->ConsiderRelationships(dt);
        }

        society->UpdatePairFormationAgents( GetTime(), dt );

        {
            RouteToContagionDecayMap_t decayMap;
            decayMap[string("contact")] = 1.0f; 
            transmissionGroups->Build( decayMap, 1, 1 );
        }

        Node::Update( dt );
    }
    std::string HIVReportEventRecorder::GetOtherData( IIndividualHumanEventContext *context, 
                                                      const std::string& StateChange )
    {
        IIndividualHumanHIV * iindividual_hiv = nullptr;
        if (s_OK != context->QueryInterface(GET_IID(IIndividualHumanHIV), (void**)&iindividual_hiv) )
        {
            throw QueryInterfaceException(__FILE__, __LINE__, __FUNCTION__, "context", "IIndividualHumanHIV", "IIndividualHumanEventContext");
        }
        const char  has_hiv    = iindividual_hiv->HasHIV() ? 'Y' : 'N' ;

        const char  on_ART = iindividual_hiv->GetHIVInterventionsContainer()->OnArtQuery() ? 'Y' : 'N' ;

        float cd4 = 1e6;
        float who_stage = -1.0f;
        if( iindividual_hiv->HasHIV() )
        {
            cd4       = iindividual_hiv->GetHIVSusceptibility()->GetCD4count();
            who_stage = iindividual_hiv->GetHIVInfection()->GetWHOStage();
        }

        IHIVCascadeOfCare *ihcc = nullptr;
        if ( s_OK != context->GetInterventionsContext()->QueryInterface(GET_IID(IHIVCascadeOfCare), (void **)&ihcc) )
        {
            throw QueryInterfaceException( __FILE__, __LINE__, __FUNCTION__, "context->GetInterventionsContext()", "IHIVCascadeOfCare", "IIndividualHumanEventContext" );
        }

        std::string cascade_state = ihcc->getCascadeState();

        if( cascade_state.length() == 0 )
        {
            cascade_state = "None";
        }

        std::stringstream ss ;
        ss                   << ","
           << has_hiv       << ","
           << on_ART        << ","
           << cd4           << ","
           << who_stage     << ","
           << cascade_state;

        return ss.str() ;
    }
示例#19
0
文件: Bednet.cpp 项目: clorton/EMOD
 void AbstractBednet::SetContextTo( IIndividualHumanContext *context )
 {
     BaseIntervention::SetContextTo( context );
     if( s_OK != context->GetInterventionsContext()->QueryInterface( GET_IID( IBednetConsumer ), (void**)&m_pConsumer ) )
     {
         throw QueryInterfaceException( __FILE__, __LINE__, __FUNCTION__, "context", "IBednetConsumer", "IIndividualHumanContext" );
     }
     m_pEffectKilling->SetContextTo( context );
     m_pEffectBlocking->SetContextTo( context );
 }
示例#20
0
    void HIVInterventionsContainer::SetContextTo(IIndividualHumanContext* context)
    {
        STIInterventionsContainer::SetContextTo( context );
        release_assert( parent );

        if( s_OK != parent->QueryInterface(GET_IID(IIndividualHumanHIV), (void**) &hiv_parent) )
        {
            throw QueryInterfaceException( __FILE__, __LINE__, __FUNCTION__, "parent", "IIndividualHumanHIV", "IIndividualHumanContext" );
        }
    }
示例#21
0
    void HIVInterventionsContainer::BroadcastNewHIVInfection()
    {
        //function called when we externally put in HIV infections through AcquireInfectionHIV
        //first get the pointer to the person, parent is the generic individual
        release_assert(parent);

        IIndividualHumanEventContext * HIVEventContext = NULL;
        if (s_OK != parent->QueryInterface(GET_IID(IIndividualHumanEventContext), (void**)&HIVEventContext))
        {
            throw QueryInterfaceException(__FILE__, __LINE__, __FUNCTION__, "parent->GetEventContext()->GetNodeEventContext()", "INodeTriggeredInterventionConsumer", "INodeEventContext");
        }

        INodeTriggeredInterventionConsumer* broadcaster = nullptr;
        if (s_OK != HIVEventContext->GetNodeEventContext()->QueryInterface(GET_IID(INodeTriggeredInterventionConsumer), (void**)&broadcaster))
        {
            throw QueryInterfaceException(__FILE__, __LINE__, __FUNCTION__, "HIVEventContext-->GetNodeEventContext()", "INodeTriggeredInterventionConsumer", "INodeEventContext");
        }
        broadcaster->TriggerNodeEventObservers(parent->GetEventContext(), EventTrigger::NewExternalHIVInfection);
    }
示例#22
0
 void PropertyValueChanger::SetContextTo(
     IIndividualHumanContext *context
 )
 {
     parent = context;
     if (s_OK != context->GetInterventionsContext()->QueryInterface(GET_IID(IPropertyValueChangerEffects), (void**)&ibc) )
     {
         throw QueryInterfaceException( __FILE__, __LINE__, __FUNCTION__, "context", "IPropertyValueChangerEffects", "IIndividualHumanContext" );
     }
 }
示例#23
0
 void SimpleVaccine::SetContextTo(
     IIndividualHumanContext *context
 )
 {
     parent = context;
     if (s_OK != parent->GetInterventionsContext()->QueryInterface(GET_IID(IVaccineConsumer), (void**)&ivc) )
     {
         throw QueryInterfaceException( __FILE__, __LINE__, __FUNCTION__, "context->GetInterventionsContext()", "IVaccineConsumer", "IIndividualHumanInterventionsContext" );
     }
     LOG_DEBUG_F( "Vaccine configured with type %d and take %f for individual %d\n", vaccine_type, vaccine_take, parent->GetSuid().data );
 } // needed for VaccineTake
示例#24
0
    void SimpleHousingModification::SetContextTo(
        IIndividualHumanContext *context
    )
    {
        LOG_DEBUG("SimpleHousingModification::SetContextTo (probably deserializing)\n");
        if (s_OK != context->GetInterventionsContext()->QueryInterface(GET_IID(IHousingModificationConsumer), (void**)&ihmc) )
        {
            throw QueryInterfaceException( __FILE__, __LINE__, __FUNCTION__, "context", "IHousingModificationConsumer", "IIndividualHumanContext" );
        }

    }
    void StiRelationshipConsummatedReporter::onNewNode(Kernel::INodeContext* node)
    {
        INodeSTI* sti = nullptr;

        if (node->QueryInterface(GET_IID(INodeSTI), (void**)&sti) != s_OK)
        {
            throw QueryInterfaceException( __FILE__, __LINE__, __FUNCTION__, "node", "INodeSTI*", "INodeContext*" );
        }

        auto manager = sti->GetRelationshipManager();
        manager->RegisterRelationshipConsummationObserver([&](IRelationship* relationship){ this->onCoitalAct(relationship); });
    }
示例#26
0
    void IndividualHumanVector::UpdateInfectiousness(float dt)
    {
        infectiousness = 0;
        float tmp_infectiousness = 0;  

        typedef std::map< StrainIdentity, float >     strain_infectivity_map_t;
        typedef strain_infectivity_map_t::value_type  strain_infectivity_t;
        strain_infectivity_map_t infectivity_by_strain;
        StrainIdentity tmp_strainIDs;

        // Loop once over all infections, caching strains and infectivity.
        // If total infectiousness exceeds unity, we will normalize all strains down accordingly.
        for (auto infection : infections)
        {
            release_assert( infection );
            tmp_infectiousness = infection->GetInfectiousness();
            infectiousness += tmp_infectiousness;

            if ( tmp_infectiousness > 0 )
            {
                infection->GetInfectiousStrainID(&tmp_strainIDs);
                infectivity_by_strain[tmp_strainIDs] += tmp_infectiousness;
            }
        }

        // Effects of transmission-reducing immunity.  N.B. interventions on vector success are not here, since they depend on vector-population-specific behavior
        release_assert( susceptibility );
        release_assert( interventions );
        float modtransmit = susceptibility->GetModTransmit() * interventions->GetInterventionReducedTransmit();

        // Maximum individual infectiousness is set here, capping the sum of unmodified infectivity at prob=1
        float truncate_infectious_mod = (infectiousness > 1 ) ? 1.0f/infectiousness : 1.0f;
        infectiousness *= truncate_infectious_mod * modtransmit;

        // Host weight is the product of MC weighting and relative biting
        float host_vector_weight = float(GetMonteCarloWeight() * GetRelativeBitingRate());

        // Effects from vector intervention container
        IVectorInterventionsEffects* ivie = nullptr;
        if ( s_OK !=  interventions->QueryInterface(GET_IID(IVectorInterventionsEffects), (void**)&ivie) )
        {
            throw QueryInterfaceException( __FILE__, __LINE__, __FUNCTION__, "interventions", "IVectorInterventionsEffects", "IndividualHumanVector" );
        }

        // Loop again over infection strains, depositing (downscaled) infectivity modified by vector intervention effects etc. (indoor + outdoor)
        for (auto& infectivity : infectivity_by_strain)
        {
            const StrainIdentity *id = &(infectivity.first);

            parent->DepositFromIndividual( const_cast<StrainIdentity*>(id), host_vector_weight * infectivity.second * truncate_infectious_mod * modtransmit * ivie->GetblockIndoorVectorTransmit(), &NodeVector::human_to_vector_indoor );
            parent->DepositFromIndividual( const_cast<StrainIdentity*>(id), host_vector_weight * infectivity.second * truncate_infectious_mod * modtransmit * ivie->GetblockOutdoorVectorTransmit(), &NodeVector::human_to_vector_outdoor );
        }
    }
示例#27
0
    void IndividualHumanMalaria::PropagateContextToDependents()
    {
        IndividualHumanVector::PropagateContextToDependents();

        if( malaria_susceptibility == nullptr && susceptibility != nullptr)
        {
            if ( s_OK != susceptibility->QueryInterface(GET_IID(IMalariaSusceptibility), (void**)&malaria_susceptibility) )
            {
                throw QueryInterfaceException( __FILE__, __LINE__, __FUNCTION__, "susceptibility", "IMalariaSusceptibility", "Susceptibility" );
            }
        }
    }
示例#28
0
 bool
 PropertyValueChanger::Distribute(
     IIndividualHumanInterventionsContext *context,
     ICampaignCostObserver * const pCCO
 )
 {
     if (s_OK != context->QueryInterface(GET_IID(IPropertyValueChangerEffects), (void**)&ibc) )
     {
         throw QueryInterfaceException( __FILE__, __LINE__, __FUNCTION__, "context", "IPropertyValueChangerEffects", "IIndividualHumanInterventionsContext" );
     }
     return BaseIntervention::Distribute( context, pCCO );
 }
    INodeTriggeredInterventionConsumer* CommunityHealthWorkerEventCoordinator::GetNodeTriggeredConsumer( INodeEventContext* pNEC )
    {
        release_assert( pNEC );
        INodeTriggeredInterventionConsumer* pNTIC = nullptr;
        if( pNEC->QueryInterface( GET_IID(INodeTriggeredInterventionConsumer), (void**)&pNTIC ) != s_OK )
        {
            throw QueryInterfaceException( __FILE__, __LINE__, __FUNCTION__, "pNEC", "INodeTriggeredInterventionConsumer", "INodeEventContext" );
        }
        release_assert( pNTIC );

        return pNTIC ;
    }
示例#30
0
    void PropertyValueChanger::Update( float dt )
    {
        release_assert( expired == false );
        release_assert( ibc );

        std::string current_prop_value = "";
        if( reversion_timer > 0 )
        {
            reversion_timer -= dt;
            if( reversion_timer <= 0 )
            {
                LOG_DEBUG_F( "Time to revert PropertyValueChanger.\n" );
                probability = 1.0;
            }
        }
        if( probability == 1.0 || action_timer < 0 )
        {
            if( revert )
            {
                // Need to ask individual (parent's parent) for current value of this property
                // TBD: use QI not static cast
                auto props = static_cast<InterventionsContainer*>(ibc)->GetParent()->GetEventContext()->GetProperties();
                current_prop_value = props->find( (std::string) target_property_key )->second;
            }
            ibc->ChangeProperty( target_property_key.c_str(), target_property_value.c_str() );

            //broadcast that the individual changed properties
            INodeTriggeredInterventionConsumer* broadcaster = nullptr;
            if (s_OK != parent->GetEventContext()->GetNodeEventContext()->QueryInterface(GET_IID(INodeTriggeredInterventionConsumer), (void**)&broadcaster))
            {
                throw QueryInterfaceException( __FILE__, __LINE__, __FUNCTION__, "parent->GetEventContext()->GetNodeEventContext()", "INodeTriggeredInterventionConsumer", "INodeEventContext" );
            }
            LOG_DEBUG_F( "Individual %d changed property, broadcasting PropertyChange \n", parent->GetSuid().data );
            broadcaster->TriggerNodeEventObservers( parent->GetEventContext(), IndividualEventTriggerType::PropertyChange );


            if( revert )
            {
                target_property_value = current_prop_value;
                probability = 0.0; // keep it simple for now, reversion is guaranteed
                reversion_timer = revert;
                action_timer= FLT_MAX;
                LOG_DEBUG_F( "Initializing reversion timer to %f\n", reversion_timer );
                revert = 0; // no more reversion from reversion
            }
            else
            {
                expired = true;
            }
        }
        action_timer -= dt;
    }