Ejemplo n.º 1
0
    private static void PutPatient()
    {
      Hl7.Fhir.Rest.FhirClient clientFhir = new Hl7.Fhir.Rest.FhirClient(StaticTestData.FhirEndpoint(), false);
      //Hl7.Fhir.Rest.FhirClient clientFhir = new Hl7.Fhir.Rest.FhirClient("https://stu3.test.pyrohealth.net/fhir", false);
      clientFhir.Timeout = 1000 * 720; // give the call a while to execute (particularly while debugging).
      //clientFhir.Timeout = 30000; // give the call a while to execute (particularly while debugging).
      Hl7.Fhir.Model.Patient Pat = new Hl7.Fhir.Model.Patient();
      //Pat.Id = Guid.NewGuid().ToString();
      Pat.Name = new List<Hl7.Fhir.Model.HumanName>()
      {
       new Hl7.Fhir.Model.HumanName()
       {
         Family = "millar104"
       }
      };
      var response = clientFhir.Create<Hl7.Fhir.Model.Patient>(Pat);
      string PatientResourceId = response.Id;
      Assert.AreEqual("1", response.VersionId);

      Pat.Id = PatientResourceId;
      Pat.Name[0].Family = "millar105";

      response = clientFhir.Update<Hl7.Fhir.Model.Patient>(Pat);
      Assert.AreEqual("2", response.VersionId);

      var PatientResult = (Hl7.Fhir.Model.Patient)clientFhir.Get($"{StaticTestData.FhirEndpoint()}/{PatientResourceId}");

      Assert.AreEqual(Hl7.Fhir.Model.ResourceType.Patient, PatientResult.ResourceType);
      
    }
Ejemplo n.º 2
0
    public void Test_CRUD()
    {

      Hl7.Fhir.Rest.FhirClient clientFhir = new Hl7.Fhir.Rest.FhirClient(StaticTestData.FhirEndpoint(), false);
      clientFhir.Timeout = 1000 * 720; // give the call a while to execute (particularly while debugging).

      string PatientResourceId = string.Empty;

      //Add a Patient resource by Update
      Patient PatientOne = new Patient();
      PatientOne.Name.Add(HumanName.ForFamily("TestPatient").WithGiven("Test"));
      PatientOne.BirthDateElement = new Date("1979-09-30");
      string PatientOneMRNIdentifer = Guid.NewGuid().ToString();
      PatientOne.Identifier.Add(new Identifier(StaticTestData.TestIdentiferSystem, PatientOneMRNIdentifer));
      PatientOne.Gender = AdministrativeGender.Unknown;

      Patient PatientResult = null;
      try
      {
        PatientResult = clientFhir.Create(PatientOne);
      }
      catch (Exception Exec)
      {
        Assert.True(false, "Exception thrown on resource Create: " + Exec.Message);
      }
      Assert.NotNull(PatientResult, "Resource create by Updated returned resource of null");
      PatientResourceId = PatientResult.Id;
      PatientResult = null;

      //Get the Added resource by Id
      try
      {
        //PatientOneResourceId
        PatientResult = (Patient)clientFhir.Get($"{StaticTestData.FhirEndpoint()}/Patient/{PatientResourceId}");
      }
      catch (Exception Exec)
      {
        Assert.True(false, "Exception thrown on resource Get: " + Exec.Message);
      }
      Assert.NotNull(PatientResult, "Resource Get returned resource of null");
      Assert.AreEqual(PatientResourceId, PatientResult.Id, "Resource created by Updated has incorrect Resource Id");
      Assert.AreEqual(AdministrativeGender.Unknown, PatientResult.Gender, "Patient gender does not match.");

      //Update
      PatientResult.Gender = AdministrativeGender.Male;
      try
      {
        clientFhir.Update(PatientResult);
      }
      catch (Exception Exec)
      {
        Assert.True(false, "Exception thrown on resource Get: " + Exec.Message);
      }
      PatientResult = null;

      //Get the Added resource by Id
      try
      {
        PatientResult = (Patient)clientFhir.Get($"{StaticTestData.FhirEndpoint()}/Patient/{PatientResourceId}");
      }
      catch (Exception Exec)
      {
        Assert.True(false, "Exception thrown on resource Get: " + Exec.Message);
      }
      Assert.NotNull(PatientResult, "Resource Get returned resource of null");
      Assert.AreEqual(AdministrativeGender.Male, PatientResult.Gender, "Patient gender does not match.");

      //Delete Resource
      try
      {
        clientFhir.Delete($"Patient/{PatientResourceId}");
      }
      catch (Exception Exec)
      {
        Assert.True(false, "Exception thrown on resource Get: " + Exec.Message);
      }

      //Get the Added resource by Id
      try
      {
        var Result = clientFhir.Get($"{StaticTestData.FhirEndpoint()}/Patient/{PatientResourceId}");
      }
      catch (Hl7.Fhir.Rest.FhirOperationException OpExec)
      {
        Assert.AreEqual(OpExec.Status, System.Net.HttpStatusCode.Gone, "Final Get did not return Http Status of Gone.");
      }

    }
Ejemplo n.º 3
0
        public void Test_ConditionalCreate()
        {
            Hl7.Fhir.Rest.FhirClient clientFhir = new Hl7.Fhir.Rest.FhirClient(StaticTestData.FhirEndpoint(), false);
            clientFhir.Timeout = 1000 * 600; // give the call a while to execute (particularly while debugging).
            string TempResourceVersion = string.Empty;
            string TempResourceId      = string.Empty;

            //Best to have this clean up here as things can get out of
            //synch with the database when debugging.
            //We always need a clean db to start run.
            var sp = new SearchParams().Where("identifier=http://TestingSystem.org/id|");

            try
            {
                clientFhir.Delete("Patient", sp);
            }
            catch (Exception Exec)
            {
                Assert.True(false, "Exception thrown on conditional delete of resource G: " + Exec.Message);
            }


            // Prepare test patient
            Patient PatientOne = new Patient();

            PatientOne.Name.Add(HumanName.ForFamily("FhirMan").WithGiven("Sam"));
            PatientOne.BirthDateElement = new Date("1970-01");
            PatientOne.Identifier.Add(new Identifier(StaticTestData.TestIdentiferSystem, "5"));

            SearchParams SearchParams = new SearchParams().Where("identifier=5");

            try
            {
                var ResultOne = clientFhir.Create(PatientOne, SearchParams);
                TempResourceId      = ResultOne.Id;
                TempResourceVersion = ResultOne.VersionId;
            }
            catch (FhirOperationException execOper)
            {
                Assert.Fail("Exception was thrown on Condition Create, message was: " + execOper.Message);
            }

            try
            {
                //This will return status OK but does not commit the resource and therefore
                //does not increment the resource version number
                clientFhir.Create(PatientOne, SearchParams);
            }
            catch (FhirOperationException execOper)
            {
                Assert.Fail("Exception was thrown on Condition Create, message was: " + execOper.Message);
            }

            try
            {
                //This will return status OK but does not commit the resource and therefore
                //does not increment the resource version number
                var PatientResult = (Patient)clientFhir.Get($"{StaticTestData.FhirEndpoint()}/Patient/{TempResourceId}");
                Assert.AreEqual(TempResourceVersion, PatientResult.VersionId, "The Version Id was not correct post Conditional Create when Resource was found.");
            }
            catch (FhirOperationException execOper)
            {
                Assert.Fail("Exception was thrown on Condition Create get operation, message was: " + execOper.Message);
            }


            // Create another Patient with the same name
            Patient PatientTwo = new Patient();

            PatientTwo.Name.Add(HumanName.ForFamily("FhirMan").WithGiven("Sam"));
            PatientTwo.BirthDateElement = new Date("1970-01");
            PatientTwo.Identifier.Add(new Identifier(StaticTestData.TestIdentiferSystem, "6"));
            try
            {
                var ResultTwo = clientFhir.Create(PatientTwo);
            }
            catch (FhirOperationException execOper)
            {
                Assert.Fail("Exception was thrown on Condition Create, message was: " + execOper.Message);
            }

            //Now try an Create another again with a search on the Name
            //This should fail as it will resolve to many resource
            Patient PatientThree = new Patient();

            PatientThree.Name.Add(HumanName.ForFamily("FhirMan").WithGiven("Sam"));
            PatientThree.BirthDateElement = new Date("1970-01");
            PatientThree.Identifier.Add(new Identifier(StaticTestData.TestIdentiferSystem, "7"));
            SearchParams = new SearchParams().Where("family=FhirMan").Where("given=Sam");
            try
            {
                var ResultThree = clientFhir.Create(PatientTwo, SearchParams);
                Assert.IsNull(ResultThree, "ResultThree should be null as the ConditionaCreate search parameters should find many resource");
            }
            catch (FhirOperationException execOper)
            {
                Assert.AreEqual(System.Net.HttpStatusCode.PreconditionFailed, execOper.Status, "Did not get Http status 412 when resolving against many resources on ConditionalCreate");
            }



            //Clean up by deleting all resources created while also testing Conditional Delete many
            sp = new SearchParams().Where("identifier=http://TestingSystem.org/id|");
            try
            {
                clientFhir.Delete("Patient", sp);
            }
            catch (Exception Exec)
            {
                Assert.True(false, "Exception thrown on conditional delete of resource G: " + Exec.Message);
            }
        }