public static void WriteResource(string pid, Resource r, string outputDirectory, bool xml)
        {
            string rid   = pid ?? r.Id;
            string rname = r.ResourceType.ToString();

            if (xml)
            {
                FhirXmlSerializer xs = new FhirXmlSerializer();
                string            sr = xs.SerializeToString(r);
                FhirHelper.Write(rid, rname, sr, outputDirectory, xml);
            }
            else
            {
                FhirJsonSerializer js = new FhirJsonSerializer();
                string             sr = js.SerializeToString(r);
                FhirHelper.Write(rid, rname, sr, outputDirectory, xml);
            }
        }