use of org.hl7.fhir.r4.model.codesystems.ResourceTypes.MEDICATIONSTATEMENT in project gpconnect-demonstrator by nhsconnect.
the class PopulateMedicationBundle method addMedicationBundleEntries.
public Bundle addMedicationBundleEntries(Bundle structuredBundle, PatientDetails patientDetails, Boolean includePrescriptionIssues, Period medicationPeriod, Set<String> practitionerIds, Set<String> orgIds) {
BundleEntryComponent listEntry = new BundleEntryComponent();
List<MedicationStatementDetail> medicationStatements = findMedicationStatements(Long.valueOf(patientDetails.getId()), medicationPeriod);
structuredBundle.addEntry(listEntry.setResource(createListEntry(medicationStatements, patientDetails.getNhsNumber())));
medicationStatements.forEach(medicationStatement -> {
createBundleEntries(medicationStatement, includePrescriptionIssues, patientDetails, practitionerIds, orgIds).forEach(bundleEntry -> structuredBundle.addEntry(bundleEntry));
});
return structuredBundle;
}
use of org.hl7.fhir.r4.model.codesystems.ResourceTypes.MEDICATIONSTATEMENT in project gpconnect-demonstrator by nhsconnect.
the class WarningCodeExtHelper method addWarningCodeExtensions.
/**
* confidential items are per record but the other two are global values per
* patient
*
* @param warningCodes
* @param list
* @param patientRepository
* @param medicationStatementRepository
* @param structuredAllergySearch
*/
public static void addWarningCodeExtensions(Set<String> warningCodes, ListResource list, PatientRepository patientRepository, MedicationStatementRepository medicationStatementRepository, StructuredAllergySearch structuredAllergySearch) {
String NHS = list.getSubject().getIdentifier().getValue();
PatientEntity patientEntity = patientRepository.findByNhsNumber(NHS);
List<MedicationStatementEntity> medicationStatements = medicationStatementRepository.findByPatientId(patientEntity.getId());
for (MedicationStatementEntity medicationStatement : medicationStatements) {
setFlags(medicationStatement.getWarningCode());
}
List<StructuredAllergyIntoleranceEntity> allergies = structuredAllergySearch.getAllergyIntollerence(NHS);
for (StructuredAllergyIntoleranceEntity allergy : allergies) {
setFlags(allergy.getWarningCode());
}
// check medication_statements for either of the global flags
if (dataInTransit) {
warningCodes.add(DATA_IN_TRANSIT);
}
if (dataAwaitingFiling) {
warningCodes.add(DATA_AWAITING_FILING);
}
StringBuilder sb = new StringBuilder();
warningCodes.forEach(warningCode -> {
if (warningCode != null) {
String warningCodeDisplay = "";
Annotation annotation = new Annotation();
switch(warningCode) {
case CONFIDENTIAL_ITEMS:
warningCodeDisplay = "Confidential Items";
// #266
annotation.setText(CONFIDENTIAL_ITEMS_NOTE);
// list.addNote(annotation);
sb.append("\r\n").append(annotation.getText());
break;
case DATA_IN_TRANSIT:
warningCodeDisplay = "Data in Transit";
Calendar cal = new GregorianCalendar();
Date now = new Date();
cal.setTime(now);
// a week before now
cal.add(Calendar.DAY_OF_YEAR, -7);
// #266
annotation.setText(String.format(DATA_IN_TRANSIT_NOTE, DATE_FORMAT.format(cal.getTime())));
// list.addNote(annotation);
sb.append("\r\n").append(annotation.getText());
break;
case DATA_AWAITING_FILING:
warningCodeDisplay = "Data Awaiting Filing";
// #266
annotation.setText(DATA_AWAITING_FILING_NOTE);
// list.addNote(annotation);
sb.append("\r\n").append(annotation.getText());
break;
default:
break;
}
// #182
Extension warningExt = new Extension(SystemURL.WARNING_CODE, new CodeType(warningCode));
list.addExtension(warningExt);
}
});
// cardinality of note 0..1 #266
if (sb.length() > 0) {
Annotation annotation = null;
if (list.getNote().size() > 0) {
annotation = list.getNote().get(0);
annotation.setText(annotation.getText());
annotation.setText(annotation.getText() + sb.toString());
} else {
annotation = new Annotation();
list.addNote(annotation);
annotation.setText(sb.toString().replaceFirst("^\r\n", ""));
}
}
}
use of org.hl7.fhir.r4.model.codesystems.ResourceTypes.MEDICATIONSTATEMENT in project gpconnect-demonstrator by nhsconnect.
the class MedicationStatementResourceProvider method getMedicationStatementResource.
public MedicationStatement getMedicationStatementResource(MedicationStatementDetail statementDetail) {
MedicationStatement medicationStatement = new MedicationStatement();
medicationStatement.setId(statementDetail.getId().toString());
List<Identifier> identifiers = new ArrayList<>();
Identifier identifier = new Identifier().setSystem("https://fhir.nhs.uk/Id/cross-care-setting-identifier").setValue(statementDetail.getGuid());
identifiers.add(identifier);
medicationStatement.setIdentifier(identifiers);
medicationStatement.setMeta(new Meta().addProfile(SystemURL.SD_GPC_MEDICATION_STATEMENT));
medicationStatement.addExtension(new Extension(SystemURL.SD_CC_EXT_MEDICATION_STATEMENT_LAST_ISSUE, new DateTimeType(statementDetail.getLastIssueDate(), TemporalPrecisionEnum.DAY)));
if (statementDetail.getMedicationRequestPlanId() != null) {
medicationStatement.addBasedOn(new Reference(new IdType("MedicationRequest", statementDetail.getMedicationRequestPlanId())));
}
try {
medicationStatement.setStatus(MedicationStatementStatus.fromCode(statementDetail.getStatusCode()));
} catch (FHIRException e) {
throw new UnprocessableEntityException(e.getMessage());
}
if (statementDetail.getMedicationId() != null) {
medicationStatement.setMedication(new Reference(new IdType("Medication", statementDetail.getMedicationId())));
}
medicationStatement.setEffective(new Period().setStart(statementDetail.getStartDate()).setEnd(statementDetail.getEndDate()));
medicationStatement.setDateAsserted(statementDetail.getDateAsserted());
if (statementDetail.getPatientId() != null)
medicationStatement.setSubject(new Reference(new IdType("Patient", statementDetail.getPatientId())));
try {
medicationStatement.setTaken(statementDetail.getTakenCode() != null ? MedicationStatementTaken.fromCode(statementDetail.getTakenCode()) : MedicationStatementTaken.UNK);
} catch (FHIRException e) {
throw new UnprocessableEntityException(e.getMessage());
}
setReasonCodes(medicationStatement, statementDetail);
setNotes(medicationStatement, statementDetail);
String dosageText = statementDetail.getDosageText();
medicationStatement.addDosage(new Dosage().setText(dosageText == null || dosageText.trim().isEmpty() ? NO_INFORMATION_AVAILABLE : dosageText).setPatientInstruction(statementDetail.getDosagePatientInstruction()));
String prescribingAgency = statementDetail.getPrescribingAgency();
if (prescribingAgency != null && !prescribingAgency.trim().isEmpty()) {
String prescribingAgencyDisplay = "";
if (prescribingAgency.equalsIgnoreCase("prescribed-at-gp-practice")) {
prescribingAgencyDisplay = "Prescribed at GP practice";
} else if (prescribingAgency.equalsIgnoreCase("prescribed-by-another-organisation")) {
prescribingAgencyDisplay = "Prescribed by another organisation";
}
Coding coding = new Coding(SystemURL.CS_CC_PRESCRIBING_AGENCY_STU3, prescribingAgency, prescribingAgencyDisplay);
CodeableConcept codeableConcept = new CodeableConcept().addCoding(coding);
medicationStatement.addExtension(new Extension(SystemURL.SD_EXTENSION_CC_PRESCRIBING_AGENCY, codeableConcept));
}
// #281 1.2.5 add dosageLastChanged
Date dosageLastChanged = statementDetail.getDosageLastChanged();
if (dosageLastChanged != null) {
medicationStatement.addExtension(new Extension(SystemURL.SD_EXTENSION_CC_DOSAGE_LAST_CHANGED, new DateTimeType(dosageLastChanged)));
}
return medicationStatement;
}
use of org.hl7.fhir.r4.model.codesystems.ResourceTypes.MEDICATIONSTATEMENT in project gpconnect-demonstrator by nhsconnect.
the class PopulateMedicationBundle method createBundleEntries.
private List<BundleEntryComponent> createBundleEntries(MedicationStatementDetail statementDetail, Boolean includePrescriptionIssues, PatientDetails patientDetails, Set<String> practitionerIds, Set<String> orgIds) {
List<BundleEntryComponent> bundleEntryComponents = new ArrayList<>();
MedicationStatement medStatement = medicationStatementResourceProvider.getMedicationStatementResource(statementDetail);
bundleEntryComponents.add(new BundleEntryComponent().setResource(medStatement));
bundleEntryComponents.add(new BundleEntryComponent().setResource(medicationResourceProvider.getMedicationResourceForBundle(statementDetail.getMedicationId())));
MedicationRequest medicationRequest = medicationRequestResourceProvider.getMedicationRequestPlanResource(statementDetail.getMedicationRequestPlanId());
bundleEntryComponents.add(new BundleEntryComponent().setResource(medicationRequest));
if (includePrescriptionIssues) {
List<MedicationRequest> prescriptionIssues = medicationRequestResourceProvider.getMedicationRequestOrderResources(medicationRequest.getGroupIdentifier().getValue());
prescriptionIssues.forEach(requestOrder -> bundleEntryComponents.add(new BundleEntryComponent().setResource(requestOrder)));
}
List<MedicationRequest> allMedReqs = new ArrayList<>();
allMedReqs.add(medicationRequest);
allMedReqs.addAll(allMedReqs);
practitionerIds.addAll(getPractitionerIds(medStatement, allMedReqs));
orgIds.addAll(getOrganisationIds(allMedReqs));
return bundleEntryComponents;
}
use of org.hl7.fhir.r4.model.codesystems.ResourceTypes.MEDICATIONSTATEMENT in project gpconnect-demonstrator by nhsconnect.
the class PopulateMedicationBundle method createListEntry.
private ListResource createListEntry(List<MedicationStatementDetail> medicationStatements, String nhsNumber) {
ListResource medicationStatementsList = new ListResource();
// #179 dont populate List.id
// medicationStatementsList.setId(new IdType(1));
medicationStatementsList.setMeta(new Meta().addProfile(SystemURL.SD_GPC_LIST));
medicationStatementsList.setStatus(ListStatus.CURRENT);
// #179 dont populate List.id
// medicationStatementsList.setId(new IdDt(1));
medicationStatementsList.setMode(ListMode.SNAPSHOT);
medicationStatementsList.setTitle(SystemConstants.MEDICATION_LIST);
medicationStatementsList.setCode(new CodeableConcept().addCoding(new Coding(SystemURL.VS_SNOMED, "933361000000108", MEDICATION_LIST)));
medicationStatementsList.setSubject(new Reference(new IdType("Patient", 1L)).setIdentifier(new Identifier().setValue(nhsNumber).setSystem(SystemURL.ID_NHS_NUMBER)));
medicationStatementsList.setDate(new Date());
medicationStatementsList.setOrderedBy(new CodeableConcept().addCoding(new Coding(SystemURL.CS_LIST_ORDER, "event-date", "Sorted by Event Date")));
medicationStatementsList.addExtension(setClinicalSetting());
if (medicationStatements.isEmpty()) {
medicationStatementsList.setEmptyReason(new CodeableConcept().setText(SystemConstants.NO_CONTENT));
medicationStatementsList.setNote(Arrays.asList(new Annotation(new StringType(SystemConstants.INFORMATION_NOT_AVAILABLE))));
}
Set<String> warningCodes = new HashSet<>();
medicationStatements.forEach(statement -> {
Reference statementRef = new Reference(new IdType("MedicationStatement", statement.getId()));
ListEntryComponent listEntryComponent = new ListEntryComponent(statementRef);
medicationStatementsList.addEntry(listEntryComponent);
if (statement.getWarningCode() != null) {
warningCodes.add(statement.getWarningCode());
}
});
WarningCodeExtHelper.addWarningCodeExtensions(warningCodes, medicationStatementsList, patientRepository, medicationStatementRepository, structuredAllergySearch);
return medicationStatementsList;
}
Aggregations