public void TestDeleteLocation() { var location = TestUtil.GetFhirMessage("CreateLocation") as Location; TestUtil.CreateAuthority("TEST", "1.2.3.4", "http://santedb.org/fhir/test", "TEST_HARNESS", this.AUTH); using (TestUtil.AuthenticateFhir("TEST_HARNESS", this.AUTH)) { var locationResourceHandler = FhirResourceHandlerUtil.GetResourceHandler(ResourceType.Location); var actual = locationResourceHandler.Create(location, TransactionMode.Commit); Assert.IsNotNull(actual); Assert.IsInstanceOf <Location>(actual); var createdLocation = (Location)actual; Assert.IsNotNull(createdLocation); var actualDeleted = locationResourceHandler.Delete(createdLocation.Id, TransactionMode.Commit); Assert.IsNotNull(actualDeleted); Assert.IsInstanceOf <Location>(actualDeleted); var deletedLocation = (Location)actualDeleted; Assert.IsNotNull(deletedLocation); Assert.AreEqual(Location.LocationStatus.Inactive, deletedLocation.Status); } }
public void TestUpdateLocationInvalidResource() { var location = TestUtil.GetFhirMessage("UpdateLocation") as Location; TestUtil.CreateAuthority("TEST", "1.2.3.4", "http://santedb.org/fhir/test", "TEST_HARNESS", this.AUTH); using (TestUtil.AuthenticateFhir("TEST_HARNESS", this.AUTH)) { var locationResourceHandler = FhirResourceHandlerUtil.GetResourceHandler(ResourceType.Location); var actual = locationResourceHandler.Create(location, TransactionMode.Commit); Assert.IsNotNull(actual); Assert.IsInstanceOf <Location>(actual); var createdLocation = (Location)actual; Assert.IsNotNull(createdLocation); Assert.AreEqual(Location.LocationStatus.Active, createdLocation.Status); Assert.AreEqual(Location.LocationMode.Instance, createdLocation.Mode); Assert.AreEqual("Ontario", createdLocation.Address.State); createdLocation.Status = Location.LocationStatus.Suspended; createdLocation.Mode = Location.LocationMode.Kind; createdLocation.Address.State = "Alberta"; Assert.Throws <InvalidDataException>(() => locationResourceHandler.Update(createdLocation.Id, new Patient(), TransactionMode.Commit)); } }
public void TestCreateOrganization() { // set up the test data var organization = TestUtil.GetFhirMessage("Organization") as Organization; Resource result; // execute the operation under test TestUtil.CreateAuthority("TEST", "1.2.3.4", "http://santedb.org/fhir/test", "TEST_HARNESS", this.AUTH); using (TestUtil.AuthenticateFhir("TEST_HARNESS", this.AUTH)) { var organizationResourceHandler = FhirResourceHandlerUtil.GetResourceHandler(ResourceType.Organization); result = organizationResourceHandler.Create(organization, TransactionMode.Commit); result = organizationResourceHandler.Read(result.Id, result.VersionId); } // assert create organization successfully Assert.NotNull(result); Assert.IsInstanceOf <Organization>(result); var actual = (Organization)result; Assert.AreEqual("Hamilton Health Sciences", actual.Name); Assert.IsTrue(actual.Alias.All(c => c == "hhs")); Assert.IsTrue(actual.Address.Count == 2); Assert.IsTrue(actual.Extension.Any(e => e.Url == "http://santedb.org/extensions/core/detectedIssue")); Assert.IsTrue(actual.Identifier.First().Value == "6324"); Assert.AreEqual("http://santedb.org/fhir/test", actual.Identifier.First().System); Assert.IsTrue(actual.Identifier.Count == 1); }
public void TestRegisterResourceHandler() { FhirResourceHandlerUtil.RegisterResourceHandler(new DummyResourceHandler()); Assert.NotNull(FhirResourceHandlerUtil.GetResourceHandler(ResourceType.DomainResource)); Assert.IsInstanceOf <DummyResourceHandler>(FhirResourceHandlerUtil.GetResourceHandler(ResourceType.DomainResource)); Assert.IsTrue(FhirResourceHandlerUtil.ResourceHandlers.Any(c => c.GetType() == typeof(DummyResourceHandler))); }
public void TestQueryPatientByGeneralPractitioner() { var practitioner = TestUtil.GetFhirMessage("CreatePatientWithGeneralPractitioner-Practitioner") as Practitioner; var patient = TestUtil.GetFhirMessage("CreatePatientWithGeneralPractitioner-Patient") as Patient; Resource actualPatient; Resource actualPractitioner; TestUtil.CreateAuthority("TEST", "1.2.3.4", "http://santedb.org/fhir/test", "TEST_HARNESS", this.AUTH); using (TestUtil.AuthenticateFhir("TEST_HARNESS", this.AUTH)) { var patientResourceHandler = FhirResourceHandlerUtil.GetResourceHandler(ResourceType.Patient); var practitionerResourceHandler = FhirResourceHandlerUtil.GetResourceHandler(ResourceType.Practitioner); actualPractitioner = practitionerResourceHandler.Create(practitioner, TransactionMode.Commit); patient.GeneralPractitioner = new List <ResourceReference> { new ResourceReference($"urn:uuid:{actualPractitioner.Id}") }; actualPatient = patientResourceHandler.Create(patient, TransactionMode.Commit); } Assert.NotNull(actualPatient); Assert.NotNull(actualPractitioner); Assert.IsInstanceOf <Patient>(actualPatient); Assert.IsInstanceOf <Practitioner>(actualPractitioner); var createdPatient = (Patient)actualPatient; using (TestUtil.AuthenticateFhir("TEST_HARNESS", this.AUTH)) { var patientResourceHandler = FhirResourceHandlerUtil.GetResourceHandler(ResourceType.Patient); var queryResult = patientResourceHandler.Query(new NameValueCollection { { "_id", createdPatient.Id }, { "_include", "Practitioner:generalPractitioner" } }); Assert.NotNull(queryResult); Assert.IsInstanceOf <Bundle>(queryResult); Assert.AreEqual(2, queryResult.Entry.Count); var queriedPatient = (Patient)queryResult.Entry.First(c => c.Resource is Patient).Resource; var includedPractitioner = (Practitioner)queryResult.Entry.First(c => c.Resource is Practitioner).Resource; Assert.IsNotNull(queriedPatient); Assert.IsNotNull(includedPractitioner); Assert.AreEqual("Jordan", queriedPatient.Name.First().Given.First()); Assert.AreEqual("Final", queriedPatient.Name.First().Given.ToList()[1]); Assert.IsTrue(queriedPatient.Active); Assert.AreEqual("905 905 9055", queriedPatient.Telecom.First().Value); Assert.AreEqual("123 Main Street", queriedPatient.Address.First().Line.First()); } }
/// <summary> /// Searches a resource from the client registry datastore /// </summary> public Bundle SearchResource(string resourceType) { this.ThrowIfNotReady(); // Get the services from the service registry var auditService = ApplicationContext.Current.GetService(typeof(IAuditorService)) as IAuditorService; // Stuff for auditing and exception handling AuditData audit = null; List <IResultDetail> details = new List <IResultDetail>(); FhirQueryResult result = null; try { // Get query parameters var queryParameters = WebOperationContext.Current.IncomingRequest.UriTemplateMatch.QueryParameters; var resourceProcessor = FhirResourceHandlerUtil.GetResourceHandler(resourceType); // Setup outgoing content WebOperationContext.Current.OutgoingRequest.Headers.Add("Last-Modified", DateTime.Now.ToString("ddd, dd MMM yyyy HH:mm:ss zzz")); if (resourceProcessor == null) // Unsupported resource { throw new FileNotFoundException(); } // TODO: Appropriately format response // Process incoming request result = resourceProcessor.Query(WebOperationContext.Current.IncomingRequest.UriTemplateMatch.QueryParameters); if (result == null || result.Outcome == ResultCode.Rejected) { throw new InvalidDataException("Message was rejected"); } else if (result.Outcome != ResultCode.Accepted) { throw new DataException("Query failed"); } audit = AuditUtil.CreateAuditData(result.Results); // Create the Atom feed return(MessageUtil.CreateBundle(result)); } catch (Exception e) { audit = AuditUtil.CreateAuditData(null); audit.Outcome = OutcomeIndicator.EpicFail; return(this.ErrorHelper(e, result, true) as Bundle); } finally { if (auditService != null) { auditService.SendAudit(audit); } } }
public void TestCreateInvalidResource() { TestUtil.CreateAuthority("TEST", "1.2.3.4", "http://santedb.org/fhir/test", "TEST_HARNESS", this.AUTH); using (TestUtil.AuthenticateFhir("TEST_HARNESS", this.AUTH)) { var organizationResourceHandler = FhirResourceHandlerUtil.GetResourceHandler(ResourceType.Organization); Assert.Throws <InvalidDataException>(() => organizationResourceHandler.Create(new Practitioner(), TransactionMode.Commit)); } }
public void TestQueryPatientByManagingOrganization() { var patient = TestUtil.GetFhirMessage("CreatePatient") as Patient; var patientLink = TestUtil.GetFhirMessage("CreatePatient-PatientLink") as Patient; var organization = TestUtil.GetFhirMessage("CreatePatientWithOrganization-Organization") as Organization; TestUtil.CreateAuthority("TEST", "1.2.3.4", "http://santedb.org/fhir/test", "TEST_HARNESS", this.AUTH); using (TestUtil.AuthenticateFhir("TEST_HARNESS", this.AUTH)) { var patientResourceHandler = FhirResourceHandlerUtil.GetResourceHandler(ResourceType.Patient); var organizationResourceHandler = FhirResourceHandlerUtil.GetResourceHandler(ResourceType.Organization); // Create the independent resources for the main Resource. var actualOrganization = organizationResourceHandler.Create(organization, TransactionMode.Commit); var createdPatientLink = patientResourceHandler.Create(patientLink, TransactionMode.Commit); // Connect the independent resources to the dependent resource patient.ManagingOrganization = new ResourceReference($"urn:uuid:{actualOrganization.Id}"); patient.Link.First().Other = new ResourceReference($"urn:uuid:{createdPatientLink.Id}"); // Create the dependent resource var actualPatient = patientResourceHandler.Create(patient, TransactionMode.Commit); Assert.IsNotNull(actualPatient); Assert.IsInstanceOf <Patient>(actualPatient); var createdPatient = (Patient)actualPatient; Assert.IsNotNull(patient.ManagingOrganization); var queryResult = patientResourceHandler.Query(new NameValueCollection { { "_id", createdPatient.Id }, { "_include", "Organization:managingOrganization" } }); Assert.NotNull(queryResult); Assert.IsInstanceOf <Bundle>(queryResult); Assert.AreEqual(2, queryResult.Entry.Count); var queriedPatient = (Patient)queryResult.Entry.First(c => c.Resource is Patient).Resource; var includedOrganization = (Organization)queryResult.Entry.First(c => c.Resource is Organization).Resource; Assert.IsNotNull(queriedPatient); Assert.IsNotNull(includedOrganization); Assert.AreEqual("Jordan", queriedPatient.Name.First().Given.First()); Assert.AreEqual("Webber", queriedPatient.Name.First().Family); Assert.AreEqual(AdministrativeGender.Male, queriedPatient.Gender); Assert.AreEqual("Hamilton", queriedPatient.Address.First().City); Assert.AreEqual("mailto:[email protected]", queriedPatient.Telecom.First().Value); Assert.AreEqual("2021-11-23", queriedPatient.BirthDate); } }
public void TestRead() { TestUtil.CreateAuthority("TEST", "1.2.3.4", "http://santedb.org/fhir/test", "TEST_HARNESS", this.AUTH); using (TestUtil.AuthenticateFhir("TEST_HARNESS", this.AUTH)) { var structureDefinitionResourceHandler = FhirResourceHandlerUtil.GetResourceHandler(ResourceType.StructureDefinition); Assert.Throws <NotSupportedException>(() => structureDefinitionResourceHandler.Read(Guid.NewGuid().ToString(), null)); } }
public void TestCreate() { TestUtil.CreateAuthority("TEST", "1.2.3.4", "http://santedb.org/fhir/test", "TEST_HARNESS", this.AUTH); using (TestUtil.AuthenticateFhir("TEST_HARNESS", this.AUTH)) { var structureDefinitionResourceHandler = FhirResourceHandlerUtil.GetResourceHandler(ResourceType.StructureDefinition); Assert.Throws <NotSupportedException>(() => structureDefinitionResourceHandler.Create(new StructureDefinition(), TransactionMode.Commit)); } }
public void TestQuery() { TestUtil.CreateAuthority("TEST", "1.2.3.4", "http://santedb.org/fhir/test", "TEST_HARNESS", this.AUTH); using (TestUtil.AuthenticateFhir("TEST_HARNESS", this.AUTH)) { var bundleResourceHandler = FhirResourceHandlerUtil.GetResourceHandler(ResourceType.Bundle); Assert.Throws <NotSupportedException>(() => bundleResourceHandler.Query(new NameValueCollection())); } }
public void TestDelete() { TestUtil.CreateAuthority("TEST", "1.2.3.4", "http://santedb.org/fhir/test", "TEST_HARNESS", this.AUTH); using (TestUtil.AuthenticateFhir("TEST_HARNESS", this.AUTH)) { var bundleResourceHandler = FhirResourceHandlerUtil.GetResourceHandler(ResourceType.Bundle); Assert.Throws <NotSupportedException>(() => bundleResourceHandler.Delete(Guid.NewGuid().ToString(), TransactionMode.Commit)); } }
public void TestCreateEncounter() { var patient = TestUtil.GetFhirMessage("CreateEncounter-Patient") as Patient; var encounter = TestUtil.GetFhirMessage("CreateEncounter-Encounter") as Encounter; Resource actualPatient; Resource actualEncounter; TestUtil.CreateAuthority("TEST", "1.2.3.4", "http://santedb.org/fhir/test", "TEST_HARNESS", AUTH); using (TestUtil.AuthenticateFhir("TEST_HARNESS", AUTH)) { var patientResourceHandler = FhirResourceHandlerUtil.GetResourceHandler(ResourceType.Patient); var encounterResourceHandler = FhirResourceHandlerUtil.GetResourceHandler(ResourceType.Encounter); actualPatient = patientResourceHandler.Create(patient, TransactionMode.Commit); encounter.Subject = new ResourceReference($"urn:uuid:{actualPatient.Id}"); actualEncounter = encounterResourceHandler.Create(encounter, TransactionMode.Commit); } Assert.NotNull(actualPatient); Assert.NotNull(actualEncounter); Assert.IsInstanceOf <Patient>(actualPatient); Assert.IsInstanceOf <Encounter>(actualEncounter); var createdPatient = (Patient)actualPatient; var createdEncounter = (Encounter)actualEncounter; Assert.NotNull(createdPatient); Assert.NotNull(createdEncounter); Resource actual; using (TestUtil.AuthenticateFhir("TEST_HARNESS", AUTH)) { var encounterResourceHandler = FhirResourceHandlerUtil.GetResourceHandler(ResourceType.Encounter); actual = encounterResourceHandler.Read(createdEncounter.Id, null); } Assert.NotNull(actual); Assert.IsInstanceOf <Encounter>(actual); var retrievedEncounter = (Encounter)actual; Assert.AreEqual(createdEncounter.Id, retrievedEncounter.Id); Assert.AreEqual(createdEncounter.Status, retrievedEncounter.Status); Assert.IsNotNull(retrievedEncounter.Subject); Assert.AreEqual(DateTimeOffset.Parse(createdEncounter.Period.Start), DateTimeOffset.Parse(retrievedEncounter.Period.Start)); Assert.AreEqual(DateTimeOffset.Parse(createdEncounter.Period.End), DateTimeOffset.Parse(retrievedEncounter.Period.End)); }
public void TestUpdatePractitioner() { //load up a practitioner to update var practitioner = TestUtil.GetFhirMessage("CreatePractitioner") as Practitioner; Resource result; Practitioner actual; TestUtil.CreateAuthority("TEST", "1.2.3.4", "http://santedb.org/fhir/test", "TEST_HARNESS", this.AUTH); using (TestUtil.AuthenticateFhir("TEST_HARNESS", this.AUTH)) { // get the resource handler var practitionerResourceHandler = FhirResourceHandlerUtil.GetResourceHandler(ResourceType.Practitioner); // create the practitioner using the resource handler result = practitionerResourceHandler.Create(practitioner, TransactionMode.Commit); // retrieve the practitioner using the resource handler result = practitionerResourceHandler.Read(result.Id, result.VersionId); Assert.NotNull(result); Assert.IsInstanceOf <Practitioner>(result); actual = (Practitioner)result; Assert.AreEqual("Test", actual.Name.Single().Given.Single()); Assert.AreEqual("Practitioner", actual.Name.Single().Family); //update name actual.Name.Clear(); actual.Name.Add(new HumanName { Given = new List <string> { "UpdatedGiven" }, Family = "UpdatedFamily" }); result = practitionerResourceHandler.Update(actual.Id, actual, TransactionMode.Commit); } actual = (Practitioner)result; Assert.AreEqual("UpdatedGiven", actual.Name.Single().Given.Single()); Assert.AreEqual("UpdatedFamily", actual.Name.Single().Family); //check to ensure previous non-updated values still exists Assert.IsTrue(actual.Telecom.Any(t => t.Value == "905 555 1234")); }
public void TestUnRegisterResourceHandler() { FhirResourceHandlerUtil.RegisterResourceHandler(new DummyResourceHandler()); Assert.NotNull(FhirResourceHandlerUtil.GetResourceHandler(ResourceType.DomainResource)); Assert.IsInstanceOf <DummyResourceHandler>(FhirResourceHandlerUtil.GetResourceHandler(ResourceType.DomainResource)); FhirResourceHandlerUtil.UnRegisterResourceHandler(new DummyResourceHandler()); Assert.IsFalse(FhirResourceHandlerUtil.ResourceHandlers.Any(c => c.GetType() == typeof(DummyResourceHandler))); Assert.Throws <NotSupportedException>(() => FhirResourceHandlerUtil.GetResourceHandler(ResourceType.DomainResource)); }
public void TestCreateInvalidResource() { TestUtil.CreateAuthority("TEST", "1.2.3.4", "http://santedb.org/fhir/test", "TEST_HARNESS", this.AUTH); using (TestUtil.AuthenticateFhir("TEST_HARNESS", this.AUTH)) { // get the resource handler var practitionerResourceHandler = FhirResourceHandlerUtil.GetResourceHandler(ResourceType.Practitioner); // expect that the create method throws an InvalidDataException Assert.Throws <InvalidDataException>(() => practitionerResourceHandler.Create(new Account(), TransactionMode.Commit)); } }
public void TestDeleteEncounter() { var patient = TestUtil.GetFhirMessage("DeleteEncounter-Patient") as Patient; var encounter = TestUtil.GetFhirMessage("DeleteEncounter-Encounter") as Encounter; Resource actualPatient; Resource actualEncounter; TestUtil.CreateAuthority("TEST", "1.2.3.4", "http://santedb.org/fhir/test", "TEST_HARNESS", AUTH); using (TestUtil.AuthenticateFhir("TEST_HARNESS", AUTH)) { var patientResourceHandler = FhirResourceHandlerUtil.GetResourceHandler(ResourceType.Patient); var encounterResourceHandler = FhirResourceHandlerUtil.GetResourceHandler(ResourceType.Encounter); actualPatient = patientResourceHandler.Create(patient, TransactionMode.Commit); encounter.Subject = new ResourceReference($"urn:uuid:{actualPatient.Id}"); actualEncounter = encounterResourceHandler.Create(encounter, TransactionMode.Commit); } Assert.IsNotNull(actualPatient); Assert.IsNotNull(actualEncounter); Assert.IsInstanceOf <Patient>(actualPatient); Assert.IsInstanceOf <Encounter>(actualEncounter); var createdEncounter = (Encounter)actualEncounter; Resource actual; using (TestUtil.AuthenticateFhir("TEST_HARNESS", AUTH)) { var encounterResourceHandler = FhirResourceHandlerUtil.GetResourceHandler(ResourceType.Encounter); actual = encounterResourceHandler.Read(createdEncounter.Id, null); Assert.NotNull(actual); Assert.IsInstanceOf <Encounter>(actual); var retrievedEncounter = (Encounter)actual; var result = encounterResourceHandler.Delete(retrievedEncounter.Id, TransactionMode.Commit); result = encounterResourceHandler.Read(result.Id, null); Assert.IsInstanceOf <Encounter>(result); var obsoletedEncounter = (Encounter)result; Assert.AreEqual(Encounter.EncounterStatus.Unknown, obsoletedEncounter.Status); } }
public void TestCreateEncounterInvalidResource() { TestUtil.CreateAuthority("TEST", "1.2.3.4", "http://santedb.org/fhir/test", "TEST_HARNESS", this.AUTH); using (TestUtil.AuthenticateFhir("TEST_HARNESS", this.AUTH)) { // get the resource handler var encounterResourceHandler = FhirResourceHandlerUtil.GetResourceHandler(ResourceType.Encounter); // create the encounter using the resource handler with an incorrect resource Assert.Throws <InvalidDataException>(() => encounterResourceHandler.Create(new Practitioner(), TransactionMode.Commit)); } }
/// <summary> /// Delete a resource /// </summary> public DomainResourceBase DeleteResource(string resourceType, string id, string mimeType) { this.ThrowIfNotReady(); FhirOperationResult result = null; AuditData audit = null; IAuditorService auditService = ApplicationContext.Current.GetService(typeof(IAuditorService)) as IAuditorService; try { // Setup outgoing content/ WebOperationContext.Current.OutgoingResponse.StatusCode = HttpStatusCode.NoContent; // Create or update? var handler = FhirResourceHandlerUtil.GetResourceHandler(resourceType); if (handler == null) { throw new FileNotFoundException(); // endpoint not found! } result = handler.Delete(id, TransactionMode.Commit); if (result == null || result.Outcome == ResultCode.Rejected) { throw new NotSupportedException(); } else if (result.Outcome == ResultCode.TypeNotAvailable) { throw new FileNotFoundException(String.Format("Resource {0} not found", WebOperationContext.Current.IncomingRequest.UriTemplateMatch.RequestUri)); } else if (result.Outcome != ResultCode.Accepted) { throw new DataException("Delete failed"); } audit = AuditUtil.CreateAuditData(result.Results); return(null); } catch (Exception e) { audit = AuditUtil.CreateAuditData(null); audit.Outcome = OutcomeIndicator.EpicFail; return(this.ErrorHelper(e, result, false) as DomainResourceBase); } finally { if (auditService != null) { auditService.SendAudit(audit); } } }
public void TestUpdatePatient() { var patient = TestUtil.GetFhirMessage("UpdatePatient") as Patient; Resource result; TestUtil.CreateAuthority("TEST", "1.2.3.4", "http://santedb.org/fhir/test", "TEST_HARNESS", this.AUTH); using (TestUtil.AuthenticateFhir("TEST_HARNESS", this.AUTH)) { // get the resource handler var patientResourceHandler = FhirResourceHandlerUtil.GetResourceHandler(ResourceType.Patient); // create the patient using the resource handler result = patientResourceHandler.Create(patient, TransactionMode.Commit); // retrieve the patient using the resource handler result = patientResourceHandler.Read(result.Id, result.VersionId); } Assert.NotNull(result); Assert.IsInstanceOf <Patient>(result); var actual = (Patient)result; Assert.AreEqual("Jessica", actual.Name.Single().Given.Single()); Assert.AreEqual(AdministrativeGender.Female, actual.Gender); Assert.IsTrue(actual.Active); actual.Gender = AdministrativeGender.Male; actual.Active = false; using (TestUtil.AuthenticateFhir("TEST_HARNESS", this.AUTH)) { // get the resource handler var patientResourceHandler = FhirResourceHandlerUtil.GetResourceHandler(ResourceType.Patient); // create the patient using the resource handler result = patientResourceHandler.Update(actual.Id, actual, TransactionMode.Commit); // retrieve the patient using the resource handler result = patientResourceHandler.Read(result.Id, result.VersionId); } Assert.NotNull(result); Assert.IsInstanceOf <Patient>(result); actual = (Patient)result; Assert.AreEqual(AdministrativeGender.Male, actual.Gender); Assert.IsFalse(actual.Active); }
public void TestCreateTwoPractitionerSameIdentifier() { //load the first practitioner var practitioner = TestUtil.GetFhirMessage("CreatePractitioner") as Practitioner; //load the second practitioner with same identifier var secondPractitioner = TestUtil.GetFhirMessage("CreatePractitionerSameIdentifier") as Practitioner; Resource resultOne, resultTwo, pracOne, pracTwo; Practitioner actualPracOne, actualPracTwo; TestUtil.CreateAuthority("TEST", "1.2.3.4", "http://santedb.org/fhir/test", "TEST_HARNESS", this.AUTH); using (TestUtil.AuthenticateFhir("TEST_HARNESS", this.AUTH)) { // get the resource handler var practitionerResourceHandler = FhirResourceHandlerUtil.GetResourceHandler(ResourceType.Practitioner); // create the practitioner using the resource handler pracOne = practitionerResourceHandler.Create(practitioner, TransactionMode.Commit); //check if the practitioner is saved properly resultOne = practitionerResourceHandler.Read(pracOne.Id, pracOne.VersionId); actualPracOne = (Practitioner)resultOne; Assert.AreEqual("Practitioner", actualPracOne.Name.Single().Family); Assert.AreEqual("Test", actualPracOne.Name.Single().Given.Single()); Assert.NotNull(resultOne); Assert.IsInstanceOf <Practitioner>(resultOne); //attempt to create the second practitioner with same identifier pracTwo = practitionerResourceHandler.Create(secondPractitioner, TransactionMode.Commit); //check if the practitioner is saved properly resultTwo = practitionerResourceHandler.Read(pracTwo.Id, pracTwo.VersionId); actualPracTwo = (Practitioner)resultTwo; Assert.AreEqual("PracTwo", actualPracTwo.Name.Single().Family); Assert.AreEqual("Second", actualPracTwo.Name.Single().Given.Single()); Assert.NotNull(resultTwo); Assert.IsInstanceOf <Practitioner>(resultTwo); //test to ensure second create attempt with same identifier just created a different version with same practitioner id Assert.AreEqual(actualPracOne.Id, actualPracTwo.Id); Assert.AreNotEqual(actualPracOne.VersionId, actualPracTwo.VersionId); //read first practitioner again and confirm that properties like name has been updated due to second create attempt with same identifier resultOne = practitionerResourceHandler.Read(pracOne.Id, pracOne.VersionId); actualPracOne = (Practitioner)resultOne; Assert.AreEqual(actualPracTwo.Name.Single().Family, actualPracOne.Name.Single().Family); Assert.AreEqual(actualPracTwo.Name.Single().Given.Single(), actualPracOne.Name.Single().Given.Single()); } }
public void TestCreateSuspendedLocation() { var location = TestUtil.GetFhirMessage("CreateLocation") as Location; location.Status = Location.LocationStatus.Suspended; TestUtil.CreateAuthority("TEST", "1.2.3.4", "http://santedb.org/fhir/test", "TEST_HARNESS", this.AUTH); using (TestUtil.AuthenticateFhir("TEST_HARNESS", this.AUTH)) { var locationResourceHandler = FhirResourceHandlerUtil.GetResourceHandler(ResourceType.Location); Assert.Throws <NotSupportedException>(() => locationResourceHandler.Create(location, TransactionMode.Commit)); } }
public void TestUpdateImmunization() { var patient = TestUtil.GetFhirMessage("ObservationSubject"); var encounter = (Encounter)TestUtil.GetFhirMessage("CreateEncounter-Encounter"); var immunization = (Immunization)TestUtil.GetFhirMessage("CreateImmunization"); var practitioner = TestUtil.GetFhirMessage("ObservationPerformer") as Practitioner; Resource actualPatient; Resource actualEncounter; Resource actualImmunization; Resource actualPractitioner; TestUtil.CreateAuthority("TEST", "1.2.3.4", "http://santedb.org/fhir/test", "TEST_HARNESS", AUTH); using (TestUtil.AuthenticateFhir("TEST_HARNESS", AUTH)) { var patientResourceHandler = FhirResourceHandlerUtil.GetResourceHandler(ResourceType.Patient); var encounterResourceHandler = FhirResourceHandlerUtil.GetResourceHandler(ResourceType.Encounter); var immunizationResourceHandler = FhirResourceHandlerUtil.GetResourceHandler(ResourceType.Immunization); var practitionerResourceHandler = FhirResourceHandlerUtil.GetResourceHandler(ResourceType.Practitioner); actualPatient = patientResourceHandler.Create(patient, TransactionMode.Commit); actualPractitioner = (Practitioner)practitionerResourceHandler.Create(practitioner, TransactionMode.Commit); encounter.Subject = new ResourceReference($"urn:uuid:{actualPatient.Id}"); actualEncounter = encounterResourceHandler.Create(encounter, TransactionMode.Commit); immunization.Patient = new ResourceReference($"urn:uuid:{actualPatient.Id}"); immunization.Encounter = new ResourceReference($"urn:uuid:{actualEncounter.Id}"); immunization.Performer = new List <Immunization.PerformerComponent> { new Immunization.PerformerComponent { Actor = new ResourceReference($"urn:uuid:{actualPractitioner.Id}") } }; actualImmunization = immunizationResourceHandler.Create(immunization, TransactionMode.Commit); var retrievedImmunization = (Immunization)immunizationResourceHandler.Read(actualImmunization.Id, null); Assert.AreEqual(retrievedImmunization.Id, actualImmunization.Id); Assert.AreEqual(12, retrievedImmunization.DoseQuantity.Value); immunization.DoseQuantity.Value = 24; immunization.Status = Immunization.ImmunizationStatusCodes.NotDone; immunizationResourceHandler = FhirResourceHandlerUtil.GetResourceHandler(ResourceType.Immunization); actualImmunization = immunizationResourceHandler.Update(actualImmunization.Id, immunization, TransactionMode.Commit); retrievedImmunization = (Immunization)immunizationResourceHandler.Read(actualImmunization.Id, null); Assert.AreEqual(24, retrievedImmunization.DoseQuantity.Value); Assert.AreEqual(Immunization.ImmunizationStatusCodes.NotDone, retrievedImmunization.Status); } }
public void Setup() { TestApplicationContext.TestAssembly = typeof(TestRelatedPersonResourceHandler).Assembly; TestApplicationContext.Initialize(TestContext.CurrentContext.TestDirectory); this.m_serviceManager = ApplicationServiceContext.Current.GetService <IServiceManager>(); var testConfiguration = new FhirServiceConfigurationSection { Resources = new List <string> { "Patient", "Practitioner", "Observation" } }; TestUtil.CreateAuthority("TEST", "1.2.3.4", "http://santedb.org/fhir/test", "TEST_HARNESS", this.AUTH); using (AuthenticationContext.EnterSystemContext()) { FhirResourceHandlerUtil.Initialize(testConfiguration, this.m_serviceManager); ExtensionUtil.Initialize(testConfiguration); //add practitioner to be used as performer var practitioner = TestUtil.GetFhirMessage("ObservationPerformer") as Practitioner; var practitionerResourceHandler = FhirResourceHandlerUtil.GetResourceHandler(ResourceType.Practitioner); // create the practitioner using the resource handler this.m_practitioner = (Practitioner)practitionerResourceHandler.Create(practitioner, TransactionMode.Commit); //add patient to be used subject var patient = TestUtil.GetFhirMessage("ObservationSubject") as Patient; var patientResourceHandler = FhirResourceHandlerUtil.GetResourceHandler(ResourceType.Patient); // create the patient using the resource handler this.m_patient = (Patient)patientResourceHandler.Create(patient, TransactionMode.Commit); //add a general observation to be used for multiple tests var observation = TestUtil.GetFhirMessage("SetupObservation") as Observation; observation.Subject = new ResourceReference($"urn:uuid:{this.m_patient.Id}"); observation.Performer.Add(new ResourceReference($"urn:uuid:{this.m_practitioner.Id}")); var observationResourceHandler = FhirResourceHandlerUtil.GetResourceHandler(ResourceType.Observation); this.m_observation = (Observation)observationResourceHandler.Create(observation, TransactionMode.Commit); } }
public void TestCreateEncounterWithServiceProvider() { var patient = TestUtil.GetFhirMessage("CreateEncounter-Patient") as Patient; var organization = TestUtil.GetFhirMessage("Organization") as Organization; var encounter = TestUtil.GetFhirMessage("CreateEncounter-Encounter") as Encounter; Resource actualPatient; Resource actualOrganization; Resource actualEncounter; Resource readEncounter; TestUtil.CreateAuthority("TEST", "1.2.3.4", "http://santedb.org/fhir/test", "TEST_HARNESS", AUTH); using (TestUtil.AuthenticateFhir("TEST_HARNESS", AUTH)) { var patientResourceHandler = FhirResourceHandlerUtil.GetResourceHandler(ResourceType.Patient); var encounterResourceHandler = FhirResourceHandlerUtil.GetResourceHandler(ResourceType.Encounter); var organizationResourceHandler = FhirResourceHandlerUtil.GetResourceHandler(ResourceType.Organization); // Create the patient and set it as the subject of the encounter actualPatient = patientResourceHandler.Create(patient, TransactionMode.Commit); encounter.Subject = new ResourceReference($"urn:uuid:{actualPatient.Id}"); // Create the patient and set it as the service provider of the encounter actualOrganization = organizationResourceHandler.Create(organization, TransactionMode.Commit); encounter.ServiceProvider = new ResourceReference($"urn:uuid:{actualOrganization.Id}"); // Create the encounter actualEncounter = encounterResourceHandler.Create(encounter, TransactionMode.Commit); readEncounter = encounterResourceHandler.Read(actualEncounter.Id, null); } Assert.IsNotNull(actualPatient); Assert.IsNotNull(actualOrganization); Assert.IsNotNull(actualEncounter); Assert.IsNotNull(readEncounter); Assert.IsInstanceOf <Patient>(actualPatient); Assert.IsInstanceOf <Organization>(actualOrganization); Assert.IsInstanceOf <Encounter>(actualEncounter); Assert.IsInstanceOf <Encounter>(readEncounter); var createdEncounter = (Encounter)actualEncounter; var retrievedEncounter = (Encounter)readEncounter; Assert.IsNotNull(createdEncounter.ServiceProvider); Assert.AreEqual(createdEncounter.ServiceProvider.Reference, retrievedEncounter.ServiceProvider.Reference); }
public void TestCreateLocation() { var partOfLocation = TestUtil.GetFhirMessage("CreatePartOfLocation") as Location; var location = TestUtil.GetFhirMessage("CreateLocation") as Location; Resource actual; Resource partOfLocationActual; TestUtil.CreateAuthority("TEST", "1.2.3.4", "http://santedb.org/fhir/test", "TEST_HARNESS", this.AUTH); using (TestUtil.AuthenticateFhir("TEST_HARNESS", this.AUTH)) { var locationResourceHandler = FhirResourceHandlerUtil.GetResourceHandler(ResourceType.Location); partOfLocationActual = locationResourceHandler.Create(partOfLocation, TransactionMode.Commit); location.PartOf = new ResourceReference($"urn:uuid:{partOfLocationActual.Id}"); actual = locationResourceHandler.Create(location, TransactionMode.Commit); } Assert.IsNotNull(actual); Assert.IsInstanceOf <Location>(actual); var createdLocation = (Location)actual; Assert.IsNotNull(createdLocation); Resource readLocation; using (TestUtil.AuthenticateFhir("TEST_HARNESS", this.AUTH)) { var locationResourceHandler = FhirResourceHandlerUtil.GetResourceHandler(ResourceType.Location); readLocation = locationResourceHandler.Read(createdLocation.Id, createdLocation.VersionId); } Assert.IsNotNull(readLocation); Assert.IsInstanceOf <Location>(readLocation); var retrievedLocation = (Location)readLocation; Assert.NotNull(retrievedLocation.Alias.First()); Assert.AreEqual("Test Location", retrievedLocation.Name); Assert.AreEqual(Location.LocationMode.Kind, retrievedLocation.Mode); Assert.AreEqual(Location.LocationStatus.Active, retrievedLocation.Status); Assert.AreEqual("Hamilton", retrievedLocation.Address.City); Assert.AreEqual("6324", retrievedLocation.Identifier.First().Value); Assert.IsNotNull(retrievedLocation.Position.Latitude); }
/// <summary> /// Validate a resource (really an update with debugging / non comit) /// </summary> public OperationOutcome ValidateResource(string resourceType, string id, DomainResourceBase target) { this.ThrowIfNotReady(); FhirOperationResult result = null; try { // Setup outgoing content // Create or update? var handler = FhirResourceHandlerUtil.GetResourceHandler(resourceType); if (handler == null) { throw new FileNotFoundException(); // endpoint not found! } result = handler.Update(id, target, TransactionMode.Rollback); if (result == null || result.Results.Count == 0) // Create { result = handler.Create(target, TransactionMode.Rollback); WebOperationContext.Current.OutgoingResponse.StatusCode = HttpStatusCode.Created; } if (result == null || result.Outcome == ResultCode.Rejected) { throw new InvalidDataException("Resource structure is not valid"); } else if (result.Outcome == ResultCode.AcceptedNonConformant) { throw new ConstraintException("Resource not conformant"); } else if (result.Outcome == ResultCode.TypeNotAvailable) { throw new FileNotFoundException(String.Format("Resource {0} not found", WebOperationContext.Current.IncomingRequest.UriTemplateMatch.RequestUri)); } else if (result.Outcome != ResultCode.Accepted) { throw new DataException("Validate failed"); } // Return constraint return(MessageUtil.CreateOutcomeResource(result)); } catch (Exception e) { return(this.ErrorHelper(e, result, false) as OperationOutcome); } }
public void TestUpdateOrganization() { // set up the test data var organization = TestUtil.GetFhirMessage("Organization") as Organization; Resource result; TestUtil.CreateAuthority("TEST", "1.2.3.4", "http://santedb.org/fhir/test", "TEST_HARNESS", this.AUTH); using (TestUtil.AuthenticateFhir("TEST_HARNESS", this.AUTH)) { var organizationResourceHandler = FhirResourceHandlerUtil.GetResourceHandler(ResourceType.Organization); result = organizationResourceHandler.Create(organization, TransactionMode.Commit); result = organizationResourceHandler.Read(result.Id, result.VersionId); } // assert create organization successfully Assert.NotNull(result); Assert.IsInstanceOf <Organization>(result); var actual = (Organization)result; Assert.AreEqual("Hamilton Health Sciences", actual.Name); Assert.IsTrue(actual.Alias.All(c => c == "hhs")); Assert.IsTrue(actual.Address.Count == 2); // update the organization organization.Name = "Hamilton Health Science"; organization.Address.RemoveAt(1); organization.Identifier.First().Value = "2021"; organization.Extension.RemoveAt(0); using (TestUtil.AuthenticateFhir("TEST_HARNESS", this.AUTH)) { var organizationResourceHandler = FhirResourceHandlerUtil.GetResourceHandler(ResourceType.Organization); result = organizationResourceHandler.Update(result.Id, organization, TransactionMode.Commit); result = organizationResourceHandler.Read(result.Id, result.VersionId); } // assert update organization successfully Assert.NotNull(result); Assert.IsInstanceOf <Organization>(result); actual = (Organization)result; Assert.AreEqual("Hamilton Health Science", actual.Name); Assert.IsTrue(actual.Address.Count == 1); Assert.IsFalse(actual.Extension.Any()); Assert.AreEqual("2021", actual.Identifier.First().Value); }
public void TestCreateImmunizationWithNonUUIDReference() { var immunizationResourceHandler = FhirResourceHandlerUtil.GetResourceHandler(ResourceType.Immunization); var immunization = new Immunization { Patient = new ResourceReference(Guid.NewGuid().ToString()) }; Assert.Throws <NotSupportedException>(() => immunizationResourceHandler.Create(immunization, TransactionMode.Commit)); immunization = new Immunization() { Encounter = new ResourceReference(Guid.NewGuid().ToString()) }; Assert.Throws <NotSupportedException>(() => immunizationResourceHandler.Create(immunization, TransactionMode.Commit)); }
public void TestCreateOrganizationWithParent() { var parentOrganization = TestUtil.GetFhirMessage("ParentOrganization") as Organization; var organization = TestUtil.GetFhirMessage("Organization") as Organization; Resource createdParentOrganization; Resource actual; TestUtil.CreateAuthority("TEST", "1.2.3.4", "http://santedb.org/fhir/test", "TEST_HARNESS", this.AUTH); using (TestUtil.AuthenticateFhir("TEST_HARNESS", this.AUTH)) { var organizationResourceHandler = FhirResourceHandlerUtil.GetResourceHandler(ResourceType.Organization); createdParentOrganization = organizationResourceHandler.Create(parentOrganization, TransactionMode.Commit); organization.PartOf = new ResourceReference($"urn:uuid:{createdParentOrganization.Id}"); actual = organizationResourceHandler.Create(organization, TransactionMode.Commit); } Assert.NotNull(actual); Assert.IsInstanceOf <Organization>(actual); var createdOrganization = (Organization)actual; Assert.IsNotNull(createdOrganization); Resource readOrganization; using (TestUtil.AuthenticateFhir("TEST_HARNESS", this.AUTH)) { var organizationResourceHandler = FhirResourceHandlerUtil.GetResourceHandler(ResourceType.Organization); readOrganization = organizationResourceHandler.Read(createdOrganization.Id, createdOrganization.VersionId); } Assert.IsNotNull(readOrganization); Assert.IsInstanceOf <Organization>(readOrganization); var actualOrganization = (Organization)readOrganization; Assert.IsNotNull(actualOrganization.Address); Assert.AreEqual("Hamilton Health Sciences", actualOrganization.Name); Assert.IsTrue(actualOrganization.Alias.All(c => c == "hhs")); Assert.IsTrue(actualOrganization.Address.Count == 2); Assert.IsTrue(actualOrganization.Extension.Any(e => e.Url == "http://santedb.org/extensions/core/detectedIssue")); Assert.IsTrue(actualOrganization.Identifier.First().Value == "6324"); Assert.AreEqual("http://santedb.org/fhir/test", actualOrganization.Identifier.First().System); Assert.IsTrue(actualOrganization.Identifier.Count == 1); }