Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merge Dev into Main #68

Merged
merged 20 commits into from
Jan 22, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 23 additions & 17 deletions routes/routes121.py
Original file line number Diff line number Diff line change
Expand Up @@ -267,30 +267,26 @@ async def create_121_program_from_kobo(

CHECKFIELDS = [
"validation",
"phase",
"location",
"ngo",
"language",
"titlePortal",
"description",
"startDate",
"endDate",
"currency",
"distributionFrequency",
"distributionDuration",
"fixedTransferValue",
"financialServiceProviders",
"targetNrRegistrations",
"tryWhatsAppFirst",
"phoneNumberPlaceholder",
"aboutProgram",
"fullnameNamingConvention",
"enableMaxPayments",
"phoneNumber",
"preferredLanguage",
"budget",
"maxPayments",
"fspName",
"fspName"
]

# First check if all setup fields are in the xlsform
Expand All @@ -302,7 +298,13 @@ async def create_121_program_from_kobo(

if len(MISSINGFIELDS) != 0:
print("Missing hidden fields in the template: ", MISSINGFIELDS)
raise HTTPException(
status_code=400,
detail=f"Missing required keys in kobo form: {MISSINGFIELDS}"
)



lookupdict = dict(zip(survey["name"], survey["default"]))
fspquestions = []

Expand All @@ -321,29 +323,35 @@ async def create_121_program_from_kobo(
survey["tags"] = False
dedupedict = dict(zip(survey["name"], survey["tags"]))

try:
start_date = datetime.strptime(lookupdict["startDate"], "%d/%m/%Y").isoformat()
end_date = datetime.strptime(lookupdict["endDate"], "%d/%m/%Y").isoformat()
except ValueError:
raise HTTPException(
status_code=400,
detail="Date format should be dd/mm/yyyyx"
)

# Create the JSON structure
data = {
"published": True,
"validation": lookupdict["validation"].upper() == "TRUE",
"phase": lookupdict["phase"],
"location": lookupdict["location"],
"ngo": lookupdict["ngo"],
"titlePortal": {lookupdict["language"]: lookupdict["titlePortal"]},
"titlePaApp": {lookupdict["language"]: lookupdict["titlePortal"]},
"description": {"en": ""},
"startDate": datetime.strptime(lookupdict["startDate"], "%d/%m/%Y").isoformat(),
"endDate": datetime.strptime(lookupdict["endDate"], "%d/%m/%Y").isoformat(),
"startDate": start_date,
"endDate": end_date,
"currency": lookupdict["currency"],
"distributionFrequency": lookupdict["distributionFrequency"],
"distributionDuration": int(lookupdict["distributionDuration"]),
"fixedTransferValue": int(lookupdict["fixedTransferValue"]),
"paymentAmountMultiplierFormula": "",
"financialServiceProviders": [{"fsp": lookupdict["financialServiceProviders"]}],
"targetNrRegistrations": int(lookupdict["targetNrRegistrations"]),
"tryWhatsAppFirst": lookupdict["tryWhatsAppFirst"].upper() == "TRUE",
"phoneNumberPlaceholder": lookupdict["phoneNumberPlaceholder"],
"programCustomAttributes": [],
"programQuestions": [],
"programRegistrationAttributes": [],
"aboutProgram": {lookupdict["language"]: lookupdict["aboutProgram"]},
"fullnameNamingConvention": [lookupdict["fullnameNamingConvention"]],
"languages": [lookupdict["language"]],
Expand All @@ -365,8 +373,7 @@ async def create_121_program_from_kobo(
"name": row["name"],
# check if label exists, otherwise use name:
"label": {"en": str(row["label"][0]) if not isinstance(row["label"], float) else row["name"]},
"answerType": type_mapping[row["type"].split()[0]],
"questionType": "standard",
"type": type_mapping[row["type"].split()[0]],
"options": [],
"scoring": {},
"persistence": True,
Expand All @@ -390,14 +397,13 @@ async def create_121_program_from_kobo(
"label": {"en": str(row["label"][0])},
}
question["options"].append(option)
data["programQuestions"].append(question)
data["programRegistrationAttributes"].append(question)
if row["name"] == "phoneNumber":
koboConnectHeader.append("phoneNumber")
question = {
"name": "phoneNumber",
"label": {"en": "Phone Number"},
"answerType": "tel",
"questionType": "standard",
"type": "tel",
"options": [],
"scoring": {},
"persistence": True,
Expand All @@ -411,7 +417,7 @@ async def create_121_program_from_kobo(
"duplicateCheck": dedupedict[row["name"]],
"placeholder": "",
}
data["programQuestions"].append(question)
data["programRegistrationAttributes"].append(question)

if test_mode:
return JSONResponse(status_code=200, content=data)
Expand Down
73 changes: 35 additions & 38 deletions tests/program121.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
{
"published": true,
"validation": true,
"phase": "registrationValidation",
"location": "Netherlands",
"ngo": "RCRC",
"titlePortal": {
Expand All @@ -20,23 +19,16 @@
"distributionDuration": 4,
"fixedTransferValue": 100,
"paymentAmountMultiplierFormula": "",
"financialServiceProviders": [
{
"fsp": "Commercial-bank-ethiopia"
}
],
"targetNrRegistrations": 10,
"tryWhatsAppFirst": false,
"phoneNumberPlaceholder": "32000000000",
"programCustomAttributes": [],
"programQuestions": [
"programRegistrationAttributes": [
{
"name": "province",
"label": {
"en": "What is the province?"
},
"answerType": "dropdown",
"questionType": "standard",
"type": "dropdown",
"options": [
{
"option": "South-Holland",
Expand Down Expand Up @@ -68,8 +60,7 @@
"label": {
"en": "What is the city?"
},
"answerType": "dropdown",
"questionType": "standard",
"type": "dropdown",
"options": [
{
"option": "Amsterdam",
Expand Down Expand Up @@ -113,8 +104,7 @@
"label": {
"en": "scope"
},
"answerType": "text",
"questionType": "standard",
"type": "text",
"options": [],
"scoring": {},
"persistence": true,
Expand All @@ -133,8 +123,7 @@
"label": {
"en": "What is your name?"
},
"answerType": "text",
"questionType": "standard",
"type": "text",
"options": [],
"scoring": {},
"persistence": true,
Expand All @@ -153,8 +142,7 @@
"label": {
"en": "What is your age?"
},
"answerType": "numeric",
"questionType": "standard",
"type": "numeric",
"options": [],
"scoring": {},
"persistence": true,
Expand All @@ -173,8 +161,7 @@
"label": {
"en": "What is your sex?"
},
"answerType": "dropdown",
"questionType": "standard",
"type": "dropdown",
"options": [
{
"option": "Female",
Expand Down Expand Up @@ -212,8 +199,7 @@
"label": {
"en": "What is your ID number?"
},
"answerType": "numeric",
"questionType": "standard",
"type": "numeric",
"options": [],
"scoring": {},
"persistence": true,
Expand All @@ -232,8 +218,7 @@
"label": {
"en": "Phone Number"
},
"answerType": "tel",
"questionType": "standard",
"type": "tel",
"options": [],
"scoring": {},
"persistence": true,
Expand All @@ -252,8 +237,7 @@
"label": {
"en": "What is the amount of members in your household?"
},
"answerType": "numeric",
"questionType": "standard",
"type": "numeric",
"options": [],
"scoring": {},
"persistence": true,
Expand All @@ -272,8 +256,7 @@
"label": {
"en": "Is this a single parent headed household?"
},
"answerType": "dropdown",
"questionType": "standard",
"type": "dropdown",
"options": [
{
"option": "Yes",
Expand Down Expand Up @@ -305,8 +288,7 @@
"label": {
"en": "Is this an elderly headed household?"
},
"answerType": "dropdown",
"questionType": "standard",
"type": "dropdown",
"options": [
{
"option": "Yes",
Expand Down Expand Up @@ -338,8 +320,7 @@
"label": {
"en": "Are there people with serious and/or chronic illness in the household?"
},
"answerType": "dropdown",
"questionType": "standard",
"type": "dropdown",
"options": [
{
"option": "Yes",
Expand Down Expand Up @@ -371,8 +352,7 @@
"label": {
"en": "Are there people with disabilities in the household?"
},
"answerType": "dropdown",
"questionType": "standard",
"type": "dropdown",
"options": [
{
"option": "Yes",
Expand Down Expand Up @@ -404,8 +384,7 @@
"label": {
"en": "Is the household displaced?"
},
"answerType": "dropdown",
"questionType": "standard",
"type": "dropdown",
"options": [
{
"option": "Yes",
Expand Down Expand Up @@ -437,8 +416,7 @@
"label": {
"en": "Is the head of household unemployed?"
},
"answerType": "dropdown",
"questionType": "standard",
"type": "dropdown",
"options": [
{
"option": "Yes",
Expand All @@ -464,6 +442,25 @@
},
"duplicateCheck": false,
"placeholder": ""
},
{
"name": "phoneNumberPlaceholder",
"label": {
"en": "phoneNumberPlaceholder"
},
"type": "text",
"options": [],
"scoring": {},
"persistence": true,
"pattern": "",
"phases": [],
"editableInPortal": true,
"export": ["all-people-affected"],
"shortLabel": {
"en": "phoneNumberPlaceholder"
},
"duplicateCheck": false,
"placeholder": ""
}
],
"aboutProgram": {
Expand Down
Loading