Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pointer on resources' properties? #9

Open
benji-bou opened this issue Feb 23, 2021 · 0 comments
Open

Pointer on resources' properties? #9

benji-bou opened this issue Feb 23, 2021 · 0 comments

Comments

@benji-bou
Copy link

Hello,

Thanks for this nice package.
I was wondering why is there pointer on each generated resources' properties?

My objective here is to read fhir data from a bigquery. But the type mapping is not possible because of properties generated with pointer
I know this is not the purpose of this package to let us map fhir data from bigquery.

For example :

func (r Request) EncounteredPatients(practitionerId string) ([]fhir.Patient, error) {
	it, err := r.Raw(fmt.Sprintf(`SELECT * 
		FROM <gcp_project_id>.<bigquery_datasets>.Patient patient 
		INNER  JOIN (
			SELECT DISTINCT subject.patientId  
			FROM bios-innov.metamedical.Encounter as encounter, UNNEST(encounter.participant) as participant  
			WHERE participant.individual.practitionerId = '%v') encounters  
		ON patient.id = encounters.PatientId`, practitionerId))
	if err != nil {
		return []fhir.Patient{}, fmt.Errorf("EncounteredPatients failed for %v: %w", practitionerId, err)
	}
	patients := make([]fhir.Patient, 0, 0)
	for {
		var patient fhir.Patient

		err := it.Next(&patient)
		if err == iterator.Done {
			break
		}
		if err != nil {
			return patients, fmt.Errorf("Failed to read result : %w", err) // TODO: Handle error.
		}
		// fmt.Println(row)
		patients = append(patients, patient)
	}
	return patients, nil
}

Will lead to an error bigquery: schema field active of type BOOLEAN is not assignable to struct field Active of type *bool

But doing this

func (r Request) EncounteredPatients(practitionerId string) ([]fhir.Patient, error) {
	it, err := r.Raw(fmt.Sprintf(`SELECT * 
		FROM <gcp_project_id>.<bigquery_datasets>.Patient patient 
		INNER  JOIN (
			SELECT DISTINCT subject.patientId  
			FROM bios-innov.metamedical.Encounter as encounter, UNNEST(encounter.participant) as participant  
			WHERE participant.individual.practitionerId = '%v') encounters  
		ON patient.id = encounters.PatientId`, practitionerId))
	if err != nil {
		return []fhir.Patient{}, fmt.Errorf("EncounteredPatients failed for %v: %w", practitionerId, err)
	}
	patients := make([]fhir.Patient, 0, 0)
	for {
		var patient fhir.Patient
		var row map[string]bigquery.Value
		err := it.Next(&row)
		if err == iterator.Done {
			break
		}
		if err != nil {
			return patients, fmt.Errorf("Failed to read result : %w", err) // TODO: Handle error.
		}
		jsonRaw, errJson := json.Marshal(row)
		if errJson != nil {
			return patients, fmt.Errorf("Failed to marshal result : %w", errJson)
		}
		errReDecode := json.Unmarshal(jsonRaw, &patient)
		if errReDecode != nil {
			return patients, fmt.Errorf("Failed to Unmarshal result : %w", errReDecode)
		}
		// fmt.Println(row)
		patients = append(patients, patient)
	}
	return patients, nil
}

Will succeed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant