from typing import List
from typing import Optional


def create_patient_resource(patient_identifier: List[dict],
                            gender: str,
                            communication: Optional[List[dict]] = None) -> dict:
    """
    Create patient resource following the FHIR format
    (http://www.hl7.org/implement/standards/fhir/patient.html)
    """
    gender_codes = {"male", "female", "other", "unknown"}

    assert gender in gender_codes, \
        f"Gender must be one of these gender codes: {gender_codes}"

    patient_resource = {
        "resourceType": "Patient",
        "identifier": patient_identifier,
        "gender": gender
    }

    if communication:
        patient_resource["communication"] = communication

    return patient_resource