use of ca.uhn.fhir.model.api.ExtensionDt in project synthea by synthetichealth.
the class FhirPractitionerExporterDstu2 method export.
/**
* Export the practitioner in FHIR DSTU2 format.
*/
public static void export(long stop) {
if (Config.getAsBoolean("exporter.practitioner.fhir_dstu2.export")) {
Bundle bundle = new Bundle();
if (Config.getAsBoolean("exporter.fhir.transaction_bundle")) {
bundle.setType(BundleTypeEnum.BATCH);
} else {
bundle.setType(BundleTypeEnum.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) {
Entry entry = FhirDstu2.practitioner(bundle, doc);
Practitioner practitioner = (Practitioner) entry.getResource();
ExtensionDt extension = new ExtensionDt();
extension.setUrl(EXTENSION_URI);
extension.setValue(new IntegerDt(doc.getEncounterCount()));
practitioner.addUndeclaredExtension(extension);
}
}
}
}
}
String bundleJson = FhirDstu2.getContext().newJsonParser().setPrettyPrint(true).encodeResourceToString(bundle);
// get output folder
List<String> folders = new ArrayList<>();
folders.add("fhir_dstu2");
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 ca.uhn.fhir.model.api.ExtensionDt in project synthea by synthetichealth.
the class HospitalExporterDstu2 method addHospitalExtensions.
/**
* Add FHIR extensions to capture additional information.
*/
public static void addHospitalExtensions(Provider h, Organization organizationResource) {
Table<Integer, String, AtomicInteger> utilization = h.getUtilization();
// calculate totals for utilization
int totalEncounters = utilization.column(Provider.ENCOUNTERS).values().stream().mapToInt(ai -> ai.get()).sum();
ExtensionDt encountersExtension = new ExtensionDt();
encountersExtension.setUrl(SYNTHEA_URI + "utilization-encounters-extension");
IntegerDt encountersValue = new IntegerDt(totalEncounters);
encountersExtension.setValue(encountersValue);
organizationResource.addUndeclaredExtension(encountersExtension);
int totalProcedures = utilization.column(Provider.PROCEDURES).values().stream().mapToInt(ai -> ai.get()).sum();
ExtensionDt proceduresExtension = new ExtensionDt();
proceduresExtension.setUrl(SYNTHEA_URI + "utilization-procedures-extension");
IntegerDt proceduresValue = new IntegerDt(totalProcedures);
proceduresExtension.setValue(proceduresValue);
organizationResource.addUndeclaredExtension(proceduresExtension);
int totalLabs = utilization.column(Provider.LABS).values().stream().mapToInt(ai -> ai.get()).sum();
ExtensionDt labsExtension = new ExtensionDt();
labsExtension.setUrl(SYNTHEA_URI + "utilization-labs-extension");
IntegerDt labsValue = new IntegerDt(totalLabs);
labsExtension.setValue(labsValue);
organizationResource.addUndeclaredExtension(labsExtension);
int totalPrescriptions = utilization.column(Provider.PRESCRIPTIONS).values().stream().mapToInt(ai -> ai.get()).sum();
ExtensionDt prescriptionsExtension = new ExtensionDt();
prescriptionsExtension.setUrl(SYNTHEA_URI + "utilization-prescriptions-extension");
IntegerDt prescriptionsValue = new IntegerDt(totalPrescriptions);
prescriptionsExtension.setValue(prescriptionsValue);
organizationResource.addUndeclaredExtension(prescriptionsExtension);
Integer bedCount = h.getBedCount();
if (bedCount != null) {
ExtensionDt bedCountExtension = new ExtensionDt();
bedCountExtension.setUrl(SYNTHEA_URI + "bed-count-extension");
IntegerDt bedCountValue = new IntegerDt(bedCount);
bedCountExtension.setValue(bedCountValue);
organizationResource.addUndeclaredExtension(bedCountExtension);
}
}
use of ca.uhn.fhir.model.api.ExtensionDt in project synthea by synthetichealth.
the class FhirDstu2 method basicInfo.
/**
* Map the given Person to a FHIR Patient resource, and add it to the given Bundle.
*
* @param person
* The Person
* @param bundle
* The Bundle to add to
* @param stopTime
* Time the simulation ended
* @return The created Entry
*/
@SuppressWarnings("rawtypes")
private static Entry basicInfo(Person person, Bundle bundle, long stopTime) {
Patient patientResource = new Patient();
patientResource.addIdentifier().setSystem("https://github.com/synthetichealth/synthea").setValue((String) person.attributes.get(Person.ID));
patientResource.addIdentifier().setType(IdentifierTypeCodesEnum.MR).setSystem("http://hospital.smarthealthit.org").setValue((String) person.attributes.get(Person.ID));
patientResource.addIdentifier().setType(IdentifierTypeCodesEnum.SOCIAL_BENEFICIARY_IDENTIFIER).setSystem("http://hl7.org/fhir/sid/us-ssn").setValue((String) person.attributes.get(Person.IDENTIFIER_SSN));
if (person.attributes.get(Person.IDENTIFIER_DRIVERS) != null) {
patientResource.addIdentifier().setType(IdentifierTypeCodesEnum.DL).setSystem("urn:oid:2.16.840.1.113883.4.3.25").setValue((String) person.attributes.get(Person.IDENTIFIER_DRIVERS));
}
ExtensionDt raceExtension = new ExtensionDt();
raceExtension.setUrl("http://hl7.org/fhir/StructureDefinition/us-core-race");
String race = (String) person.attributes.get(Person.RACE);
ExtensionDt ethnicityExtension = new ExtensionDt();
ethnicityExtension.setUrl("http://hl7.org/fhir/StructureDefinition/us-core-ethnicity");
String ethnicity = (String) person.attributes.get(Person.ETHNICITY);
String raceDisplay;
switch(race) {
case "white":
raceDisplay = "White";
break;
case "black":
raceDisplay = "Black or African American";
break;
case "asian":
raceDisplay = "Asian";
break;
case "native":
raceDisplay = "American Indian or Alaska Native";
break;
case "hawaiian":
raceDisplay = "Native Hawaiian or Other Pacific Islander";
break;
default:
raceDisplay = "Other";
break;
}
String ethnicityDisplay;
if (ethnicity.equals("hispanic")) {
ethnicityDisplay = "Hispanic or Latino";
} else {
ethnicityDisplay = "Not Hispanic or Latino";
}
Code raceCode = new Code("http://hl7.org/fhir/v3/Race", (String) raceEthnicityCodes.get(race), raceDisplay);
Code ethnicityCode = new Code("http://hl7.org/fhir/v3/Ethnicity", (String) raceEthnicityCodes.get(ethnicity), ethnicityDisplay);
raceExtension.setValue(mapCodeToCodeableConcept(raceCode, "http://hl7.org/fhir/v3/Race"));
ethnicityExtension.setValue(mapCodeToCodeableConcept(ethnicityCode, "http://hl7.org/fhir/v3/Ethnicity"));
patientResource.addUndeclaredExtension(raceExtension);
patientResource.addUndeclaredExtension(ethnicityExtension);
String firstLanguage = (String) person.attributes.get(Person.FIRST_LANGUAGE);
Map languageMap = (Map) languageLookup.get(firstLanguage);
Code languageCode = new Code((String) languageMap.get("system"), (String) languageMap.get("code"), (String) languageMap.get("display"));
List<Communication> communication = new ArrayList<Communication>();
Communication language = new Communication();
language.setLanguage(mapCodeToCodeableConcept(languageCode, (String) languageMap.get("system")));
communication.add(language);
patientResource.setCommunication(communication);
HumanNameDt name = patientResource.addName();
name.setUse(NameUseEnum.OFFICIAL);
name.addGiven((String) person.attributes.get(Person.FIRST_NAME));
List<StringDt> officialFamilyNames = new ArrayList<StringDt>();
officialFamilyNames.add(new StringDt((String) person.attributes.get(Person.LAST_NAME)));
name.setFamily(officialFamilyNames);
if (person.attributes.get(Person.NAME_PREFIX) != null) {
name.addPrefix((String) person.attributes.get(Person.NAME_PREFIX));
}
if (person.attributes.get(Person.NAME_SUFFIX) != null) {
name.addSuffix((String) person.attributes.get(Person.NAME_SUFFIX));
}
if (person.attributes.get(Person.MAIDEN_NAME) != null) {
HumanNameDt maidenName = patientResource.addName();
maidenName.setUse(NameUseEnum.MAIDEN);
maidenName.addGiven((String) person.attributes.get(Person.FIRST_NAME));
List<StringDt> maidenFamilyNames = new ArrayList<StringDt>();
maidenFamilyNames.add(new StringDt((String) person.attributes.get(Person.MAIDEN_NAME)));
maidenName.setFamily(maidenFamilyNames);
if (person.attributes.get(Person.NAME_PREFIX) != null) {
maidenName.addPrefix((String) person.attributes.get(Person.NAME_PREFIX));
}
if (person.attributes.get(Person.NAME_SUFFIX) != null) {
maidenName.addSuffix((String) person.attributes.get(Person.NAME_SUFFIX));
}
}
ExtensionDt mothersMaidenNameExtension = new ExtensionDt();
mothersMaidenNameExtension.setUrl("http://hl7.org/fhir/StructureDefinition/patient-mothersMaidenName");
String mothersMaidenName = (String) person.attributes.get(Person.NAME_MOTHER);
mothersMaidenNameExtension.setValue(new StringDt(mothersMaidenName));
patientResource.addUndeclaredExtension(mothersMaidenNameExtension);
long birthdate = (long) person.attributes.get(Person.BIRTHDATE);
patientResource.setBirthDate(new DateDt(new Date(birthdate)));
ExtensionDt birthSexExtension = new ExtensionDt();
birthSexExtension.setUrl("http://hl7.org/fhir/us/core/StructureDefinition/us-core-birthsex");
if (person.attributes.get(Person.GENDER).equals("M")) {
patientResource.setGender(AdministrativeGenderEnum.MALE);
birthSexExtension.setValue(new CodeDt("M"));
} else if (person.attributes.get(Person.GENDER).equals("F")) {
patientResource.setGender(AdministrativeGenderEnum.FEMALE);
birthSexExtension.setValue(new CodeDt("F"));
}
patientResource.addUndeclaredExtension(birthSexExtension);
String state = (String) person.attributes.get(Person.STATE);
AddressDt addrResource = patientResource.addAddress();
addrResource.addLine((String) person.attributes.get(Person.ADDRESS)).setCity((String) person.attributes.get(Person.CITY)).setPostalCode((String) person.attributes.get(Person.ZIP)).setState(state);
if (COUNTRY_CODE != null) {
addrResource.setCountry(COUNTRY_CODE);
}
Point2D.Double coord = person.getLonLat();
if (coord != null) {
ExtensionDt geolocationExtension = new ExtensionDt();
geolocationExtension.setUrl("http://hl7.org/fhir/StructureDefinition/geolocation");
ExtensionDt latitudeExtension = new ExtensionDt();
ExtensionDt longitudeExtension = new ExtensionDt();
latitudeExtension.setUrl("latitude");
longitudeExtension.setUrl("longitude");
latitudeExtension.setValue(new DecimalDt(coord.getY()));
longitudeExtension.setValue(new DecimalDt(coord.getX()));
geolocationExtension.addUndeclaredExtension(latitudeExtension);
geolocationExtension.addUndeclaredExtension(longitudeExtension);
addrResource.addUndeclaredExtension(geolocationExtension);
}
AddressDt birthplace = new AddressDt();
birthplace.setCity((String) person.attributes.get(Person.BIRTH_CITY)).setState((String) person.attributes.get(Person.BIRTH_STATE)).setCountry((String) person.attributes.get(Person.BIRTH_COUNTRY));
ExtensionDt birthplaceExtension = new ExtensionDt();
birthplaceExtension.setUrl("http://hl7.org/fhir/StructureDefinition/birthPlace");
birthplaceExtension.setValue(birthplace);
patientResource.addUndeclaredExtension(birthplaceExtension);
if (person.attributes.get(Person.MULTIPLE_BIRTH_STATUS) != null) {
patientResource.setMultipleBirth(new IntegerDt((int) person.attributes.get(Person.MULTIPLE_BIRTH_STATUS)));
} else {
patientResource.setMultipleBirth(new BooleanDt(false));
}
patientResource.addTelecom().setSystem(ContactPointSystemEnum.PHONE).setUse(ContactPointUseEnum.HOME).setValue((String) person.attributes.get(Person.TELECOM));
String maritalStatus = ((String) person.attributes.get(Person.MARITAL_STATUS));
if (maritalStatus != null) {
patientResource.setMaritalStatus(MaritalStatusCodesEnum.forCode(maritalStatus.toUpperCase()));
} else {
patientResource.setMaritalStatus(MaritalStatusCodesEnum.S);
}
if (!person.alive(stopTime)) {
patientResource.setDeceased(convertFhirDateTime((Long) person.attributes.get(Person.DEATHDATE), true));
}
String generatedBySynthea = "Generated by <a href=\"https://github.com/synthetichealth/synthea\">Synthea</a>." + "Version identifier: " + Utilities.SYNTHEA_VERSION + " . " + " Person seed: " + person.seed + " Population seed: " + person.populationSeed;
patientResource.setText(new NarrativeDt(new XhtmlDt(generatedBySynthea), NarrativeStatusEnum.GENERATED));
// DALY and QALY values
// we only write the last(current) one to the patient record
Double dalyValue = (Double) person.attributes.get("most-recent-daly");
Double qalyValue = (Double) person.attributes.get("most-recent-qaly");
if (dalyValue != null) {
ExtensionDt dalyExtension = new ExtensionDt();
dalyExtension.setUrl(SYNTHEA_EXT + "disability-adjusted-life-years");
DecimalDt daly = new DecimalDt(dalyValue);
dalyExtension.setValue(daly);
patientResource.addUndeclaredExtension(dalyExtension);
ExtensionDt qalyExtension = new ExtensionDt();
qalyExtension.setUrl(SYNTHEA_EXT + "quality-adjusted-life-years");
DecimalDt qaly = new DecimalDt(qalyValue);
qalyExtension.setValue(qaly);
patientResource.addUndeclaredExtension(qalyExtension);
}
return newEntry(bundle, patientResource, (String) person.attributes.get(Person.ID));
}
Aggregations