{
  "$schema": "http://json-schema.org/draft-07/schema#",
  "title": "Detailschein Transport",
  "description": "Detailschein fuer Transportleistungen",

  "x-detailschein": {
    "leistungsgruppe": "TRAN",
    "version": "1.3.13"
  },
  "type": "object",
  "additionalProperties": false,
  "required": [
    "transportgrund",
    "rollstuhl",
    "anzahlFahrten",
    "transportVon",
    "transportNach",
    "naechstgelegeneGeeigneteBehandlungsstelle"
  ],
  "properties": {
    "transportgrund": {
      "type": "string",
      "title": "Transportgrund",
      "maxLength": 30,
      "oneOf": [
        {
          "const": "ERKRANKUNG",
          "title": "Erkrankung inkl. Kontrolluntersuchung"
        },
        {
          "const": "DIALYSE",
          "title": "Dialyse/Apherese"
        },
        {
          "const": "STRAHLENTHERAPIE",
          "title": "Strahlentherapie/Chemotherapie"
        },
        {
          "const": "THERAPIE",
          "title": "Therapie (ausgenommen Immuntherapie)"
        },
        {
          "const": "VERKEHRSUNFALL",
          "title": "Verkehrsunfall"
        },
        {
          "const": "ANDERER_UNFALL",
          "title": "anderer Unfall (z.B. Freizeit, Arbeit, Schüler, Tierverletzung)"
        },
        {
          "const": "REHA",
          "title": "Kur/Rehabilitation"
        },
        {
          "const": "HEILBEHELFE",
          "title": "Anpassung von Heilbehelfen und Hilfsmitteln"
        },
        {
          "const": "ENTBINDUNG",
          "title": "Entbindung"
        },
        {
          "const": "SUCHT",
          "title": "Alkoholmissbrauch/Suchtgiftmissbrauch"
        },
        {
          "const": "RAUFHANDEL",
          "title": "Raufhandel/Verbrechen"
        },
        {
          "const": "TRANSPLANTATION",
          "title": "Organtransplantation"
        },
        {
          "const": "IMMUNTHERAPIE",
          "title": "Immuntherapie (nach Krebserkrankungen oder Transplantationen)"
        },
        {
          "const": "PALLIATIV",
          "title": "Palliativ"
        }
      ]
    },
    "rollstuhl": {
      "type": "boolean",
      "title": "Wird ein Rollstuhl für den Transport benötigt?"
    },
    "rollstuhlArt": {
      "type": "string",
      "default": "leih",
      "title": "Eigener / Leihrollstuhl",
      "oneOf": [
        {
          "const": "eigen",
          "title": "Eigener Rollstuhl"
        },
        {
          "const": "leih",
          "title": "Leihrollstuhl"
        }
      ]
    },
    "begruendungGehunfaehigkeit": {
      "type": "string",
      "title": "Begründung Gehunfähigkeit",
      "maxLength": 200,
	  "pattern": ".*\\S.*"
    },
    "anzahlFahrten": {
      "type": "string",
      "title": "Anzahl an Fahrten",
      "oneOf": [
        {
          "const": "1",
          "title": "1 Fahrt"
        },
        {
          "const": "2",
          "title": "2 Fahrten"
        }
      ]
    },
    "transportVon": {
      "$ref": "#/definitions/transportOrt"
    },
    "transportNach": {
      "$ref": "#/definitions/transportOrt"
    },
    "naechstgelegeneGeeigneteBehandlungsstelle": {
      "type": "boolean",
      "title": "Transport zur nächstgelegenen geeigneten Behandlungsstelle möglich?",      
      "default": true
    },
    "begruendungNichtNaechstgelegeneGeeignete": {
      "type": "string",
      "maxLength": 200,
	  "pattern": ".*\\S.*"
    }
  },
  "allOf": [
    {
      "if": {
        "properties": {
          "rollstuhl": {
            "const": true
          }
        },
        "required": [
          "rollstuhl"
        ]
      },
      "then": {
        "required": [
          "rollstuhlArt"
        ]
      }
    },
    {
      "if": {
        "properties": {
          "rollstuhl": {
            "const": false
          }
        },
        "required": ["rollstuhl"]
      },
      "then": {
        "not": {
          "required": ["rollstuhlArt"]
        }
      }
    }, 		
    {
      "if": {
        "properties": {
          "naechstgelegeneGeeigneteBehandlungsstelle": {
            "const": false
          }
        },
        "required": [
          "naechstgelegeneGeeigneteBehandlungsstelle"
        ]
      },
      "then": {
        "required": [
          "begruendungNichtNaechstgelegeneGeeignete"
        ]
      }
    },
	{
	  "if": {
		"properties": {
		  "naechstgelegeneGeeigneteBehandlungsstelle": {
			"const": true
		  }
		},
		"required": [
		  "naechstgelegeneGeeigneteBehandlungsstelle"
		]
	  },
	  "then": {
		"not": {
		  "required": [
			"begruendungNichtNaechstgelegeneGeeignete"
		  ]
		}
	  }
	}
  ],
  "definitions": {
    "adresse": {
      "type": "object",
	  "additionalProperties": false,
      "required": [
        "strasse",
        "plz",
        "ort"
      ],
      "properties": {
        "strasse": {
          "type": "string",
          "maxLength": 100,
		  "pattern": ".*\\S.*"
        },
        "hausnummer": {
          "type": "string",
          "maxLength": 20,
		  "pattern": ".*\\S.*"
        },
        "plz": {
          "type": "string",
          "pattern": "^[0-9]{4}$",
          "maxLength": 4
        },
        "ort": {
          "type": "string",
          "maxLength": 100,
		  "pattern": ".*\\S.*"
        },
        "zusatz": {
          "type": "string",
          "maxLength": 100,
		  "pattern": ".*\\S.*"
        }		
      }
    },
    "transportOrt": {
      "type": "object",
	  "additionalProperties": false,
      "required": [
        "typ"
      ],
      "properties": {
        "typ": {
          "type": "string",
          "oneOf": [
            {
              "const": "wohnort",
              "title": "Wohnort"
            },
            {
              "const": "behandlungsstelle",
              "title": "Behandlungsstelle"
            }
          ]
        },
        "behandlungsstellenTyp": {
          "type": "string",
          "default": "adresse",
          "oneOf": [
            {
              "const": "adresse",
              "title": "Adresse"
            },
            {
              "const": "fachgebiet",
              "title": "Fachgebiet"
            },
            {
              "const": "andereAngabe",
              "title": "Andere Angabe"
            }
          ]
        },
        "adresse": {
          "$ref": "#/definitions/adresse"
        },
        "fachgebiet": {
          "type": "string",
          "oneOf": [
            { "const": "01", "title": "Allgemein-/Allgemein- und Familienmedizin" },
            { "const": "02", "title": "Anästhesiologie und Intensivmedizin" },
            { "const": "03", "title": "Augenheilkunde und Optometrie" },
            { "const": "04", "title": "Chirurgie" },
            { "const": "05", "title": "Haut- und Geschlechtskrankheiten" },
            { "const": "06", "title": "Frauenheilkunde und Geburtshilfe" },
            { "const": "07", "title": "Innere Medizin" },
            { "const": "08", "title": "Kinder- und Jugendheilkunde" },
            { "const": "09", "title": "Hals-, Nasen- und Ohrenheilkunde" },
            { "const": "10", "title": "Lungenkrankheiten" },
            { "const": "11", "title": "Neurologie und Psychiatrie" },
            { "const": "12", "title": "Orthopädie und orthopädische Chirurgie" },
            { "const": "13", "title": "Physikalische Medizin" },
            { "const": "14", "title": "Radiologie" },
            { "const": "15", "title": "Unfallchirurgie" },
            { "const": "16", "title": "Urologie" },
            { "const": "17", "title": "Zahn-, Mund- und Kieferheilkunde" },
            { "const": "18", "title": "Neurochirurgie" },
            { "const": "19", "title": "Neurologie" },
            { "const": "20", "title": "Psychiatrie" },
            { "const": "21", "title": "Plastische Chirurgie" },
            { "const": "22", "title": "Kinder- und Jugendchirurgie" },
            { "const": "23", "title": "Mund-, Kiefer- und Gesichtschirurgie" },
            { "const": "24", "title": "Nuklearmedizin" },
            { "const": "26", "title": "Strahlentherapie - Radioonkologie" },
            { "const": "27", "title": "Zahnmedizin" },
            { "const": "28", "title": "Blutgruppenserologie und Transfusionsmedizin" },
            { "const": "29", "title": "Immunologie" },
            { "const": "33", "title": "Histologie und Embryologie" },
            { "const": "34", "title": "Medizinische Biologie" },
            { "const": "35", "title": "Virologie" },
            { "const": "38", "title": "Pharmakologie und Toxikologie" },
            { "const": "50", "title": "Medizinische und Chemische Labordiagnostik" },
            { "const": "51", "title": "Labor, EEG" },
            { "const": "52", "title": "Labor, zytodiagnostisch" },
            { "const": "53", "title": "Pathologie und Histologie" },
            { "const": "55", "title": "Hyg. u. Mikrob. bzw. mikrob.serolog.Labordia." },
            { "const": "72", "title": "Psychotherapie" },
            { "const": "84", "title": "CT, MR und sonst. bildgeb. techn. Leistungen" },
            { "const": "85", "title": "Ambulatorium (ausg. ZMK, phys. Med, CT u. MR)" },
            { "const": "86", "title": "Ambulat. für Zahn-, Mund- und Kieferheilkunde" },
            { "const": "90", "title": "Kurheim, Genesungsheim, sonstige Heime" },
            { "const": "91", "title": "Selbst. Ambulatorium f. physikalische Medizin" },
            { "const": "80", "title": "Bettenführende Krankenanstalten" },
            { "const": "99", "title": "Sonstige Leistungserbringung" },
            { "const": "60", "title": "Öffentliche Apotheke" },
            { "const": "65", "title": "Rettungsdienste, Beförd.gew. Krankentransport" },
            { "const": "42", "title": "Leihfirmen für Heilbehelfe und Hilfsmittel" },
            { "const": "61", "title": "Bandagist:innen" },
            { "const": "68", "title": "Orthopädieschuhherstellung" },
            { "const": "69", "title": "Orthopädietechnik (inkl.Prothesenherstellung)" },
            { "const": "32", "title": "Kinder- und Jugendpsychiatrie" },
            { "const": "59", "title": "Hausapotheke" },
            { "const": "87", "title": "Pflegeheim, Pensionistenheim" },
            { "const": "40", "title": "Hörgeräteakustik" },
            { "const": "67", "title": "Augen-/Kontaktlinsen Optik" },
            { "const": "73", "title": "Klinische Psychologie" },
            { "const": "75", "title": "Ergotherapie" },
            { "const": "63", "title": "Physiotherapie" },
            { "const": "66", "title": "Logopädie" },
            { "const": "37", "title": "Arbeits- und Betriebsmedizin" },
            { "const": "39", "title": "Medizinische Genetik" },
            { "const": "49", "title": "Sonstige, nicht kurative Leistungserbringung" },
            { "const": "81", "title": "Ambulanzen bettenführender Krankenanstalten" },
            { "const": "30", "title": "Kieferorthopädie" },
            { "const": "96", "title": "Selbst. Ambulatorium für Kieferorthopädie" },
            { "const": "88", "title": "Stationäre Rehabilitationseinrichtungen" },
            { "const": "89", "title": "Ambulante Rehabilitationseinrichtungen" },
            { "const": "31", "title": "Innere Medizin und Kardiologie" },
            { "const": "44", "title": "Innere Medizin und Pneumologie" },
            { "const": "45", "title": "Orthopädie und Traumatologie" }

          ]
        },
        "freitext": {
          "type": "string",
          "maxLength": 100,
		  "pattern": ".*\\S.*"
        }
      },
      "allOf": [
        {
          "if": {
            "properties": {
              "typ": {
                "const": "wohnort"
              }
            },
            "required": [
              "typ"
            ]
          },
          "then": {
            "required": [
              "adresse"
            ],
            "not": {
              "anyOf": [
                { "required": ["fachgebiet"] },
                { "required": ["freitext"] }
              ]
            }             
          }
        },
        {
          "if": {
            "properties": {
              "typ": {
                "const": "behandlungsstelle"
              }
            },
            "required": [
              "typ"
            ]
          },
          "then": {
            "required": [
              "behandlungsstellenTyp"
            ]
          }
        },
        {
          "if": {
            "properties": {
              "behandlungsstellenTyp": {
                "const": "adresse"
              }
            },
            "required": [
              "behandlungsstellenTyp"
            ]
          },
          "then": {
            "required": [
              "adresse"
            ],
            "not": {
              "anyOf": [
                { "required": ["fachgebiet"] },
                { "required": ["freitext"] }
              ]
            }                   
          }
        },       
        {
          "if": {
            "properties": {
              "behandlungsstellenTyp": {
                "const": "fachgebiet"
              }
            },
            "required": [
              "behandlungsstellenTyp"
            ]
          },
          "then": {
            "required": [
              "fachgebiet"
            ],
            "not": {
              "anyOf": [
                { "required": ["adresse"] },
                { "required": ["freitext"] }
              ]
            }                   
          }
        },
        {
          "if": {
            "properties": {
              "behandlungsstellenTyp": {
                "const": "andereAngabe"
              }
            },
            "required": [
              "behandlungsstellenTyp"
            ]
          },
          "then": {
            "required": [
              "freitext"
            ],
            "not": {
              "anyOf": [
                { "required": ["adresse"] },
                { "required": ["fachgebiet"] }
              ]
            }              
          }
        }
      ]
    }
  }
}