use of org.mitre.synthea.helpers.RandomNumberGenerator in project synthea by synthetichealth.
the class HospitalExporterR4 method export.
/**
* Export the hospital in FHIR R4 format.
*/
public static void export(RandomNumberGenerator rand, long stop) {
if (Config.getAsBoolean("exporter.hospital.fhir.export")) {
Bundle bundle = new Bundle();
if (Config.getAsBoolean("exporter.fhir.transaction_bundle")) {
bundle.setType(BundleType.BATCH);
} else {
bundle.setType(BundleType.COLLECTION);
}
for (Provider h : Provider.getProviderList()) {
// filter - exports only those hospitals in use
Table<Integer, String, AtomicInteger> utilization = h.getUtilization();
int totalEncounters = utilization.column(Provider.ENCOUNTERS).values().stream().mapToInt(ai -> ai.get()).sum();
if (totalEncounters > 0) {
BundleEntryComponent entry = FhirR4.provider(rand, bundle, h);
addHospitalExtensions(h, (Organization) entry.getResource());
}
}
String bundleJson = FhirR4.getContext().newJsonParser().setPrettyPrint(true).encodeResourceToString(bundle);
// get output folder
List<String> folders = new ArrayList<>();
folders.add("fhir");
String baseDirectory = Config.get("exporter.baseDirectory");
File f = Paths.get(baseDirectory, folders.toArray(new String[0])).toFile();
f.mkdirs();
Path outFilePath = f.toPath().resolve("hospitalInformation" + stop + ".json");
try {
Files.write(outFilePath, Collections.singleton(bundleJson), StandardOpenOption.CREATE_NEW);
} catch (IOException e) {
e.printStackTrace();
}
}
}
use of org.mitre.synthea.helpers.RandomNumberGenerator in project synthea by synthetichealth.
the class BB2RIFExporterTest method testStaticFieldConfig.
@Test
public void testStaticFieldConfig() throws IOException, NoSuchMethodException {
RandomNumberGenerator rand = new Person(System.currentTimeMillis());
assertEquals("foo", StaticFieldConfig.processCell("foo", rand));
String randomVal = StaticFieldConfig.processCell("1, 2, 3", rand);
assertTrue(randomVal.equalsIgnoreCase("1") || randomVal.equalsIgnoreCase("2") || randomVal.equalsIgnoreCase("3"));
StaticFieldConfig config = new StaticFieldConfig();
assertEquals("INSERT", config.getValue("DML_IND", INPATIENT.class));
assertEquals("82 (DMEPOS)", config.getValue("NCH_CLM_TYPE_CD", DME.class));
assertEquals("71 (local carrier, non-DME)", config.getValue("NCH_CLM_TYPE_CD", CARRIER.class));
HashMap<BENEFICIARY, String> values = new HashMap<>();
config.setValues(values, BENEFICIARY.class, rand);
assertEquals("INSERT", values.get(BENEFICIARY.DML_IND));
String sexIdent = values.get(BENEFICIARY.BENE_SEX_IDENT_CD);
assertTrue(sexIdent.equals("1") || sexIdent.equals("2"));
}
use of org.mitre.synthea.helpers.RandomNumberGenerator in project synthea by synthetichealth.
the class FhirR4 method media.
/**
* Map the given Observation with attachment element to a FHIR Media resource, and add it to the
* given Bundle.
*
* @param rand Source of randomness to use when generating ids etc
* @param personEntry The Entry for the Person
* @param bundle Bundle to add the Media to
* @param encounterEntry Current Encounter entry
* @param obs The Observation to map to FHIR and add to the bundle
* @return The added Entry
*/
private static BundleEntryComponent media(RandomNumberGenerator rand, BundleEntryComponent personEntry, Bundle bundle, BundleEntryComponent encounterEntry, Observation obs) {
org.hl7.fhir.r4.model.Media mediaResource = new org.hl7.fhir.r4.model.Media();
// Hard code as Image since we don't anticipate using video or audio any time soon
Code mediaType = new Code("http://terminology.hl7.org/CodeSystem/media-type", "image", "Image");
if (obs.codes != null && obs.codes.size() > 0) {
List<CodeableConcept> reasonList = obs.codes.stream().map(code -> mapCodeToCodeableConcept(code, SNOMED_URI)).collect(Collectors.toList());
mediaResource.setReasonCode(reasonList);
}
mediaResource.setType(mapCodeToCodeableConcept(mediaType, MEDIA_TYPE_URI));
mediaResource.setStatus(MediaStatus.COMPLETED);
mediaResource.setSubject(new Reference(personEntry.getFullUrl()));
mediaResource.setEncounter(new Reference(encounterEntry.getFullUrl()));
Attachment content = (Attachment) obs.value;
org.hl7.fhir.r4.model.Attachment contentResource = new org.hl7.fhir.r4.model.Attachment();
contentResource.setContentType(content.contentType);
contentResource.setLanguage(content.language);
if (content.data != null) {
contentResource.setDataElement(new org.hl7.fhir.r4.model.Base64BinaryType(content.data));
} else {
contentResource.setSize(content.size);
}
contentResource.setUrl(content.url);
contentResource.setTitle(content.title);
if (content.hash != null) {
contentResource.setHashElement(new org.hl7.fhir.r4.model.Base64BinaryType(content.hash));
}
mediaResource.setWidth(content.width);
mediaResource.setHeight(content.height);
mediaResource.setContent(contentResource);
return newEntry(rand, bundle, mediaResource);
}
use of org.mitre.synthea.helpers.RandomNumberGenerator in project synthea by synthetichealth.
the class FhirPractitionerExporterR4 method export.
/**
* Export the practitioner in FHIR R4 format.
*/
public static void export(RandomNumberGenerator rand, long stop) {
if (Config.getAsBoolean("exporter.practitioner.fhir.export")) {
Bundle bundle = new Bundle();
if (Config.getAsBoolean("exporter.fhir.transaction_bundle")) {
bundle.setType(BundleType.BATCH);
} else {
bundle.setType(BundleType.COLLECTION);
}
for (Provider h : Provider.getProviderList()) {
// filter - exports only those hospitals in use
Table<Integer, String, AtomicInteger> utilization = h.getUtilization();
int totalEncounters = utilization.column(Provider.ENCOUNTERS).values().stream().mapToInt(ai -> ai.get()).sum();
if (totalEncounters > 0) {
Map<String, ArrayList<Clinician>> clinicians = h.clinicianMap;
for (String specialty : clinicians.keySet()) {
ArrayList<Clinician> docs = clinicians.get(specialty);
for (Clinician doc : docs) {
if (doc.getEncounterCount() > 0) {
BundleEntryComponent entry = FhirR4.practitioner(rand, bundle, doc);
Practitioner practitioner = (Practitioner) entry.getResource();
practitioner.addExtension().setUrl(EXTENSION_URI).setValue(new IntegerType(doc.getEncounterCount()));
}
}
}
}
}
String bundleJson = FhirR4.getContext().newJsonParser().setPrettyPrint(true).encodeResourceToString(bundle);
// get output folder
List<String> folders = new ArrayList<>();
folders.add("fhir");
String baseDirectory = Config.get("exporter.baseDirectory");
File f = Paths.get(baseDirectory, folders.toArray(new String[0])).toFile();
f.mkdirs();
Path outFilePath = f.toPath().resolve("practitionerInformation" + stop + ".json");
try {
Files.write(outFilePath, Collections.singleton(bundleJson), StandardOpenOption.CREATE_NEW);
} catch (IOException e) {
e.printStackTrace();
}
}
}
use of org.mitre.synthea.helpers.RandomNumberGenerator in project synthea by synthetichealth.
the class FhirStu3 method media.
/**
* Map the given Media element to a FHIR Media resource, and add it to the given Bundle.
*
* @param rand Source of randomness to use when generating ids etc
* @param personEntry The Entry for the Person
* @param bundle Bundle to add the Media to
* @param encounterEntry Current Encounter entry
* @param obs The Observation to map to FHIR and add to the bundle
* @return The added Entry
*/
private static BundleEntryComponent media(RandomNumberGenerator rand, BundleEntryComponent personEntry, Bundle bundle, BundleEntryComponent encounterEntry, Observation obs) {
org.hl7.fhir.dstu3.model.Media mediaResource = new org.hl7.fhir.dstu3.model.Media();
if (obs.codes != null && obs.codes.size() > 0) {
List<CodeableConcept> reasonList = obs.codes.stream().map(code -> mapCodeToCodeableConcept(code, SNOMED_URI)).collect(Collectors.toList());
mediaResource.setReasonCode(reasonList);
}
// Hard code as an image
mediaResource.setType(DigitalMediaType.PHOTO);
mediaResource.setSubject(new Reference(personEntry.getFullUrl()));
Attachment content = (Attachment) obs.value;
org.hl7.fhir.dstu3.model.Attachment contentResource = new org.hl7.fhir.dstu3.model.Attachment();
contentResource.setContentType(content.contentType);
contentResource.setLanguage(content.language);
if (content.data != null) {
contentResource.setDataElement(new org.hl7.fhir.dstu3.model.Base64BinaryType(content.data));
}
contentResource.setUrl(content.url);
contentResource.setSize(content.size);
contentResource.setTitle(content.title);
if (content.hash != null) {
contentResource.setHashElement(new org.hl7.fhir.dstu3.model.Base64BinaryType(content.hash));
}
mediaResource.setWidth(content.width);
mediaResource.setHeight(content.height);
mediaResource.setContent(contentResource);
return newEntry(rand, bundle, mediaResource);
}
Aggregations