use of org.hl7.fhir.r5.model.Coding in project gpconnect-demonstrator by nhsconnect.
the class AppointmentValidation method validateParticipantType.
/**
* This method is effectively disabled since we dont check against value sets
* This was experimental code that never worked correctly.
* @param participantType
* @return
*/
public Boolean validateParticipantType(CodeableConcept participantType) {
Boolean hasCode = !participantType.isEmpty();
Coding code = participantType.getCodingFirstRep();
Boolean isValid = !hasCode;
if (hasCode) {
// isValid = valueSetValidator.validateCode(code);
isValid = true;
if (!isValid) {
throwUnprocessableEntity422_InvalidResourceException(MessageFormat.format("Invalid Participant Type Code. Code: {0} [Display: {1}, System:{2}]", code.getCode(), code.getDisplay(), code.getSystem()));
}
}
return isValid;
}
use of org.hl7.fhir.r5.model.Coding in project loinc2hpo by monarch-initiative.
the class FhirObservationAnalyzer method getHPO4ObservationOutcome.
/**
* A core function that tries three ways to return a LabTestResultInHPO object:
* first, it tries to return the result through the interpretation field. If it fails,
* second, it tries to return the result through the quantative value, or
* third, it tries to return the retult through the coded value (ordinal Loinc)
* @param loinc2HPOannotationMap
* @param loincIds
* @return
*/
public static LabTestResultInHPO getHPO4ObservationOutcome(HashSet<LoincId> loincIds, Map<LoincId, UniversalLoinc2HPOAnnotation> loinc2HPOannotationMap) {
// first make sure the observation has a valid loinc code; otherwise, we cannot handle it
if (!hasValidLoincCode(loincIds)) {
// TODO: consider handling this as a future project
return null;
}
LoincId loincId = null;
try {
loincId = getLoincIdOfObservation();
} catch (MalformedLoincCodeException e) {
logger.error("malformed loinc code; should never happen");
return null;
} catch (LoincCodeNotFoundException e) {
logger.error("No loinc code was found in the observation; should never happen");
return null;
} catch (UnsupportedCodingSystemException e) {
logger.error("coding system not recognized");
return null;
}
if (!loinc2HPOannotationMap.containsKey(loincId)) {
return null;
}
if (observation.hasInterpretation()) {
logger.debug("enter analyzer using the interpretation field");
try {
// return getHPOFromInterpretation(observation.getInterpretation(), loinc2HPOannotationMap);
HpoTermId4LoincTest hpoterm = new ObservationAnalysisFromInterpretation(getLoincIdOfObservation(), observation.getInterpretation(), loinc2HPOannotationMap).getHPOforObservation();
return new BasicLabTestResultInHPO(hpoterm, null);
} catch (UnrecognizedCodeException e) {
// this means the interpretation code is not recognized
logger.info("The interpretation codes for this loinc code is not annotated; system will try using raw values");
} catch (MalformedLoincCodeException e1) {
// not going to happen
logger.error("malformed loinc code.");
return null;
} catch (LoincCodeNotFoundException e2) {
// not going to happen
logger.error("no loinc code is found in the observation");
return null;
} catch (UnsupportedCodingSystemException e3) {
// not going to happen
logger.error("The interpretation coding system cannot be recognized.");
return null;
} catch (AmbiguousResultsFoundException e) {
logger.error("The observation has conflicting interpretation codes.");
return null;
} catch (AnnotationNotFoundException e) {
logger.error("There is no annotation for the loinc code used in the observation");
}
}
// Qn will have a value field
if (observation.hasValueQuantity()) {
try {
HpoTermId4LoincTest hpoterm = new ObservationAnalysisFromQnValue(loincId, observation, loinc2HPOannotationMap).getHPOforObservation();
if (hpoterm != null)
return new BasicLabTestResultInHPO(hpoterm, null);
} catch (ReferenceNotFoundException e) {
// if there is no reference
logger.error("The observation has no reference field.");
// TODO: make a list of our own references
} catch (AmbiguousReferenceException e) {
logger.info("There are two reference ranges or more");
} catch (UnrecognizedCodeException e) {
logger.error("uncognized coding system");
}
}
// Ord will have a ValueCodeableConcept field
if (observation.hasValueCodeableConcept()) {
try {
HpoTermId4LoincTest hpoterm = null;
hpoterm = new ObservationAnalysisFromCodedValues(loincId, observation.getValueCodeableConcept(), loinc2HPOannotationMap).getHPOforObservation();
if (hpoterm != null)
return new BasicLabTestResultInHPO(hpoterm, null);
} catch (AmbiguousResultsFoundException e) {
logger.error("multiple results are found");
} catch (UnrecognizedCodeException e) {
logger.error("unrecognized codes");
} catch (FHIRException e) {
// not going to happen
logger.error("Could not get HPO term from coded value");
} catch (AnnotationNotFoundException e) {
logger.error("There is no annotation for the loinc code used in the observation");
}
}
// if all the above fails, we cannot do nothing
logger.error("Could not return HPO for observation: " + observation.getId());
return null;
}
use of org.hl7.fhir.r5.model.Coding in project gpconnect-demonstrator by nhsconnect.
the class LocationResourceProvider method locationDetailsToLocation.
/**
* convert locationDetails to fhir resource
* @param locationDetails
* @return Location resource
*/
private Location locationDetailsToLocation(LocationDetails locationDetails) {
Location location = new Location();
String resourceId = String.valueOf(locationDetails.getId());
String versionId = String.valueOf(locationDetails.getLastUpdated().getTime());
String resourceType = location.getResourceType().toString();
IdType id = new IdType(resourceType, resourceId, versionId);
location.setId(id);
location.getMeta().setVersionId(versionId);
location.getMeta().setLastUpdated(locationDetails.getLastUpdated());
location.getMeta().addProfile(SystemURL.SD_GPC_LOCATION);
location.setName(locationDetails.getName());
// #207 no site code
// location.setIdentifier(Collections.singletonList(new Identifier().setSystem(SystemURL.ID_ODS_SITE_CODE).setValue(locationDetails.getSiteOdsCode())));
// #246 remove type element
// Coding locationCommTypeCode = new Coding();
// locationCommTypeCode.setCode("COMM");
// locationCommTypeCode.setSystem(SystemURL.VS_CC_SER_DEL_LOCROLETYPE);
// locationCommTypeCode.setDisplay("Community Location");
//
// Coding locationGachTypeCode = new Coding();
// locationGachTypeCode.setCode("GACH");
// locationGachTypeCode.setSystem(SystemURL.VS_CC_SER_DEL_LOCROLETYPE);
// locationGachTypeCode.setDisplay("Hospitals; General Acute Care Hospital");
//
// @SuppressWarnings("deprecation")
// CodeableConcept locationType = new CodeableConcept();
// locationType.addCoding(locationCommTypeCode);
// locationType.addCoding(locationGachTypeCode);
// location.setType(locationType);
Organization orgz = FindOrganization(locationDetails.getOrgOdsCode());
if (orgz != null) {
Reference mngOrg = new Reference();
mngOrg.setReference(orgz.getId());
// #246 remove display element
// mngOrg.setDisplay(orgz.getName());
location.setManagingOrganization(mngOrg);
}
EnumSet<LocationStatus> statusList = EnumSet.allOf(LocationStatus.class);
LocationStatus locationStatus = null;
String status = locationDetails.getStatus();
if (status != null) {
for (LocationStatus statusItem : statusList) {
if (statusItem.toCode().equalsIgnoreCase(status)) {
locationStatus = statusItem;
break;
}
}
}
location.setAddress(createAddress(locationDetails));
location.setStatus(locationStatus);
return location;
}
use of org.hl7.fhir.r5.model.Coding 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.r5.model.Coding in project gpconnect-demonstrator by nhsconnect.
the class PatientResourceProvider method addWarningIssue.
/**
* see
* https://gpconnect-1-2-4.netlify.com/accessrecord_structured_development_version_compatibility.html
* add an issue to the OperationOutcome to be returned in a successful
* response bundle this is for forward compatibility as specified in 1.2.4
*
* @param param
* @param paramPart
* @param issueType
* @param details lower level details to be added to the text element
*/
private void addWarningIssue(ParametersParameterComponent param, ParametersParameterComponent paramPart, IssueType issueType, String details) {
if (operationOutcome == null) {
createOperationOutcome();
}
OperationOutcomeIssueComponent issue = new OperationOutcomeIssueComponent();
issue.setSeverity(OperationOutcome.IssueSeverity.WARNING);
CodeableConcept codeableConcept = new CodeableConcept();
Coding coding = new Coding();
coding.setSystem(VS_GPC_ERROR_WARNING_CODE);
switch(issueType) {
case NOTSUPPORTED:
issue.setCode(issueType);
coding.setCode(SystemCode.NOT_IMPLEMENTED);
coding.setDisplay("Not implemented");
break;
case REQUIRED:
issue.setCode(issueType);
coding.setCode(SystemCode.PARAMETER_NOT_FOUND);
coding.setDisplay("Parameter not found");
break;
case INVALID:
issue.setCode(issueType);
coding.setCode(SystemCode.INVALID_PARAMETER);
coding.setDisplay("Invalid Parameter");
break;
}
codeableConcept.addCoding(coding);
issue.setDetails(codeableConcept);
String locus = paramPart != null ? "." + paramPart.getName() : "";
issue.setDiagnostics(param.getName() + locus);
if (details == null) {
// mod to remove more informative text which was off spec
codeableConcept.setText(param.getName() + locus + " is an unrecognised parameter");
} else {
codeableConcept.setText(details);
}
operationOutcome.addIssue(issue);
}
Aggregations