use of org.hl7.fhir.dstu3.model.Device in project synthea by synthetichealth.
the class FhirR4 method convertToFHIR.
/**
* Convert the given Person into a FHIR Bundle of the Patient and the
* associated entries from their health record.
*
* @param person Person to generate the FHIR JSON for
* @param stopTime Time the simulation ended
* @return FHIR Bundle containing the Person's health record
*/
public static Bundle convertToFHIR(Person person, long stopTime) {
Bundle bundle = new Bundle();
if (TRANSACTION_BUNDLE) {
bundle.setType(BundleType.TRANSACTION);
} else {
bundle.setType(BundleType.COLLECTION);
}
BundleEntryComponent personEntry = basicInfo(person, bundle, stopTime);
for (Encounter encounter : person.record.encounters) {
BundleEntryComponent encounterEntry = encounter(person, personEntry, bundle, encounter);
for (HealthRecord.Entry condition : encounter.conditions) {
condition(person, personEntry, bundle, encounterEntry, condition);
}
for (HealthRecord.Allergy allergy : encounter.allergies) {
allergy(person, personEntry, bundle, encounterEntry, allergy);
}
for (Observation observation : encounter.observations) {
// Observation resources in v4 don't support Attachments
if (observation.value instanceof Attachment) {
media(person, personEntry, bundle, encounterEntry, observation);
} else {
observation(person, personEntry, bundle, encounterEntry, observation);
}
}
for (Procedure procedure : encounter.procedures) {
procedure(person, personEntry, bundle, encounterEntry, procedure);
}
for (HealthRecord.Device device : encounter.devices) {
device(person, personEntry, bundle, device);
}
for (HealthRecord.Supply supply : encounter.supplies) {
supplyDelivery(person, personEntry, bundle, supply, encounter);
}
for (Medication medication : encounter.medications) {
medicationRequest(person, personEntry, bundle, encounterEntry, medication);
}
for (HealthRecord.Entry immunization : encounter.immunizations) {
immunization(person, personEntry, bundle, encounterEntry, immunization);
}
for (Report report : encounter.reports) {
report(person, personEntry, bundle, encounterEntry, report);
}
for (CarePlan careplan : encounter.careplans) {
BundleEntryComponent careTeamEntry = careTeam(person, personEntry, bundle, encounterEntry, careplan);
carePlan(person, personEntry, bundle, encounterEntry, encounter.provider, careTeamEntry, careplan);
}
for (ImagingStudy imagingStudy : encounter.imagingStudies) {
imagingStudy(person, personEntry, bundle, encounterEntry, imagingStudy);
}
if (USE_US_CORE_IG) {
String clinicalNoteText = ClinicalNoteExporter.export(person, encounter);
boolean lastNote = (encounter == person.record.encounters.get(person.record.encounters.size() - 1));
clinicalNote(person, personEntry, bundle, encounterEntry, clinicalNoteText, lastNote);
}
// one claim per encounter
BundleEntryComponent encounterClaim = encounterClaim(person, personEntry, bundle, encounterEntry, encounter.claim);
explanationOfBenefit(personEntry, bundle, encounterEntry, person, encounterClaim, encounter);
}
if (USE_US_CORE_IG) {
// Add Provenance to the Bundle
provenance(bundle, person, stopTime);
}
return bundle;
}
use of org.hl7.fhir.dstu3.model.Device in project synthea by synthetichealth.
the class FhirR4 method supplyDelivery.
/**
* Map the JsonObject for a Supply into a FHIR SupplyDelivery and add it to the Bundle.
*
* @param rand Source of randomness to use when generating ids etc
* @param personEntry The Person entry.
* @param bundle Bundle to add to.
* @param supply The supplied object to add.
* @param encounter The encounter during which the supplies were delivered
* @return The added Entry.
*/
private static BundleEntryComponent supplyDelivery(RandomNumberGenerator rand, BundleEntryComponent personEntry, Bundle bundle, HealthRecord.Supply supply, Encounter encounter) {
SupplyDelivery supplyResource = new SupplyDelivery();
supplyResource.setStatus(SupplyDeliveryStatus.COMPLETED);
supplyResource.setPatient(new Reference(personEntry.getFullUrl()));
CodeableConcept type = new CodeableConcept();
type.addCoding().setCode("device").setDisplay("Device").setSystem("http://terminology.hl7.org/CodeSystem/supply-item-type");
supplyResource.setType(type);
SupplyDeliverySuppliedItemComponent suppliedItem = new SupplyDeliverySuppliedItemComponent();
suppliedItem.setItem(mapCodeToCodeableConcept(supply.codes.get(0), SNOMED_URI));
suppliedItem.setQuantity(new Quantity(supply.quantity));
supplyResource.setSuppliedItem(suppliedItem);
supplyResource.setOccurrence(convertFhirDateTime(supply.start, true));
return newEntry(rand, bundle, supplyResource);
}
use of org.hl7.fhir.dstu3.model.Device in project synthea by synthetichealth.
the class FhirR4 method device.
/**
* Map the HealthRecord.Device into a FHIR Device and add it to the Bundle.
*
* @param rand Source of randomness to use when generating ids etc
* @param personEntry The Person entry.
* @param bundle Bundle to add to.
* @param device The device to add.
* @return The added Entry.
*/
private static BundleEntryComponent device(RandomNumberGenerator rand, BundleEntryComponent personEntry, Bundle bundle, HealthRecord.Device device) {
Device deviceResource = new Device();
if (USE_US_CORE_IG) {
Meta meta = new Meta();
meta.addProfile("http://hl7.org/fhir/us/core/StructureDefinition/us-core-implantable-device");
deviceResource.setMeta(meta);
}
deviceResource.addUdiCarrier().setDeviceIdentifier(device.deviceIdentifier).setCarrierHRF(device.udi);
deviceResource.setStatus(FHIRDeviceStatus.ACTIVE);
deviceResource.setDistinctIdentifier(device.deviceIdentifier);
if (device.manufacturer != null) {
deviceResource.setManufacturer(device.manufacturer);
}
if (device.model != null) {
deviceResource.setModelNumber(device.model);
}
deviceResource.setManufactureDate(new Date(device.manufactureTime));
deviceResource.setExpirationDate(new Date(device.expirationTime));
deviceResource.setLotNumber(device.lotNumber);
deviceResource.setSerialNumber(device.serialNumber);
deviceResource.addDeviceName().setName(device.codes.get(0).display).setType(DeviceNameType.USERFRIENDLYNAME);
deviceResource.setType(mapCodeToCodeableConcept(device.codes.get(0), SNOMED_URI));
deviceResource.setPatient(new Reference(personEntry.getFullUrl()));
return newEntry(rand, bundle, deviceResource);
}
use of org.hl7.fhir.dstu3.model.Device in project synthea by synthetichealth.
the class FHIRSTU3ExporterTest method testFHIRSTU3Export.
@Test
public void testFHIRSTU3Export() throws Exception {
TestHelper.loadTestProperties();
Generator.DEFAULT_STATE = Config.get("test_state.default", "Massachusetts");
Config.set("exporter.baseDirectory", tempFolder.newFolder().toString());
FhirContext ctx = FhirStu3.getContext();
IParser parser = ctx.newJsonParser().setPrettyPrint(true);
FhirValidator validator = ctx.newValidator();
validator.setValidateAgainstStandardSchema(true);
validator.setValidateAgainstStandardSchematron(true);
ValidationResources validationResources = new ValidationResources();
List<String> errors = ParallelTestingService.runInParallel((person) -> {
List<String> validationErrors = new ArrayList<String>();
TestHelper.exportOff();
Config.set("exporter.fhir_stu3.export", "true");
Config.set("exporter.fhir.use_shr_extensions", "true");
FhirStu3.TRANSACTION_BUNDLE = person.randBoolean();
String fhirJson = FhirStu3.convertToFHIRJson(person, System.currentTimeMillis());
// (these should have been converted into URIs)
if (fhirJson.contains("SNOMED-CT")) {
validationErrors.add("JSON contains unconverted references to 'SNOMED-CT' (should be URIs)");
}
// let's crack open the Bundle and validate
// each individual entry.resource to get context-sensitive error
// messages...
Bundle bundle = parser.parseResource(Bundle.class, fhirJson);
for (BundleEntryComponent entry : bundle.getEntry()) {
ValidationResult eresult = validator.validateWithResult(entry.getResource());
if (!eresult.isSuccessful()) {
for (SingleValidationMessage emessage : eresult.getMessages()) {
boolean valid = false;
if (emessage.getMessage().contains("@ Observation obs-7")) {
/*
* The obs-7 invariant basically says that Observations should have values, unless
* they are made of components. This test replaces an invalid XPath expression
* that was causing correct instances to fail validation.
*/
valid = validateObs7((Observation) entry.getResource());
} else if (emessage.getMessage().contains("@ Condition con-4")) {
/*
* The con-4 invariant says "If condition is abated, then clinicalStatus must be
* either inactive, resolved, or remission" which is very clear and sensical.
* However, the XPath expression does not evaluate correctly for valid instances,
* so we must manually validate.
*/
valid = validateCon4((Condition) entry.getResource());
} else if (emessage.getMessage().contains("@ MedicationRequest mps-1")) {
/*
* The mps-1 invariant says MedicationRequest.requester.onBehalfOf can only be
* specified if MedicationRequest.requester.agent is practitioner or device.
* But the invariant is poorly written and does not correctly handle references
* starting with "urn:uuid"
*/
// ignore this error
valid = true;
} else if (emessage.getMessage().contains("per-1: If present, start SHALL have a lower value than end")) {
/*
* The per-1 invariant does not account for daylight savings time... so, if the
* daylight savings switch happens between the start and end, the validation
* fails, even if it is valid.
*/
// ignore this error
valid = true;
}
if (!valid) {
System.out.println(parser.encodeResourceToString(entry.getResource()));
System.out.println("ERROR: " + emessage.getMessage());
validationErrors.add(emessage.getMessage());
}
}
}
// Check ExplanationOfBenefit Resources against BlueButton
if (entry.getResource().fhirType().equals("ExplanationOfBenefit")) {
ValidationResult bbResult = validationResources.validateSTU3(entry.getResource());
for (SingleValidationMessage message : bbResult.getMessages()) {
if (message.getMessage().contains("extension https://bluebutton.cms.gov/assets")) {
/*
* The instance validator complains about the BlueButton extensions, ignore
*/
continue;
} else if (message.getSeverity() == ResultSeverityEnum.ERROR) {
if (!(message.getMessage().contains("Element 'ExplanationOfBenefit.id': minimum required = 1, but only found 0") || message.getMessage().contains("Could not verify slice for profile"))) {
// For some reason the validator is not detecting the IDs on the resources,
// even though they appear to be present while debugging and during normal
// operations.
System.out.println(message.getSeverity() + ": " + message.getMessage());
Assert.fail(message.getSeverity() + ": " + message.getMessage());
}
}
}
}
}
if (!validationErrors.isEmpty()) {
FailedExportHelper.dumpInfo("FHIRSTU3", fhirJson, validationErrors, person);
}
return validationErrors;
});
assertTrue("Validation of exported FHIR bundle failed: " + String.join("|", errors), errors.size() == 0);
}
use of org.hl7.fhir.dstu3.model.Device in project java-docs-samples by GoogleCloudPlatform.
the class DeviceRegistryExample method listDevices.
// [END iot_clear_registry]
// [START iot_list_devices]
/**
* Print all of the devices in this registry to standard out.
*/
protected static void listDevices(String projectId, String cloudRegion, String registryName) throws GeneralSecurityException, IOException {
GoogleCredentials credential = GoogleCredentials.getApplicationDefault().createScoped(CloudIotScopes.all());
JsonFactory jsonFactory = JacksonFactory.getDefaultInstance();
HttpRequestInitializer init = new HttpCredentialsAdapter(credential);
final CloudIot service = new CloudIot.Builder(GoogleNetHttpTransport.newTrustedTransport(), jsonFactory, init).setApplicationName(APP_NAME).build();
final String registryPath = String.format("projects/%s/locations/%s/registries/%s", projectId, cloudRegion, registryName);
List<Device> devices = service.projects().locations().registries().devices().list(registryPath).execute().getDevices();
if (devices != null) {
System.out.println("Found " + devices.size() + " devices");
for (Device d : devices) {
System.out.println("Id: " + d.getId());
if (d.getConfig() != null) {
// Note that this will show the device config in Base64 encoded format.
System.out.println("Config: " + d.getConfig().toPrettyString());
}
System.out.println();
}
} else {
System.out.println("Registry has no devices.");
}
}
Aggregations