public enum EncounterType { Inpatient, Outpatient, Emergency }

public static class EncounterTypeExtensions
{
    public static string ToDbString(this EncounterType t) => t switch
    {
        EncounterType.Inpatient  => "INPATIENT",
        EncounterType.Outpatient => "OUTPATIENT",
        EncounterType.Emergency  => "EMERGENCY",
        _ => throw new ArgumentOutOfRangeException(nameof(t))
    };

    public static EncounterType FromDbString(string v) => v switch
    {
        "INPATIENT"  => EncounterType.Inpatient,
        "OUTPATIENT" => EncounterType.Outpatient,
        "EMERGENCY"  => EncounterType.Emergency,
        _ => throw new ArgumentOutOfRangeException(nameof(v), $"Unknown encounter type: '{v}'")
    };
}
