Function: getCultivationPlan()
getCultivationPlan(
fdm
,principal_id
,b_id_farm
,timeframe?
):Promise
<cultivationPlanType
[]>
Defined in: fdm-core/src/cultivation.ts:535
Alpha
Retrieves a comprehensive cultivation plan for a specified farm.
This function aggregates cultivation data from multiple related tables and returns an array of cultivation entries. Each entry includes the catalogue identifier, its name, sowing and termination dates (if available), and an array of fields on which the cultivation was applied. Each field entry details associated fertilizer applications and harvest records (with accompanying analyses).
Parameters
fdm
any
The FDM instance providing the connection to the database. The instance can be created with createFdmServer.
principal_id
any
The identifier of the principal requesting access to the cultivation plan.
b_id_farm
any
The unique ID of the farm for which the cultivation plan is to be retrieved.
timeframe?
Optional timeframe to filter cultivations by start and end dates.
Returns
Promise
<cultivationPlanType
[]>
A Promise that resolves to an array representing the cultivation plan. Each element in the array has the following structure:
{
b_lu_catalogue: string; // Unique ID of the cultivation catalogue item
b_lu_name: string; // Name of the cultivation
b_lu_start: Date; // Sowing date for the cultivation (if available)
b_lu_end: Date; // Termination date for the cultivation (if available)
fields: [
{
b_lu: string; // Unique ID of the cultivation record
b_id: string; // Unique ID of the field
b_name: string; // Name of the field
fertilizer_applications: [
{
p_id_catalogue: string; // Fertilizer catalogue ID
p_name_nl: string; // Fertilizer name (Dutch)
p_app_amount: number; // Amount applied
p_app_method: string; // Application method
p_app_date: Date; // Application date
p_app_id: string; // Unique ID of the fertilizer application
}
],
harvests: [
{
b_id_harvesting: string; // Unique ID of the harvest record
b_lu_harvest_date: Date; // Harvest date
harvestables: [
{
b_id_harvestable: string; // Unique ID of the harvestable
harvestable_analyses: [
{
b_lu_yield: number; // Yield in kg/ha
b_lu_n_harvestable: number; // N content in harvestable yield (g N/kg)
b_lu_n_residue: number; // N content in residue (g N/kg)
b_lu_p_harvestable: number; // P content in harvestable yield (g P2O5/kg)
b_lu_p_residue: number; // P content in residue (g P2O5/kg)
b_lu_k_harvestable: number; // K content in harvestable yield (g K2O/kg)
b_lu_k_residue: number; // K content in residue (g K2O/kg)
}
]
}
]
}
]
}
]
}
If no cultivations are found for the specified farm, an empty array is returned.
Example
const cultivationPlan = await getCultivationPlan(fdm, 'principal123', 'farm123');
if (cultivationPlan.length) {
console.log("Cultivation Plan:", cultivationPlan);
} else {
console.log("No cultivations found for this farm.");
}