{
  "$schema": "https://schemas.rasd.dev/form/v1.json",
  "rasd": "1.0",
  "id": "nutrition-screening-2026",
  "version": "2.0",
  "requires": {
    "rasd": ">=1.0",
    "features": ["type:video", "type:file", "cap:encryption"]
  },
  "meta": {
    "title": { "ar": "فحص التغذية والإحالة", "en": "Nutrition screening and referral" },
    "description": {
      "ar": "فحص محيط العضد للأطفال من ٦ إلى ٥٩ شهراً في العيادة المتنقلة، مع إحالة الحالات الشديدة.",
      "en": "MUAC screening of children aged 6–59 months at the mobile clinic, with referral of severe cases."
    },
    "tags": ["nutrition", "health", "referral"],
    "author": "Nutrition sector",
    "createdAt": "2026-03-02T07:30:00Z",
    "changelog": {
      "ar": "إضافة مقطع التحقق من أسلوب القياس ومرفق قسيمة الإحالة الورقية.",
      "en": "Added the measurement-technique verification clip and the paper referral slip attachment."
    }
  },
  "settings": {
    "defaultLocale": "ar",
    "locales": ["ar", "en"],
    "navigation": "paged",
    "showProgress": true,
    "allowDrafts": true,
    "autosaveMs": 1500,
    "instanceName": "concat(${muac_class}, ' · ', ${age_months}, 'm')",
    "submissionIdPrefix": "NUT",
    "numbering": "native",
    "calendar": "islamic-umalqura",
    "localeMeta": {
      "ar": { "dir": "rtl", "numbering": "native", "calendar": "islamic-umalqura" },
      "en": { "dir": "ltr", "numbering": "latn", "calendar": "gregorian" }
    },
    "audit": { "enabled": true, "trackChanges": true, "identifyUser": true, "changeReasons": "onEdit" },
    "encryption": { "mode": "submission", "publicKeyId": "nut-clinic-2026" },
    "theme": { "themeId": "rasd-field" }
  },
  "choiceLists": {
    "sex": {
      "choices": [
        { "value": "f", "label": { "ar": "أنثى", "en": "Female" } },
        { "value": "m", "label": { "ar": "ذكر", "en": "Male" } }
      ]
    },
    "oedema": {
      "choices": [
        { "value": "none", "label": { "ar": "لا يوجد", "en": "None" } },
        { "value": "plus", "label": { "ar": "+ القدمان", "en": "+ Both feet" } },
        { "value": "plus2", "label": { "ar": "++ القدمان والساقان", "en": "++ Feet and legs" } },
        { "value": "plus3", "label": { "ar": "+++ معمم", "en": "+++ Generalised" } }
      ]
    },
    "referral_outcome": {
      "choices": [
        { "value": "otp", "label": { "ar": "برنامج العلاج الخارجي", "en": "Outpatient therapeutic programme" } },
        { "value": "sc", "label": { "ar": "المركز التثبيتي", "en": "Stabilisation centre" } },
        { "value": "tsfp", "label": { "ar": "برنامج التغذية التكميلية", "en": "Supplementary feeding programme" } },
        { "value": "declined", "label": { "ar": "رفض مقدم الرعاية", "en": "Caregiver declined" } }
      ]
    }
  },
  "pages": [
    {
      "id": "consent",
      "title": { "ar": "الموافقة", "en": "Consent" },
      "elements": [
        {
          "type": "consent",
          "name": "caregiver_consent",
          "label": { "ar": "موافقة مقدم الرعاية", "en": "Caregiver consent" },
          "required": true,
          "props": {
            "text": {
              "ar": "سنقيس محيط عضد طفلك ونسجّل النتيجة لتحديد ما إذا كان مؤهلاً للعلاج. يمكنك الرفض في أي وقت دون أن يؤثر ذلك على أي خدمة أخرى.",
              "en": "We will measure your child's upper-arm circumference and record the result to decide whether they qualify for treatment. You may refuse at any time without it affecting any other service."
            },
            "textVersion": "2026-03",
            "method": "tap",
            "allowWithdraw": true,
            "onWithdraw": "clearSensitive"
          }
        }
      ]
    },
    {
      "id": "child",
      "title": { "ar": "بيانات الطفل", "en": "Child details" },
      "elements": [
        {
          "type": "text",
          "name": "child_code",
          "label": { "ar": "رمز الطفل", "en": "Child code" },
          "hint": { "ar": "من بطاقة العيادة، مثل NUT-40318", "en": "From the clinic card, e.g. NUT-40318" },
          "required": true,
          "bind": { "sensitive": true },
          "validators": [
            {
              "type": "regex",
              "pattern": "^NUT-\\d{5}$",
              "message": { "ar": "الرمز على شكل NUT-40318", "en": "Codes look like NUT-40318" }
            }
          ]
        },
        {
          "type": "select_one",
          "name": "sex",
          "label": { "ar": "الجنس", "en": "Sex" },
          "required": true,
          "props": { "list": "sex" }
        },
        {
          "type": "date",
          "name": "dob",
          "label": { "ar": "تاريخ الميلاد", "en": "Date of birth" },
          "required": true,
          "bind": { "sensitive": true },
          "props": { "max": "2026-12-31" }
        },
        {
          "type": "calculate",
          "name": "age_months",
          "calculate": "round((today() - ${dob}) / 30.4375)"
        },
        {
          "type": "note",
          "name": "age_note",
          "label": {
            "ar": "عمر الطفل {age_months} شهراً.",
            "en": "The child is {age_months} months old."
          },
          "relevant": "${age_months} > 0"
        },
        {
          "type": "note",
          "name": "out_of_range",
          "label": {
            "ar": "هذا الطفل خارج نطاق ٦ إلى ٥٩ شهراً. سجّل القياس على أي حال ولكن لا تُحِل عبر هذا البرنامج.",
            "en": "This child is outside the 6–59 month range. Record the measurement anyway but do not refer through this programme."
          },
          "relevant": "${age_months} < 6 or ${age_months} > 59"
        }
      ]
    },
    {
      "id": "measurement",
      "title": { "ar": "القياس", "en": "Measurement" },
      "elements": [
        {
          "type": "number",
          "name": "muac_mm",
          "label": { "ar": "محيط منتصف العضد (مم)", "en": "MUAC (mm)" },
          "required": true,
          "props": { "min": 60, "max": 250, "step": 1 },
          "validators": [
            {
              "type": "range",
              "min": 80,
              "max": 220,
              "severity": "warning",
              "message": {
                "ar": "قيمة غير معتادة — أعد القياس قبل الحفظ",
                "en": "Unusual value — measure again before saving"
              }
            }
          ]
        },
        {
          "type": "select_one",
          "name": "oedema",
          "label": { "ar": "الوذمة الانطباعية الثنائية", "en": "Bilateral pitting oedema" },
          "required": true,
          "props": { "list": "oedema" }
        },
        {
          "type": "calculate",
          "name": "muac_class",
          "calculate": "if(${oedema} != 'none', 'sam', if(${muac_mm} < 115, 'sam', if(${muac_mm} < 125, 'mam', 'normal')))"
        },
        {
          "type": "note",
          "name": "sam_note",
          "label": {
            "ar": "سوء تغذية حاد وخيم. أكمل الإحالة في هذه الزيارة ولا تؤجلها.",
            "en": "Severe acute malnutrition. Complete the referral during this visit; do not defer it."
          },
          "relevant": "${muac_class} = 'sam'"
        },
        {
          "type": "video",
          "name": "technique_clip",
          "label": { "ar": "مقطع للتحقق من أسلوب القياس", "en": "Measurement technique verification clip" },
          "hint": {
            "ar": "عشر ثوانٍ تُظهر الشريط على منتصف العضد. للإشراف فقط.",
            "en": "Ten seconds showing the tape at the mid-point of the arm. For supervision only."
          },
          "relevant": "${muac_class} = 'sam'",
          "props": { "maxDurationSeconds": 20, "maxBytes": 12000000 }
        },
        {
          "type": "number",
          "name": "weight_kg",
          "label": { "ar": "الوزن (كجم)", "en": "Weight (kg)" },
          "props": { "min": 1, "max": 40, "step": 0.1 }
        },
        {
          "type": "number",
          "name": "height_cm",
          "label": { "ar": "الطول (سم)", "en": "Height (cm)" },
          "props": { "min": 40, "max": 140, "step": 0.1 }
        }
      ]
    },
    {
      "id": "referral",
      "title": { "ar": "الإحالة", "en": "Referral" },
      "elements": [
        {
          "type": "select_one",
          "name": "referral",
          "label": { "ar": "نتيجة الإحالة", "en": "Referral outcome" },
          "relevant": "${muac_class} != 'normal'",
          "required": "${muac_class} = 'sam'",
          "props": { "list": "referral_outcome" }
        },
        {
          "type": "text",
          "name": "declined_reason",
          "label": { "ar": "سبب الرفض", "en": "Reason for declining" },
          "relevant": "${referral} = 'declined'",
          "required": true,
          "props": { "multiline": true, "maxLength": 400 }
        },
        {
          "type": "file",
          "name": "referral_slip",
          "label": { "ar": "قسيمة الإحالة الورقية", "en": "Paper referral slip" },
          "hint": {
            "ar": "صوّر القسيمة الموقّعة أو أرفق ملف PDF من العيادة.",
            "en": "Photograph the signed slip or attach a PDF from the clinic."
          },
          "relevant": "${referral} = 'otp' or ${referral} = 'sc'",
          "props": { "accept": ["application/pdf", "image/jpeg", "image/png"], "maxBytes": 5000000, "maxCount": 3, "multiple": true }
        },
        {
          "type": "datetime",
          "name": "referred_at",
          "label": { "ar": "وقت الإحالة", "en": "Time of referral" },
          "relevant": "${referral} = 'otp' or ${referral} = 'sc'",
          "default": { "expr": "now()" }
        },
        {
          "type": "signature",
          "name": "caregiver_signature",
          "label": { "ar": "توقيع مقدم الرعاية", "en": "Caregiver signature" },
          "relevant": "${referral} = 'otp' or ${referral} = 'sc'",
          "bind": { "sensitive": true }
        },
        {
          "type": "hidden",
          "name": "clinic_round",
          "default": { "value": "2026-03-mobile-7" }
        }
      ]
    }
  ],
  "logic": {
    "triggers": [
      {
        "id": "clear-referral-when-normal",
        "when": "${muac_class} = 'normal'",
        "actions": [
          { "type": "clearValue", "target": "referral" },
          { "type": "clearValue", "target": "declined_reason" }
        ]
      },
      {
        "id": "stabilisation-centre-for-oedema-3",
        "when": "${oedema} = 'plus3'",
        "actions": [
          { "type": "setValue", "target": "referral", "value": "sc" },
          {
            "type": "showMessage",
            "message": {
              "ar": "وذمة معممة: يجب التحويل إلى المركز التثبيتي، وليس إلى العلاج الخارجي.",
              "en": "Generalised oedema: this is a stabilisation centre case, not outpatient."
            }
          }
        ]
      }
    ]
  }
}
