package jobs.table.columns

import com.google.common.collect.ImmutableMap
import groovy.transform.CompileStatic
import org.transmartproject.core.dataquery.clinical.ClinicalVariableColumn
import org.transmartproject.core.dataquery.clinical.PatientRow

@CompileStatic
class SimpleConceptVariableColumn extends AbstractColumn {

    final boolean globalComputation = false

    ClinicalVariableColumn column

    private PatientRow lastRow

    @Override
    void onReadRow(String dataSourceName, Object row) {
        /* if we only subscribe one source, as we should, there calls to
         * onReadRow() are guaranteed to be called interleaved with
         * consumeResultingTableRow */
        assert lastRow == null
        assert row instanceof PatientRow

        lastRow = (PatientRow) row
    }

    @Override
    Map<String, Object> consumeResultingTableRows() {
        if (!lastRow) return ImmutableMap.of()

        def res = ImmutableMap.of(getPrimaryKey(lastRow),
                lastRow.getAt(column))
        lastRow = null
        res
    }

    protected String getPrimaryKey(PatientRow row) {
        lastRow.patient.inTrialId
    }
}

package jobs.table.columns

import com.google.common.collect.ImmutableMap
import groovy.transform.CompileStatic
import org.transmartproject.core.dataquery.clinical.ClinicalVariableColumn
import org.transmartproject.core.dataquery.clinical.PatientRow

@CompileStatic
class SimpleConceptVariableColumn extends AbstractColumn {

    final boolean globalComputation = false

    ClinicalVariableColumn column

    private PatientRow lastRow

    @Override
    void onReadRow(String dataSourceName, Object row) {
        /* if we only subscribe one source, as we should, there calls to
         * onReadRow() are guaranteed to be called interleaved with
         * consumeResultingTableRow */
        assert lastRow == null
        assert row instanceof PatientRow

        lastRow = (PatientRow) row
    }

    @Override
    Map<String, Object> consumeResultingTableRows() {
        if (!lastRow) return ImmutableMap.of()

        def cellValue = lastRow.getAt(column)
        def res

        if (cellValue != null) {
            res = ImmutableMap.of(getPrimaryKey(lastRow), cellValue)
        } else {
            res = ImmutableMap.of()
        }

        lastRow = null
        res
    }

    protected String getPrimaryKey(PatientRow row) {
        lastRow.patient.inTrialId
    }
}

Fix handling of missing clinical data
Fix handling of missing clinical data
