use of ca.uhn.fhir.model.dstu2.resource.Practitioner in project synthea by synthetichealth.
the class FhirDstu2 method encounter.
/**
* Map the given Encounter into a FHIR Encounter resource, and add it to the given Bundle.
*
* @param person
* Patient at the encounter.
* @param personEntry
* Entry for the Person
* @param bundle
* The Bundle to add to
* @param encounter
* The current Encounter
* @return The added Entry
*/
private static Entry encounter(Person person, Entry personEntry, Bundle bundle, Encounter encounter) {
ca.uhn.fhir.model.dstu2.resource.Encounter encounterResource = new ca.uhn.fhir.model.dstu2.resource.Encounter();
encounterResource.setPatient(new ResourceReferenceDt(personEntry.getFullUrl()));
encounterResource.setStatus(EncounterStateEnum.FINISHED);
if (encounter.codes.isEmpty()) {
// wellness encounter
encounterResource.addType().addCoding().setCode("185349003").setDisplay("Encounter for check up").setSystem(SNOMED_URI);
} else {
Code code = encounter.codes.get(0);
encounterResource.addType(mapCodeToCodeableConcept(code, SNOMED_URI));
}
EncounterClassEnum encounterClass = EncounterClassEnum.forCode(encounter.type);
if (encounterClass == null) {
encounterClass = EncounterClassEnum.AMBULATORY;
}
encounterResource.setClassElement(encounterClass);
encounterResource.setPeriod(new PeriodDt().setStart(new DateTimeDt(new Date(encounter.start))).setEnd(new DateTimeDt(new Date(encounter.stop))));
if (encounter.reason != null) {
encounterResource.addReason().addCoding().setCode(encounter.reason.code).setDisplay(encounter.reason.display).setSystem(SNOMED_URI);
}
Provider provider = encounter.provider;
if (provider == null) {
// no associated provider, patient goes to wellness provider
provider = person.getProvider(EncounterType.WELLNESS, encounter.start);
}
if (TRANSACTION_BUNDLE) {
encounterResource.setServiceProvider(new ResourceReferenceDt(ExportHelper.buildFhirSearchUrl("Organization", provider.getResourceID())));
} else {
String providerFullUrl = findProviderUrl(provider, bundle);
if (providerFullUrl != null) {
encounterResource.setServiceProvider(new ResourceReferenceDt(providerFullUrl));
} else {
Entry providerOrganization = provider(bundle, provider);
encounterResource.setServiceProvider(new ResourceReferenceDt(providerOrganization.getFullUrl()));
}
}
encounterResource.getServiceProvider().setDisplay(provider.name);
if (encounter.clinician != null) {
if (TRANSACTION_BUNDLE) {
encounterResource.addParticipant().setIndividual(new ResourceReferenceDt(ExportHelper.buildFhirNpiSearchUrl(encounter.clinician)));
} else {
String practitionerFullUrl = findPractitioner(encounter.clinician, bundle);
if (practitionerFullUrl != null) {
encounterResource.addParticipant().setIndividual(new ResourceReferenceDt(practitionerFullUrl));
} else {
Entry practitioner = practitioner(bundle, encounter.clinician);
encounterResource.addParticipant().setIndividual(new ResourceReferenceDt(practitioner.getFullUrl()));
}
}
encounterResource.getParticipantFirstRep().getIndividual().setDisplay(encounter.clinician.getFullname());
}
if (encounter.discharge != null) {
Hospitalization hospitalization = new Hospitalization();
Code dischargeDisposition = new Code(DISCHARGE_URI, encounter.discharge.code, encounter.discharge.display);
hospitalization.setDischargeDisposition(mapCodeToCodeableConcept(dischargeDisposition, DISCHARGE_URI));
encounterResource.setHospitalization(hospitalization);
}
return newEntry(person, bundle, encounterResource);
}
use of ca.uhn.fhir.model.dstu2.resource.Practitioner 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.dstu2.resource.Practitioner in project eCRNow by drajer-health.
the class Dstu2CdaHeaderGenerator method getEncompassingEncounter.
public static String getEncompassingEncounter(Encounter en, Practitioner pr, Location loc, Organization org, LaunchDetails details) {
StringBuilder sb = new StringBuilder(2000);
sb.append(CdaGeneratorUtils.getXmlForStartElement(CdaGeneratorConstants.COMPONENT_OF_EL_NAME));
sb.append(CdaGeneratorUtils.getXmlForStartElement(CdaGeneratorConstants.ENCOMPASSING_ENC_EL_NAME));
if (en != null) {
sb.append(CdaGeneratorUtils.getXmlForII(details.getAssigningAuthorityId(), en.getId().getIdPart()));
// Add all the encounter identifiers to the Ids
List<IdentifierDt> ids = en.getIdentifier();
if (ids != null) {
for (IdentifierDt id : ids) {
if (id.getSystem() != null && id.getValue() != null) {
sb.append(CdaGeneratorUtils.getXmlForII(CdaGeneratorUtils.getRootOid(id.getSystem(), details.getAssigningAuthorityId()), id.getValue()));
}
}
}
sb.append(Dstu2CdaFhirUtilities.getCodeableConceptXml(en.getType(), CdaGeneratorConstants.CODE_EL_NAME, false));
sb.append(Dstu2CdaFhirUtilities.getPeriodXml(en.getPeriod(), CdaGeneratorConstants.EFF_TIME_EL_NAME));
} else {
sb.append(CdaGeneratorUtils.getXmlForIIUsingGuid());
sb.append(CdaGeneratorUtils.getXmlForNullCD(CdaGeneratorConstants.CODE_EL_NAME, CdaGeneratorConstants.NF_NI));
sb.append(CdaGeneratorUtils.getXmlForNullEffectiveTime(CdaGeneratorConstants.EFF_TIME_EL_NAME, CdaGeneratorConstants.NF_NI));
}
sb.append(CdaGeneratorUtils.getXmlForStartElement(CdaGeneratorConstants.RESP_PARTY_EL_NAME));
sb.append(CdaGeneratorUtils.getXmlForStartElement(CdaGeneratorConstants.ASSIGNED_ENTITY_EL_NAME));
sb.append(getPractitionerXml(pr));
sb.append(CdaGeneratorUtils.getXmlForStartElement(CdaGeneratorConstants.REP_ORG_EL_NAME));
sb.append(getOrganizationXml(org, details));
sb.append(CdaGeneratorUtils.getXmlForEndElement(CdaGeneratorConstants.REP_ORG_EL_NAME));
sb.append(CdaGeneratorUtils.getXmlForEndElement(CdaGeneratorConstants.ASSIGNED_ENTITY_EL_NAME));
sb.append(CdaGeneratorUtils.getXmlForEndElement(CdaGeneratorConstants.RESP_PARTY_EL_NAME));
sb.append(CdaGeneratorUtils.getXmlForStartElement(CdaGeneratorConstants.LOCATION_EL_NAME));
sb.append(CdaGeneratorUtils.getXmlForStartElement(CdaGeneratorConstants.HEALTHCARE_FACILITY_EL_NAME));
sb.append(getLocationXml(loc));
sb.append(CdaGeneratorUtils.getXmlForStartElement(CdaGeneratorConstants.SERVICE_PROVIDER_ORG_EL_NAME));
sb.append(getOrganizationXml(org, details));
sb.append(CdaGeneratorUtils.getXmlForEndElement(CdaGeneratorConstants.SERVICE_PROVIDER_ORG_EL_NAME));
sb.append(CdaGeneratorUtils.getXmlForEndElement(CdaGeneratorConstants.HEALTHCARE_FACILITY_EL_NAME));
sb.append(CdaGeneratorUtils.getXmlForEndElement(CdaGeneratorConstants.LOCATION_EL_NAME));
sb.append(CdaGeneratorUtils.getXmlForEndElement(CdaGeneratorConstants.ENCOMPASSING_ENC_EL_NAME));
sb.append(CdaGeneratorUtils.getXmlForEndElement(CdaGeneratorConstants.COMPONENT_OF_EL_NAME));
return sb.toString();
}
use of ca.uhn.fhir.model.dstu2.resource.Practitioner in project eCRNow by drajer-health.
the class Dstu2CdaEicrGenerator method convertDstu2FhirBundletoCdaEicr.
public static String convertDstu2FhirBundletoCdaEicr(Dstu2FhirData data, LaunchDetails details, Eicr ecr) {
StringBuilder eICR = new StringBuilder();
if (data != null) {
Bundle bundle = data.getData();
if (bundle != null) {
List<Entry> entries = bundle.getEntry();
for (Entry ent : entries) {
// Populate data ..this can be moved to the APIs where the bundle is getting created.
if (ent.getResource() instanceof Patient) {
logger.info(" Bundle contains Patient ");
data.setPatient((Patient) ent.getResource());
} else if (ent.getResource() instanceof Practitioner) {
logger.info(" Bundle contains Practitioner ");
data.setPractitioner((Practitioner) ent.getResource());
} else if (ent.getResource() instanceof Encounter) {
logger.info(" Bundle contains Encounter ");
data.setEncounter((Encounter) ent.getResource());
} else if (ent.getResource() instanceof Location) {
logger.info(" Bundle contains Location ");
data.setLocation((Location) ent.getResource());
} else if (ent.getResource() instanceof Organization) {
logger.info(" Bundle contains Organization ");
data.setOrganization((Organization) ent.getResource());
} else if (ent.getResource() instanceof Condition) {
logger.info(" Bundle contains Condition ");
data.getConditions().add((Condition) ent.getResource());
} else if (ent.getResource() instanceof Observation) {
Observation obs = (Observation) ent.getResource();
if (obs.getCategory() != null && obs.getCategory().getCodingFirstRep() != null && obs.getCategory().getCodingFirstRep().getCode() != null && obs.getCategory().getCodingFirstRep().getCode().contentEquals(CdaGeneratorConstants.FHIR_LAB_RESULT_CATEGORY)) {
logger.info(" Bundle contains Lab Results ");
data.getLabResults().add((Observation) ent.getResource());
} else if (obs.getCategory() != null && obs.getCategory().getCodingFirstRep() != null && obs.getCategory().getCodingFirstRep().getCode() != null) {
logger.info("Code for Observation Category = " + obs.getCategory().getCodingFirstRep().getCode());
}
// Compare Code for Travel Obs
// Compare Codes for Pregnancy Obs and sort it out.
} else if (ent.getResource() instanceof DiagnosticReport) {
logger.info(" Bundle contains Diagnostic Report ");
data.getDiagReports().add((DiagnosticReport) ent.getResource());
} else if (ent.getResource() instanceof DiagnosticOrder) {
logger.info(" Bundle contains Diagnostic Order ");
data.getDiagOrders().add((DiagnosticOrder) ent.getResource());
} else if (ent.getResource() instanceof MedicationStatement) {
logger.info(" Bundle contains MedicationStatement ");
data.getMedications().add((MedicationStatement) ent.getResource());
} else if (ent.getResource() instanceof Immunization) {
logger.info(" Bundle contains Immunization ");
data.getImmunizations().add((Immunization) ent.getResource());
}
}
eICR.append(Dstu2CdaHeaderGenerator.createCdaHeader(data, details));
eICR.append(Dstu2CdaBodyGenerator.generateCdaBody(data, details));
eICR.append(CdaGeneratorUtils.getEndXMLHeaderForCdaDocument());
}
} else {
logger.error(" No Fhir Bundle Available to create CDA Documents ");
}
return eICR.toString();
}
use of ca.uhn.fhir.model.dstu2.resource.Practitioner in project eCRNow by drajer-health.
the class Dstu2CdaFhirUtilities method getPractitioner.
public static Practitioner getPractitioner(List<Entry> entries, Encounter en) {
List<Participant> participants = en.getParticipant();
if (participants != null && participants.size() > 0) {
for (Participant part : participants) {
if (part.getIndividual().getReference().hasIdPart()) {
logger.info(" Individual is present ");
List<BoundCodeableConceptDt<ParticipantTypeEnum>> types = part.getType();
for (BoundCodeableConceptDt<ParticipantTypeEnum> conc : types) {
List<CodingDt> typeCodes = conc.getCoding();
for (CodingDt cd : typeCodes) {
if (cd.getCode().contentEquals(ParticipantTypeEnum.PPRF.getCode())) {
// Found the participant.
// Look for the Practitioner.
Entry ent = getResourceEntryForId(part.getIndividual().getReference().getIdPart(), "Practitioner", entries);
if (ent != null) {
logger.info(" Found Practitioner for Id " + part.getIndividual().getReference().getIdPart());
return (Practitioner) ent.getResource();
} else {
logger.info(" Did not find the practitioner for : " + part.getIndividual().getReference().getIdPart());
}
}
}
}
}
}
}
logger.info(" Did not find the practitioner for encounter ");
return null;
}
Aggregations