journal/tool/lib/journalTypes.jq

115 lines
3.9 KiB
Plaintext
Raw Normal View History

2024-11-09 09:52:33 +00:00
import "typeLib" as typeLib;
2024-11-07 13:10:18 +00:00
2024-11-09 00:49:08 +00:00
def ensureAdministrationRoute:
. as $administrationRoute |
if typeLib::typecheckingEnabled then
[
"ORAL",
"SUBLINGUAL",
"BUCCAL",
"INSUFFLATED",
"RECTAL",
"TRANSDERMAL",
"SUBCUTANEOUS",
"INTRAMUSCULAR",
"INTRAVENOUS",
"SMOKED",
"INHALED"
] | any(index($administrationRoute))
end;
2024-11-07 21:45:22 +00:00
def ensureIngestion:
. as $ingestion |
2024-11-09 00:49:08 +00:00
if typeLib::typecheckingEnabled then
typeLib::ensureObject |
2024-11-07 21:45:22 +00:00
2024-11-09 00:49:08 +00:00
$ingestion | typeLib::ensureKey("ingestion"; "substanceName") |
.substanceName | typeLib::ensureWrapError("experience:substanceName"; typeLib::ensureString) |
$ingestion | typeLib::ensureKey("ingestion"; "time") |
.time | typeLib::ensureWrapError("experience:time"; typeLib::ensureNumber) |
2024-11-07 21:45:22 +00:00
2024-11-09 00:49:08 +00:00
$ingestion | typeLib::ensureKey("ingestion"; "creationDate") |
.creationDate | typeLib::ensureWrapError("experience:creationDate"; typeLib::ensureNumber) |
# TODO: check routes
$ingestion |
typeLib::ensureKey("ingestion"; "administrationRoute") |
$ingestion.administrationRoute |
typeLib::ensureWrapError("experience:administrationRoute"; typeLib::ensureString) |
$ingestion.administrationRoute |
ensureAdministrationRoute |
typeLib::ensureWrapError(
"experience:dose";
$ingestion | typeLib::ensureIfKey("dose"; typeLib::ensureNullOr(typeLib::ensureNumber))
) |
$ingestion | typeLib::ensureKey("ingestion"; "isDoseAnEstimate") |
.isDoseAnEstimate | typeLib::ensureWrapError("experience:isDoseAnEstimate"; typeLib::ensureBool) |
$ingestion | typeLib::ensureKey("ingestion"; "units") |
.units | typeLib::ensureWrapError("experience:units"; typeLib::ensureString) |
$ingestion | typeLib::ensureKey("ingestion"; "notes") |
.notes | typeLib::ensureWrapError("experience:notes"; typeLib::ensureString) |
typeLib::ensureWrapError(
"experience:stomachFullness";
$ingestion | typeLib::ensureIfKey("stomachFullness"; typeLib::ensureNullOr(typeLib::ensureString))
) |
typeLib::ensureWrapError(
"experience:customUnitId";
$ingestion | typeLib::ensureIfKey("customUnitId"; typeLib::ensureNullOr(typeLib::ensureNumber))
) |
$ingestion
2024-11-07 21:45:22 +00:00
end;
2024-11-09 13:13:47 +00:00
def ensureIngestions:
. as $ingestions |
if typeLib::typecheckingEnabled then
(reduce $ingestions[] as $ingestion (null; $ingestion | ensureIngestion))
end;
2024-11-07 11:39:39 +00:00
def ensureExperience:
. as $experience |
2024-11-07 21:45:22 +00:00
if typeLib::typecheckingEnabled then
$experience | typeLib::ensureObject |
2024-11-07 13:10:18 +00:00
2024-11-07 21:45:22 +00:00
$experience | typeLib::ensureKey("experience"; "title") |
$experience.title | typeLib::ensureWrapError("experience:title"; typeLib::ensureString) |
2024-11-07 13:10:18 +00:00
2024-11-07 21:45:22 +00:00
$experience | typeLib::ensureKey("experience"; "text") |
$experience.text | typeLib::ensureWrapError("experience:text"; typeLib::ensureString) |
2024-11-07 11:39:39 +00:00
2024-11-07 21:45:22 +00:00
$experience | typeLib::ensureKey("experience"; "creationDate") |
$experience.creationDate | typeLib::ensureWrapError("experience:creationDate"; typeLib::ensureNumber) |
2024-11-07 13:10:18 +00:00
2024-11-07 21:45:22 +00:00
$experience | typeLib::ensureKey("experience"; "sortDate") |
$experience.sortDate | typeLib::ensureWrapError("experience:sortDate"; typeLib::ensureNumber) |
2024-11-07 13:10:18 +00:00
2024-11-07 21:45:22 +00:00
$experience | typeLib::ensureKey("experience"; "ingestions") |
$experience.ingestions | typeLib::ensureWrapError("experience:ingestions"; typeLib::ensureArray) |
2024-11-09 13:13:47 +00:00
$experience.ingestions | ensureIngestions |
2024-11-09 00:49:08 +00:00
$experience
2024-11-07 21:45:22 +00:00
end;
2024-11-07 11:39:39 +00:00
2024-11-09 13:13:47 +00:00
def ensureExperiences:
. as $experiences |
if typeLib::typecheckingEnabled then
(reduce $experiences[] as $experience (null; $experience | ensureExperience))
end;
2024-11-07 11:39:39 +00:00
def ensureExportData:
. as $exportData |
if typeLib::typecheckingEnabled then
typeLib::ensureObject |
typeLib::ensureKey("exportData"; "customSubstances") |
typeLib::ensureKey("exportData"; "customUnits") |
typeLib::ensureKey("exportData"; "experiences") |
typeLib::ensureKey("exportData"; "substanceCompanions") |
2024-11-09 13:13:47 +00:00
.experiences | ensureExperiences
2024-11-07 11:39:39 +00:00
end;