本文整理汇总了C#中FhirClient.Create方法的典型用法代码示例。如果您正苦于以下问题:C# FhirClient.Create方法的具体用法?C# FhirClient.Create怎么用?C# FhirClient.Create使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类FhirClient
的用法示例。
在下文中一共展示了FhirClient.Create方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GetMedicationDetails
public async static Task<Tuple<List<Medication>, Hl7.Fhir.Model.Patient>> GetMedicationDetails(string id, ApplicationUserManager userManager)
{
Tuple<List<Medication>, Hl7.Fhir.Model.Patient> tup;
using (var dbcontext = new ApplicationDbContext())
{
// Should be FhirID
var user = await userManager.FindByIdAsync(id);
if (user == null)
{
return null;
}
var client = new FhirClient(Constants.HapiFhirServerBase);
if (string.IsNullOrWhiteSpace(user.FhirPatientId))
{
var result = client.Create(new Hl7.Fhir.Model.Patient() { });
user.FhirPatientId = result.Id;
await userManager.UpdateAsync(user);
}
var patient = client.Read<Hl7.Fhir.Model.Patient>(Constants.PatientBaseUrl + user.FhirPatientId);
tup= new Tuple<List<Medication>, Patient>(await EhrBase.GetMedicationDataForPatientAsync(user.FhirPatientId, client), patient);
return tup;
}
}
示例2: Register
public async Task<ActionResult> Register(RegisterViewModel model)
{
if(ModelState.IsValid)
{
var client = new FhirClient(Constants.HapiFhirServerBase);
var fhirResult = client.Create(new Hl7.Fhir.Model.Patient() { });
var user = new ApplicationUser { UserName = model.Email, Email = model.Email, FhirPatientId = fhirResult.Id };
var result = await UserManager.CreateAsync(user, model.Password);
if(result.Succeeded)
{
await UserManager.AddToRolesAsync(user.Id, Enum.GetName(typeof(AccountLevel), model.Account_Level));
await SignInManager.SignInAsync(user, isPersistent: false, rememberBrowser: false);
// For more information on how to enable account confirmation and password reset please visit http://go.microsoft.com/fwlink/?LinkID=320771
// Send an email with this link
// string code = await UserManager.GenerateEmailConfirmationTokenAsync(user.Id);
// var callbackUrl = Url.Action("ConfirmEmail", "Account", new { userId = user.Id, code = code }, protocol: Request.Url.Scheme);
// await UserManager.SendEmailAsync(user.Id, "Confirm your account", "Please confirm your account by clicking <a href=\"" + callbackUrl + "\">here</a>");
return RedirectToAction("Index", "Home");
}
AddErrors(result);
}
// If we got this far, something failed, redisplay form
return View(viewName: "Register");
}
示例3: CreateEditDelete
public void CreateEditDelete()
{
var furore = new Organization
{
Name = "Furore",
Identifier = new List<Identifier> { new Identifier("http://hl7.org/test/1", "3141") },
Telecom = new List<Contact> { new Contact { System = Contact.ContactSystem.Phone, Value = "+31-20-3467171" } }
};
FhirClient client = new FhirClient(testEndpoint);
var tags = new List<Tag> { new Tag("http://nu.nl/testname", Tag.FHIRTAGNS, "TestCreateEditDelete") };
var fe = client.Create(furore,tags);
Assert.IsNotNull(furore);
Assert.IsNotNull(fe);
Assert.IsNotNull(fe.Id);
Assert.IsNotNull(fe.SelfLink);
Assert.AreNotEqual(fe.Id,fe.SelfLink);
Assert.IsNotNull(fe.Tags);
Assert.AreEqual(1, fe.Tags.Count());
Assert.AreEqual(fe.Tags.First(), tags[0]);
createdTestOrganization = fe.Id;
fe.Resource.Identifier.Add(new Identifier("http://hl7.org/test/2", "3141592"));
var fe2 = client.Update(fe);
Assert.IsNotNull(fe2);
Assert.AreEqual(fe.Id, fe2.Id);
Assert.AreNotEqual(fe.SelfLink, fe2.SelfLink);
Assert.IsNotNull(fe2.Tags);
Assert.AreEqual(1, fe2.Tags.Count());
Assert.AreEqual(fe2.Tags.First(), tags[0]);
client.Delete(fe2.Id);
try
{
fe = client.Read<Organization>(ResourceLocation.GetIdFromResourceId(fe.Id));
Assert.Fail();
}
catch
{
Assert.IsTrue(client.LastResponseDetails.Result == HttpStatusCode.Gone);
}
Assert.IsNull(fe);
}
示例4: button2_Click
// When button 2 is clikced, create patient
private void button2_Click(object sender, EventArgs e)
{
// Edit status text
createPatientStatus.Text = "Creating...";
// Set FHIR endpoint and create client
var endpoint = new Uri("http://fhirtest.uhn.ca/baseDstu2");
var client = new FhirClient(endpoint);
// Create new patient birthdate and name
var pat = new Patient() {BirthDate = birthDate.Text, Name= new List<HumanName>()};
pat.Name.Add(HumanName.ForFamily(lastName.Text).WithGiven(givenName.Text));
// Upload to server
//client.ReturnFullResource = true;
client.Create(pat);
createPatientStatus.Text = "Created!";
}
示例5: ManipulateMeta
public void ManipulateMeta()
{
FhirClient client = new FhirClient(testEndpoint);
var pat = FhirParser.ParseResourceFromXml(File.ReadAllText(@"TestData\TestPatient.xml"));
var key = new Random().Next();
pat.Id = "NetApiMetaTestPatient" + key;
var meta = new Meta();
meta.ProfileElement.Add(new FhirUri("http://someserver.org/fhir/Profile/XYZ1-" + key));
meta.Security.Add(new Coding("http://mysystem.com/sec", "1234-" + key));
meta.Tag.Add(new Coding("http://mysystem.com/tag", "sometag1-" + key));
pat.Meta = meta;
//Before we begin, ensure that our new tags are not actually used when doing System Meta()
var wsm = client.Meta();
Assert.IsFalse(wsm.Meta.Profile.Contains("http://someserver.org/fhir/Profile/XYZ1-" + key));
Assert.IsFalse(wsm.Meta.Security.Select(c => c.Code + "@" + c.System).Contains("1234-" + key + "@http://mysystem.com/sec"));
Assert.IsFalse(wsm.Meta.Tag.Select(c => c.Code + "@" + c.System).Contains("sometag1-" + key + "@http://mysystem.com/tag"));
Assert.IsFalse(wsm.Meta.Profile.Contains("http://someserver.org/fhir/Profile/XYZ2-" + key));
Assert.IsFalse(wsm.Meta.Security.Select(c => c.Code + "@" + c.System).Contains("5678-" + key + "@http://mysystem.com/sec"));
Assert.IsFalse(wsm.Meta.Tag.Select(c => c.Code + "@" + c.System).Contains("sometag2-" + key + "@http://mysystem.com/tag"));
// First, create a patient with the first set of meta
var pat2 = client.Create(pat);
var loc = pat2.ResourceIdentity(testEndpoint);
// Meta should be present on created patient
verifyMeta(pat2.Meta, false,key);
// Should be present when doing instance Meta()
var par = client.Meta(loc);
verifyMeta(par.Meta, false,key);
// Should be present when doing type Meta()
par = client.Meta(ResourceType.Patient);
verifyMeta(par.Meta, false,key);
// Should be present when doing System Meta()
par = client.Meta();
verifyMeta(par.Meta, false,key);
// Now add some additional meta to the patient
var newMeta = new Meta();
newMeta.ProfileElement.Add(new FhirUri("http://someserver.org/fhir/Profile/XYZ2-" + key));
newMeta.Security.Add(new Coding("http://mysystem.com/sec", "5678-" + key));
newMeta.Tag.Add(new Coding("http://mysystem.com/tag", "sometag2-" + key));
client.AddMeta(loc, newMeta);
var pat3 = client.Read<Patient>(loc);
// New and old meta should be present on instance
verifyMeta(pat3.Meta, true, key);
// New and old meta should be present on Meta()
par = client.Meta(loc);
verifyMeta(par.Meta, true, key);
// New and old meta should be present when doing type Meta()
par = client.Meta(ResourceType.Patient);
verifyMeta(par.Meta, true, key);
// New and old meta should be present when doing system Meta()
par = client.Meta();
verifyMeta(par.Meta, true, key);
// Now, remove those new meta tags
client.DeleteMeta(loc, newMeta);
// Should no longer be present on instance
var pat4 = client.Read<Patient>(loc);
verifyMeta(pat4.Meta, false, key);
// Should no longer be present when doing instance Meta()
par = client.Meta(loc);
verifyMeta(par.Meta, false, key);
// Should no longer be present when doing type Meta()
par = client.Meta(ResourceType.Patient);
verifyMeta(par.Meta, false, key);
// clear out the client that we created, no point keeping it around
client.Delete(pat4);
// Should no longer be present when doing System Meta()
par = client.Meta();
verifyMeta(par.Meta, false, key);
}
示例6: CreateEditDelete
public void CreateEditDelete()
{
var pat = (Patient)FhirParser.ParseResourceFromXml(File.ReadAllText(@"TestData\TestPatient.xml"));
var key = new Random().Next();
pat.Id = "NetApiCRUDTestPatient" + key;
FhirClient client = new FhirClient(testEndpoint);
var fe = client.Create(pat);
Assert.IsNotNull(fe);
Assert.IsNotNull(fe.Id);
Assert.IsNotNull(fe.Meta.VersionId);
createdTestPatientUrl = fe.ResourceIdentity();
fe.Identifier.Add(new Identifier("http://hl7.org/test/2", "3141592"));
var fe2 = client.Update(fe);
Assert.IsNotNull(fe2);
Assert.AreEqual(fe.Id, fe2.Id);
Assert.AreNotEqual(fe.ResourceIdentity(), fe2.ResourceIdentity());
Assert.AreEqual(2, fe2.Identifier.Count);
fe.Identifier.Add(new Identifier("http://hl7.org/test/3", "3141592"));
var fe3 = client.Update(fe);
Assert.IsNotNull(fe3);
Assert.AreEqual(3, fe3.Identifier.Count);
client.Delete(fe3);
try
{
// Get most recent version
fe = client.Read<Patient>(fe.ResourceIdentity().WithoutVersion());
Assert.Fail();
}
catch
{
Assert.IsTrue(client.LastResult.Status == HttpStatusCode.Gone.ToString());
}
}
示例7: RequestFullResource
public void RequestFullResource()
{
var client = new FhirClient(testEndpoint);
var minimal = false;
client.OnBeforeRequest += (object s, BeforeRequestEventArgs e) => e.RawRequest.Headers["Prefer"] = minimal ? "return=minimal" : "return=representation";
var result = client.Read<Patient>("Patient/example");
Assert.IsNotNull(result);
result.Id = null;
result.Meta = null;
client.ReturnFullResource = true;
minimal = false;
var posted = client.Create(result);
Assert.IsNotNull(posted, "Patient example not found");
minimal = true; // simulate a server that does not return a body, even if ReturnFullResource = true
posted = client.Create(result);
Assert.IsNotNull(posted, "Did not return a resource, even when ReturnFullResource=true");
client.ReturnFullResource = false;
minimal = true;
posted = client.Create(result);
Assert.IsNull(posted);
}
示例8: CreateEditDelete
public void CreateEditDelete()
{
FhirClient client = new FhirClient(testEndpoint);
var pat = client.Read<Patient>("Patient/example");
pat.Id = null;
pat.Identifier.Clear();
pat.Identifier.Add(new Identifier("http://hl7.org/test/2", "99999"));
var fe = client.Create(pat);
Assert.IsNotNull(fe);
Assert.IsNotNull(fe.Id);
Assert.IsNotNull(fe.Meta.VersionId);
createdTestPatientUrl = fe.ResourceIdentity();
fe.Identifier.Add(new Identifier("http://hl7.org/test/2", "3141592"));
var fe2 = client.Update(fe);
Assert.IsNotNull(fe2);
Assert.AreEqual(fe.Id, fe2.Id);
Assert.AreNotEqual(fe.ResourceIdentity(), fe2.ResourceIdentity());
Assert.AreEqual(2, fe2.Identifier.Count);
fe.Identifier.Add(new Identifier("http://hl7.org/test/3", "3141592"));
var fe3 = client.Update(fe);
Assert.IsNotNull(fe3);
Assert.AreEqual(3, fe3.Identifier.Count);
client.Delete(fe3);
try
{
// Get most recent version
fe = client.Read<Patient>(fe.ResourceIdentity().WithoutVersion());
Assert.Fail();
}
catch
{
Assert.IsTrue(client.LastResult.Status == "410");
}
}
示例9: CreateAndFullRepresentation
public void CreateAndFullRepresentation()
{
FhirClient client = new FhirClient(testEndpoint);
client.ReturnFullResource = true; // which is also the default
var pat = client.Read<Patient>("Patient/example");
pat.Id = null;
pat.Identifier.Clear();
var patC = client.Create<Patient>(pat);
Assert.IsNotNull(patC);
client.ReturnFullResource = false;
patC = client.Create<Patient>(pat);
Assert.IsNull(patC);
if (client.LastBody != null)
{
var returned = client.LastBodyAsResource;
Assert.IsTrue(returned is OperationOutcome);
}
}
示例10: tryCreatePatient
private Uri tryCreatePatient(FhirClient client, ResourceFormat formatIn, string id = null)
{
client.PreferredFormat = formatIn;
ResourceEntry<Patient> created = null;
Patient demopat = DemoData.GetDemoPatient();
if (id == null)
{
HttpTests.AssertSuccess(client, () => created = client.Create<Patient>(demopat));
}
else
{
HttpTests.AssertSuccess(client, () => created = client.Create<Patient>(demopat, id));
var ep = new RestUrl(client.Endpoint);
if (!ep.IsEndpointFor(created.Id))
TestResult.Fail("Location of created resource is not located within server endpoint");
var rl = new ResourceIdentity(created.Id);
if (rl.Id != id)
TestResult.Fail("Server refused to honor client-assigned id");
}
HttpTests.AssertLocationPresentAndValid(client);
// Create bevat geen response content meer. Terecht verwijderd?:
// EK: Niet helemaal, er is weliswaar geen data meer gereturned, maar de headers (id, versie, modified) worden
// nog wel geupdate
HttpTests.AssertContentLocationValidIfPresent(client);
return created.SelfLink;
}
示例11: AddMedicationOrder
public static void AddMedicationOrder(string id, string medicationName)
{
using (var dbcontext = new ApplicationDbContext())
{
var user = dbcontext.Users.FirstOrDefault(a => a.Id == id);
//todo: I'm not sure about the web portion with regards with what the view should return, I leave
// leave that to you, but I left logic to return the medication order ID if you desire. To
// show whether the post was successful
//todo: I do not know where the medicationName will be pulled from, so change harcoded "medicationName"
// to the parameter name you expect to use.
//Full list of Parameters you may also decide to pass in:
//patientID (done), medicationName, system, and display
//First let us create the FHIR client
var fhirClient = new FhirClient(Constants.HapiFhirServerBase);
//First we need to create our medication
var medication = new Medication
{
Code = new CodeableConcept("ICD-10", medicationName)
};
//Now we need to push this to the server and grab the ID
var medicationResource = fhirClient.Create<Hl7.Fhir.Model.Medication>(medication);
var medicationResourceID = medicationResource.Id;
//Create an empty medication order resource and then assign attributes
var fhirMedicationOrder = new Hl7.Fhir.Model.MedicationOrder();
//There is no API for "Reference" in MedicationOrder model, unlike Patient model.
//You must initialize ResourceReference inline.
fhirMedicationOrder.Medication = new ResourceReference()
{
Reference = fhirClient.Endpoint.OriginalString + "Medication/" + medicationResourceID,
Display = "EhrgoHealth"
};
//Now associate Medication Order to a Patient
fhirMedicationOrder.Patient = new ResourceReference();
fhirMedicationOrder.Patient.Reference = "Patient/" + user.FhirPatientId;
//Push the local patient resource to the FHIR Server and expect a newly assigned ID
var medicationOrderResource = fhirClient.Create<Hl7.Fhir.Model.MedicationOrder>(fhirMedicationOrder);
}
}
示例12: Create_ObservationWithValueAsSimpleQuantity_ReadReturnsValueAsQuantity
//Test for github issue https://github.com/ewoutkramer/fhir-net-api/issues/145
public void Create_ObservationWithValueAsSimpleQuantity_ReadReturnsValueAsQuantity()
{
FhirClient client = new FhirClient(testEndpoint);
var observation = new Observation();
observation.Status = Observation.ObservationStatus.Preliminary;
observation.Code = new CodeableConcept("http://loinc.org", "2164-2");
observation.Value = new SimpleQuantity()
{
System = "http://unitsofmeasure.org",
Value = 23,
Code = "mg",
Unit = "miligram"
};
observation.BodySite = new CodeableConcept("http://snomed.info/sct", "182756003");
var fe = client.Create(observation);
fe = client.Read<Observation>(fe.ResourceIdentity().WithoutVersion());
Assert.IsInstanceOfType(fe.Value, typeof(Quantity));
}
示例13: CreateAndFullRepresentation
public void CreateAndFullRepresentation()
{
FhirClient client = new FhirClient(testEndpoint);
client.ReturnFullResource = true; // which is also the default
var pat = client.Read<Patient>("Patient/example");
ResourceIdentity ri = pat.ResourceIdentity().WithBase(client.Endpoint);
pat.Id = null;
pat.Identifier.Clear();
var patC = client.Create<Patient>(pat);
Assert.IsNotNull(patC);
client.ReturnFullResource = false;
patC = client.Create<Patient>(pat);
Assert.IsNull(patC);
if (client.LastBody != null)
{
var returned = client.LastBodyAsResource;
Assert.IsTrue(returned is OperationOutcome);
}
// Now validate this resource
client.ReturnFullResource = true; // which is also the default
Parameters p = new Parameters();
// p.Add("mode", new FhirString("create"));
p.Add("resource", pat);
OperationOutcome ooI = (OperationOutcome)client.InstanceOperation(ri.WithoutVersion(), "validate", p);
Assert.IsNotNull(ooI);
}
示例14: button1_Click_2
private void button1_Click_2(object sender, EventArgs e)
{
var endpoint = new Uri("http://fhirtest.uhn.ca/baseDstu2");
var client = new FhirClient(endpoint);
// Create new value for observation
SampledData val = new SampledData();
CodeableConcept concept = new CodeableConcept();
concept.Coding = new List<Coding>();
if (conversionList.Text.Equals("age"))
{
val.Data = CurrentMeasurement.age.ToString();
Coding code = new Coding();
code.Code = "410668003";
concept.Coding.Add(code);
}
else if (conversionList.Text.Equals("bmr"))
{
val.Data = CurrentMeasurement.bmr.ToString();
Coding code = new Coding();
code.Code = "60621009";
concept.Coding.Add(code);
}
else if (conversionList.Text.Equals("height"))
{
val.Data = CurrentMeasurement.height.ToString();
Coding code = new Coding();
code.Code = "60621009"; //SNOMED CT code
concept.Coding.Add(code);
}
else if (conversionList.Text.Equals("m_active_time")) val.Data = CurrentMeasurement.m_active_time.ToString();
else if (conversionList.Text.Equals("m_calories")) val.Data = CurrentMeasurement.m_calories.ToString();
else if (conversionList.Text.Equals("m_distance")) val.Data = CurrentMeasurement.m_distance.ToString();
else if (conversionList.Text.Equals("m_inactive_time")) val.Data = CurrentMeasurement.m_inactive_time.ToString();
else if (conversionList.Text.Equals("m_lcat")) val.Data = CurrentMeasurement.m_lcat.ToString();
else if (conversionList.Text.Equals("m_lcit")) val.Data = CurrentMeasurement.m_lcit.ToString();
else if (conversionList.Text.Equals("m_steps")) val.Data = CurrentMeasurement.m_steps.ToString();
else if (conversionList.Text.Equals("m_total_calories")) val.Data = CurrentMeasurement.m_total_calories.ToString();
else if (conversionList.Text.Equals("s_asleep_time")) val.Data = CurrentMeasurement.s_asleep_time.ToString();
else if (conversionList.Text.Equals("s_awake")) val.Data = CurrentMeasurement.s_awake.ToString();
else if (conversionList.Text.Equals("s_awake_time")) val.Data = CurrentMeasurement.s_awake_time.ToString();
else if (conversionList.Text.Equals("s_awakenings")) val.Data = CurrentMeasurement.s_awakenings.ToString();
else if (conversionList.Text.Equals("s_bedtime")) val.Data = CurrentMeasurement.s_bedtime.ToString();
else if (conversionList.Text.Equals("s_clinical_deep")) val.Data = CurrentMeasurement.s_clinical_deep.ToString();
else if (conversionList.Text.Equals("s_count")) val.Data = CurrentMeasurement.s_count.ToString();
else if (conversionList.Text.Equals("s_duration")) val.Data = CurrentMeasurement.s_duration.ToString();
else if (conversionList.Text.Equals("s_light")) val.Data = CurrentMeasurement.s_light.ToString();
else if (conversionList.Text.Equals("s_quality")) val.Data = CurrentMeasurement.s_quality.ToString();
else if (conversionList.Text.Equals("s_rem")) val.Data = CurrentMeasurement.s_rem.ToString();
else if (conversionList.Text.Equals("weight")) val.Data = CurrentMeasurement.weight.ToString();
else val.Data = "E"; // Error
Console.WriteLine("Value data: " + val.Data);
ResourceReference dev = new ResourceReference();
dev.Reference = "Device/" + CurrentDevice.Id;
ResourceReference pat = new ResourceReference();
pat.Reference = "Patient/" + CurrentPatient.Id;
Console.WriteLine("Patient reference: " + pat.Reference);
Console.WriteLine("Conversion: " + conversionList.Text);
CodeableConcept naam = new CodeableConcept();
naam.Text = conversionList.Text;
DateTime date = DateTime.ParseExact(CurrentMeasurement.date, "yyyymmdd", null);
Console.WriteLine("" + date.ToString());
var obs = new Observation() {Device = dev, Subject = pat, Value = val, Issued = date, Code = naam, Category = concept, Status = Observation.ObservationStatus.Final};
client.Create(obs);
conversionStatus.Text = "Done!";
}
示例15: btnDeviceCreate_Click
// Create a device
private void btnDeviceCreate_Click(object sender, EventArgs e)
{
createDeviceStatus.Text = "Creating...";
var endpoint = new Uri("http://fhirtest.uhn.ca/baseDstu2");
var client = new FhirClient(endpoint);
var dev = new Device() { Manufacturer = createDeviceManufacturer.Text, Model = createDeviceModel.Text};
client.Create(dev);
createDeviceStatus.Text = "Done!";
}