use of org.hl7.fhir.r4.model.codesystems.ClaimCareteamrole in project beneficiary-fhir-data by CMSgov.
the class TransformerUtilsV2 method addCareTeamPractitioner.
/**
* Ensures that the specified {@link ExplanationOfBenefit} has the specified {@link
* CareTeamComponent}, and links the specified {@link ItemComponent} to that {@link
* CareTeamComponent} (via {@link ItemComponent#addCareTeamLinkId(int)}).
*
* @param eob the {@link ExplanationOfBenefit} that the {@link CareTeamComponent} should be part
* of
* @param eobItem the {@link ItemComponent} that should be linked to the {@link CareTeamComponent}
* @param practitionerIdSystem the {@link Identifier#getSystem()} of the practitioner to reference
* in {@link CareTeamComponent#getProvider()}
* @param practitionerIdValue the {@link Identifier#getValue()} of the practitioner to reference
* in {@link CareTeamComponent#getProvider()}
* @param careTeamRole the {@link ClaimCareteamrole} to use for the {@link
* CareTeamComponent#getRole()}
* @return the {@link CareTeamComponent} that was created/linked
*/
private static CareTeamComponent addCareTeamPractitioner(ExplanationOfBenefit eob, ItemComponent eobItem, C4BBPractitionerIdentifierType type, String practitionerIdValue, String roleSystem, String roleCode, String roleDisplay) {
// Try to find a matching pre-existing entry.
CareTeamComponent careTeamEntry = eob.getCareTeam().stream().filter(ctc -> ctc.getProvider().hasIdentifier()).filter(ctc -> type.getSystem().equals(ctc.getProvider().getIdentifier().getSystem()) && practitionerIdValue.equals(ctc.getProvider().getIdentifier().getValue())).filter(ctc -> ctc.hasRole()).filter(ctc -> roleCode.equals(ctc.getRole().getCodingFirstRep().getCode()) && roleSystem.equals(ctc.getRole().getCodingFirstRep().getSystem())).findAny().orElse(null);
// <ID Value> => ExplanationOfBenefit.careTeam.provider
if (careTeamEntry == null) {
careTeamEntry = eob.addCareTeam();
// addItem adds and returns, so we want size() not size() + 1 here
careTeamEntry.setSequence(eob.getCareTeam().size());
careTeamEntry.setProvider(createPractitionerIdentifierReference(type, practitionerIdValue));
CodeableConcept careTeamRoleConcept = createCodeableConcept(roleSystem, roleCode);
careTeamRoleConcept.getCodingFirstRep().setDisplay(roleDisplay);
careTeamEntry.setRole(careTeamRoleConcept);
}
// care team entry is at eob level so no need to create item link id
if (eobItem == null) {
return careTeamEntry;
}
// ExplanationOfBenefit.careTeam.sequence => ExplanationOfBenefit.item.careTeamSequence
if (!eobItem.getCareTeamSequence().contains(new PositiveIntType(careTeamEntry.getSequence()))) {
eobItem.addCareTeamSequence(careTeamEntry.getSequence());
}
return careTeamEntry;
}
Aggregations