use of org.hl7.fhir.r4.model.Procedure.ProcedureStatus.COMPLETED in project eCRNow by drajer-health.
the class CdaMedicationGenerator method generateMedicationSection.
public static String generateMedicationSection(R4FhirData data, LaunchDetails details) {
StringBuilder sb = new StringBuilder(2000);
List<Medication> medList = data.getMedicationList();
List<MedicationStatement> meds = data.getMedications();
List<MedicationAdministration> medAdms = data.getMedicationAdministrations();
List<MedicationRequest> medReqs = getValidMedicationRequests(data, medList);
if ((meds != null && !meds.isEmpty()) || (medAdms != null && !medAdms.isEmpty()) || (medReqs != null && !medReqs.isEmpty())) {
// Generate the component and section end tags
sb.append(CdaGeneratorUtils.getXmlForStartElement(CdaGeneratorConstants.COMP_EL_NAME));
sb.append(CdaGeneratorUtils.getXmlForStartElement(CdaGeneratorConstants.SECTION_EL_NAME));
sb.append(CdaGeneratorUtils.getXmlForTemplateId(CdaGeneratorConstants.MED_ADM_SEC_TEMPLATE_ID));
sb.append(CdaGeneratorUtils.getXmlForTemplateId(CdaGeneratorConstants.MED_ADM_SEC_TEMPLATE_ID, CdaGeneratorConstants.MED_SEC_TEMPLATE_ID_EXT));
sb.append(CdaGeneratorUtils.getXmlForCD(CdaGeneratorConstants.CODE_EL_NAME, CdaGeneratorConstants.MED_ADM_SEC_CODE, CdaGeneratorConstants.LOINC_CODESYSTEM_OID, CdaGeneratorConstants.LOINC_CODESYSTEM_NAME, CdaGeneratorConstants.MED_ADM_SEC_NAME));
// add Title
sb.append(CdaGeneratorUtils.getXmlForText(CdaGeneratorConstants.TITLE_EL_NAME, CdaGeneratorConstants.MED_ADM_SEC_TITLE));
// add Narrative Text
sb.append(CdaGeneratorUtils.getXmlForStartElement(CdaGeneratorConstants.TEXT_EL_NAME));
// Create Table Header.
List<String> list = new ArrayList<>();
list.add(CdaGeneratorConstants.MED_TABLE_COL_1_TITLE);
list.add(CdaGeneratorConstants.MED_TABLE_COL_2_TITLE);
sb.append(CdaGeneratorUtils.getXmlForTableHeader(list, CdaGeneratorConstants.TABLE_BORDER, CdaGeneratorConstants.TABLE_WIDTH));
// add Table Body
sb.append(CdaGeneratorUtils.getXmlForStartElement(CdaGeneratorConstants.TABLE_BODY_EL_NAME));
// add Body Rows
int rowNum = 1;
StringBuilder medEntries = new StringBuilder();
for (MedicationStatement med : meds) {
String medDisplayName = CdaGeneratorConstants.UNKNOWN_VALUE;
if (med.getMedication() != null) {
medDisplayName = CdaFhirUtilities.getStringForMedicationType(med);
}
String dt = null;
if (med.getEffective() != null) {
dt = CdaFhirUtilities.getStringForType(med.getEffective());
}
Map<String, String> bodyvals = new LinkedHashMap<>();
bodyvals.put(CdaGeneratorConstants.MED_TABLE_COL_1_BODY_CONTENT, medDisplayName);
bodyvals.put(CdaGeneratorConstants.MED_TABLE_COL_2_BODY_CONTENT, dt);
sb.append(CdaGeneratorUtils.addTableRow(bodyvals, rowNum));
// TODO: ++rowNum or rowNum++
++rowNum;
// Create the Med Entry for the Medication Statement.
String medstatus = "";
if (med.getStatus() != null) {
medstatus = CdaFhirUtilities.getStatusCodeForFhirMedStatusCodes(med.getStatus().toString());
} else {
medstatus = COMPLETED;
}
Dosage dosage = null;
if (med.getDosageFirstRep() != null)
dosage = med.getDosageFirstRep();
medEntries.append(getEntryForMedication(med.getId(), med.getMedication(), med.getEffective(), medstatus, dosage, details, null, null, CdaGeneratorConstants.MOOD_CODE_DEF, med));
}
// Add Medication Administration
for (MedicationAdministration medAdm : medAdms) {
String medDisplayName = CdaGeneratorConstants.UNKNOWN_VALUE;
if (medAdm.getMedication() != null) {
medDisplayName = CdaFhirUtilities.getStringForMedicationType(medAdm);
}
String dt = null;
if (medAdm.getEffective() != null) {
dt = CdaFhirUtilities.getStringForType(medAdm.getEffective());
}
Map<String, String> bodyvals = new HashMap<>();
bodyvals.put(CdaGeneratorConstants.MED_TABLE_COL_1_BODY_CONTENT, medDisplayName);
bodyvals.put(CdaGeneratorConstants.MED_TABLE_COL_2_BODY_CONTENT, dt);
sb.append(CdaGeneratorUtils.addTableRow(bodyvals, rowNum));
// TODO: ++rowNum or rowNum++
++rowNum;
// Create the Med Entry for the Medication Statement.
String medstatus = "";
if (medAdm.getStatus() != null) {
medstatus = CdaFhirUtilities.getStatusCodeForFhirMedStatusCodes(medAdm.getStatus());
} else {
medstatus = COMPLETED;
}
Quantity dose = null;
if (medAdm.getDosage() != null && medAdm.getDosage().getDose() != null)
dose = medAdm.getDosage().getDose();
medEntries.append(getEntryForMedication(medAdm.getId(), medAdm.getMedication(), medAdm.getEffective(), medstatus, null, details, dose, null, CdaGeneratorConstants.MOOD_CODE_DEF, medAdm));
}
// Add Medication Requests
for (MedicationRequest medReq : medReqs) {
String medDisplayName = CdaGeneratorConstants.UNKNOWN_VALUE;
if (medReq.getMedication() != null) {
medDisplayName = CdaFhirUtilities.getStringForMedicationType(medReq);
}
DateTimeType startDate = null;
Dosage dosage = null;
if (medReq.getDosageInstructionFirstRep() != null && medReq.getDosageInstructionFirstRep().getTiming() != null) {
dosage = medReq.getDosageInstructionFirstRep();
Timing t = medReq.getDosageInstructionFirstRep().getTiming();
if (t != null && t.getRepeat() != null && t.getRepeat().getBoundsPeriod() != null) {
startDate = t.getRepeat().getBoundsPeriod().getStartElement();
}
}
String dt = CdaGeneratorConstants.UNKNOWN_VALUE;
if (startDate != null) {
dt = CdaFhirUtilities.getDisplayStringForDateTimeType(startDate);
} else {
logger.error(" Dosage field does not have a valid period either due to datetime or timezone being null ");
}
Map<String, String> bodyvals = new HashMap<>();
bodyvals.put(CdaGeneratorConstants.MED_TABLE_COL_1_BODY_CONTENT, medDisplayName);
bodyvals.put(CdaGeneratorConstants.MED_TABLE_COL_2_BODY_CONTENT, dt);
sb.append(CdaGeneratorUtils.addTableRow(bodyvals, rowNum));
// TODO: ++rowNum or rowNum++
++rowNum;
// Create the Med Entry for the Medication Request.
String medstatus = "";
String moodCode = CdaGeneratorConstants.MOOD_CODE_INT;
if (medReq.getStatus() != null) {
medstatus = CdaFhirUtilities.getStatusCodeForFhirMedStatusCodes(medReq.getStatus().toString());
if (medstatus.equalsIgnoreCase(COMPLETED)) {
moodCode = CdaGeneratorConstants.MOOD_CODE_DEF;
}
} else {
medstatus = "active";
}
medEntries.append(getEntryForMedication(medReq.getId(), medReq.getMedication(), null, medstatus, dosage, details, null, startDate, moodCode, medReq));
}
sb.append(CdaGeneratorUtils.getXmlForEndElement(CdaGeneratorConstants.TABLE_BODY_EL_NAME));
// End Table.
sb.append(CdaGeneratorUtils.getXmlForEndElement(CdaGeneratorConstants.TABLE_EL_NAME));
sb.append(CdaGeneratorUtils.getXmlForEndElement(CdaGeneratorConstants.TEXT_EL_NAME));
// Add Medication Entries
sb.append(medEntries);
// Complete the section end tags.
sb.append(CdaGeneratorUtils.getXmlForEndElement(CdaGeneratorConstants.SECTION_EL_NAME));
sb.append(CdaGeneratorUtils.getXmlForEndElement(CdaGeneratorConstants.COMP_EL_NAME));
} else {
sb.append(generateEmptyMedications());
}
return sb.toString();
}
use of org.hl7.fhir.r4.model.Procedure.ProcedureStatus.COMPLETED in project eCRNow by drajer-health.
the class ApplicationUtils method readBundleFromFile.
public Bundle readBundleFromFile(String filename) {
logger.info("About to read File {}", filename);
Bundle bundle = null;
try (InputStream in = new FileInputStream(new File(filename))) {
logger.info("Reading File ");
bundle = jsonParser.parseResource(Bundle.class, in);
logger.info("Completed Reading File");
} catch (Exception e) {
logger.error("Exception Reading File", e);
}
return bundle;
}
Aggregations