use of org.hl7.fhir.r4.model.Period in project gpconnect-demonstrator by nhsconnect.
the class PatientResourceProvider method setStaticPatientData.
private Patient setStaticPatientData(Patient patient) {
patient.setLanguage(("en-GB"));
patient.addExtension(createCodingExtension("CG", "Greek Cypriot", SystemURL.CS_CC_ETHNIC_CATEGORY, SystemURL.SD_CC_EXT_ETHNIC_CATEGORY));
patient.addExtension(createCodingExtension("SomeSnomedCode", "Some Snomed Code", SystemURL.CS_CC_RELIGIOUS_AFFILI, SystemURL.SD_CC_EXT_RELIGIOUS_AFFILI));
patient.addExtension(new Extension(SystemURL.SD_PATIENT_CADAVERIC_DON, new BooleanType(false)));
patient.addExtension(createCodingExtension("H", "UK Resident", SystemURL.CS_CC_RESIDENTIAL_STATUS, SystemURL.SD_CC_EXT_RESIDENTIAL_STATUS));
patient.addExtension(createCodingExtension("3", "To pay hotel fees only", SystemURL.CS_CC_TREATMENT_CAT, SystemURL.SD_CC_EXT_TREATMENT_CAT));
Extension nhsCommExtension = new Extension();
nhsCommExtension.setUrl(SystemURL.SD_CC_EXT_NHS_COMMUNICATION);
nhsCommExtension.addExtension(createCodingExtension("en", "English", SystemURL.CS_CC_HUMAN_LANG, SystemURL.SD_CC_EXT_COMM_LANGUAGE));
nhsCommExtension.addExtension(new Extension(SystemURL.SD_CC_COMM_PREFERRED, new BooleanType(false)));
nhsCommExtension.addExtension(createCodingExtension("RWR", "Received written", SystemURL.CS_CC_LANG_ABILITY_MODE, SystemURL.SD_CC_MODE_OF_COMM));
nhsCommExtension.addExtension(createCodingExtension("E", "Excellent", SystemURL.CS_CC_LANG_ABILITY_PROFI, SystemURL.SD_CC_COMM_PROFICIENCY));
nhsCommExtension.addExtension(new Extension(SystemURL.SD_CC_INTERPRETER_REQUIRED, new BooleanType(false)));
patient.addExtension(nhsCommExtension);
Identifier localIdentifier = new Identifier();
localIdentifier.setUse(IdentifierUse.USUAL);
localIdentifier.setSystem(SystemURL.ID_LOCAL_PATIENT_IDENTIFIER);
localIdentifier.setValue("123456");
CodeableConcept liType = new CodeableConcept();
Coding liTypeCoding = new Coding();
liTypeCoding.setCode("EN");
liTypeCoding.setDisplay("Employer number");
liTypeCoding.setSystem(SystemURL.VS_IDENTIFIER_TYPE);
liType.addCoding(liTypeCoding);
localIdentifier.setType(liType);
localIdentifier.setAssigner(new Reference("Organization/1"));
patient.addIdentifier(localIdentifier);
Calendar calendar = Calendar.getInstance();
calendar.set(2017, 1, 1);
DateTimeDt endDate = new DateTimeDt(calendar.getTime());
calendar.set(2016, 1, 1);
DateTimeDt startDate = new DateTimeDt(calendar.getTime());
Period pastPeriod = new Period().setStart(calendar.getTime()).setEnd(calendar.getTime());
patient.addName().setFamily("AnotherOfficialFamilyName").addGiven("AnotherOfficialGivenName").setUse(NameUse.OFFICIAL).setPeriod(pastPeriod);
patient.addName().setFamily("AdditionalFamily").addGiven("AdditionalGiven").setUse(NameUse.TEMP);
patient.addTelecom(staticElHelper.getValidTelecom());
patient.addAddress(staticElHelper.getValidAddress());
return patient;
}
use of org.hl7.fhir.r4.model.Period in project gpconnect-demonstrator by nhsconnect.
the class ScheduleResourceProvider method scheduleDetailToScheduleResourceConverter.
private Schedule scheduleDetailToScheduleResourceConverter(ScheduleDetail scheduleDetail) {
Schedule schedule = new Schedule();
String resourceId = String.valueOf(scheduleDetail.getId());
String versionId = String.valueOf(scheduleDetail.getLastUpdated().getTime());
String resourceType = schedule.getResourceType().toString();
IdType id = new IdType(resourceType, resourceId, versionId);
schedule.setId(id);
schedule.getMeta().setVersionId(versionId);
schedule.getMeta().setLastUpdated(scheduleDetail.getLastUpdated());
if (scheduleDetail.getPractitionerId() != null) {
schedule.addActor(new Reference("Practitioner/" + scheduleDetail.getPractitionerId()));
}
if (scheduleDetail.getPractitionerRoleCode() != null) {
Coding roleCoding = new Coding(SystemURL.VS_GPC_PRACTITIONER_ROLE, scheduleDetail.getPractitionerRoleCode(), scheduleDetail.getPractitionerRoleDisplay());
Extension practitionerRoleExtension = new Extension(SystemURL.SD_EXTENSION_GPC_PRACTITIONER_ROLE, new CodeableConcept().addCoding(roleCoding));
schedule.addExtension(practitionerRoleExtension);
}
// # 194
// Identifier identifier = new Identifier();
// identifier.setSystem(SystemURL.ID_GPC_SCHEDULE_IDENTIFIER);
// identifier.setValue(scheduleDetail.getIdentifier());
// schedule.addIdentifier(identifier);
Coding coding = new Coding().setSystem(SystemURL.HL7_VS_C80_PRACTICE_CODES).setCode(scheduleDetail.getTypeCode()).setDisplay(scheduleDetail.getTypeDescription());
CodeableConcept codableConcept = new CodeableConcept().addCoding(coding);
codableConcept.setText(scheduleDetail.getTypeDescription());
schedule.addActor(new Reference("Location/" + scheduleDetail.getLocationId()));
Period period = new Period();
period.setStart(scheduleDetail.getStartDateTime());
period.setEnd(scheduleDetail.getEndDateTime());
schedule.setPlanningHorizon(period);
// 1.2.7 remove comment
// schedule.setComment(scheduleDetail.getComment());
// 1.2.7 add schedule type description as service category
schedule.setServiceCategory(new CodeableConcept().setText(scheduleDetail.getTypeDescription()));
return schedule;
}
use of org.hl7.fhir.r4.model.Period in project gpconnect-demonstrator by nhsconnect.
the class PatientResourceProvider method StructuredRecordOperation.
@Operation(name = GET_STRUCTURED_RECORD_OPERATION_NAME)
public Bundle StructuredRecordOperation(@ResourceParam Parameters params) throws FHIRException {
Bundle structuredBundle = new Bundle();
Boolean getAllergies = false;
Boolean includeResolved = false;
Boolean getMedications = false;
Boolean includePrescriptionIssues = false;
Period medicationPeriod = null;
String NHS = getNhsNumber(params);
PatientDetails patientDetails = patientSearch.findPatient(NHS);
// see https://nhsconnect.github.io/gpconnect/accessrecord_structured_development_retrieve_patient_record.html#error-handling
if (patientDetails == null || patientDetails.isSensitive() || patientDetails.isDeceased() || !patientDetails.isActive()) {
throw OperationOutcomeFactory.buildOperationOutcomeException(new ResourceNotFoundException("No patient details found for patient ID: " + NHS), SystemCode.PATIENT_NOT_FOUND, IssueType.NOTFOUND);
}
if (NHS.equals(patientNoconsent)) {
throw OperationOutcomeFactory.buildOperationOutcomeException(new ForbiddenOperationException("No patient consent to share for patient ID: " + NHS), SystemCode.NO_PATIENT_CONSENT, IssueType.FORBIDDEN);
}
operationOutcome = null;
for (ParametersParameterComponent param : params.getParameter()) {
if (validateParametersName(param.getName())) {
if (param.getName().equals(SystemConstants.INCLUDE_ALLERGIES)) {
getAllergies = true;
if (param.getPart().isEmpty()) {
// addWarningIssue(param, IssueType.REQUIRED, "Miss parameter part : " + SystemConstants.INCLUDE_RESOLVED_ALLERGIES);
throw OperationOutcomeFactory.buildOperationOutcomeException(new UnprocessableEntityException("Miss parameter : " + SystemConstants.INCLUDE_RESOLVED_ALLERGIES), SystemCode.INVALID_PARAMETER, IssueType.REQUIRED);
}
boolean includeResolvedParameterPartPresent = false;
for (ParametersParameterComponent paramPart : param.getPart()) {
if (paramPart.getName().equals(SystemConstants.INCLUDE_RESOLVED_ALLERGIES)) {
if (paramPart.getValue() instanceof BooleanType) {
includeResolved = Boolean.valueOf(paramPart.getValue().primitiveValue());
includeResolvedParameterPartPresent = true;
} else {
throw OperationOutcomeFactory.buildOperationOutcomeException(new UnprocessableEntityException("Miss parameter : " + SystemConstants.INCLUDE_RESOLVED_ALLERGIES), SystemCode.INVALID_PARAMETER, IssueType.REQUIRED);
}
} else {
addWarningIssue(param, paramPart, IssueType.NOTSUPPORTED);
// throw OperationOutcomeFactory.buildOperationOutcomeException(
// new UnprocessableEntityException("Incorrect parameter passed : " + paramPart.getName()),
// SystemCode.INVALID_PARAMETER, IssueType.INVALID);
}
}
if (!includeResolvedParameterPartPresent) {
throw OperationOutcomeFactory.buildOperationOutcomeException(new UnprocessableEntityException("Miss parameter : " + SystemConstants.INCLUDE_RESOLVED_ALLERGIES), SystemCode.INVALID_PARAMETER, IssueType.REQUIRED);
}
}
if (param.getName().equals(SystemConstants.INCLUDE_MEDICATION)) {
getMedications = true;
boolean isIncludedPrescriptionIssuesExist = false;
for (ParametersParameterComponent paramPart : param.getPart()) {
if (paramPart.getName().equals(SystemConstants.INCLUDE_PRESCRIPTION_ISSUES)) {
if (paramPart.getValue() instanceof BooleanType) {
includePrescriptionIssues = Boolean.valueOf(paramPart.getValue().primitiveValue());
isIncludedPrescriptionIssuesExist = true;
}
} else if (paramPart.getName().equals(SystemConstants.MEDICATION_SEARCH_FROM_DATE) && paramPart.getValue() instanceof DateType) {
DateType startDateDt = (DateType) paramPart.getValue();
medicationPeriod = new Period();
medicationPeriod.setStart(startDateDt.getValue());
medicationPeriod.setEnd(null);
String startDate = startDateDt.asStringValue();
if (!validateStartDateParamAndEndDateParam(startDate, null)) {
// addWarningIssue(param, paramPart, IssueType.INVALID, "Invalid date used");
}
} else {
addWarningIssue(param, paramPart, IssueType.NOTSUPPORTED);
// throw OperationOutcomeFactory.buildOperationOutcomeException(
// new UnprocessableEntityException("Incorrect parameter passed : " + paramPart.getName()),
// SystemCode.INVALID_PARAMETER, IssueType.INVALID);
}
}
if (!isIncludedPrescriptionIssuesExist) {
// # 1.2.6 now defaults to true if not provided
includePrescriptionIssues = true;
}
}
} else {
// invalid parameter
addWarningIssue(param, IssueType.NOTSUPPORTED);
}
}
// for parameter
// Add Patient
Patient patient = patientDetailsToPatientResourceConverter(patientDetails);
if (patient.getIdentifierFirstRep().getValue().equals(NHS)) {
structuredBundle.addEntry().setResource(patient);
}
// Organization from patient
Set<String> orgIds = new HashSet<>();
orgIds.add(patientDetails.getManagingOrganization());
// Practitioner from patient
Set<String> practitionerIds = new HashSet<>();
List<Reference> practitionerReferenceList = patient.getGeneralPractitioner();
practitionerReferenceList.forEach(practitionerReference -> {
String[] pracRef = practitionerReference.getReference().split("/");
if (pracRef.length > 1) {
practitionerIds.add(pracRef[1]);
}
});
if (getAllergies) {
structuredBundle = structuredAllergyIntoleranceBuilder.buildStructuredAllergyIntolerence(NHS, practitionerIds, structuredBundle, includeResolved);
}
if (getMedications) {
structuredBundle = populateMedicationBundle.addMedicationBundleEntries(structuredBundle, patientDetails, includePrescriptionIssues, medicationPeriod, practitionerIds, orgIds);
}
// Add all practitioners and practitioner roles
for (String practitionerId : practitionerIds) {
Practitioner pracResource = practitionerResourceProvider.getPractitionerById(new IdType(practitionerId));
structuredBundle.addEntry().setResource(pracResource);
List<PractitionerRole> practitionerRoleList = practitionerRoleResourceProvider.getPractitionerRoleByPracticionerId(new IdType(practitionerId));
for (PractitionerRole role : practitionerRoleList) {
String[] split = role.getOrganization().getReference().split("/");
orgIds.add(split[1]);
structuredBundle.addEntry().setResource(role);
}
}
// Add all organizations
for (String orgId : orgIds) {
OrganizationDetails organizationDetails = organizationSearch.findOrganizationDetails(new Long(orgId));
Organization organization = organizationResourceProvider.convertOrganizationDetailsToOrganization(organizationDetails);
structuredBundle.addEntry().setResource(organization);
}
structuredBundle.setType(BundleType.COLLECTION);
structuredBundle.getMeta().addProfile(SystemURL.SD_GPC_STRUCTURED_BUNDLE);
if (operationOutcome != null) {
structuredBundle.addEntry().setResource(operationOutcome);
} else {
removeDuplicateResources(structuredBundle);
}
return structuredBundle;
}
use of org.hl7.fhir.r4.model.Period 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.Period in project beneficiary-fhir-data by CMSgov.
the class CoverageTransformer method transformPartA.
/**
* @param metricRegistry the {@link MetricRegistry} to use
* @param beneficiary the {@link Beneficiary} to generate a {@link MedicareSegment#PART_A} {@link
* Coverage} resource for
* @return {@link MedicareSegment#PART_A} {@link Coverage} resource for the specified {@link
* Beneficiary}
*/
private static Coverage transformPartA(MetricRegistry metricRegistry, Beneficiary beneficiary) {
Timer.Context timer = metricRegistry.timer(MetricRegistry.name(CoverageTransformer.class.getSimpleName(), "transform", "part_a")).time();
Objects.requireNonNull(beneficiary);
Coverage coverage = new Coverage();
coverage.setId(TransformerUtils.buildCoverageId(MedicareSegment.PART_A, beneficiary));
if (beneficiary.getPartATerminationCode().isPresent() && beneficiary.getPartATerminationCode().get().equals('0'))
coverage.setStatus(CoverageStatus.ACTIVE);
else
coverage.setStatus(CoverageStatus.CANCELLED);
if (beneficiary.getMedicareCoverageStartDate().isPresent()) {
TransformerUtils.setPeriodStart(coverage.getPeriod(), beneficiary.getMedicareCoverageStartDate().get());
}
// deh start
coverage.addContract().setId("ptc-contract1");
Contract newContract = new Contract();
LocalDate localDate = LocalDate.now();
newContract.setIdentifier(new Identifier().setSystem("part C System").setValue("contract 5555"));
newContract.setApplies((new Period().setStart((TransformerUtils.convertToDate(localDate)), TemporalPrecisionEnum.DAY)));
coverage.addContained(newContract);
coverage.addContract(TransformerUtils.referenceCoverage("contract1 reference", MedicareSegment.PART_A));
coverage.getGrouping().setSubGroup(TransformerConstants.COVERAGE_PLAN).setSubPlan(TransformerConstants.COVERAGE_PLAN_PART_A);
coverage.setType(TransformerUtils.createCodeableConcept(TransformerConstants.COVERAGE_PLAN, TransformerConstants.COVERAGE_PLAN_PART_A));
coverage.setBeneficiary(TransformerUtils.referencePatient(beneficiary));
if (beneficiary.getMedicareEnrollmentStatusCode().isPresent()) {
coverage.addExtension(TransformerUtils.createExtensionCoding(coverage, CcwCodebookVariable.MS_CD, beneficiary.getMedicareEnrollmentStatusCode()));
}
if (beneficiary.getEntitlementCodeOriginal().isPresent()) {
coverage.addExtension(TransformerUtils.createExtensionCoding(coverage, CcwCodebookVariable.OREC, beneficiary.getEntitlementCodeOriginal()));
}
if (beneficiary.getEntitlementCodeCurrent().isPresent()) {
coverage.addExtension(TransformerUtils.createExtensionCoding(coverage, CcwCodebookVariable.CREC, beneficiary.getEntitlementCodeCurrent()));
}
if (beneficiary.getEndStageRenalDiseaseCode().isPresent()) {
coverage.addExtension(TransformerUtils.createExtensionCoding(coverage, CcwCodebookVariable.ESRD_IND, beneficiary.getEndStageRenalDiseaseCode()));
}
if (beneficiary.getPartATerminationCode().isPresent()) {
coverage.addExtension(TransformerUtils.createExtensionCoding(coverage, CcwCodebookVariable.A_TRM_CD, beneficiary.getPartATerminationCode()));
}
// The reference year of the enrollment data
if (beneficiary.getBeneEnrollmentReferenceYear().isPresent()) {
coverage.addExtension(TransformerUtils.createExtensionDate(CcwCodebookVariable.RFRNC_YR, beneficiary.getBeneEnrollmentReferenceYear()));
}
// Monthly Medicare-Medicaid dual eligibility codes
if (beneficiary.getMedicaidDualEligibilityJanCode().isPresent()) {
coverage.addExtension(TransformerUtils.createExtensionCoding(coverage, CcwCodebookVariable.DUAL_01, beneficiary.getMedicaidDualEligibilityJanCode()));
}
if (beneficiary.getMedicaidDualEligibilityFebCode().isPresent()) {
coverage.addExtension(TransformerUtils.createExtensionCoding(coverage, CcwCodebookVariable.DUAL_02, beneficiary.getMedicaidDualEligibilityFebCode()));
}
if (beneficiary.getMedicaidDualEligibilityMarCode().isPresent()) {
coverage.addExtension(TransformerUtils.createExtensionCoding(coverage, CcwCodebookVariable.DUAL_03, beneficiary.getMedicaidDualEligibilityMarCode()));
}
if (beneficiary.getMedicaidDualEligibilityAprCode().isPresent()) {
coverage.addExtension(TransformerUtils.createExtensionCoding(coverage, CcwCodebookVariable.DUAL_04, beneficiary.getMedicaidDualEligibilityAprCode()));
}
if (beneficiary.getMedicaidDualEligibilityMayCode().isPresent()) {
coverage.addExtension(TransformerUtils.createExtensionCoding(coverage, CcwCodebookVariable.DUAL_05, beneficiary.getMedicaidDualEligibilityMayCode()));
}
if (beneficiary.getMedicaidDualEligibilityJunCode().isPresent()) {
coverage.addExtension(TransformerUtils.createExtensionCoding(coverage, CcwCodebookVariable.DUAL_06, beneficiary.getMedicaidDualEligibilityJunCode()));
}
if (beneficiary.getMedicaidDualEligibilityJulCode().isPresent()) {
coverage.addExtension(TransformerUtils.createExtensionCoding(coverage, CcwCodebookVariable.DUAL_07, beneficiary.getMedicaidDualEligibilityJulCode()));
}
if (beneficiary.getMedicaidDualEligibilityAugCode().isPresent()) {
coverage.addExtension(TransformerUtils.createExtensionCoding(coverage, CcwCodebookVariable.DUAL_08, beneficiary.getMedicaidDualEligibilityAugCode()));
}
if (beneficiary.getMedicaidDualEligibilitySeptCode().isPresent()) {
coverage.addExtension(TransformerUtils.createExtensionCoding(coverage, CcwCodebookVariable.DUAL_09, beneficiary.getMedicaidDualEligibilitySeptCode()));
}
if (beneficiary.getMedicaidDualEligibilityOctCode().isPresent()) {
coverage.addExtension(TransformerUtils.createExtensionCoding(coverage, CcwCodebookVariable.DUAL_10, beneficiary.getMedicaidDualEligibilityOctCode()));
}
if (beneficiary.getMedicaidDualEligibilityNovCode().isPresent()) {
coverage.addExtension(TransformerUtils.createExtensionCoding(coverage, CcwCodebookVariable.DUAL_11, beneficiary.getMedicaidDualEligibilityNovCode()));
}
if (beneficiary.getMedicaidDualEligibilityDecCode().isPresent()) {
coverage.addExtension(TransformerUtils.createExtensionCoding(coverage, CcwCodebookVariable.DUAL_12, beneficiary.getMedicaidDualEligibilityDecCode()));
}
transformEntitlementBuyInIndicators(coverage, beneficiary);
TransformerUtils.setLastUpdated(coverage, beneficiary.getLastUpdated());
timer.stop();
return coverage;
}
Aggregations