...
Extract client_id from token
Check legal entity status (status = ACTIVE)
In case of error - return 409 (Legal entity must be ACTIVE)
Check legal entity has at least one healthcare service with status = ACTIVE and providing_condition = INPATIENT and speciality_type in PREPERSON_HEALTHCARE_SERVICES_SPECIALITY_TYPES variable (value should exist in SPECIALITY_TYPE dict)
if no such healthcare services - return 409 (Legal entity does not have appropriate healthcare services)
Validate request
Validate request using schema (TBD)
Validate birth_date - must be < today()
else error 422 "Birth date can't be in the future"
Validate external_id
Check external_id is not empty.
In case of error - return 422 (external_id should not be empty)
Validate according to regexp -
8-10.8-10.1-10 [0-9]
Generate preperson_id
Generate preperson_id (will be returned in response). Ensure there is no such person_id in MPI.persons
Generate patient_id to save it in patients collection (separate job).
...