0
votes

background first: I have the following agent types: activity and pathway. pathways are agents that contain populations of activities. activities contain specific instructions given to other agents (orders). And pathways are collections of those instructions. The pathway collections are defined via a database where each row is 1 pathway agent & each column is the String ID of an activity, with the cell value being 0, 1, 2 etc depending on number of each activity allocated to that pathway.

Goal: I need to create a population of activities within the pathway agent at agent startup

What I have tried: I have created a population of activities in Main. Each pathway has an activityList which contains the string ID of all the activities. The intention is when a cell value is 1 or above, the code would pick the corresponding activity agent from main and place it into the population in pathway. Code below, I noticed from other posts an index is used to go through rows, but this does not seem to work for columns.

Problem: I cannot get the code to search the columns dynamically, based on the list of string IDs

activityIndex = 0;
// there are 115 activities in the list, the code would repeat for each one
while (activityIndex <= 114)
{
    activityName = activityList.get(activityIndex);
// search below returns the cell value from row with pathway ID = agAssess
// it searches the column with string ID matching activityName
// note: error returned as the database does not contain a column named "activityName"
// in this case "activityName" in the search below would need to be replaced with the parameter's value
// error message: activityName cannot be resolved or is not a field
    double value = selectFrom(activity_groups_assess).
        where(activity_groups_assess.code.eq(agAssess)).
        uniqueResult(activity_groups_assess.activityName);
// if the value > 0, create agent with string ID activityName
// for agents with value > 1, multiple agents with the same string ID would be created, hence while function
    while (value > 0)
    {
// find the agent with the same string ID
        Activity newActivity = findFirst(main.activities, p -> p.code == activityName);
// add agent to population activitiesAssess
// error when adding agent: Description: The method add_activitiesAssess() in the type ClinicalPathway is not applicable for the arguments (Activity).
        add_activitiesAssess( newActivity );
        value--;
    }
    activityIndex++;
}
2

2 Answers

0
votes

Maybe this helps:

You can store a reference to a database table in a variable by using the following type:

com.mysema.query.sql.RelationalPathBase

When selecting values of double (int, String, etc.) type in a particular column, you may get the column by index calling variable.getColumns().get(index). Then you need to cast it to the corresponding type like below:

List<Double> resultRows = selectFrom(variable).where( ( (com.mysema.query.types.path.NumberPath<Double>) variable.getColumns().get(1) ).eq(2.0)) .list(( (com.mysema.query.types.path.NumberPath<Double>) variable.getColumns().get(1) ));

0
votes

Could I clarify first, so what you have is a table that looks like this:

Pathway id Activity 1 Activity 2 Activity 3
one 0 3 2
two 1 0 1
three 1 1 0

And you'd like to create 3 'Activity 2' and 2 'Activity 3' agent in Path 'one' agent. Is that correct?

If so, I am afraid there isn't a clean way to do it 'out-of-the-box'. I would suggest reading one row at a time and then calling 'add_activity'. So code looks something like the below.

List<Tuple> records = selectFrom(testdbtable).list();
records.forEach(rec -> {
    String pathway = rec.get(testdbtable.pathway);
    testdbtable.getColumns().forEach(col -> {
        String activityName = col.getMetadata().getName(); // <-  this is the column name which in your case is Activity Id
        if (!activityName.equalsIgnoreCase(testdbtable.pathway.getMetadata().getName())) {
            int activityCount = (int)rec.get(col);
            // ... and below you add Acitivity agent to Pathway agent
            traceln("Pathway [%s], Activity [%s] -> count is %d", pathway, activityName, activityCount); 
        }
    });
});

The above code produces the following output:

Pathway [one], Activity [activity1] -> count is 0
Pathway [one], Activity [activity2] -> count is 3
Pathway [one], Activity [activity3] -> count is 2
Pathway [one], Activity [al_id] -> count is 0
Pathway [two], Activity [activity1] -> count is 1
Pathway [two], Activity [activity2] -> count is 0
Pathway [two], Activity [activity3] -> count is 1
Pathway [two], Activity [al_id] -> count is 1
Pathway [three], Activity [activity1] -> count is 1
Pathway [three], Activity [activity2] -> count is 1
Pathway [three], Activity [activity3] -> count is 0
Pathway [three], Activity [al_id] -> count is 2

So you just need add your code for creating appropriate Activity agents after the traceln statement. Hope that helps.